diff --git a/bin/reth/src/args/rpc_server_args.rs b/bin/reth/src/args/rpc_server_args.rs index 4bcc67c86..99a4c1c1d 100644 --- a/bin/reth/src/args/rpc_server_args.rs +++ b/bin/reth/src/args/rpc_server_args.rs @@ -11,7 +11,16 @@ use reth_provider::{ BlockProviderIdExt, CanonStateSubscriptions, EvmEnvProvider, HeaderProvider, StateProviderFactory, }; -use reth_rpc::{eth::gas_oracle::GasPriceOracleConfig, JwtError, JwtSecret}; +use reth_rpc::{ + eth::{ + cache::{ + DEFAULT_BLOCK_CACHE_SIZE_BYTES_MB, DEFAULT_ENV_CACHE_SIZE_BYTES_MB, + DEFAULT_RECEIPT_CACHE_SIZE_BYTES_MB, + }, + gas_oracle::GasPriceOracleConfig, + }, + JwtError, JwtSecret, +}; use reth_rpc_builder::{ auth::{AuthServerConfig, AuthServerHandle}, constants, @@ -127,6 +136,18 @@ pub struct RpcServerArgs { /// Gas price oracle configuration. #[clap(flatten)] pub gas_price_oracle: GasPriceOracleArgs, + + /// Max size for cached block data in megabytes. + #[arg(long, default_value_t = DEFAULT_BLOCK_CACHE_SIZE_BYTES_MB)] + pub block_cache_size: usize, + + /// Max size for cached receipt data in megabytes. + #[arg(long, default_value_t = DEFAULT_RECEIPT_CACHE_SIZE_BYTES_MB)] + pub receipt_cache_size: usize, + + /// Max size for cached evm env data in megabytes. + #[arg(long, default_value_t = DEFAULT_ENV_CACHE_SIZE_BYTES_MB)] + pub env_cache_size: usize, } impl RpcServerArgs { @@ -140,6 +161,21 @@ impl RpcServerArgs { self.rpc_max_response_size * 1024 * 1024 } + /// Returns the max number of bytes for cached block data in bytes + pub fn block_cache_size_bytes(&self) -> usize { + self.block_cache_size * 1024 * 1024 + } + + /// Returns the max number of bytes for cached receipt data in bytes + pub fn receipt_cache_size_bytes(&self) -> usize { + self.receipt_cache_size * 1024 * 1024 + } + + /// Returns the max number of bytes for cached evm env data in bytes + pub fn env_cache_size_bytes(&self) -> usize { + self.env_cache_size * 1024 * 1024 + } + /// Extracts the gas price oracle config from the args. pub fn gas_price_oracle_config(&self) -> GasPriceOracleConfig { GasPriceOracleConfig::new( diff --git a/crates/rpc/rpc/src/eth/cache.rs b/crates/rpc/rpc/src/eth/cache.rs index fe14fa2e1..0ac644b17 100644 --- a/crates/rpc/rpc/src/eth/cache.rs +++ b/crates/rpc/rpc/src/eth/cache.rs @@ -24,10 +24,13 @@ use tokio_stream::wrappers::UnboundedReceiverStream; /// Default cache size for the block cache: 500MB /// /// With an average block size of ~100kb this should be able to cache ~5000 blocks. -const DEFAULT_BLOCK_CACHE_SIZE_BYTES: usize = 500 * 1024 * 1024; +pub const DEFAULT_BLOCK_CACHE_SIZE_BYTES_MB: usize = 500; /// Default cache size for the receipts cache: 500MB -const DEFAULT_RECEIPT_CACHE_SIZE_BYTES: usize = 500 * 1024 * 1024; +pub const DEFAULT_RECEIPT_CACHE_SIZE_BYTES_MB: usize = 500; + +/// Default cache size for the env cache: 1MB +pub const DEFAULT_ENV_CACHE_SIZE_BYTES_MB: usize = 1; /// The type that can send the response to a requested [Block] type BlockResponseSender = oneshot::Sender>>; @@ -73,9 +76,9 @@ pub struct EthStateCacheConfig { impl Default for EthStateCacheConfig { fn default() -> Self { Self { - max_block_bytes: DEFAULT_BLOCK_CACHE_SIZE_BYTES, - max_receipt_bytes: DEFAULT_RECEIPT_CACHE_SIZE_BYTES, - max_env_bytes: 1024 * 1024, + max_block_bytes: DEFAULT_BLOCK_CACHE_SIZE_BYTES_MB * 1024 * 1024, + max_receipt_bytes: DEFAULT_RECEIPT_CACHE_SIZE_BYTES_MB * 1024 * 1024, + max_env_bytes: DEFAULT_ENV_CACHE_SIZE_BYTES_MB * 1024 * 1024, } } }