diff --git a/crates/node/src/geth.rs b/crates/node/src/geth.rs index 57cb2db..52a8aed 100644 --- a/crates/node/src/geth.rs +++ b/crates/node/src/geth.rs @@ -14,9 +14,13 @@ use std::{ }; use alloy::{ - network::EthereumWallet, + network::{Ethereum, EthereumWallet}, primitives::Address, - providers::{Provider, ProviderBuilder, ext::DebugApi}, + providers::{ + Provider, ProviderBuilder, + ext::DebugApi, + fillers::{FillProvider, TxFiller}, + }, rpc::types::{ TransactionReceipt, TransactionRequest, trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, @@ -191,6 +195,24 @@ impl Instance { fn geth_stderr_log_file_path(&self) -> PathBuf { self.logs_directory.join(Self::GETH_STDERR_LOG_FILE_NAME) } + + fn provider( + &self, + ) -> impl Future< + Output = anyhow::Result< + FillProvider, impl Provider, Ethereum>, + >, + > + 'static { + let connection_string = self.connection_string(); + let wallet = self.wallet.clone(); + Box::pin(async move { + ProviderBuilder::new() + .wallet(wallet) + .connect(&connection_string) + .await + .map_err(Into::into) + }) + } } impl EthereumNode for Instance { @@ -199,17 +221,12 @@ impl EthereumNode for Instance { &self, transaction: TransactionRequest, ) -> anyhow::Result { - let connection_string = self.connection_string(); - let wallet = self.wallet.clone(); - + let provider = self.provider(); BlockingExecutor::execute(async move { let outer_span = tracing::debug_span!("Submitting transaction", ?transaction,); let _outer_guard = outer_span.enter(); - let provider = ProviderBuilder::new() - .wallet(wallet) - .connect(&connection_string) - .await?; + let provider = provider.await?; let pending_transaction = provider.send_transaction(transaction).await?; let transaction_hash = pending_transaction.tx_hash(); @@ -289,18 +306,15 @@ impl EthereumNode for Instance { &self, transaction: TransactionReceipt, ) -> anyhow::Result { - let connection_string = self.connection_string(); let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig { diff_mode: Some(true), disable_code: None, disable_storage: None, }); - let wallet = self.wallet.clone(); + let provider = self.provider(); BlockingExecutor::execute(async move { - Ok(ProviderBuilder::new() - .wallet(wallet) - .connect(&connection_string) + Ok(provider .await? .debug_trace_transaction(transaction.transaction_hash, trace_options) .await?) @@ -323,13 +337,9 @@ impl EthereumNode for Instance { #[tracing::instrument(skip_all, fields(geth_node_id = self.id))] fn fetch_add_nonce(&self, address: Address) -> anyhow::Result { - let connection_string = self.connection_string.clone(); - let wallet = self.wallet.clone(); - + let provider = self.provider(); let onchain_nonce = BlockingExecutor::execute::>(async move { - ProviderBuilder::new() - .wallet(wallet) - .connect(&connection_string) + provider .await? .get_transaction_count(address) .await diff --git a/crates/node/src/kitchensink.rs b/crates/node/src/kitchensink.rs index 768c1aa..b8586a9 100644 --- a/crates/node/src/kitchensink.rs +++ b/crates/node/src/kitchensink.rs @@ -13,9 +13,13 @@ use std::{ use alloy::{ hex, - network::EthereumWallet, + network::{Ethereum, EthereumWallet}, primitives::Address, - providers::{Provider, ProviderBuilder, ext::DebugApi}, + providers::{ + Provider, ProviderBuilder, + ext::DebugApi, + fillers::{FillProvider, TxFiller}, + }, rpc::types::{ TransactionReceipt, trace::geth::{DiffMode, GethDebugTracingOptions, PreStateConfig, PreStateFrame}, @@ -323,6 +327,24 @@ impl KitchensinkNode { fn proxy_stderr_log_file_path(&self) -> PathBuf { self.logs_directory.join(Self::PROXY_STDERR_LOG_FILE_NAME) } + + fn provider( + &self, + ) -> impl Future< + Output = anyhow::Result< + FillProvider, impl Provider, Ethereum>, + >, + > + 'static { + let connection_string = self.connection_string(); + let wallet = self.wallet.clone(); + Box::pin(async move { + ProviderBuilder::new() + .wallet(wallet) + .connect(&connection_string) + .await + .map_err(Into::into) + }) + } } impl EthereumNode for KitchensinkNode { @@ -331,16 +353,10 @@ impl EthereumNode for KitchensinkNode { &self, transaction: alloy::rpc::types::TransactionRequest, ) -> anyhow::Result { - let url = self.rpc_url.clone(); - let wallet = self.wallet.clone(); - - tracing::debug!("Submitting transaction: {transaction:#?}"); - - tracing::info!("Submitting tx to kitchensink"); + tracing::debug!(?transaction, "Submitting transaction"); + let provider = self.provider(); let receipt = BlockingExecutor::execute(async move { - Ok(ProviderBuilder::new() - .wallet(wallet) - .connect(&url) + Ok(provider .await? .send_transaction(transaction) .await? @@ -356,19 +372,15 @@ impl EthereumNode for KitchensinkNode { &self, transaction: TransactionReceipt, ) -> anyhow::Result { - let url = self.rpc_url.clone(); let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig { diff_mode: Some(true), disable_code: None, disable_storage: None, }); - - let wallet = self.wallet.clone(); + let provider = self.provider(); BlockingExecutor::execute(async move { - Ok(ProviderBuilder::new() - .wallet(wallet) - .connect(&url) + Ok(provider .await? .debug_trace_transaction(transaction.transaction_hash, trace_options) .await?) @@ -388,13 +400,9 @@ impl EthereumNode for KitchensinkNode { #[tracing::instrument(skip_all, fields(kitchensink_node_id = self.id))] fn fetch_add_nonce(&self, address: Address) -> anyhow::Result { - let url = self.rpc_url.clone(); - let wallet = self.wallet.clone(); - + let provider = self.provider(); let onchain_nonce = BlockingExecutor::execute::>(async move { - ProviderBuilder::new() - .wallet(wallet) - .connect(&url) + provider .await? .get_transaction_count(address) .await