From 45fb2e5ea604b0f6c014337b6dbd1c1bc64d5c39 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Mon, 23 Oct 2023 15:38:44 -0700 Subject: [PATCH] require premium for debug module --- web3_proxy/src/app/mod.rs | 10 ++++++++++ web3_proxy/src/block_number.rs | 3 +++ web3_proxy/src/jsonrpc/request_builder.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 31be8201..b7e3814a 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -1633,6 +1633,16 @@ impl App { method )).into()); } + if method.starts_with("debug_") { + // make sure its premium + if !(self.config.free_subscriptions + || web3_request.authorization.active_premium().await) + { + return Err(Web3ProxyError::AccessDenied( + "debug methods require an active premium account".into(), + )); + } + } if web3_request.cache_mode.is_some() { // don't cache anything larger than 16 MiB diff --git a/web3_proxy/src/block_number.rs b/web3_proxy/src/block_number.rs index 53166434..84e71d2b 100644 --- a/web3_proxy/src/block_number.rs +++ b/web3_proxy/src/block_number.rs @@ -469,6 +469,7 @@ impl CacheMode { } } + #[inline] pub fn cache_jsonrpc_errors(&self) -> bool { match self { Self::Never => false, @@ -478,6 +479,7 @@ impl CacheMode { } } + #[inline] pub fn from_block(&self) -> Option<&BlockNumAndHash> { match self { Self::SuccessForever => None, @@ -492,6 +494,7 @@ impl CacheMode { !matches!(self, Self::Never) } + #[inline] pub fn to_block(&self) -> Option<&BlockNumAndHash> { match self { Self::SuccessForever => None, diff --git a/web3_proxy/src/jsonrpc/request_builder.rs b/web3_proxy/src/jsonrpc/request_builder.rs index 610d42e2..af574f41 100644 --- a/web3_proxy/src/jsonrpc/request_builder.rs +++ b/web3_proxy/src/jsonrpc/request_builder.rs @@ -501,6 +501,7 @@ impl ValidatedRequest { self.cache_mode.to_block().map(|x| *x.num()) } + #[inline] pub fn min_block_needed(&self) -> Option { if self.archive_request.load(atomic::Ordering::Relaxed) { Some(U64::zero())