From 0b62ffcdfcf8b86c5d5ba7437acff9d5092abf86 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 30 May 2023 21:08:21 -0700 Subject: [PATCH] no need to move the semaphore around like this --- web3_proxy/src/frontend/authorization.rs | 4 ++++ web3_proxy/src/frontend/rpc_proxy_http.rs | 10 ++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/web3_proxy/src/frontend/authorization.rs b/web3_proxy/src/frontend/authorization.rs index 85d92048..ad6adb9d 100644 --- a/web3_proxy/src/frontend/authorization.rs +++ b/web3_proxy/src/frontend/authorization.rs @@ -766,6 +766,7 @@ pub async fn login_is_authorized(app: &Web3ProxyApp, ip: IpAddr) -> Web3ProxyRes } /// semaphore won't ever be None, but its easier if key auth and ip auth work the same way +/// keep the semaphore alive until the user's request is entirely complete pub async fn ip_is_authorized( app: &Arc, ip: IpAddr, @@ -831,6 +832,7 @@ pub async fn ip_is_authorized( } /// like app.rate_limit_by_rpc_key but converts to a Web3ProxyError; +/// keep the semaphore alive until the user's request is entirely complete pub async fn key_is_authorized( app: &Arc, rpc_key: RpcSecretKey, @@ -916,6 +918,7 @@ impl Web3ProxyApp { } /// Limit the number of concurrent requests for a given user across all of their keys + /// keep the semaphore alive until the user's request is entirely complete pub async fn user_semaphore( &self, authorization_checks: &AuthorizationChecks, @@ -946,6 +949,7 @@ impl Web3ProxyApp { /// Verify that the given bearer token and address are allowed to take the specified action. /// This includes concurrent request limiting. + /// keep the semaphore alive until the user's request is entirely complete pub async fn bearer_is_authorized( &self, bearer: Bearer, diff --git a/web3_proxy/src/frontend/rpc_proxy_http.rs b/web3_proxy/src/frontend/rpc_proxy_http.rs index c82f9e03..d01b72e5 100644 --- a/web3_proxy/src/frontend/rpc_proxy_http.rs +++ b/web3_proxy/src/frontend/rpc_proxy_http.rs @@ -62,7 +62,7 @@ async fn _proxy_web3_rpc( let first_id = payload.first_id().map_err(|e| e.into_response())?; - let (authorization, semaphore) = ip_is_authorized(&app, ip, origin, proxy_mode) + let (authorization, _semaphore) = ip_is_authorized(&app, ip, origin, proxy_mode) .await .map_err(|e| e.into_response_with_id(first_id.to_owned()))?; @@ -70,10 +70,9 @@ async fn _proxy_web3_rpc( // TODO: calculate payload bytes here (before turning into serde_json::Value). that will save serializing later - let (status_code, response, rpcs, _semaphore) = app + let (status_code, response, rpcs) = app .proxy_web3_rpc(authorization, payload) .await - .map(|(s, x, y)| (s, x, y, semaphore)) .map_err(|e| e.into_response_with_id(first_id.to_owned()))?; let mut response = (status_code, Json(response)).into_response(); @@ -227,7 +226,7 @@ async fn _proxy_web3_rpc_with_key( .parse() .map_err(|e: Web3ProxyError| e.into_response_with_id(first_id.to_owned()))?; - let (authorization, semaphore) = key_is_authorized( + let (authorization, _semaphore) = key_is_authorized( &app, rpc_key, ip, @@ -243,10 +242,9 @@ async fn _proxy_web3_rpc_with_key( let rpc_secret_key_id = authorization.checks.rpc_secret_key_id; - let (status_code, response, rpcs, _semaphore) = app + let (status_code, response, rpcs) = app .proxy_web3_rpc(authorization, payload) .await - .map(|(s, x, y)| (s, x, y, semaphore)) .map_err(|e| e.into_response_with_id(first_id.to_owned()))?; let mut response = (status_code, Json(response)).into_response();