From d6e9f61ee230cb412c51a7257739f88801794bfb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Fri, 6 Oct 2023 00:04:46 -0700 Subject: [PATCH] only send to 2 servers (not 3x2) --- web3_proxy/src/app/mod.rs | 44 +++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index eccfe487..354eb37b 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1369,22 +1369,32 @@ impl Web3ProxyApp { let mut result = self .balanced_rpcs - .try_send_all_synced_connections::( + .try_proxy_connection::>( web3_request, - Some(Duration::from_secs(30)), - Some(crate::rpcs::request::RequestErrorHandler::DebugLevel), - Some(3), ) .await; + // TODO: helper for doing parsed() inside a result? + if let Ok(SingleResponse::Stream(x)) = result { + result = x.read().await.map(SingleResponse::Parsed).map_err(Into::into); + } + // if we got "null" or "", it is probably because the tx is old. retry on nodes with old block data // TODO: this feels fragile. how should we do this better/ let try_archive = match &result { - Ok(serde_json::Value::Null) => true, - Ok(serde_json::Value::Array(x)) => x.is_empty(), - Ok(serde_json::Value::String(x)) => x.is_empty(), + Ok(SingleResponse::Parsed(x)) => { + let x = x.result().map(|x| json!(x)); + + match x { + Some(serde_json::Value::Null) => true, + Some(serde_json::Value::Array(x)) => x.is_empty(), + Some(serde_json::Value::String(x)) => x.is_empty(), + None => true, + _ => false, + } + }, + Ok(SingleResponse::Stream(..)) => unimplemented!(), Err(..) => true, - _ => false, }; if try_archive { @@ -1394,20 +1404,18 @@ impl Web3ProxyApp { .store(true, atomic::Ordering::Relaxed); // TODO: we don't actually want try_send_all. we want the first non-null, non-error response - result = self + self .balanced_rpcs - .try_send_all_synced_connections::( + .try_proxy_connection::>( web3_request, - Some(Duration::from_secs(30)), - Some(crate::rpcs::request::RequestErrorHandler::DebugLevel), - Some(3), ) - .await; + .await? + } else { + + // TODO: if result is an error, return a null instead? + + result? } - - // TODO: if parsed is an error, return a null instead - - jsonrpc::ParsedResponse::from_value(result?, web3_request.id()).into() } // TODO: eth_gasPrice that does awesome magic to predict the future "eth_hashrate" => jsonrpc::ParsedResponse::from_value(json!(U64::zero()), web3_request.id()).into(),