diff --git a/web3_proxy/src/frontend/rpc_proxy_http.rs b/web3_proxy/src/frontend/rpc_proxy_http.rs index 4dc02e21..8455eca9 100644 --- a/web3_proxy/src/frontend/rpc_proxy_http.rs +++ b/web3_proxy/src/frontend/rpc_proxy_http.rs @@ -10,7 +10,6 @@ use axum::{response::IntoResponse, Extension, Json}; use axum_client_ip::ClientIp; use axum_macros::debug_handler; use itertools::Itertools; -use log::debug; use std::sync::Arc; /// POST /rpc -- Public entrypoint for HTTP JSON-RPC requests. Web3 wallets use this. diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index 154cd818..2de4fc3d 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -415,60 +415,62 @@ impl Web3Connections { skip: &[Arc], min_block_needed: Option<&U64>, ) -> anyhow::Result { - let usable_rpcs_by_head_num_and_weight: BTreeMap<(U64, u64), Vec>> = - if let Some(min_block_needed) = min_block_needed { - // need a potentially old block. check all the rpcs - let mut m = BTreeMap::new(); + let usable_rpcs_by_head_num_and_weight: BTreeMap< + (Option, u64), + Vec>, + > = if let Some(min_block_needed) = min_block_needed { + // need a potentially old block. check all the rpcs + let mut m = BTreeMap::new(); - for x in self - .conns - .values() - .filter(|x| !skip.contains(x)) - .filter(|x| x.has_block_data(min_block_needed)) - .cloned() - { - let x_head_block = x.head_block.read().clone(); + for x in self + .conns + .values() + .filter(|x| !skip.contains(x)) + .filter(|x| x.has_block_data(min_block_needed)) + .cloned() + { + let x_head_block = x.head_block.read().clone(); - match x_head_block { - None => continue, - Some(x_head) => { - let key = (Some(x_head.number()), u64::MAX - x.tier); + match x_head_block { + None => continue, + Some(x_head) => { + let key = (Some(x_head.number()), u64::MAX - x.tier); - m.entry(key).or_insert_with(Vec::new).push(x); - } + m.entry(key).or_insert_with(Vec::new).push(x); } } + } - m - } else { - // need latest. filter the synced rpcs - let synced_connections = self.synced_connections.load(); + m + } else { + // need latest. filter the synced rpcs + let synced_connections = self.synced_connections.load(); - let head_block = match synced_connections.head_block.as_ref() { - None => return Ok(OpenRequestResult::NotReady), - Some(x) => x, - }; - - // TODO: self.allowed_lag instead of taking as an arg - if head_block.syncing(allowed_lag) { - return Ok(OpenRequestResult::NotReady); - } - - let mut m = BTreeMap::new(); - - for x in synced_connections - .conns - .iter() - .filter(|x| !skip.contains(x)) - { - let key = (None, u64::MAX - x.tier); - - m.entry(key).or_insert_with(Vec::new).push(x.clone()); - } - - m + let head_block = match synced_connections.head_block.as_ref() { + None => return Ok(OpenRequestResult::NotReady), + Some(x) => x, }; + // TODO: self.allowed_lag instead of taking as an arg + if head_block.syncing(allowed_lag) { + return Ok(OpenRequestResult::NotReady); + } + + let mut m = BTreeMap::new(); + + for x in synced_connections + .conns + .iter() + .filter(|x| !skip.contains(x)) + { + let key = (None, u64::MAX - x.tier); + + m.entry(key).or_insert_with(Vec::new).push(x.clone()); + } + + m + }; + let mut earliest_retry_at = None; for usable_rpcs in usable_rpcs_by_head_num_and_weight.into_values().rev() {