diff --git a/TODO.md b/TODO.md index c67e07d1..38281cb0 100644 --- a/TODO.md +++ b/TODO.md @@ -89,6 +89,7 @@ - [x] I'm hitting infura rate limits very quickly. I feel like that means something is very inefficient - whenever blocks were slow, we started checking as fast as possible - [x] create user script should allow setting requests per minute +- [x] cache api keys that are not in the database - [-] basic request method stats (using the user_id and other fields that are in the tracing frame) - [ ] use siwe messages and signatures for sign up and login - [ ] "chain is forked" message is wrong. it includes nodes just being on different heights of the same chain. need a smarter check @@ -254,7 +255,6 @@ in another repo: event subscriber eth_1 | 2022-08-10T23:26:10.195014Z WARN web3_proxy::connections: chain is forked! 262 possible heads. 1/2/5/5 rpcs have 0x0538…bfff eth_1 | 2022-08-10T23:26:10.195658Z WARN web3_proxy::connections: chain is forked! 262 possible heads. 2/3/5/5 rpcs have 0x0538…bfff - [ ] fix ip detection when running in dev -- [ ] cache api keys that are not in the database? - [ ] double check weight sorting code - [ ] sea-orm brings in async-std, but we are using tokio. benchmark switching - [ ] this query always times out, but erigon can serve it quickly: `curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"debug_traceBlockByNumber","params":["latest"],"id":1}' 127.0.0.1:8544' 127.0.0.1:8544` diff --git a/web3_proxy/src/frontend/rate_limit.rs b/web3_proxy/src/frontend/rate_limit.rs index c6511376..2cecbbc0 100644 --- a/web3_proxy/src/frontend/rate_limit.rs +++ b/web3_proxy/src/frontend/rate_limit.rs @@ -130,7 +130,12 @@ impl Web3ProxyApp { )) } None => { - return Err(anyhow::anyhow!("unknown api key")); + UserCacheValue::from(( + // TODO: how long should this cache last? get this from config + Instant::now() + Duration::from_secs(60), + 0, + 0, + )) } }; @@ -147,6 +152,10 @@ impl Web3ProxyApp { user_data.unwrap() }; + if user_data.user_id == 0 { + return Err(anyhow::anyhow!("unknown key!")); + } + // user key is valid. now check rate limits if let Some(rate_limiter) = &self.rate_limiter { if rate_limiter diff --git a/web3_proxy/src/frontend/users.rs b/web3_proxy/src/frontend/users.rs index d8bea264..092d669f 100644 --- a/web3_proxy/src/frontend/users.rs +++ b/web3_proxy/src/frontend/users.rs @@ -10,7 +10,7 @@ use super::{errors::anyhow_error_into_response, rate_limit::RateLimitResult}; use crate::app::Web3ProxyApp; use axum::{ - response::{IntoResponse, Response}, + response::{ErrorResponse, IntoResponse, Response}, Extension, Json, }; use axum_client_ip::ClientIp; @@ -22,8 +22,11 @@ use sea_orm::ActiveModelTrait; use serde::Deserialize; use std::sync::Arc; +// TODO: how do we customize axum's error response? I think we probably want an enum that implements IntoResponse instead #[debug_handler] -pub async fn get_login(Extension(app): Extension>) -> Result { +pub async fn get_login( + Extension(app): Extension>, +) -> Result { // let redis: RedisPool = app...; let redis_pool = app.redis_pool.as_ref().unwrap(); @@ -32,6 +35,7 @@ pub async fn get_login(Extension(app): Extension>) -> Result>, ClientIp(ip): ClientIp, @@ -56,6 +58,7 @@ pub async fn public_websocket_handler( } } +#[debug_handler] pub async fn user_websocket_handler( Extension(app): Extension>, Path(user_key): Path,