From 25b04db3b5aa923f03cf3deec577ea8275625381 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 28 Jun 2023 21:08:43 -0700 Subject: [PATCH] lower log level and optional to --- web3_proxy/src/rpcs/one.rs | 5 +++-- web3_proxy/src/rpcs/request.rs | 30 ++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index d5804042..396016e5 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -515,7 +515,7 @@ impl Web3Rpc { } } Err(err) => { - warn!("unable to get block from {}. err={:?}", self, err); + warn!(?err, "unable to get block from {}", self); // send an empty block to take this server out of rotation head_block_sender.send_replace(None); @@ -646,7 +646,8 @@ impl Web3Rpc { let error_handler = if self.backup { Some(RequestErrorHandler::DebugLevel) } else { - Some(RequestErrorHandler::ErrorLevel) + // TODO: info level? + Some(RequestErrorHandler::InfoLevel) }; if self.should_disconnect() { diff --git a/web3_proxy/src/rpcs/request.rs b/web3_proxy/src/rpcs/request.rs index 9f5ab6c5..c45c8b9f 100644 --- a/web3_proxy/src/rpcs/request.rs +++ b/web3_proxy/src/rpcs/request.rs @@ -15,7 +15,7 @@ use serde_json::json; use std::sync::atomic; use std::sync::Arc; use tokio::time::{Duration, Instant}; -use tracing::{debug, error, trace, warn, Level}; +use tracing::{debug, error, info, trace, warn, Level}; #[derive(Debug, From)] pub enum OpenRequestResult { @@ -43,6 +43,8 @@ pub enum RequestErrorHandler { TraceLevel, /// Log at the debug level. Use when errors are expected. DebugLevel, + /// Log at the info level. Use when errors are expected. + InfoLevel, /// Log at the error level. Use when errors are bad. ErrorLevel, /// Log at the warn level. Use when errors do not cause problems. @@ -57,18 +59,18 @@ struct EthCallParams((EthCallFirstParams, Option)); #[derive(serde::Deserialize, serde::Serialize)] struct EthCallFirstParams { - to: Address, + to: Option
, data: Option, } impl From for RequestErrorHandler { fn from(level: Level) -> Self { match level { - Level::TRACE => RequestErrorHandler::TraceLevel, Level::DEBUG => RequestErrorHandler::DebugLevel, Level::ERROR => RequestErrorHandler::ErrorLevel, + Level::INFO => RequestErrorHandler::InfoLevel, + Level::TRACE => RequestErrorHandler::TraceLevel, Level::WARN => RequestErrorHandler::WarnLevel, - _ => unimplemented!("unexpected tracing Level"), } } } @@ -94,12 +96,10 @@ impl Authorization { // we intentionally use "now" and not the time the request started // why? because we aggregate stats and setting one in the past could cause confusion let timestamp = Utc::now(); - let to: Vec = params - .to - .as_bytes() - .try_into() - .expect("address should always convert to a Vec"); - let call_data = params.data.map(|x| format!("{}", x)); + + let to = params.to.unwrap_or_else(Address::zero).as_bytes().to_vec(); + + let call_data = params.data.map(|x| x.to_string()); let rl = revert_log::ActiveModel { rpc_key_id: sea_orm::Set(rpc_key_id), @@ -333,6 +333,15 @@ impl OpenRequestHandle { ); } } + RequestErrorHandler::InfoLevel => { + info!( + rpc=%self.rpc, + %method, + ?params, + ?err, + "bad response", + ); + } RequestErrorHandler::TraceLevel => { trace!( rpc=%self.rpc, @@ -374,6 +383,7 @@ impl OpenRequestHandle { // TODO: do not unwrap! (doesn't matter much since we check method as a string above) let method: Method = Method::try_from_value(&method.to_string()).unwrap(); + // TODO: i don't think this prsing is correct match serde_json::from_value::(json!(params)) { Ok(params) => { // spawn saving to the database so we don't slow down the request