Skip to content

Commit 9cb2398

Browse files
committed
feat(engine): cli argument to disable state cache
1 parent 9712fe5 commit 9cb2398

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

crates/engine/primitives/src/config.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ pub struct TreeConfig {
8989
/// Whether to always compare trie updates from the state root task to the trie updates from
9090
/// the regular state root calculation.
9191
always_compare_trie_updates: bool,
92+
/// Whether to disable state cache.
93+
disable_state_cache: bool,
9294
/// Whether to disable parallel prewarming.
9395
disable_prewarming: bool,
9496
/// Whether to disable the parallel sparse trie state root algorithm.
@@ -143,6 +145,7 @@ impl Default for TreeConfig {
143145
max_execute_block_batch_size: DEFAULT_MAX_EXECUTE_BLOCK_BATCH_SIZE,
144146
legacy_state_root: false,
145147
always_compare_trie_updates: false,
148+
disable_state_cache: false,
146149
disable_prewarming: false,
147150
disable_parallel_sparse_trie: false,
148151
state_provider_metrics: false,
@@ -173,6 +176,7 @@ impl TreeConfig {
173176
max_execute_block_batch_size: usize,
174177
legacy_state_root: bool,
175178
always_compare_trie_updates: bool,
179+
disable_state_cache: bool,
176180
disable_prewarming: bool,
177181
disable_parallel_sparse_trie: bool,
178182
state_provider_metrics: bool,
@@ -197,6 +201,7 @@ impl TreeConfig {
197201
max_execute_block_batch_size,
198202
legacy_state_root,
199203
always_compare_trie_updates,
204+
disable_state_cache,
200205
disable_prewarming,
201206
disable_parallel_sparse_trie,
202207
state_provider_metrics,
@@ -271,7 +276,12 @@ impl TreeConfig {
271276
self.disable_parallel_sparse_trie
272277
}
273278

274-
/// Returns whether or not parallel prewarming should be used.
279+
/// Returns whether or not state cache is disabled.
280+
pub const fn disable_state_cache(&self) -> bool {
281+
self.disable_state_cache
282+
}
283+
284+
/// Returns whether or not parallel prewarming is disabled.
275285
pub const fn disable_prewarming(&self) -> bool {
276286
self.disable_prewarming
277287
}
@@ -363,6 +373,12 @@ impl TreeConfig {
363373
self
364374
}
365375

376+
/// Setter for whether to disable state cache.
377+
pub const fn without_state_cache(mut self, disable_state_cache: bool) -> Self {
378+
self.disable_state_cache = disable_state_cache;
379+
self
380+
}
381+
366382
/// Setter for whether to disable parallel prewarming.
367383
pub const fn without_prewarming(mut self, disable_prewarming: bool) -> Self {
368384
self.disable_prewarming = disable_prewarming;

crates/engine/tree/src/tree/payload_validator.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ where
353353
)
354354
.into())
355355
};
356-
let state_provider = ensure_ok!(provider_builder.build());
356+
let mut state_provider: Box<dyn StateProvider> =
357+
Box::new(ensure_ok!(provider_builder.build()));
357358
drop(_enter);
358359

359360
// fetch parent block
@@ -396,11 +397,13 @@ where
396397

397398
// Use cached state provider before executing, used in execution after prewarming threads
398399
// complete
399-
let state_provider = CachedStateProvider::new_with_caches(
400-
state_provider,
401-
handle.caches(),
402-
handle.cache_metrics(),
403-
);
400+
if !self.config.disable_state_cache() {
401+
state_provider = Box::new(CachedStateProvider::new_with_caches(
402+
state_provider,
403+
handle.caches(),
404+
handle.cache_metrics(),
405+
));
406+
};
404407

405408
// Execute the block and handle any execution errors
406409
let (output, senders) = match if self.config.state_provider_metrics() {

crates/node/core/src/args/engine.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub struct EngineArgs {
3535
#[deprecated]
3636
pub caching_and_prewarming_enabled: bool,
3737

38+
/// Disable state cache
39+
#[arg(long = "engine.disable-state-cache")]
40+
pub state_cache_disabled: bool,
41+
3842
/// Disable parallel prewarming
3943
#[arg(long = "engine.disable-prewarming", alias = "engine.disable-caching-and-prewarming")]
4044
pub prewarming_disabled: bool,
@@ -130,6 +134,7 @@ impl Default for EngineArgs {
130134
legacy_state_root_task_enabled: false,
131135
state_root_task_compare_updates: false,
132136
caching_and_prewarming_enabled: true,
137+
state_cache_disabled: false,
133138
prewarming_disabled: false,
134139
parallel_sparse_trie_enabled: true,
135140
parallel_sparse_trie_disabled: false,
@@ -157,6 +162,7 @@ impl EngineArgs {
157162
.with_persistence_threshold(self.persistence_threshold)
158163
.with_memory_block_buffer_target(self.memory_block_buffer_target)
159164
.with_legacy_state_root(self.legacy_state_root_task_enabled)
165+
.without_state_cache(self.state_cache_disabled)
160166
.without_prewarming(self.prewarming_disabled)
161167
.with_disable_parallel_sparse_trie(self.parallel_sparse_trie_disabled)
162168
.with_state_provider_metrics(self.state_provider_metrics)

docs/vocs/docs/pages/cli/op-reth/node.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,9 @@ Engine:
885885
--engine.legacy-state-root
886886
Enable legacy state root
887887
888+
--engine.disable-state-cache
889+
Disable state cache
890+
888891
--engine.disable-prewarming
889892
Disable parallel prewarming
890893

docs/vocs/docs/pages/cli/reth/node.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,9 @@ Engine:
885885
--engine.legacy-state-root
886886
Enable legacy state root
887887
888+
--engine.disable-state-cache
889+
Disable state cache
890+
888891
--engine.disable-prewarming
889892
Disable parallel prewarming
890893

0 commit comments

Comments
 (0)