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

@ -511,12 +511,13 @@ impl Web3Rpcs {
min_block_needed: Option<&U64>,
max_block_needed: Option<&U64>,
) -> 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() {
// 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() {
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<Some(*x_head_num)>);
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<None>);
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!(