From fc8beb52b0ae993a8bccf53f4a846f3eb518ba7c Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 6 Nov 2022 21:05:03 +0000 Subject: [PATCH] maybe fix next_upstream_server --- web3_proxy/src/rpcs/connection.rs | 2 +- web3_proxy/src/rpcs/connections.rs | 33 ++++++++++++++---------------- web3_proxy/src/user_queries.rs | 4 ++-- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/web3_proxy/src/rpcs/connection.rs b/web3_proxy/src/rpcs/connection.rs index 9eee22d3..f7ed6eca 100644 --- a/web3_proxy/src/rpcs/connection.rs +++ b/web3_proxy/src/rpcs/connection.rs @@ -6,7 +6,7 @@ use crate::app::{flatten_handle, AnyhowJoinHandle}; use crate::config::BlockAndRpc; use crate::frontend::authorization::AuthorizedRequest; use anyhow::Context; -use ethers::prelude::{Block, Bytes, Middleware, ProviderError, TxHash, H256, U64}; +use ethers::prelude::{Bytes, Middleware, ProviderError, TxHash, H256, U64}; use futures::future::try_join_all; use futures::StreamExt; use parking_lot::RwLock; diff --git a/web3_proxy/src/rpcs/connections.rs b/web3_proxy/src/rpcs/connections.rs index bc200c6d..b2091d55 100644 --- a/web3_proxy/src/rpcs/connections.rs +++ b/web3_proxy/src/rpcs/connections.rs @@ -10,6 +10,7 @@ use crate::config::{BlockAndRpc, TxHashAndRpc, Web3ConnectionConfig}; use crate::frontend::authorization::{AuthorizedRequest, RequestMetadata}; use crate::jsonrpc::{JsonRpcForwardedResponse, JsonRpcRequest}; use crate::rpcs::transactions::TxStatus; +use anyhow::Context; use arc_swap::ArcSwap; use counter::Counter; use derive_more::From; @@ -379,30 +380,26 @@ impl Web3Connections { ) -> anyhow::Result { let mut earliest_retry_at = None; + let min_block_needed = if let Some(min_block_needed) = min_block_needed { + *min_block_needed + } else { + self.head_block_num().context("not servers are synced")? + }; + // filter the synced rpcs // TODO: we are going to be checking "has_block_data" a lot now - let mut synced_rpcs: Vec> = - if let Some(min_block_needed) = min_block_needed { - self.conns - .values() - .filter(|x| !skip.contains(x)) - .filter(|x| x.has_block_data(min_block_needed)) - .cloned() - .collect() - } else { - self.synced_connections - .load() - .conns - .iter() - .filter(|x| !skip.contains(x)) - .cloned() - .collect() - }; + let mut synced_rpcs: Vec> = self + .conns + .values() + .filter(|x| !skip.contains(x)) + .filter(|x| x.has_block_data(&min_block_needed)) + .cloned() + .collect(); if synced_rpcs.is_empty() { // TODO: what should happen here? automatic retry? // TODO: more detailed error - return Err(anyhow::anyhow!("not synced")); + return Err(anyhow::anyhow!("no servers are synced")); } // we sort on a bunch of values. cache them here so that we don't do this math multiple times. diff --git a/web3_proxy/src/user_queries.rs b/web3_proxy/src/user_queries.rs index 5208820a..90f166cc 100644 --- a/web3_proxy/src/user_queries.rs +++ b/web3_proxy/src/user_queries.rs @@ -171,7 +171,7 @@ pub fn filter_query_window_seconds( response: &mut HashMap<&str, serde_json::Value>, q: Select, ) -> Result, FrontendErrorResponse> { - let query_window_seconds = get_query_window_seconds_from_params(¶ms)?; + let query_window_seconds = get_query_window_seconds_from_params(params)?; if query_window_seconds == 0 { // TODO: order by more than this? @@ -343,7 +343,7 @@ pub async fn query_user_stats<'a>( // TODO: trace log query here? i think sea orm has a useful log level for this // set up pagination - let page = get_page_from_params(¶ms)?; + let page = get_page_from_params(params)?; response.insert("page", serde_json::to_value(page).expect("can't fail")); // TODO: page size from param with a max from the config