From c4afad5b496077f9a56f2de16cae5a7a749549b9 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 14 Nov 2023 14:32:39 -0800 Subject: [PATCH] call add_response for internal requests --- web3_proxy/src/jsonrpc/request_builder.rs | 9 ++++++++- web3_proxy/src/rpcs/one.rs | 16 ++++++++++++++-- web3_proxy/src/stats/mod.rs | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/web3_proxy/src/jsonrpc/request_builder.rs b/web3_proxy/src/jsonrpc/request_builder.rs index 37eaadff..a371a2fd 100644 --- a/web3_proxy/src/jsonrpc/request_builder.rs +++ b/web3_proxy/src/jsonrpc/request_builder.rs @@ -2,7 +2,7 @@ use super::{JsonRpcParams, LooseId, SingleRequest}; use crate::{ app::App, block_number::CacheMode, - errors::Web3ProxyResult, + errors::{Web3ProxyError, Web3ProxyResult}, frontend::{ authorization::{key_is_authorized, Authorization, RequestOrMethod, ResponseOrBytes}, rpc_proxy_ws::ProxyMode, @@ -570,6 +570,13 @@ impl ValidatedRequest { Ok(()) } + pub fn add_error_response(&self, _err: &Web3ProxyError) { + self.error_response.store(true, atomic::Ordering::SeqCst); + + // TODO: add actual response size + self.add_response(0); + } + pub fn add_response<'a, R: Into>>(&'a self, response: R) { // TODO: fetch? set? should it be None in a Mutex? or a OnceCell? let response = response.into(); diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index bcee7081..555de6d9 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -1286,8 +1286,20 @@ impl Web3Rpc { // TODO: if we are inside the health checks and we aren't healthy yet. we need some sort of flag to force try_handle to not error - self.authorized_request(&web3_request, error_handler, true) - .await + let response = self + .authorized_request(&web3_request, error_handler, true) + .await; + + match &response { + Ok(x) => { + // TODO: this is not efficient :( + let x = json!(x); + web3_request.add_response(&x) + } + Err(e) => web3_request.add_error_response(e), + } + + response } pub async fn authorized_request( diff --git a/web3_proxy/src/stats/mod.rs b/web3_proxy/src/stats/mod.rs index fd3b57cb..1c4912f5 100644 --- a/web3_proxy/src/stats/mod.rs +++ b/web3_proxy/src/stats/mod.rs @@ -570,7 +570,7 @@ impl RpcQueryStats { if !error_response { // force error_response to true // this can happen when a try operator escapes and metadata.add_response() isn't called - trace!( + warn!( "no response known, but no errors logged. investigate. {:?}", metadata );