From 6766f5342219253effcbc610c70645ce577e48f6 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Thu, 11 Aug 2022 02:57:01 +0000 Subject: [PATCH] make it work inside and outside docker --- TODO.md | 1 + docker-compose.yml | 2 +- web3_proxy/src/connection.rs | 2 +- web3_proxy/src/frontend/mod.rs | 18 +++++++++++++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 8dfd5529..18325eca 100644 --- a/TODO.md +++ b/TODO.md @@ -92,6 +92,7 @@ - [ ] active requests on /status is always 0 even when i'm running requests through - [ ] redis cell is giving errors under high load. maybe replace with https://redis.com/redis-best-practices/basic-rate-limiting/ - [ ] cli tool for resetting api keys +- [ ] cli tool for checking config - [ ] nice output when cargo doc is run - [ ] if we request an old block, more servers can handle it than we currently use. - [ ] instead of the one list of just heads, store our intermediate mappings (rpcs_by_hash, rpcs_by_num, blocks_by_hash) in SyncedConnections. this shouldn't be too much slower than what we have now diff --git a/docker-compose.yml b/docker-compose.yml index fcb35791..ff9f889d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -33,4 +33,4 @@ services: volumes: - ./config/example.toml:/config.toml ports: - - 127.0.0.1:8544:8544 + - 8544:8544 diff --git a/web3_proxy/src/connection.rs b/web3_proxy/src/connection.rs index 6f59d1ac..763c0446 100644 --- a/web3_proxy/src/connection.rs +++ b/web3_proxy/src/connection.rs @@ -560,7 +560,7 @@ impl Web3Connection { // TODO: periodically check for listeners. if no one is subscribed, unsubscribe and wait for a subscription } - warn!("subscription ended"); + warn!(?self, "subscription ended"); } } } diff --git a/web3_proxy/src/frontend/mod.rs b/web3_proxy/src/frontend/mod.rs index 5562a1a6..0a3b5a32 100644 --- a/web3_proxy/src/frontend/mod.rs +++ b/web3_proxy/src/frontend/mod.rs @@ -39,11 +39,23 @@ pub async fn serve(port: u16, proxy_app: Arc) -> anyhow::Result<() let addr = SocketAddr::from(([0, 0, 0, 0], port)); info!("listening on port {}", port); // TODO: into_make_service is enough if we always run behind a proxy. make into_make_service_with_connect_info optional? + + /* + It sequentially looks for an IP in: + - x-forwarded-for header (de-facto standard) + - x-real-ip header + - forwarded header (new standard) + - axum::extract::ConnectInfo (if not behind proxy) + + So we probably won't need into_make_service_with_connect_info, but it shouldn't hurt + */ + let service = app.into_make_service_with_connect_info::(); + // let service = app.into_make_service(); + axum::Server::bind(&addr) // TODO: option to use with_connect_info. we want it in dev, but not when running behind a proxy, but not - .serve(app.into_make_service_with_connect_info::()) - .with_graceful_shutdown(signal_shutdown()) - // .serve(app.into_make_service()) + .serve(service) + .with_graceful_shutdown(async { signal_shutdown().await }) .await .map_err(Into::into) }