diff --git a/bin/silius/src/cli/args.rs b/bin/silius/src/cli/args.rs index a50f85d5..192d606b 100644 --- a/bin/silius/src/cli/args.rs +++ b/bin/silius/src/cli/args.rs @@ -1,5 +1,5 @@ use crate::utils::{ - parse_address, parse_enr, parse_send_bundle_mode, parse_u256, parse_uopool_mode, + parse_address, parse_duration, parse_enr, parse_send_bundle_mode, parse_u256, parse_uopool_mode, }; use clap::{Parser, ValueEnum}; use discv5::Enr; @@ -19,6 +19,7 @@ use silius_primitives::{ use std::{ net::{IpAddr, Ipv4Addr}, path::PathBuf, + time::Duration, }; #[derive(ValueEnum, Debug, Clone)] @@ -124,6 +125,10 @@ pub struct BundlerAndUoPoolArgs { /// Entry point addresses. #[clap(long, value_delimiter=',', value_parser=parse_address)] pub entry_points: Vec
, + + /// Poll interval event filters and pending transactions in milliseconds. + #[clap(long, default_value = "500", value_parser= parse_duration)] + pub poll_interval: Duration, } /// RPC CLI args @@ -328,6 +333,32 @@ mod tests { ); } + #[test] + fn bundler_and_uopool_args() { + let args = vec![ + "bundleranduopoolargs", + "--eth-client-address", + "http://127.0.0.1:8545", + "--chain", + "holesky", + "--entry-points", + "0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990", + "--poll-interval", + "5000", + ]; + assert_eq!( + BundlerAndUoPoolArgs { + eth_client_address: String::from("http://127.0.0.1:8545"), + chain: Some(NamedChain::Holesky), + entry_points: vec![ + Address::from_str("0x690B9A9E9aa1C9dB991C7721a92d351Db4FaC990").unwrap() + ], + poll_interval: Duration::from_millis(5000), + }, + BundlerAndUoPoolArgs::try_parse_from(args).unwrap() + ); + } + #[test] fn rpc_args_when_http_and_ws_flag() { let args = vec![ diff --git a/bin/silius/src/cli/commands.rs b/bin/silius/src/cli/commands.rs index e0aaa6f2..55a9a590 100644 --- a/bin/silius/src/cli/commands.rs +++ b/bin/silius/src/cli/commands.rs @@ -30,7 +30,10 @@ impl NodeCommand { /// Execute the command pub async fn execute(self) -> eyre::Result<()> { if self.common.eth_client_address.clone().starts_with("http") { - let eth_client = Arc::new(create_http_provider(&self.common.eth_client_address).await?); + let eth_client = Arc::new( + create_http_provider(&self.common.eth_client_address, self.common.poll_interval) + .await?, + ); let block_streams = create_http_block_streams(eth_client.clone(), self.common.entry_points.len()).await; launch_bundler( @@ -81,7 +84,10 @@ impl BundlerCommand { /// Execute the command pub async fn execute(self) -> eyre::Result<()> { if self.common.eth_client_address.clone().starts_with("http") { - let eth_client = Arc::new(create_http_provider(&self.common.eth_client_address).await?); + let eth_client = Arc::new( + create_http_provider(&self.common.eth_client_address, self.common.poll_interval) + .await?, + ); launch_bundling( self.bundler, eth_client, @@ -122,7 +128,10 @@ impl UoPoolCommand { /// Execute the command pub async fn execute(self) -> eyre::Result<()> { if self.common.eth_client_address.clone().starts_with("http") { - let eth_client = Arc::new(create_http_provider(&self.common.eth_client_address).await?); + let eth_client = Arc::new( + create_http_provider(&self.common.eth_client_address, self.common.poll_interval) + .await?, + ); let block_streams = create_http_block_streams(eth_client.clone(), self.common.entry_points.len()).await; launch_uopool( diff --git a/bin/silius/src/utils.rs b/bin/silius/src/utils.rs index 59cac4a4..bc935f70 100644 --- a/bin/silius/src/utils.rs +++ b/bin/silius/src/utils.rs @@ -4,7 +4,7 @@ use ethers::types::{Address, U256}; use expanded_pathbuf::ExpandedPathBuf; use pin_utils::pin_mut; use silius_primitives::{bundler::SendStrategy, UoPoolMode}; -use std::{future::Future, str::FromStr}; +use std::{future::Future, str::FromStr, time::Duration}; use tracing::info; /// Unwrap path or returns home directory @@ -44,6 +44,11 @@ pub fn parse_enr(enr: &str) -> Result { Enr::from_str(enr).map_err(|_| format!("Enr {enr} is not a valid enr.")) } +pub fn parse_duration(duration: &str) -> Result { + let seconds: u64 = duration.parse().map_err(|_| format!("{duration} must be unsigned int"))?; + Ok(Duration::from_millis(seconds)) +} + /// Runs the future to completion or until: /// - `ctrl-c` is received. /// - `SIGTERM` is received (unix only). diff --git a/crates/primitives/src/provider.rs b/crates/primitives/src/provider.rs index 02956088..0d3abd4d 100644 --- a/crates/primitives/src/provider.rs +++ b/crates/primitives/src/provider.rs @@ -11,16 +11,13 @@ use std::{pin::Pin, sync::Arc, time::Duration}; pub type BlockStream = Pin> + Send>>; /// Creates ethers provider with HTTP connection -pub async fn create_http_provider(addr: &str) -> eyre::Result> { +pub async fn create_http_provider( + addr: &str, + poll_interval: Duration, +) -> eyre::Result> { let provider = Provider::::try_from(addr)?; - let chain_id = provider.get_chainid().await?; - - Ok(provider.interval(if chain_id == Chain::Dev.into() { - Duration::from_millis(5u64) - } else { - Duration::from_millis(500u64) - })) + Ok(provider.interval(poll_interval)) } /// Creates ethers provider with WebSockets connection