From ff14045b64eec62ed77dcda3c3cbb63e6ba88cbb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 1 Nov 2023 22:55:28 -0700 Subject: [PATCH] make checking block data optional this is needed so that private/bundler rpcs can send requests --- web3_proxy/src/rpcs/consensus.rs | 31 +++++++++++++++++++++---------- web3_proxy/src/rpcs/many.rs | 7 ++++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/web3_proxy/src/rpcs/consensus.rs b/web3_proxy/src/rpcs/consensus.rs index 78a80f13..fa3cac98 100644 --- a/web3_proxy/src/rpcs/consensus.rs +++ b/web3_proxy/src/rpcs/consensus.rs @@ -73,7 +73,9 @@ pub enum ShouldWaitForBlock { #[derive(Clone, Debug, Serialize)] enum SortMethod { + /// shuffle the servers randomly instead of by latency Shuffle, + /// sort the servers by latency (among other things) Sort, } @@ -87,6 +89,7 @@ pub struct RankedRpcs { pub head_block: Web3ProxyBlock, pub num_synced: usize, pub backups_needed: bool, + pub check_block_data: bool, pub(crate) inner: HashSet>, @@ -102,7 +105,11 @@ pub struct RpcsForRequest { } impl RankedRpcs { - pub fn from_rpcs(rpcs: Vec>, head_block: Option) -> Self { + pub fn from_rpcs( + rpcs: Vec>, + head_block: Option, + check_block_data: bool, + ) -> Self { // we don't need to sort the rpcs now. we will sort them when a request neds them // TODO: the shame about this is that we lose just being able to compare 2 random servers @@ -119,6 +126,7 @@ impl RankedRpcs { Self { backups_needed, + check_block_data, head_block, inner: rpcs, num_synced, @@ -195,6 +203,7 @@ impl RankedRpcs { let consensus = RankedRpcs { backups_needed, + check_block_data: true, head_block: best_block, sort_mode, inner: best_rpcs, @@ -233,16 +242,18 @@ impl RankedRpcs { continue; } - if let Some(block_needed) = min_block_needed { - if !rpc.has_block_data(block_needed) { - outer_for_request.push(rpc); - continue; + if self.check_block_data { + if let Some(block_needed) = min_block_needed { + if !rpc.has_block_data(block_needed) { + outer_for_request.push(rpc); + continue; + } } - } - if let Some(block_needed) = max_block_needed { - if !rpc.has_block_data(block_needed) { - outer_for_request.push(rpc); - continue; + if let Some(block_needed) = max_block_needed { + if !rpc.has_block_data(block_needed) { + outer_for_request.push(rpc); + continue; + } } } diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 3f88e446..e010cee7 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -45,6 +45,7 @@ pub struct Web3Rpcs { /// Geth's subscriptions have the same potential for skipping blocks. pub(crate) watch_ranked_rpcs: watch::Sender>>, /// this head receiver makes it easy to wait until there is a new block + /// this is None if none of the child Rpcs are subscribed to newHeads pub(super) watch_head_block: Option>>, /// TODO: this map is going to grow forever unless we do some sort of pruning. maybe store pruned in redis? /// all blocks, including uncles @@ -416,7 +417,11 @@ impl Web3Rpcs { let rpcs = self.by_name.read().values().cloned().collect(); // TODO: does this need the head_block? i don't think so - let x = RankedRpcs::from_rpcs(rpcs, web3_request.head_block.clone()); + let x = RankedRpcs::from_rpcs( + rpcs, + web3_request.head_block.clone(), + self.watch_head_block.is_some(), + ); Arc::new(x) };