From 91acbcaf751cf4f5d8f16d7852ee98ffc78c4088 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 29 Apr 2023 18:38:31 -0700 Subject: [PATCH] Fix sort order --- web3_proxy/src/rpcs/many.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 7a48cdf0..dca48282 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -511,12 +511,13 @@ impl Web3Rpcs { min_block_needed: Option<&U64>, max_block_needed: Option<&U64>, ) -> Web3ProxyResult { - let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Option), Vec>> = { + let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Reverse>), Vec>> = { + let mut m = BTreeMap::new(); + if self.watch_consensus_head_sender.is_none() { // pick any server - let mut m = BTreeMap::new(); - let key = (0, None); + let key = (0, Reverse); for x in self.by_name.read().values() { if skip.contains(x) { @@ -527,8 +528,6 @@ impl Web3Rpcs { m.entry(key).or_insert_with(Vec::new).push(x.clone()); } - - m } else { let synced_connections = self.watch_consensus_rpcs_sender.borrow().clone(); @@ -569,9 +568,6 @@ impl Web3Rpcs { trace!("needed_blocks_comparison: {:?}", needed_blocks_comparison); // collect "usable_rpcs_by_head_num_and_weight" - // TODO: MAKE SURE None SORTS LAST? - let mut m = BTreeMap::new(); - match needed_blocks_comparison { cmp::Ordering::Less => { // need an old block. check all the rpcs. ignore rpcs that are still syncing @@ -634,7 +630,7 @@ impl Web3Rpcs { } } - let key = (x.tier, Some(*x_head_num)); + let key = (x.tier, Reverse); m.entry(key).or_insert_with(Vec::new).push(x); } @@ -647,7 +643,7 @@ impl Web3Rpcs { // the key doesn't matter if we are checking synced connections // they are all at the same block and it is already sized to what we need - let key = (0, None); + let key = (0, Reverse); for x in synced_connections.best_rpcs.iter() { if skip.contains(x) { @@ -664,9 +660,9 @@ impl Web3Rpcs { return Ok(OpenRequestResult::NotReady); } } - - m } + + m }; trace!(