Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): eth state cache args #5664

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/reth/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 17 additions & 23 deletions bin/reth/src/args/rpc_server_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
args::{
types::{MaxU32, ZeroAsNoneU64},
GasPriceOracleArgs,
GasPriceOracleArgs, RpcStateCacheArgs,
},
cli::{
components::{RethNodeComponents, RethRpcComponents, RethRpcServerHandles},
Expand All @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(),
}
}
}
Expand Down
54 changes: 54 additions & 0 deletions bin/reth/src/args/rpc_state_cache_args.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
8 changes: 7 additions & 1 deletion bin/reth/src/cli/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;

Expand Down