From ceb202b53c71c242d1d8c255ed2383549906c0cb Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 12 Sep 2023 13:35:51 -0700 Subject: [PATCH] allow the string 'Archive' when setting block data limit --- config/example.toml | 6 ++++++ web3_proxy/src/config.rs | 28 +++++++++++++++++++++++++++- web3_proxy/src/rpcs/one.rs | 2 +- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/config/example.toml b/config/example.toml index 9c98171a..a74995d8 100644 --- a/config/example.toml +++ b/config/example.toml @@ -66,6 +66,12 @@ response_cache_max_bytes = 10_000_000_000 [balanced_rpcs] + [balanced_rpcs.llamanodes] + display_name = "LlamaNodes" + block_data_limit = "Archive" + http_url = "https://ethereum.llamarpc.com" + ws_url = "wss://ethereum.llamarpc.com" + [balanced_rpcs.ankr] display_name = "Ankr" http_url = "https://rpc.ankr.com/eth" diff --git a/web3_proxy/src/config.rs b/web3_proxy/src/config.rs index c4bb6917..c2817fda 100644 --- a/web3_proxy/src/config.rs +++ b/web3_proxy/src/config.rs @@ -3,6 +3,7 @@ use crate::compute_units::default_usd_per_cu; use crate::rpcs::blockchain::{BlocksByHashCache, Web3ProxyBlock}; use crate::rpcs::one::Web3Rpc; use argh::FromArgs; +use derivative::Derivative; use ethers::prelude::{Address, TxHash}; use ethers::types::{U256, U64}; use hashbrown::HashMap; @@ -10,6 +11,7 @@ use migration::sea_orm::prelude::Decimal; use sentry::types::Dsn; use serde::Deserialize; use serde_inline_default::serde_inline_default; +use std::sync::atomic::AtomicU64; use std::sync::Arc; use std::time::Duration; use tokio::sync::mpsc; @@ -276,6 +278,29 @@ pub fn average_block_interval(chain_id: u64) -> Duration { } } +#[derive(Clone, Debug, Derivative, Deserialize, PartialEq, Eq)] +#[derivative(Default(bound = ""))] +pub enum BlockDataLimit { + /// archive nodes can return all data + Archive, + /// prune nodes don't have all the data + /// some devs will argue about what "prune" means but we use it to mean that any of the data is gone. + Limit(u64), + /// Automatically detect the limit + #[derivative(Default)] + Unknown, +} + +impl From for AtomicU64 { + fn from(value: BlockDataLimit) -> Self { + match value { + BlockDataLimit::Archive => AtomicU64::new(u64::MAX), + BlockDataLimit::Limit(limit) => AtomicU64::new(limit), + BlockDataLimit::Unknown => AtomicU64::new(0), + } + } +} + /// Configuration for a backend web3 RPC server #[serde_inline_default] #[derive(Clone, Debug, Deserialize, PartialEq, Eq)] @@ -290,7 +315,8 @@ pub struct Web3RpcConfig { /// while not absolutely required, a http:// or https:// connection will allow erigon to stream JSON pub http_url: Option, /// block data limit. If None, will be queried - pub block_data_limit: Option, + #[serde(default = "Default::default")] + pub block_data_limit: BlockDataLimit, /// the requests per second at which the server starts slowing down #[serde_inline_default(1u32)] pub soft_limit: u32, diff --git a/web3_proxy/src/rpcs/one.rs b/web3_proxy/src/rpcs/one.rs index 6dfec1aa..1313b31d 100644 --- a/web3_proxy/src/rpcs/one.rs +++ b/web3_proxy/src/rpcs/one.rs @@ -134,7 +134,7 @@ impl Web3Rpc { let backup = config.backup; - let block_data_limit: AtomicU64 = config.block_data_limit.unwrap_or_default().into(); + let block_data_limit: AtomicU64 = config.block_data_limit.into(); let automatic_block_limit = (block_data_limit.load(atomic::Ordering::Acquire) == 0) && block_and_rpc_sender.is_some();