diff --git a/Cargo.lock b/Cargo.lock index 10533b9e..45f5d336 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -235,17 +235,6 @@ dependencies = [ "event-listener", ] -[[package]] -name = "async-recursion" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.38", -] - [[package]] name = "async-stream" version = "0.3.5" @@ -6595,7 +6584,6 @@ dependencies = [ "anyhow", "arc-swap", "argh", - "async-recursion", "async-stream", "async-stripe", "async-trait", diff --git a/web3_proxy/Cargo.toml b/web3_proxy/Cargo.toml index 3c88d628..2a9f45b2 100644 --- a/web3_proxy/Cargo.toml +++ b/web3_proxy/Cargo.toml @@ -40,7 +40,6 @@ siwe = { git = "https://github.com/llamanodes/siwe-rs", branch = "for_web3_proxy anyhow = { version = "1.0.75", features = ["backtrace"] } arc-swap = { version = "1.6.0" } argh = "0.1.12" -async-recursion = "1.0.5" async-stream = "0.3.5" async-stripe = { version = "0.25.2", default-features = false, features = ["billing", "checkout", "connect", "runtime-tokio-hyper-rustls", "webhook-events"], optional = true } async-trait = "0.1.73" diff --git a/web3_proxy/src/block_number.rs b/web3_proxy/src/block_number.rs index 54c7c849..2ed7578d 100644 --- a/web3_proxy/src/block_number.rs +++ b/web3_proxy/src/block_number.rs @@ -1,6 +1,4 @@ //! Helper functions for turning ether's BlockNumber into numbers and updating incoming queries to match. -use std::time::Duration; - use crate::app::Web3ProxyApp; use crate::jsonrpc::JsonRpcRequest; use crate::{ @@ -8,7 +6,6 @@ use crate::{ rpcs::blockchain::Web3ProxyBlock, }; use anyhow::Context; -use async_recursion::async_recursion; use derive_more::From; use ethers::{ prelude::{BlockNumber, U64}, @@ -68,7 +65,6 @@ impl From<&Web3ProxyBlock> for BlockNumAndHash { /// modify params to always have a block hash and not "latest" /// TODO: it would be nice to replace "latest" with the hash, but not all methods support that -#[async_recursion] pub async fn clean_block_number<'a>( params: &'a mut serde_json::Value, block_param_id: usize, @@ -109,7 +105,8 @@ pub async fn clean_block_number<'a>( } else if let Some(app) = app { let block = app .balanced_rpcs - .block(&block_hash, None, None) + .blocks_by_hash + .get(&block_hash) .await .context("fetching block number from hash")?; @@ -142,7 +139,8 @@ pub async fn clean_block_number<'a>( // TODO: what should this max_wait be? let block = app .balanced_rpcs - .block(&block_hash, None, Some(Duration::from_secs(3))) + .blocks_by_hash + .get(&block_hash) .await .context("fetching block number from hash")?; @@ -173,15 +171,18 @@ pub async fn clean_block_number<'a>( if block_num == head_block_num { (head_block.into(), changed) } else if let Some(app) = app { + // TODO: we used to make a query here, but thats causing problems with recursion now. come back to this let block_hash = app .balanced_rpcs - .block_hash(&block_num) + .blocks_by_number + .get(&block_num) .await .context("fetching block hash from number")?; let block = app .balanced_rpcs - .block(&block_hash, None, None) + .blocks_by_hash + .get(&block_hash) .await .context("fetching block from hash")?; @@ -269,17 +270,8 @@ impl CacheMode { warn!( method = %request.method, params = ?request.params, - "no servers available to get block from params. caching with head block" + "no servers available to get block from params but head block known. caching with head block" ); - if let Some(head_block) = head_block { - // TODO: strange to get NoBlocksKnown **and** have a head block. think about this more - CacheMode::Standard { - block: head_block.into(), - cache_errors: true, - } - } else { - CacheMode::Never - } } Err(err) => { error!( @@ -288,16 +280,17 @@ impl CacheMode { ?err, "could not get block from params. caching with head block" ); - if let Some(head_block) = head_block { - CacheMode::Standard { - block: head_block.into(), - cache_errors: true, - } - } else { - CacheMode::Never - } } } + + if let Some(head_block) = head_block { + CacheMode::Standard { + block: head_block.into(), + cache_errors: true, + } + } else { + CacheMode::Never + } } pub async fn try_new( diff --git a/web3_proxy/src/rpcs/many.rs b/web3_proxy/src/rpcs/many.rs index f4e63e30..c31984eb 100644 --- a/web3_proxy/src/rpcs/many.rs +++ b/web3_proxy/src/rpcs/many.rs @@ -50,9 +50,9 @@ pub struct Web3Rpcs { /// TODO: this map is going to grow forever unless we do some sort of pruning. maybe store pruned in redis? /// all blocks, including uncles /// TODO: i think uncles should be excluded - pub(super) blocks_by_hash: BlocksByHashCache, + pub(crate) blocks_by_hash: BlocksByHashCache, /// blocks on the heaviest chain - pub(super) blocks_by_number: BlocksByNumberCache, + pub(crate) blocks_by_number: BlocksByNumberCache, /// the number of rpcs required to agree on consensus for the head block (thundering herd protection) pub(super) min_synced_rpcs: usize, /// the soft limit required to agree on consensus for the head block. (thundering herd protection)