get rid of async recursion
This commit is contained in:
parent
6ccdb9e0cd
commit
a9d5006ced
12
Cargo.lock
generated
12
Cargo.lock
generated
@ -235,17 +235,6 @@ dependencies = [
|
|||||||
"event-listener",
|
"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]]
|
[[package]]
|
||||||
name = "async-stream"
|
name = "async-stream"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
@ -6595,7 +6584,6 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"arc-swap",
|
"arc-swap",
|
||||||
"argh",
|
"argh",
|
||||||
"async-recursion",
|
|
||||||
"async-stream",
|
"async-stream",
|
||||||
"async-stripe",
|
"async-stripe",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
|
@ -40,7 +40,6 @@ siwe = { git = "https://github.com/llamanodes/siwe-rs", branch = "for_web3_proxy
|
|||||||
anyhow = { version = "1.0.75", features = ["backtrace"] }
|
anyhow = { version = "1.0.75", features = ["backtrace"] }
|
||||||
arc-swap = { version = "1.6.0" }
|
arc-swap = { version = "1.6.0" }
|
||||||
argh = "0.1.12"
|
argh = "0.1.12"
|
||||||
async-recursion = "1.0.5"
|
|
||||||
async-stream = "0.3.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-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"
|
async-trait = "0.1.73"
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
//! Helper functions for turning ether's BlockNumber into numbers and updating incoming queries to match.
|
//! 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::app::Web3ProxyApp;
|
||||||
use crate::jsonrpc::JsonRpcRequest;
|
use crate::jsonrpc::JsonRpcRequest;
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -8,7 +6,6 @@ use crate::{
|
|||||||
rpcs::blockchain::Web3ProxyBlock,
|
rpcs::blockchain::Web3ProxyBlock,
|
||||||
};
|
};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use async_recursion::async_recursion;
|
|
||||||
use derive_more::From;
|
use derive_more::From;
|
||||||
use ethers::{
|
use ethers::{
|
||||||
prelude::{BlockNumber, U64},
|
prelude::{BlockNumber, U64},
|
||||||
@ -68,7 +65,6 @@ impl From<&Web3ProxyBlock> for BlockNumAndHash {
|
|||||||
|
|
||||||
/// modify params to always have a block hash and not "latest"
|
/// 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
|
/// 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>(
|
pub async fn clean_block_number<'a>(
|
||||||
params: &'a mut serde_json::Value,
|
params: &'a mut serde_json::Value,
|
||||||
block_param_id: usize,
|
block_param_id: usize,
|
||||||
@ -109,7 +105,8 @@ pub async fn clean_block_number<'a>(
|
|||||||
} else if let Some(app) = app {
|
} else if let Some(app) = app {
|
||||||
let block = app
|
let block = app
|
||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.block(&block_hash, None, None)
|
.blocks_by_hash
|
||||||
|
.get(&block_hash)
|
||||||
.await
|
.await
|
||||||
.context("fetching block number from hash")?;
|
.context("fetching block number from hash")?;
|
||||||
|
|
||||||
@ -142,7 +139,8 @@ pub async fn clean_block_number<'a>(
|
|||||||
// TODO: what should this max_wait be?
|
// TODO: what should this max_wait be?
|
||||||
let block = app
|
let block = app
|
||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.block(&block_hash, None, Some(Duration::from_secs(3)))
|
.blocks_by_hash
|
||||||
|
.get(&block_hash)
|
||||||
.await
|
.await
|
||||||
.context("fetching block number from hash")?;
|
.context("fetching block number from hash")?;
|
||||||
|
|
||||||
@ -173,15 +171,18 @@ pub async fn clean_block_number<'a>(
|
|||||||
if block_num == head_block_num {
|
if block_num == head_block_num {
|
||||||
(head_block.into(), changed)
|
(head_block.into(), changed)
|
||||||
} else if let Some(app) = app {
|
} 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
|
let block_hash = app
|
||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.block_hash(&block_num)
|
.blocks_by_number
|
||||||
|
.get(&block_num)
|
||||||
.await
|
.await
|
||||||
.context("fetching block hash from number")?;
|
.context("fetching block hash from number")?;
|
||||||
|
|
||||||
let block = app
|
let block = app
|
||||||
.balanced_rpcs
|
.balanced_rpcs
|
||||||
.block(&block_hash, None, None)
|
.blocks_by_hash
|
||||||
|
.get(&block_hash)
|
||||||
.await
|
.await
|
||||||
.context("fetching block from hash")?;
|
.context("fetching block from hash")?;
|
||||||
|
|
||||||
@ -269,17 +270,8 @@ impl CacheMode {
|
|||||||
warn!(
|
warn!(
|
||||||
method = %request.method,
|
method = %request.method,
|
||||||
params = ?request.params,
|
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) => {
|
Err(err) => {
|
||||||
error!(
|
error!(
|
||||||
@ -288,16 +280,17 @@ impl CacheMode {
|
|||||||
?err,
|
?err,
|
||||||
"could not get block from params. caching with head block"
|
"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(
|
pub async fn try_new(
|
||||||
|
@ -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?
|
/// TODO: this map is going to grow forever unless we do some sort of pruning. maybe store pruned in redis?
|
||||||
/// all blocks, including uncles
|
/// all blocks, including uncles
|
||||||
/// TODO: i think uncles should be excluded
|
/// TODO: i think uncles should be excluded
|
||||||
pub(super) blocks_by_hash: BlocksByHashCache,
|
pub(crate) blocks_by_hash: BlocksByHashCache,
|
||||||
/// blocks on the heaviest chain
|
/// 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)
|
/// the number of rpcs required to agree on consensus for the head block (thundering herd protection)
|
||||||
pub(super) min_synced_rpcs: usize,
|
pub(super) min_synced_rpcs: usize,
|
||||||
/// the soft limit required to agree on consensus for the head block. (thundering herd protection)
|
/// the soft limit required to agree on consensus for the head block. (thundering herd protection)
|
||||||
|
Loading…
Reference in New Issue
Block a user