lower log level and optional to

This commit is contained in:
Bryan Stitt 2023-06-28 21:08:43 -07:00
parent 342adb528d
commit 25b04db3b5
2 changed files with 23 additions and 12 deletions

View File

@ -515,7 +515,7 @@ impl Web3Rpc {
} }
} }
Err(err) => { 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 // send an empty block to take this server out of rotation
head_block_sender.send_replace(None); head_block_sender.send_replace(None);
@ -646,7 +646,8 @@ impl Web3Rpc {
let error_handler = if self.backup { let error_handler = if self.backup {
Some(RequestErrorHandler::DebugLevel) Some(RequestErrorHandler::DebugLevel)
} else { } else {
Some(RequestErrorHandler::ErrorLevel) // TODO: info level?
Some(RequestErrorHandler::InfoLevel)
}; };
if self.should_disconnect() { if self.should_disconnect() {

View File

@ -15,7 +15,7 @@ use serde_json::json;
use std::sync::atomic; use std::sync::atomic;
use std::sync::Arc; use std::sync::Arc;
use tokio::time::{Duration, Instant}; use tokio::time::{Duration, Instant};
use tracing::{debug, error, trace, warn, Level}; use tracing::{debug, error, info, trace, warn, Level};
#[derive(Debug, From)] #[derive(Debug, From)]
pub enum OpenRequestResult { pub enum OpenRequestResult {
@ -43,6 +43,8 @@ pub enum RequestErrorHandler {
TraceLevel, TraceLevel,
/// Log at the debug level. Use when errors are expected. /// Log at the debug level. Use when errors are expected.
DebugLevel, DebugLevel,
/// Log at the info level. Use when errors are expected.
InfoLevel,
/// Log at the error level. Use when errors are bad. /// Log at the error level. Use when errors are bad.
ErrorLevel, ErrorLevel,
/// Log at the warn level. Use when errors do not cause problems. /// Log at the warn level. Use when errors do not cause problems.
@ -57,18 +59,18 @@ struct EthCallParams((EthCallFirstParams, Option<serde_json::Value>));
#[derive(serde::Deserialize, serde::Serialize)] #[derive(serde::Deserialize, serde::Serialize)]
struct EthCallFirstParams { struct EthCallFirstParams {
to: Address, to: Option<Address>,
data: Option<Bytes>, data: Option<Bytes>,
} }
impl From<Level> for RequestErrorHandler { impl From<Level> for RequestErrorHandler {
fn from(level: Level) -> Self { fn from(level: Level) -> Self {
match level { match level {
Level::TRACE => RequestErrorHandler::TraceLevel,
Level::DEBUG => RequestErrorHandler::DebugLevel, Level::DEBUG => RequestErrorHandler::DebugLevel,
Level::ERROR => RequestErrorHandler::ErrorLevel, Level::ERROR => RequestErrorHandler::ErrorLevel,
Level::INFO => RequestErrorHandler::InfoLevel,
Level::TRACE => RequestErrorHandler::TraceLevel,
Level::WARN => RequestErrorHandler::WarnLevel, 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 // 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 // why? because we aggregate stats and setting one in the past could cause confusion
let timestamp = Utc::now(); let timestamp = Utc::now();
let to: Vec<u8> = params
.to let to = params.to.unwrap_or_else(Address::zero).as_bytes().to_vec();
.as_bytes()
.try_into() let call_data = params.data.map(|x| x.to_string());
.expect("address should always convert to a Vec<u8>");
let call_data = params.data.map(|x| format!("{}", x));
let rl = revert_log::ActiveModel { let rl = revert_log::ActiveModel {
rpc_key_id: sea_orm::Set(rpc_key_id), 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 => { RequestErrorHandler::TraceLevel => {
trace!( trace!(
rpc=%self.rpc, 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) // 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(); 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::<EthCallParams>(json!(params)) { match serde_json::from_value::<EthCallParams>(json!(params)) {
Ok(params) => { Ok(params) => {
// spawn saving to the database so we don't slow down the request // spawn saving to the database so we don't slow down the request