From 2829ce7a7d1d553beab912591520a631cd14895b Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 16 Nov 2022 07:19:56 +0000 Subject: [PATCH] lint more --- TODO.md | 4 ++++ web3_proxy/src/frontend/errors.rs | 18 ++++++++++-------- web3_proxy/src/frontend/rpc_proxy_ws.rs | 13 ++++++++----- web3_proxy/src/rpcs/request.rs | 4 ++-- web3_proxy/src/rpcs/transactions.rs | 18 +++++++++--------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/TODO.md b/TODO.md index f766e094..7b0476ad 100644 --- a/TODO.md +++ b/TODO.md @@ -247,6 +247,10 @@ These are roughly in order of completition - [ ] tests should use `test-env-log = "0.2.8"` - [ ] weighted random choice should still prioritize non-archive servers - maybe shuffle randomly and then sort by (block_limit, random_index)? + - maybe sum available_requests grouped by archive/non-archive. only limit to non-archive if they have enough? +- [ ] cli commands to search users by key +- [ ] cli command to change user_tier by key +- [ ] change invite codes to set the user_tier - [ ] actually block unauthenticated requests instead of emitting warning of "allowing without auth during development!" diff --git a/web3_proxy/src/frontend/errors.rs b/web3_proxy/src/frontend/errors.rs index b72d4d55..5ec03a5f 100644 --- a/web3_proxy/src/frontend/errors.rs +++ b/web3_proxy/src/frontend/errors.rs @@ -11,7 +11,7 @@ use axum::{ use derive_more::From; use http::header::InvalidHeaderValue; use ipnet::AddrParseError; -use log::warn; +use log::{trace, warn}; use migration::sea_orm::DbErr; use redis_rate_limiter::redis::RedisError; use reqwest::header::ToStrError; @@ -185,15 +185,17 @@ impl IntoResponse for FrontendErrorResponse { return r; } Self::StatusCode(status_code, err_msg, err) => { - // TODO: warn is way too loud. different status codes should get different error levels. 500s should warn. 400s should stat - // trace!(?status_code, ?err_msg, ?err); + // different status codes should get different error levels. 500s should warn. 400s should stat + let code = status_code.as_u16(); + if (500..600).contains(&code) { + warn!("user error {} {:?}: {:?}", code, err_msg, err); + } else { + trace!("user error {} {:?}: {:?}", code, err_msg, err); + } + ( status_code, - JsonRpcForwardedResponse::from_str( - &err_msg, - Some(status_code.as_u16().into()), - None, - ), + JsonRpcForwardedResponse::from_str(&err_msg, Some(code.into()), None), ) } Self::HeaderToString(err) => { diff --git a/web3_proxy/src/frontend/rpc_proxy_ws.rs b/web3_proxy/src/frontend/rpc_proxy_ws.rs index 496ed682..e98877b0 100644 --- a/web3_proxy/src/frontend/rpc_proxy_ws.rs +++ b/web3_proxy/src/frontend/rpc_proxy_ws.rs @@ -21,7 +21,7 @@ use futures::{ use handlebars::Handlebars; use hashbrown::HashMap; use http::StatusCode; -use log::{error, info}; +use log::{error, info, trace}; use serde_json::{json, value::RawValue}; use std::sync::Arc; use std::{str::from_utf8_mut, sync::atomic::AtomicUsize}; @@ -276,9 +276,12 @@ async fn read_web3_socket( ) .await } - Message::Ping(x) => Message::Pong(x), + Message::Ping(x) => { + trace!("ping: {:?}", x); + Message::Pong(x) + } Message::Pong(x) => { - // // trace!("pong: {:?}", x); + trace!("pong: {:?}", x); continue; } Message::Close(_) => { @@ -324,8 +327,8 @@ async fn write_web3_socket( // forward the response to through the websocket if let Err(err) = ws_tx.send(msg).await { - // this isn't a problem. this is common and happens whenever a client disconnects - // trace!(?err, "unable to write to websocket"); + // this is common. it happens whenever a client disconnects + trace!("unable to write to websocket: {:?}", err); break; }; } diff --git a/web3_proxy/src/rpcs/request.rs b/web3_proxy/src/rpcs/request.rs index 314ca655..21c40b0d 100644 --- a/web3_proxy/src/rpcs/request.rs +++ b/web3_proxy/src/rpcs/request.rs @@ -8,7 +8,7 @@ use entities::revert_log; use entities::sea_orm_active_enums::Method; use ethers::providers::{HttpClientError, ProviderError, WsClientError}; use ethers::types::{Address, Bytes}; -use log::{debug, error, warn, Level}; +use log::{debug, error, trace, warn, Level}; use metered::metered; use metered::HitCount; use metered::ResponseTime; @@ -117,7 +117,7 @@ impl Authorization { // TODO: what log level? // TODO: better format - // trace!(?rl); + trace!("revert_log: {:?}", rl); // TODO: return something useful Ok(()) diff --git a/web3_proxy/src/rpcs/transactions.rs b/web3_proxy/src/rpcs/transactions.rs index 868ec855..88f4db9f 100644 --- a/web3_proxy/src/rpcs/transactions.rs +++ b/web3_proxy/src/rpcs/transactions.rs @@ -5,7 +5,7 @@ use super::connection::Web3Connection; use super::connections::Web3Connections; use super::request::OpenRequestResult; use ethers::prelude::{ProviderError, Transaction, TxHash}; -use log::{debug, Level}; +use log::{debug, trace, Level}; use std::sync::Arc; use tokio::sync::broadcast; @@ -43,12 +43,12 @@ impl Web3Connections { return Ok(None); } Err(err) => { - // trace!( - // ?pending_tx_id, - // ?rpc, - // ?err, - // "cancelled funneling transaction" - // ); + trace!( + "cancelled funneling transaction {} from {}: {:?}", + pending_tx_id, + rpc, + err, + ); return Ok(None); } }; @@ -94,14 +94,14 @@ impl Web3Connections { Ok(Some(tx_state)) => { let _ = pending_tx_sender.send(tx_state); - // trace!(?pending_tx_id, "sent"); + trace!("sent tx {:?}", pending_tx_id); // we sent the transaction. return now. don't break looping because that gives a warning return Ok(()); } Ok(None) => {} Err(err) => { - // trace!(?err, ?pending_tx_id, "failed fetching transaction"); + trace!("failed fetching transaction {:?}: {:?}", pending_tx_id, err); // unable to update the entry. sleep and try again soon // TODO: retry with exponential backoff with jitter starting from a much smaller time // sleep(Duration::from_millis(100)).await;