From 499d50b5fcddeb0c7fe35cf086c0a21568c74eb8 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 1 Mar 2023 23:21:09 +0000 Subject: [PATCH] handle empty private_rpcs --- web3_proxy/src/app/mod.rs | 5 +++-- web3_proxy/src/rpcs/many.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 15959a5c..31700b68 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1265,7 +1265,7 @@ impl Web3ProxyApp { }; let (private_rpcs, num) = if let Some(private_rpcs) = self.private_rpcs.as_ref() { - if authorization.checks.private_txs { + if !private_rpcs.is_empty() && authorization.checks.private_txs { // if we are sending the transaction privately, no matter the proxy_mode, we send to ALL private rpcs (private_rpcs, None) } else { @@ -1283,12 +1283,13 @@ impl Web3ProxyApp { // TODO: error/wait if no head block! // try_send_all_upstream_servers puts the request id into the response. no need to do that ourselves here. + // TODO: what lag should we allow? let mut response = private_rpcs .try_send_all_synced_connections( authorization, &request, Some(request_metadata.clone()), - None, + Some(&head_block_num.saturating_sub(2.into())), None, Level::Trace, num, diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 66a0f720..ea95ad63 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -315,6 +315,14 @@ impl Web3Rpcs { self.by_name.read().get(conn_name).cloned() } + pub fn len(&self) -> usize { + self.by_name.read().len() + } + + pub fn is_empty(&self) -> bool { + self.by_name.read().is_empty() + } + pub fn min_head_rpcs(&self) -> usize { self.min_head_rpcs }