From 1aefcf166de30555cde68c3ce8d0aad0109c417a Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 3 Jan 2023 11:37:42 -0800 Subject: [PATCH] different polling for different chains --- web3_proxy/src/rpcs/connections.rs | 19 ++++++++++++++++++- web3_proxy/src/rpcs/provider.rs | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index a4a2b7ff..8399659a 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -71,13 +71,30 @@ impl Web3Connections { let (pending_tx_id_sender, pending_tx_id_receiver) = flume::unbounded(); let (block_sender, block_receiver) = flume::unbounded::(); + // TODO: query the rpc to get the actual expected block time, or get from config? + let expected_block_time_ms = match chain_id { + // ethereum + 1 => 12_000, + // polygon + 137 => 2_000, + // fantom + 250 => 1_000, + // arbitrum + 42161 => 0_500, + // anything else + _ => { + warn!("unexpected chain_id. polling every {} seconds", 10); + 10_000 + } + }; + let http_interval_sender = if http_client.is_some() { let (sender, receiver) = broadcast::channel(1); drop(receiver); // TODO: what interval? follow a websocket also? maybe by watching synced connections with a timeout. will need debounce - let mut interval = interval(Duration::from_secs(13)); + let mut interval = interval(Duration::from_millis(expected_block_time_ms)); interval.set_missed_tick_behavior(MissedTickBehavior::Delay); let sender = Arc::new(sender); diff --git a/web3_proxy/src/rpcs/provider.rs b/web3_proxy/src/rpcs/provider.rs index 3093a4e4..add17a43 100644 --- a/web3_proxy/src/rpcs/provider.rs +++ b/web3_proxy/src/rpcs/provider.rs @@ -35,7 +35,7 @@ impl Web3Provider { // TODO: dry this up (needs https://github.com/gakonst/ethers-rs/issues/592) // TODO: i don't think this interval matters for our uses, but we should probably set it to like `block time / 2` ethers::providers::Provider::new(provider) - .interval(Duration::from_secs(13)) + .interval(Duration::from_secs(12)) .into() } else if url_str.starts_with("ws") { let provider = ethers::providers::Ws::connect(url_str).await?;