fix: ensure tx forwarder is set (#8664)

This commit is contained in:
Matthias Seitz
2024-06-07 12:09:41 +02:00
committed by GitHub
parent e0c22ace34
commit 04d3191ca8
3 changed files with 17 additions and 3 deletions

View File

@ -1016,6 +1016,10 @@ impl<Provider, Pool, Network, Tasks, Events, EvmConfig>
&mut self,
forwarder: Arc<dyn RawTransactionForwarder>,
) {
if let Some(eth) = self.eth.as_ref() {
// in case the eth api has been created before the forwarder was set: <https://github.com/paradigmxyz/reth/issues/8661>
eth.api.set_eth_raw_transaction_forwarder(forwarder.clone());
}
self.eth_raw_transaction_forwarder = Some(forwarder);
}

View File

@ -88,6 +88,15 @@ pub struct EthApi<Provider, Pool, Network, EvmConfig> {
inner: Arc<EthApiInner<Provider, Pool, Network, EvmConfig>>,
}
impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig> {
/// Sets a forwarder for `eth_sendRawTransaction`
///
/// Note: this might be removed in the future in favor of a more generic approach.
pub fn set_eth_raw_transaction_forwarder(&self, forwarder: Arc<dyn RawTransactionForwarder>) {
self.inner.raw_transaction_forwarder.write().replace(forwarder);
}
}
impl<Provider, Pool, Network, EvmConfig> EthApi<Provider, Pool, Network, EvmConfig>
where
Provider: BlockReaderIdExt + ChainSpecProvider,
@ -158,7 +167,7 @@ where
blocking_task_pool,
fee_history_cache,
evm_config,
raw_transaction_forwarder,
raw_transaction_forwarder: parking_lot::RwLock::new(raw_transaction_forwarder),
};
Self { inner: Arc::new(inner) }
@ -490,5 +499,5 @@ struct EthApiInner<Provider, Pool, Network, EvmConfig> {
/// The type that defines how to configure the EVM
evm_config: EvmConfig,
/// Allows forwarding received raw transactions
raw_transaction_forwarder: Option<Arc<dyn RawTransactionForwarder>>,
raw_transaction_forwarder: parking_lot::RwLock<Option<Arc<dyn RawTransactionForwarder>>>,
}

View File

@ -849,7 +849,8 @@ where
async fn send_raw_transaction(&self, tx: Bytes) -> EthResult<B256> {
// On optimism, transactions are forwarded directly to the sequencer to be included in
// blocks that it builds.
if let Some(client) = self.inner.raw_transaction_forwarder.as_ref() {
let maybe_forwarder = self.inner.raw_transaction_forwarder.read().clone();
if let Some(client) = maybe_forwarder {
tracing::debug!( target: "rpc::eth", "forwarding raw transaction to");
client.forward_raw_transaction(&tx).await?;
}