handle empty private_rpcs

This commit is contained in:
Bryan Stitt 2023-03-01 23:21:09 +00:00
parent c8bc0d288f
commit 499d50b5fc
2 changed files with 11 additions and 2 deletions

@ -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,

@ -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
}