From 30828ccae278b4c90cb029e45195f68ba8f092f0 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sat, 24 Jun 2023 00:41:30 -0700 Subject: [PATCH] prioritize block. queries to syncing nodes ends up being slower --- web3_proxy/src/rpcs/consensus.rs | 12 ++++-------- web3_proxy/src/rpcs/many.rs | 3 ++- web3_proxy/src/rpcs/one.rs | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/web3_proxy/src/rpcs/consensus.rs b/web3_proxy/src/rpcs/consensus.rs index 8421ba0a..c3fd1215 100644 --- a/web3_proxy/src/rpcs/consensus.rs +++ b/web3_proxy/src/rpcs/consensus.rs @@ -64,12 +64,12 @@ impl RpcRanking { } } - fn sort_key(&self) -> (bool, u32, Reverse>) { + fn sort_key(&self) -> (bool, Reverse>, 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) diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index cad5f63a..7c16f9eb 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -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)] diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index 52c41d34..fb64c28b 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -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) -> (bool, u32, Reverse) { + fn sort_on(&self, max_block: Option) -> (bool, Reverse, 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, - ) -> ((bool, u32, Reverse), Duration) { + ) -> ((bool, Reverse, 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, - ) -> ((bool, u32, Reverse), u8) { + ) -> ((bool, Reverse, u32), u8) { let sort_on = self.sort_on(max_block); let mut rng = nanorand::tls_rng();