Fix sort order

This commit is contained in:
Bryan Stitt 2023-04-29 18:38:31 -07:00 committed by GitHub
parent 93f243696a
commit 91acbcaf75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -511,12 +511,13 @@ impl Web3Rpcs {
min_block_needed: Option<&U64>, min_block_needed: Option<&U64>,
max_block_needed: Option<&U64>, max_block_needed: Option<&U64>,
) -> Web3ProxyResult<OpenRequestResult> { ) -> Web3ProxyResult<OpenRequestResult> {
let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Option<U64>), Vec<Arc<Web3Rpc>>> = { let usable_rpcs_by_tier_and_head_number: BTreeMap<(u64, Reverse<Option<U64>>), Vec<Arc<Web3Rpc>>> = {
let mut m = BTreeMap::new();
if self.watch_consensus_head_sender.is_none() { if self.watch_consensus_head_sender.is_none() {
// pick any server // pick any server
let mut m = BTreeMap::new();
let key = (0, None); let key = (0, Reverse<None>);
for x in self.by_name.read().values() { for x in self.by_name.read().values() {
if skip.contains(x) { if skip.contains(x) {
@ -527,8 +528,6 @@ impl Web3Rpcs {
m.entry(key).or_insert_with(Vec::new).push(x.clone()); m.entry(key).or_insert_with(Vec::new).push(x.clone());
} }
m
} else { } else {
let synced_connections = self.watch_consensus_rpcs_sender.borrow().clone(); let synced_connections = self.watch_consensus_rpcs_sender.borrow().clone();
@ -569,9 +568,6 @@ impl Web3Rpcs {
trace!("needed_blocks_comparison: {:?}", needed_blocks_comparison); trace!("needed_blocks_comparison: {:?}", needed_blocks_comparison);
// collect "usable_rpcs_by_head_num_and_weight" // collect "usable_rpcs_by_head_num_and_weight"
// TODO: MAKE SURE None SORTS LAST?
let mut m = BTreeMap::new();
match needed_blocks_comparison { match needed_blocks_comparison {
cmp::Ordering::Less => { cmp::Ordering::Less => {
// need an old block. check all the rpcs. ignore rpcs that are still syncing // 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<Some(*x_head_num)>);
m.entry(key).or_insert_with(Vec::new).push(x); 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 // 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 // they are all at the same block and it is already sized to what we need
let key = (0, None); let key = (0, Reverse<None>);
for x in synced_connections.best_rpcs.iter() { for x in synced_connections.best_rpcs.iter() {
if skip.contains(x) { if skip.contains(x) {
@ -664,9 +660,9 @@ impl Web3Rpcs {
return Ok(OpenRequestResult::NotReady); return Ok(OpenRequestResult::NotReady);
} }
} }
m
} }
m
}; };
trace!( trace!(