From 996d1fb11bbaf36b737035edcda6a27eb017fb98 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 10 Aug 2022 03:38:04 +0000 Subject: [PATCH] no need for async lock --- web3_proxy/src/app.rs | 7 +++---- web3_proxy/src/connection.rs | 1 + web3_proxy/src/frontend/rate_limit.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web3_proxy/src/app.rs b/web3_proxy/src/app.rs index b1979bfc..2536dd3f 100644 --- a/web3_proxy/src/app.rs +++ b/web3_proxy/src/app.rs @@ -25,7 +25,6 @@ use std::str::FromStr; use std::sync::atomic::{self, AtomicUsize}; use std::sync::Arc; use std::time::Duration; -use tokio::sync::RwLock as AsyncRwLock; use tokio::sync::{broadcast, watch}; use tokio::task::JoinHandle; use tokio::time::{timeout, Instant}; @@ -142,7 +141,7 @@ pub struct Web3ProxyApp { head_block_receiver: watch::Receiver>>, pending_tx_sender: broadcast::Sender, pending_transactions: Arc>, - user_cache: AsyncRwLock>, + user_cache: RwLock>, redis_pool: Option, rate_limiter: Option, db_conn: Option, @@ -172,7 +171,7 @@ impl Web3ProxyApp { self.redis_pool.as_ref() } - pub fn user_cache(&self) -> &AsyncRwLock> { + pub fn user_cache(&self) -> &RwLock> { &self.user_cache } @@ -327,7 +326,7 @@ impl Web3ProxyApp { redis_pool, // TODO: make the size configurable // TODO: why does this need to be async but the other one doesn't? - user_cache: AsyncRwLock::new(FifoCountMap::new(1_000)), + user_cache: RwLock::new(FifoCountMap::new(1_000)), }; let app = Arc::new(app); diff --git a/web3_proxy/src/connection.rs b/web3_proxy/src/connection.rs index d343f738..00bce794 100644 --- a/web3_proxy/src/connection.rs +++ b/web3_proxy/src/connection.rs @@ -78,6 +78,7 @@ pub struct Web3Connection { /// keep track of currently open requests. We sort on this active_requests: AtomicU32, /// provider is in a RwLock so that we can replace it if re-connecting + /// it is an async lock because we hold it open across awaits provider: AsyncRwLock>>, /// rate limits are stored in a central redis so that multiple proxies can share their rate limits hard_limit: Option, diff --git a/web3_proxy/src/frontend/rate_limit.rs b/web3_proxy/src/frontend/rate_limit.rs index 937513f4..246b1827 100644 --- a/web3_proxy/src/frontend/rate_limit.rs +++ b/web3_proxy/src/frontend/rate_limit.rs @@ -55,7 +55,7 @@ impl Web3ProxyApp { let user_cache = self.user_cache(); // check the local cache - let user_data = if let Some(cached_user) = user_cache.read().await.get(&user_key) { + let user_data = if let Some(cached_user) = user_cache.read().get(&user_key) { // TODO: also include the time this value was last checked! otherwise we cache forever! if cached_user.expires_at < Instant::now() { // old record found @@ -105,7 +105,7 @@ impl Web3ProxyApp { }; // save for the next run - user_cache.write().await.insert(user_key, user_data); + user_cache.write().insert(user_key, user_data); user_data } else {