mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(cli): eth state cache args (#5664)
This commit is contained in:
@ -8,6 +8,10 @@ pub use network_args::{DiscoveryArgs, NetworkArgs};
|
||||
mod rpc_server_args;
|
||||
pub use rpc_server_args::RpcServerArgs;
|
||||
|
||||
/// RpcStateCacheArgs struct for configuring RPC state cache
|
||||
mod rpc_state_cache_args;
|
||||
pub use rpc_state_cache_args::RpcStateCacheArgs;
|
||||
|
||||
/// DebugArgs struct for debugging purposes
|
||||
mod debug_args;
|
||||
pub use debug_args::DebugArgs;
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
use crate::{
|
||||
args::{
|
||||
types::{MaxU32, ZeroAsNoneU64},
|
||||
GasPriceOracleArgs,
|
||||
GasPriceOracleArgs, RpcStateCacheArgs,
|
||||
},
|
||||
cli::{
|
||||
components::{RethNodeComponents, RethRpcComponents, RethRpcServerHandles},
|
||||
@ -23,13 +23,7 @@ use reth_provider::{
|
||||
EvmEnvProvider, HeaderProvider, StateProviderFactory,
|
||||
};
|
||||
use reth_rpc::{
|
||||
eth::{
|
||||
cache::{
|
||||
DEFAULT_BLOCK_CACHE_MAX_LEN, DEFAULT_ENV_CACHE_MAX_LEN, DEFAULT_RECEIPT_CACHE_MAX_LEN,
|
||||
},
|
||||
gas_oracle::GasPriceOracleConfig,
|
||||
RPC_DEFAULT_GAS_CAP,
|
||||
},
|
||||
eth::{cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig, RPC_DEFAULT_GAS_CAP},
|
||||
JwtError, JwtSecret,
|
||||
};
|
||||
use reth_rpc_builder::{
|
||||
@ -175,21 +169,13 @@ pub struct RpcServerArgs {
|
||||
)]
|
||||
pub rpc_gas_cap: u64,
|
||||
|
||||
/// State cache configuration.
|
||||
#[clap(flatten)]
|
||||
pub rpc_state_cache: RpcStateCacheArgs,
|
||||
|
||||
/// Gas price oracle configuration.
|
||||
#[clap(flatten)]
|
||||
pub gas_price_oracle: GasPriceOracleArgs,
|
||||
|
||||
/// Maximum number of block cache entries.
|
||||
#[arg(long, default_value_t = DEFAULT_BLOCK_CACHE_MAX_LEN)]
|
||||
pub block_cache_len: u32,
|
||||
|
||||
/// Maximum number of receipt cache entries.
|
||||
#[arg(long, default_value_t = DEFAULT_RECEIPT_CACHE_MAX_LEN)]
|
||||
pub receipt_cache_len: u32,
|
||||
|
||||
/// Maximum number of env cache entries.
|
||||
#[arg(long, default_value_t = DEFAULT_ENV_CACHE_MAX_LEN)]
|
||||
pub env_cache_len: u32,
|
||||
}
|
||||
|
||||
impl RpcServerArgs {
|
||||
@ -350,9 +336,19 @@ impl RethRpcConfig for RpcServerArgs {
|
||||
.max_blocks_per_filter(self.rpc_max_blocks_per_filter.unwrap_or_max())
|
||||
.max_logs_per_response(self.rpc_max_logs_per_response.unwrap_or_max() as usize)
|
||||
.rpc_gas_cap(self.rpc_gas_cap)
|
||||
.state_cache(self.state_cache_config())
|
||||
.gpo_config(self.gas_price_oracle_config())
|
||||
}
|
||||
|
||||
fn state_cache_config(&self) -> EthStateCacheConfig {
|
||||
EthStateCacheConfig {
|
||||
max_blocks: self.rpc_state_cache.max_blocks,
|
||||
max_receipts: self.rpc_state_cache.max_receipts,
|
||||
max_envs: self.rpc_state_cache.max_envs,
|
||||
max_concurrent_db_requests: self.rpc_state_cache.max_concurrent_db_requests,
|
||||
}
|
||||
}
|
||||
|
||||
fn rpc_max_request_size_bytes(&self) -> u32 {
|
||||
self.rpc_max_request_size.get().saturating_mul(1024 * 1024)
|
||||
}
|
||||
@ -487,9 +483,7 @@ impl Default for RpcServerArgs {
|
||||
rpc_max_logs_per_response: (constants::DEFAULT_MAX_LOGS_PER_RESPONSE as u64).into(),
|
||||
rpc_gas_cap: RPC_DEFAULT_GAS_CAP.into(),
|
||||
gas_price_oracle: GasPriceOracleArgs::default(),
|
||||
block_cache_len: DEFAULT_BLOCK_CACHE_MAX_LEN,
|
||||
receipt_cache_len: DEFAULT_RECEIPT_CACHE_MAX_LEN,
|
||||
env_cache_len: DEFAULT_ENV_CACHE_MAX_LEN,
|
||||
rpc_state_cache: RpcStateCacheArgs::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
54
bin/reth/src/args/rpc_state_cache_args.rs
Normal file
54
bin/reth/src/args/rpc_state_cache_args.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use clap::{builder::RangedU64ValueParser, Args};
|
||||
use reth_rpc::eth::cache::{
|
||||
DEFAULT_BLOCK_CACHE_MAX_LEN, DEFAULT_CONCURRENT_DB_REQUESTS, DEFAULT_ENV_CACHE_MAX_LEN,
|
||||
DEFAULT_RECEIPT_CACHE_MAX_LEN,
|
||||
};
|
||||
|
||||
/// Parameters to configure RPC state cache.
|
||||
#[derive(Debug, Clone, Args, PartialEq, Eq)]
|
||||
#[clap(next_help_heading = "RPC State Cache")]
|
||||
|
||||
pub struct RpcStateCacheArgs {
|
||||
/// Max number of blocks in cache.
|
||||
#[arg(
|
||||
long = "rpc-cache.max-blocks",
|
||||
default_value_t = DEFAULT_BLOCK_CACHE_MAX_LEN,
|
||||
value_parser = RangedU64ValueParser::<u32>::new().range(1..)
|
||||
)]
|
||||
pub max_blocks: u32,
|
||||
|
||||
/// Max number receipts in cache.
|
||||
#[arg(
|
||||
long = "rpc-cache.max-receipts",
|
||||
default_value_t = DEFAULT_RECEIPT_CACHE_MAX_LEN,
|
||||
value_parser = RangedU64ValueParser::<u32>::new().range(1..)
|
||||
)]
|
||||
pub max_receipts: u32,
|
||||
|
||||
/// Max number of bytes for cached env data.
|
||||
#[arg(
|
||||
long = "rpc-cache.max-envs",
|
||||
default_value_t = DEFAULT_ENV_CACHE_MAX_LEN,
|
||||
value_parser = RangedU64ValueParser::<u32>::new().range(1..)
|
||||
)]
|
||||
pub max_envs: u32,
|
||||
|
||||
/// Max number of concurrent database requests.
|
||||
#[arg(
|
||||
long = "rpc-cache.max-concurrent-db-requests",
|
||||
default_value_t = DEFAULT_CONCURRENT_DB_REQUESTS,
|
||||
value_parser = RangedU64ValueParser::<usize>::new().range(1..)
|
||||
)]
|
||||
pub max_concurrent_db_requests: usize,
|
||||
}
|
||||
|
||||
impl Default for RpcStateCacheArgs {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
max_blocks: DEFAULT_BLOCK_CACHE_MAX_LEN,
|
||||
max_receipts: DEFAULT_RECEIPT_CACHE_MAX_LEN,
|
||||
max_envs: DEFAULT_ENV_CACHE_MAX_LEN,
|
||||
max_concurrent_db_requests: DEFAULT_CONCURRENT_DB_REQUESTS,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,10 @@
|
||||
use alloy_rlp::Encodable;
|
||||
use reth_network::protocol::IntoRlpxSubProtocol;
|
||||
use reth_primitives::{Bytes, BytesMut};
|
||||
use reth_rpc::{eth::gas_oracle::GasPriceOracleConfig, JwtError, JwtSecret};
|
||||
use reth_rpc::{
|
||||
eth::{cache::EthStateCacheConfig, gas_oracle::GasPriceOracleConfig},
|
||||
JwtError, JwtSecret,
|
||||
};
|
||||
use reth_rpc_builder::{
|
||||
auth::AuthServerConfig, error::RpcError, EthConfig, IpcServerBuilder, RpcServerConfig,
|
||||
ServerBuilder, TransportRpcModuleConfig,
|
||||
@ -24,6 +27,9 @@ pub trait RethRpcConfig {
|
||||
/// The configured ethereum RPC settings.
|
||||
fn eth_config(&self) -> EthConfig;
|
||||
|
||||
/// Returns state cache configuration.
|
||||
fn state_cache_config(&self) -> EthStateCacheConfig;
|
||||
|
||||
/// Returns the max request size in bytes.
|
||||
fn rpc_max_request_size_bytes(&self) -> u32;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user