From fc287d24ea2b1476b0ecddda3d962f6d022250e7 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 18 Sep 2023 23:27:44 -0700 Subject: [PATCH] borrow_and_update instead of borrow i think this won't matter and the update is probably a waste, but it feels wrong to leave it in a changed state --- web3_proxy/src/frontend/mod.rs | 7 ++----- web3_proxy/src/rpcs/many.rs | 3 +-- web3_proxy/src/rpcs/one.rs | 12 +++++------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/web3_proxy/src/frontend/mod.rs b/web3_proxy/src/frontend/mod.rs index b7879b2e..00a0a514 100644 --- a/web3_proxy/src/frontend/mod.rs +++ b/web3_proxy/src/frontend/mod.rs @@ -10,12 +10,11 @@ pub mod rpc_proxy_ws; pub mod status; pub mod users; +use crate::app::Web3ProxyApp; use crate::errors::Web3ProxyResult; -use crate::{app::Web3ProxyApp, errors::Web3ProxyError}; use axum::{ - error_handling::HandleErrorLayer, routing::{get, post}, - BoxError, Extension, Router, + Extension, Router, }; use http::{header::AUTHORIZATION, Request, StatusCode}; use hyper::Body; @@ -26,8 +25,6 @@ use std::{iter::once, time::Duration}; use std::{net::SocketAddr, sync::atomic::Ordering}; use strum::{EnumCount, EnumIter}; use tokio::sync::broadcast; -use tower::timeout::TimeoutLayer; -use tower::ServiceBuilder; use tower_http::sensitive_headers::SetSensitiveRequestHeadersLayer; use tower_http::{cors::CorsLayer, normalize_path::NormalizePathLayer, trace::TraceLayer}; use tracing::{error_span, info}; diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index 22ee132b..ac025b3d 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -993,7 +993,6 @@ impl Web3Rpcs { } } - yield_now().await; } OpenRequestResult::NotReady => { if let Some(request_metadata) = request_metadata { @@ -1032,7 +1031,7 @@ impl Web3Rpcs { let needed = min_block_needed.max(max_block_needed); let head_block_num = watch_consensus_rpcs - .borrow() + .borrow_and_update() .as_ref() .map(|x| *x.head_block.number()); diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index c2572b3e..3747a1d3 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -814,7 +814,7 @@ impl Web3Rpc { // rpcs opt-into subscribing to transactions. its a lot of bandwidth if !self.subscribe_txs { loop { - if *subscribe_stop_rx.borrow() { + if *subscribe_stop_rx.borrow_and_update() { trace!("stopping ws block subscription on {}", self); return Ok(()); } @@ -837,7 +837,7 @@ impl Web3Rpc { drop(active_request_handle); while let Some(x) = pending_txs_sub.next().await { - if *subscribe_stop_rx.borrow() { + if *subscribe_stop_rx.borrow_and_update() { // TODO: this is checking way too often. have this on a timer instead trace!("stopping ws block subscription on {}", self); break; @@ -854,7 +854,7 @@ impl Web3Rpc { } else { // TODO: what should we do here? loop { - if *subscribe_stop_rx.borrow() { + if *subscribe_stop_rx.borrow_and_update() { trace!("stopping ws block subscription on {}", self); return Ok(()); } @@ -870,7 +870,7 @@ impl Web3Rpc { self: &Arc, block_sender: mpsc::UnboundedSender, block_map: BlocksByHashCache, - subscribe_stop_rx: watch::Receiver, + mut subscribe_stop_rx: watch::Receiver, ) -> Web3ProxyResult<()> { trace!("subscribing to new heads on {}", self); @@ -926,7 +926,7 @@ impl Web3Rpc { i.set_missed_tick_behavior(MissedTickBehavior::Delay); loop { - if *subscribe_stop_rx.borrow() { + if *subscribe_stop_rx.borrow_and_update() { trace!(%self, "stopping http block subscription"); break; } @@ -992,8 +992,6 @@ impl Web3Rpc { } sleep_until(retry_at).await; - - yield_now().await; } Ok(OpenRequestResult::NotReady) => { // TODO: when can this happen? log? emit a stat?