feat: Integrate cache config in rpc args (#2924)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
chirag-bgh
2023-05-31 18:48:25 +05:30
committed by GitHub
parent adffd0aac9
commit c4764d4f27
2 changed files with 45 additions and 6 deletions

View File

@ -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(

View File

@ -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<Result<Option<Block>>>;
@ -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,
}
}
}