From 44365d7b39637e13e2aee0e89858368f7f87cb94 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Wed, 10 Aug 2022 06:22:49 +0000 Subject: [PATCH] polish small things while reading through the code --- web3_proxy/src/bin/web3_proxy.rs | 2 +- web3_proxy/src/frontend/mod.rs | 4 +++- web3_proxy/src/frontend/rate_limit.rs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/web3_proxy/src/bin/web3_proxy.rs b/web3_proxy/src/bin/web3_proxy.rs index de0ab1f4..1b4304b7 100644 --- a/web3_proxy/src/bin/web3_proxy.rs +++ b/web3_proxy/src/bin/web3_proxy.rs @@ -72,7 +72,7 @@ fn run( rt.block_on(async { let (app, app_handle) = Web3ProxyApp::spawn(app_config, num_workers).await?; - let frontend_handle = tokio::spawn(frontend::run(cli_config.port, app)); + let frontend_handle = tokio::spawn(frontend::serve(cli_config.port, app)); // if everything is working, these should both run forever // TODO: try_join these instead? use signal_shutdown here? diff --git a/web3_proxy/src/frontend/mod.rs b/web3_proxy/src/frontend/mod.rs index f9767bdf..5562a1a6 100644 --- a/web3_proxy/src/frontend/mod.rs +++ b/web3_proxy/src/frontend/mod.rs @@ -17,7 +17,8 @@ use tracing::info; use crate::app::Web3ProxyApp; -pub async fn run(port: u16, proxy_app: Arc) -> anyhow::Result<()> { +/// +pub async fn serve(port: u16, proxy_app: Arc) -> anyhow::Result<()> { // build our application with a route // order most to least common let app = Router::new() @@ -50,6 +51,7 @@ pub async fn run(port: u16, proxy_app: Arc) -> anyhow::Result<()> /// Tokio signal handler that will wait for a user to press CTRL+C. /// We use this in our hyper `Server` method `with_graceful_shutdown`. async fn signal_shutdown() { + info!("ctrl-c to quit"); tokio::signal::ctrl_c() .await .expect("expect tokio signal ctrl-c"); diff --git a/web3_proxy/src/frontend/rate_limit.rs b/web3_proxy/src/frontend/rate_limit.rs index c55d096b..89455e0e 100644 --- a/web3_proxy/src/frontend/rate_limit.rs +++ b/web3_proxy/src/frontend/rate_limit.rs @@ -154,6 +154,7 @@ pub async fn handle_rate_limit_error_response( Ok(RateLimitResult::RateLimitExceeded) => Some(handle_anyhow_error( Some(StatusCode::TOO_MANY_REQUESTS), None, + // TODO: how can we attach context here? maybe add a request id tracing field? anyhow::anyhow!("rate limit exceeded"), )), Ok(RateLimitResult::UnknownKey) => Some(handle_anyhow_error(