From 3c2d06324e72abad133c86e7580f5762f3e0c7c7 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 13 Jul 2023 18:13:16 -0700 Subject: [PATCH] faster rpc. backups always lose --- web3_proxy/src/rpcs/many.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 988942a6..ce6b0bf7 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -454,9 +454,9 @@ impl Web3Rpcs { for (rpc_a, rpc_b) in potential_rpcs.iter().circular_tuple_windows() { trace!("{} vs {}", rpc_a, rpc_b); - // TODO: cached key to save a read lock - // TODO: ties to the server with the smallest block_data_limit - let faster_rpc = min_by_key(rpc_a, rpc_b, |x| x.weighted_peak_latency()); + // TODO: ties within X% to the server with the smallest block_data_limit + // faster rpc. backups always lose. + let faster_rpc = min_by_key(rpc_a, rpc_b, |x| (x.backup, x.weighted_peak_latency())); trace!("winner: {}", faster_rpc); // add to the skip list in case this one fails @@ -2030,4 +2030,14 @@ mod test { assert_eq!(test_vec, sorted_vec); } + + #[test] + fn test_bool_sort() { + let test_vec = vec![false, true]; + + let mut sorted_vec = test_vec.clone(); + sorted_vec.sort(); + + assert_eq!(test_vec, sorted_vec); + } }