From 5ffe2aa72a6530ae43e372db28bf8ccdc6c641c1 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 9 Feb 2023 11:47:56 -0800 Subject: [PATCH] eth_sendRawTransactions should use backups more often --- web3_proxy/src/app/mod.rs | 7 ++++--- web3_proxy/src/rpcs/many.rs | 25 +++++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 0cc0147b..5f977fed 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1217,6 +1217,7 @@ impl Web3ProxyApp { // if we are sending the transaction privately, no matter the proxy_mode, we send to ALL private rpcs (private_rpcs, None) } else { + // TODO: send to balanced_rpcs AND private_rpcs (&self.balanced_rpcs, default_num) } } else { @@ -1232,6 +1233,7 @@ impl Web3ProxyApp { None, Level::Trace, num, + true, ) .await?; @@ -1528,10 +1530,7 @@ impl Web3ProxyApp { self.response_cache .try_get_with(cache_key, async move { - // TODO: retry some failures automatically! - // TODO: try private_rpcs if all the balanced_rpcs fail! // TODO: put the hash here instead of the block number? its in the request already. - let mut response = self .balanced_rpcs .try_proxy_connection( @@ -1547,6 +1546,8 @@ impl Web3ProxyApp { response.id = Default::default(); // TODO: only cache the inner response + // TODO: how are we going to stream this? + // TODO: check response size. if its very large, return it in a custom Error type that bypasses caching Ok::<_, anyhow::Error>(response) }) .await diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index ac88191b..1af2cf44 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -639,12 +639,15 @@ impl Web3Rpcs { authorization: &Arc, block_needed: Option<&U64>, max_count: Option, + always_include_backups: bool, ) -> Result, Option> { - if let Ok(without_backups) = self - ._all_connections(false, authorization, block_needed, max_count) - .await - { - return Ok(without_backups); + if !always_include_backups { + if let Ok(without_backups) = self + ._all_connections(false, authorization, block_needed, max_count) + .await + { + return Ok(without_backups); + } } self._all_connections(true, authorization, block_needed, max_count) @@ -1008,10 +1011,16 @@ impl Web3Rpcs { block_needed: Option<&U64>, error_level: Level, max_count: Option, + always_include_backups: bool, ) -> anyhow::Result { loop { match self - .all_connections(authorization, block_needed, max_count) + .all_connections( + authorization, + block_needed, + max_count, + always_include_backups, + ) .await { Ok(active_request_handles) => { @@ -1382,10 +1391,10 @@ mod tests { // no head block because the rpcs haven't communicated through their channels assert!(conns.head_block_hash().is_none()); - // all_backend_connections gives everything regardless of sync status + // all_backend_connections gives all non-backup servers regardless of sync status assert_eq!( conns - .all_connections(&authorization, None, None) + .all_connections(&authorization, None, None, false) .await .unwrap() .len(),