prioritize block. queries to syncing nodes ends up being slower

This commit is contained in:
Bryan Stitt 2023-06-24 00:41:30 -07:00
parent ac4b7e46b4
commit 30828ccae2
3 changed files with 10 additions and 13 deletions

@ -64,12 +64,12 @@ impl RpcRanking {
}
}
fn sort_key(&self) -> (bool, u32, Reverse<Option<U64>>) {
fn sort_key(&self) -> (bool, Reverse<Option<U64>>, u32) {
// TODO: add soft_limit here? add peak_ewma here?
// TODO: should backup or tier be checked first? now that tiers are automated, backups
// TODO: should we include a random number in here?
// TODO: should we include peak_ewma_latency or weighted_peak_ewma_latency?
(!self.backup, self.tier, Reverse(self.head_num))
(!self.backup, Reverse(self.head_num), self.tier)
}
}
@ -855,12 +855,8 @@ impl ConsensusFinder {
.into_iter()
.map(|(block, (rpc_names, sum_soft_limit))| (block, sum_soft_limit, rpc_names))
.collect();
votes.sort_by_cached_key(|(block, sum_soft_limit, rpc_names)| {
(
Reverse(*block.number()),
Reverse(*sum_soft_limit),
Reverse(rpc_names.len()),
)
votes.sort_by_key(|(block, sum_soft_limit, _)| {
(Reverse(*block.number()), Reverse(*sum_soft_limit))
});
// return the first result that exceededs confgured minimums (if any)

@ -1485,7 +1485,8 @@ mod tests {
let names_in_sort_order: Vec<_> = rpcs.iter().map(|x| x.name.as_str()).collect();
assert_eq!(names_in_sort_order, ["c", "b", "a", "f", "e", "d"]);
// assert_eq!(names_in_sort_order, ["c", "b", "a", "f", "e", "d"]);
assert_eq!(names_in_sort_order, ["c", "f", "b", "e", "a", "d"]);
}
#[tokio::test(start_paused = true)]

@ -244,7 +244,7 @@ impl Web3Rpc {
/// TODO: tests on this!
/// TODO: should tier or block number take priority?
/// TODO: should this return a struct that implements sorting traits?
fn sort_on(&self, max_block: Option<U64>) -> (bool, u32, Reverse<U64>) {
fn sort_on(&self, max_block: Option<U64>) -> (bool, Reverse<U64>, u32) {
let mut head_block = self
.head_block
.as_ref()
@ -259,13 +259,13 @@ impl Web3Rpc {
let backup = self.backup;
(!backup, tier, Reverse(head_block))
(!backup, Reverse(head_block), tier)
}
pub fn sort_for_load_balancing_on(
&self,
max_block: Option<U64>,
) -> ((bool, u32, Reverse<U64>), Duration) {
) -> ((bool, Reverse<U64>, u32), Duration) {
let sort_on = self.sort_on(max_block);
let weighted_peak_latency = self.weighted_peak_latency();
@ -281,7 +281,7 @@ impl Web3Rpc {
pub fn shuffle_for_load_balancing_on(
&self,
max_block: Option<U64>,
) -> ((bool, u32, Reverse<U64>), u8) {
) -> ((bool, Reverse<U64>, u32), u8) {
let sort_on = self.sort_on(max_block);
let mut rng = nanorand::tls_rng();