From dfb98ede2059886bf261c304a489bdad79250caf Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Sun, 15 May 2022 01:51:24 +0000 Subject: [PATCH] cleanup --- TODO.md | 4 ++-- web3-proxy/Cargo.toml | 2 +- web3-proxy/src/connection.rs | 12 +++++------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 5c6db3d0..90f37552 100644 --- a/TODO.md +++ b/TODO.md @@ -17,9 +17,9 @@ - maybe always try at least two servers in parallel? and then return the first? or only if the first one doesn't respond very quickly? - [ ] incoming rate limiting (by ip or by api key or what?) - [ ] improve caching - - [ ] if the params include a block, we can cache for longer + - [ ] if the eth_call (or similar) params include a block, we can cache for longer - [ ] if the call is something simple like "symbol" or "decimals", cache that too - - [ ] when we receive a block, we should store it for later eth_getBlockByNumber and similar calls + - [ ] when we receive a block, we should store it for later eth_getBlockByNumber, eth_blockNumber, and similar calls - [ ] measure latency to nodes? - [ ] one proxy for mulitple chains? - [ ] zero downtime deploys diff --git a/web3-proxy/Cargo.toml b/web3-proxy/Cargo.toml index 8698afac..bf7d034f 100644 --- a/web3-proxy/Cargo.toml +++ b/web3-proxy/Cargo.toml @@ -15,7 +15,7 @@ flume = "0.10.12" futures = { version = "0.3.21", features = ["thread-pool"] } governor = { version = "0.4.2", features = ["dashmap", "std"] } hashbrown = "0.12.1" -linkedhashmap = { path = "../linkedhashmap" } +linkedhashmap = { path = "../linkedhashmap", features = ["inline-more"] } parking_lot = "0.12.0" proctitle = "0.1.1" regex = "1.5.5" diff --git a/web3-proxy/src/connection.rs b/web3-proxy/src/connection.rs index 38b73a5a..dbbc21ad 100644 --- a/web3-proxy/src/connection.rs +++ b/web3-proxy/src/connection.rs @@ -68,6 +68,7 @@ impl Web3Connection { pub async fn try_new( chain_id: usize, url_str: String, + // optional because this is only used for http providers. websocket providers don't use it http_client: Option, hard_rate_limit: Option, clock: &QuantaClock, @@ -112,7 +113,7 @@ impl Web3Connection { let connection = Web3Connection { clock: clock.clone(), url: url_str.clone(), - active_requests: Default::default(), + active_requests: 0.into(), provider, ratelimiter: hard_rate_limiter, soft_limit, @@ -121,14 +122,11 @@ impl Web3Connection { let connection = Arc::new(connection); - // TODO: check the chain_id here + // check the server's chain_id here let active_request_handle = connection.wait_for_request_handle().await; - - // TODO: passing empty_params like this feels awkward. - let empty_params: Option<()> = None; - // TODO: some rpcs (on bsc and fantom) do not return an id + // TODO: some public rpcs (on bsc and fantom) do not return an id and so this ends up being an error let found_chain_id: Result = active_request_handle - .request("eth_chainId", empty_params) + .request("eth_chainId", Option::None::<()>) .await; match found_chain_id {