Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure tx forwarder is set #8664

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/rpc/rpc-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 11 additions & 2 deletions crates/rpc/rpc/src/eth/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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>>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldnt this be an arc<rwlock<_>> instead? no need to check if ethapi has been init already

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this type is already behind an arc

}
3 changes: 2 additions & 1 deletion crates/rpc/rpc/src/eth/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
}
Expand Down
Loading