Skip to content
Open
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
10 changes: 10 additions & 0 deletions cmd/ethrex/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ pub struct Options {
env = "ETHREX_NO_MIGRATE"
)]
pub no_migrate: bool,
#[arg(
long = "no-precompile-cache",
action = ArgAction::SetTrue,
help = "Disable the per-block precompile result cache (benchmarking only).",
help_heading = "Node options",
env = "ETHREX_NO_PRECOMPILE_CACHE"
)]
pub no_precompile_cache: bool,
#[arg(
long = "log.dir",
value_name = "LOG_DIR",
Expand Down Expand Up @@ -450,6 +458,7 @@ impl Default for Options {
max_blobs_per_block: None,
precompute_witnesses: false,
no_migrate: false,
no_precompile_cache: false,
}
}
}
Expand Down Expand Up @@ -641,6 +650,7 @@ impl Subcommand {
BlockchainOptions {
r#type: blockchain_type,
perf_logs_enabled: true,
precompile_cache_enabled: !opts.no_precompile_cache,
..Default::default()
},
)
Expand Down
1 change: 1 addition & 0 deletions cmd/ethrex/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ pub async fn init_l1(
r#type: BlockchainType::L1,
max_blobs_per_block: opts.max_blobs_per_block,
precompute_witnesses: opts.precompute_witnesses,
precompile_cache_enabled: !opts.no_precompile_cache,
},
);

Expand Down
1 change: 1 addition & 0 deletions cmd/ethrex/l2/initializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub async fn init_l2(
perf_logs_enabled: true,
max_blobs_per_block: None, // L2 doesn't support blob transactions
precompute_witnesses: opts.node_opts.precompute_witnesses,
precompile_cache_enabled: true,
};

let blockchain = init_blockchain(store.clone(), blockchain_opts.clone());
Expand Down
10 changes: 8 additions & 2 deletions crates/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ pub struct BlockchainOptions {
pub max_blobs_per_block: Option<u32>,
/// If true, computes execution witnesses upon receiving newPayload messages and stores them in local storage
pub precompute_witnesses: bool,
/// If true (default), per-block execution caches precompile results between the
/// warmer thread and the executor. Set to false (via `--no-precompile-cache`) to
/// disable the cache for benchmarking purposes.
pub precompile_cache_enabled: bool,
Comment on lines +230 to +233
}

impl Default for BlockchainOptions {
Expand All @@ -237,6 +241,7 @@ impl Default for BlockchainOptions {
r#type: BlockchainType::default(),
max_blobs_per_block: None,
precompute_witnesses: false,
precompile_cache_enabled: true,
}
}
}
Expand Down Expand Up @@ -447,8 +452,9 @@ impl Blockchain {
// Wrap the store with CachingDatabase so both warming and execution
// can benefit from shared caching of state lookups
let original_store = vm.db.store.clone();
let caching_store: Arc<dyn ethrex_vm::backends::LevmDatabase> =
Arc::new(CachingDatabase::new(original_store));
let caching_store: Arc<dyn ethrex_vm::backends::LevmDatabase> = Arc::new(
CachingDatabase::new(original_store, self.options.precompile_cache_enabled),
);

// Replace the VM's store with the caching version
vm.db.store = caching_store.clone();
Expand Down
16 changes: 6 additions & 10 deletions crates/vm/levm/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,25 @@ pub struct CachingDatabase {
storage: RwLock<StorageCache>,
/// Cached contract code
code: RwLock<CodeCache>,
/// Shared precompile result cache (warmer populates, executor reuses)
precompile_cache: PrecompileCache,
/// Shared precompile result cache (warmer populates, executor reuses).
/// `None` when the cache is disabled via `BlockchainOptions::precompile_cache_enabled = false`.
precompile_cache: Option<PrecompileCache>,
/// Cached chain config (constant for the lifetime of this database)
chain_config: OnceLock<ChainConfig>,
}

impl CachingDatabase {
pub fn new(inner: Arc<dyn Database>) -> Self {
pub fn new(inner: Arc<dyn Database>, precompile_cache_enabled: bool) -> Self {
Self {
inner,
accounts: RwLock::new(FxHashMap::default()),
storage: RwLock::new(FxHashMap::default()),
Comment on lines +69 to 73
code: RwLock::new(FxHashMap::default()),
precompile_cache: PrecompileCache::new(),
precompile_cache: precompile_cache_enabled.then(PrecompileCache::new),
chain_config: OnceLock::new(),
}
}

/// Access the shared precompile result cache.
pub fn precompile_cache(&self) -> &PrecompileCache {
&self.precompile_cache
}

fn read_accounts(&self) -> Result<RwLockReadGuard<'_, AccountCache>, DatabaseError> {
self.accounts.read().map_err(poison_error_to_db_error)
}
Expand Down Expand Up @@ -180,7 +176,7 @@ impl Database for CachingDatabase {
}

fn precompile_cache(&self) -> Option<&PrecompileCache> {
Some(&self.precompile_cache)
self.precompile_cache.as_ref()
}

fn prefetch_accounts(&self, addresses: &[Address]) -> Result<(), DatabaseError> {
Expand Down
Loading