Skip to main content

reth_node_core/args/
engine.rs

1//! clap [`Args`] for engine purposes.
2
3use clap::{
4    builder::{RangedU64ValueParser, Resettable},
5    Args,
6};
7use eyre::ensure;
8use reth_cli_util::{
9    parse_duration_from_secs_or_ms,
10    parsers::{format_duration_as_secs_or_ms, parse_duration},
11};
12use reth_engine_primitives::{
13    TreeConfig, DEFAULT_BACKFILL_RUN_THRESHOLD, DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD,
14    DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE, DEFAULT_NUM_STATE_MASKING_BLOCKS,
15    MIN_PERSISTENCE_BACKPRESSURE_THRESHOLD,
16};
17use std::{num::NonZeroUsize, sync::OnceLock, time::Duration};
18
19use crate::node_config::{
20    DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB, DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
21    DEFAULT_PERSISTENCE_THRESHOLD, DEFAULT_RESERVED_CPU_CORES,
22};
23
24/// Global static engine defaults
25static ENGINE_DEFAULTS: OnceLock<DefaultEngineValues> = OnceLock::new();
26
27/// Default values for engine that can be customized
28///
29/// Global defaults can be set via [`DefaultEngineValues::try_init`].
30#[derive(Debug, Clone)]
31pub struct DefaultEngineValues {
32    persistence_threshold: u64,
33    persistence_backpressure_threshold: u64,
34    num_state_masking_blocks: u64,
35    memory_block_buffer_target: u64,
36    backfill_run_threshold: u64,
37    invalid_header_hit_eviction_threshold: u8,
38    state_cache_disabled: bool,
39    prewarming_disabled: bool,
40    txpool_prewarming_enabled: bool,
41    sender_recovery_cache_enabled: bool,
42    state_provider_metrics: bool,
43    cross_block_cache_size: usize,
44    accept_execution_requests_hash: bool,
45    multiproof_chunk_size: usize,
46    reserved_cpu_cores: usize,
47    precompile_cache_disabled: bool,
48    state_root_fallback: bool,
49    always_process_payload_attributes_on_canonical_head: bool,
50    allow_unwind_canonical_header: bool,
51    storage_worker_count: Option<usize>,
52    account_worker_count: Option<usize>,
53    prewarming_threads: Option<usize>,
54    cache_metrics_disabled: bool,
55    slow_block_threshold: Option<Duration>,
56    disable_sparse_trie_cache_pruning: bool,
57    state_root_task_timeout: Option<String>,
58    share_execution_cache_with_payload_builder: bool,
59    share_sparse_trie_with_payload_builder: bool,
60    suppress_persistence_during_build: bool,
61    bal_parallel_execution_disabled: bool,
62    bal_parallel_state_root_disabled: bool,
63}
64
65impl DefaultEngineValues {
66    /// Initialize the global engine defaults with this configuration
67    pub fn try_init(self) -> Result<(), Self> {
68        ENGINE_DEFAULTS.set(self)
69    }
70
71    /// Get a reference to the global engine defaults
72    pub fn get_global() -> &'static Self {
73        ENGINE_DEFAULTS.get_or_init(Self::default)
74    }
75
76    /// Set the default persistence threshold
77    pub const fn with_persistence_threshold(mut self, v: u64) -> Self {
78        self.persistence_threshold = v;
79        self
80    }
81
82    /// Set the minimum default persistence backpressure threshold.
83    pub const fn with_persistence_backpressure_threshold(mut self, v: u64) -> Self {
84        self.persistence_backpressure_threshold = v;
85        self
86    }
87
88    /// Set the default number of state masking blocks.
89    pub const fn with_num_state_masking_blocks(mut self, v: u64) -> Self {
90        self.num_state_masking_blocks = v;
91        self
92    }
93
94    /// Set the default memory block buffer target
95    pub const fn with_memory_block_buffer_target(mut self, v: u64) -> Self {
96        self.memory_block_buffer_target = v;
97        self
98    }
99
100    /// Set the default backfill run threshold
101    pub const fn with_backfill_run_threshold(mut self, v: u64) -> Self {
102        self.backfill_run_threshold = v;
103        self
104    }
105
106    /// Set the invalid header cache hit eviction threshold
107    pub const fn with_invalid_header_hit_eviction_threshold(mut self, v: u8) -> Self {
108        self.invalid_header_hit_eviction_threshold = v;
109        self
110    }
111
112    /// Set whether to disable state cache by default
113    pub const fn with_state_cache_disabled(mut self, v: bool) -> Self {
114        self.state_cache_disabled = v;
115        self
116    }
117
118    /// Set whether to disable prewarming by default
119    pub const fn with_prewarming_disabled(mut self, v: bool) -> Self {
120        self.prewarming_disabled = v;
121        self
122    }
123
124    /// Set whether to enable txpool prewarming by default
125    pub const fn with_txpool_prewarming_enabled(mut self, v: bool) -> Self {
126        self.txpool_prewarming_enabled = v;
127        self
128    }
129
130    /// Set whether to enable sender recovery caching by default
131    pub const fn with_sender_recovery_cache_enabled(mut self, v: bool) -> Self {
132        self.sender_recovery_cache_enabled = v;
133        self
134    }
135
136    /// Set whether to enable state provider metrics by default
137    pub const fn with_state_provider_metrics(mut self, v: bool) -> Self {
138        self.state_provider_metrics = v;
139        self
140    }
141
142    /// Set the default cross-block cache size in MB
143    pub const fn with_cross_block_cache_size(mut self, v: usize) -> Self {
144        self.cross_block_cache_size = v;
145        self
146    }
147
148    /// Set whether to accept execution requests hash by default
149    pub const fn with_accept_execution_requests_hash(mut self, v: bool) -> Self {
150        self.accept_execution_requests_hash = v;
151        self
152    }
153
154    /// Set the default multiproof chunk size
155    pub const fn with_multiproof_chunk_size(mut self, v: usize) -> Self {
156        self.multiproof_chunk_size = v;
157        self
158    }
159
160    /// Set the default number of reserved CPU cores
161    pub const fn with_reserved_cpu_cores(mut self, v: usize) -> Self {
162        self.reserved_cpu_cores = v;
163        self
164    }
165
166    /// Set whether to disable precompile cache by default
167    pub const fn with_precompile_cache_disabled(mut self, v: bool) -> Self {
168        self.precompile_cache_disabled = v;
169        self
170    }
171
172    /// Set whether to enable state root fallback by default
173    pub const fn with_state_root_fallback(mut self, v: bool) -> Self {
174        self.state_root_fallback = v;
175        self
176    }
177
178    /// Set whether to always process payload attributes on canonical head by default
179    pub const fn with_always_process_payload_attributes_on_canonical_head(
180        mut self,
181        v: bool,
182    ) -> Self {
183        self.always_process_payload_attributes_on_canonical_head = v;
184        self
185    }
186
187    /// Set whether to allow unwinding canonical header by default
188    pub const fn with_allow_unwind_canonical_header(mut self, v: bool) -> Self {
189        self.allow_unwind_canonical_header = v;
190        self
191    }
192
193    /// Set the default storage worker count
194    pub const fn with_storage_worker_count(mut self, v: Option<usize>) -> Self {
195        self.storage_worker_count = v;
196        self
197    }
198
199    /// Set the default account worker count
200    pub const fn with_account_worker_count(mut self, v: Option<usize>) -> Self {
201        self.account_worker_count = v;
202        self
203    }
204
205    /// Set the default prewarming thread count
206    pub const fn with_prewarming_threads(mut self, v: Option<usize>) -> Self {
207        self.prewarming_threads = v;
208        self
209    }
210
211    /// Set whether to disable cache metrics by default
212    pub const fn with_cache_metrics_disabled(mut self, v: bool) -> Self {
213        self.cache_metrics_disabled = v;
214        self
215    }
216
217    /// Set the default slow block threshold.
218    pub const fn with_slow_block_threshold(mut self, v: Option<Duration>) -> Self {
219        self.slow_block_threshold = v;
220        self
221    }
222
223    /// Set whether to disable sparse trie cache pruning by default
224    pub const fn with_disable_sparse_trie_cache_pruning(mut self, v: bool) -> Self {
225        self.disable_sparse_trie_cache_pruning = v;
226        self
227    }
228
229    /// Set the default state root task timeout
230    pub fn with_state_root_task_timeout(mut self, v: Option<String>) -> Self {
231        self.state_root_task_timeout = v;
232        self
233    }
234
235    /// Set whether to share the execution cache with the payload builder by default
236    pub const fn with_share_execution_cache_with_payload_builder(mut self, v: bool) -> Self {
237        self.share_execution_cache_with_payload_builder = v;
238        self
239    }
240
241    /// Set whether to share the sparse trie with the payload builder by default
242    pub const fn with_share_sparse_trie_with_payload_builder(mut self, v: bool) -> Self {
243        self.share_sparse_trie_with_payload_builder = v;
244        self
245    }
246
247    /// Set whether to suppress persistence during payload building by default
248    pub const fn with_suppress_persistence_during_build(mut self, v: bool) -> Self {
249        self.suppress_persistence_during_build = v;
250        self
251    }
252
253    /// Set whether to disable BAL-based parallel execution by default
254    pub const fn with_bal_parallel_execution_disabled(mut self, v: bool) -> Self {
255        self.bal_parallel_execution_disabled = v;
256        self
257    }
258
259    /// Set whether to disable BAL-driven parallel state root by default
260    pub const fn with_bal_parallel_state_root_disabled(mut self, v: bool) -> Self {
261        self.bal_parallel_state_root_disabled = v;
262        self
263    }
264}
265
266impl Default for DefaultEngineValues {
267    fn default() -> Self {
268        Self {
269            persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
270            persistence_backpressure_threshold: MIN_PERSISTENCE_BACKPRESSURE_THRESHOLD,
271            num_state_masking_blocks: DEFAULT_NUM_STATE_MASKING_BLOCKS,
272            memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
273            backfill_run_threshold: DEFAULT_BACKFILL_RUN_THRESHOLD,
274            invalid_header_hit_eviction_threshold: DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD,
275            state_cache_disabled: false,
276            prewarming_disabled: false,
277            txpool_prewarming_enabled: false,
278            sender_recovery_cache_enabled: true,
279            state_provider_metrics: false,
280            cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB,
281            accept_execution_requests_hash: false,
282            multiproof_chunk_size: DEFAULT_MULTIPROOF_TASK_CHUNK_SIZE,
283            reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
284            precompile_cache_disabled: false,
285            state_root_fallback: false,
286            always_process_payload_attributes_on_canonical_head: false,
287            allow_unwind_canonical_header: false,
288            storage_worker_count: None,
289            account_worker_count: None,
290            prewarming_threads: None,
291            cache_metrics_disabled: false,
292            slow_block_threshold: None,
293            disable_sparse_trie_cache_pruning: false,
294            state_root_task_timeout: Some("4s".to_string()),
295            share_execution_cache_with_payload_builder: false,
296            share_sparse_trie_with_payload_builder: false,
297            suppress_persistence_during_build: false,
298            bal_parallel_execution_disabled: false,
299            bal_parallel_state_root_disabled: false,
300        }
301    }
302}
303
304fn default_persistence_backpressure_threshold(persistence_threshold: u64) -> u64 {
305    DefaultEngineValues::get_global()
306        .persistence_backpressure_threshold
307        .max(persistence_threshold.saturating_mul(2))
308}
309
310/// Parameters for configuring the engine driver.
311#[derive(Debug, Clone, Args, PartialEq, Eq)]
312#[command(next_help_heading = "Engine")]
313pub struct EngineArgs {
314    /// Configure persistence threshold for the engine. This determines how many canonical blocks
315    /// must be in-memory, ahead of the last persisted block, before flushing canonical blocks to
316    /// disk again.
317    ///
318    /// To persist blocks as fast as the node receives them, set this value to zero. This disables
319    /// state masking and causes more frequent DB writes.
320    #[arg(
321        long = "engine.persistence-threshold",
322        env = "RETH_ENGINE_PERSISTENCE_THRESHOLD",
323        default_value_t = DefaultEngineValues::get_global().persistence_threshold
324    )]
325    pub persistence_threshold: u64,
326
327    /// Configure the maximum number of blocks beyond the in-memory buffer target that may await
328    /// persistence before engine API processing stalls.
329    ///
330    /// If omitted, this defaults to the larger of the minimum backpressure threshold and twice
331    /// `--engine.persistence-threshold`.
332    ///
333    /// This value must be greater than `--engine.persistence-threshold`.
334    #[arg(long = "engine.persistence-backpressure-threshold")]
335    pub persistence_backpressure_threshold: Option<u64>,
336
337    /// Configure how many of the blocks being persisted should only mask state/trie
338    /// writes instead of durably persisting their state/trie updates in the current cycle.
339    #[arg(
340        long = "engine.num-state-masking-blocks",
341        env = "RETH_ENGINE_NUM_STATE_MASKING_BLOCKS",
342        default_value_t = DefaultEngineValues::get_global().num_state_masking_blocks
343    )]
344    pub num_state_masking_blocks: u64,
345
346    /// Configure how many of the most recent canonical blocks persistence leaves in memory.
347    ///
348    /// When more than `--engine.persistence-threshold` canonical blocks are held in memory, the
349    /// engine writes the canonical chain to disk up to `head - memory-block-buffer-target`. The
350    /// blocks above that height are kept only in memory, so a reorg of them does not unwind the
351    /// database. With state masking enabled, the `--engine.num-state-masking-blocks` blocks below
352    /// that height also stay in memory until a later cycle persists their state/trie updates.
353    ///
354    /// This is also the in-memory buffer that `--engine.persistence-backpressure-threshold` is
355    /// measured from.
356    ///
357    /// If omitted, this defaults to the lesser of `--engine.persistence-threshold` and the
358    /// configured default memory block buffer target. The value must not exceed
359    /// `--engine.persistence-threshold`, and with state masking enabled, its sum with
360    /// `--engine.num-state-masking-blocks` must be less than `--engine.persistence-threshold`.
361    #[arg(long = "engine.memory-block-buffer-target")]
362    pub memory_block_buffer_target: Option<u64>,
363
364    /// Configure the largest gap, in blocks, between the local head and the forkchoice head that
365    /// is closed by downloading the missing blocks directly. Larger gaps trigger a full pipeline
366    /// (backfill) run instead.
367    ///
368    /// On chains with short block times a pipeline run may take longer than it takes the chain to
369    /// produce another gap of this size, in which case raising this value lets the node catch up
370    /// via live sync. Values above 1024 are clamped to the peer header response limit.
371    #[arg(
372        long = "engine.backfill-threshold",
373        env = "RETH_ENGINE_BACKFILL_THRESHOLD",
374        default_value_t = DefaultEngineValues::get_global().backfill_run_threshold
375    )]
376    pub backfill_run_threshold: u64,
377
378    /// Configure how many cache hits an invalid header can accumulate before it is evicted and
379    /// reprocessed.
380    ///
381    /// Set to `0` to effectively disable the cache because entries are evicted on the first
382    /// lookup.
383    #[arg(long = "engine.invalid-header-cache-hit-eviction-threshold", default_value_t = DefaultEngineValues::get_global().invalid_header_hit_eviction_threshold)]
384    pub invalid_header_hit_eviction_threshold: u8,
385
386    /// Disable state cache
387    #[arg(long = "engine.disable-state-cache", default_value_t = DefaultEngineValues::get_global().state_cache_disabled)]
388    pub state_cache_disabled: bool,
389
390    /// Disable parallel prewarming
391    #[arg(long = "engine.disable-prewarming", alias = "engine.disable-caching-and-prewarming", default_value_t = DefaultEngineValues::get_global().prewarming_disabled)]
392    pub prewarming_disabled: bool,
393
394    /// Enable best-effort txpool transaction prewarming between payloads.
395    #[arg(
396        long = "engine.txpool-prewarming",
397        env = "RETH_ENGINE_TXPOOL_PREWARMING",
398        default_value_t = DefaultEngineValues::get_global().txpool_prewarming_enabled
399    )]
400    pub txpool_prewarming_enabled: bool,
401
402    /// Cache recovered transaction senders across transaction ingress and payload execution.
403    ///
404    /// Enabled by default, use `--engine.sender-recovery-cache=false` to disable it.
405    #[arg(
406        long = "engine.sender-recovery-cache",
407        env = "RETH_ENGINE_SENDER_RECOVERY_CACHE",
408        default_value_t = DefaultEngineValues::get_global().sender_recovery_cache_enabled,
409        num_args = 0..=1,
410        default_missing_value = "true",
411    )]
412    pub sender_recovery_cache_enabled: bool,
413
414    /// Enable state provider latency metrics. This allows the engine to collect and report stats
415    /// about how long state provider calls took during execution, but this does introduce slight
416    /// overhead to state provider calls.
417    #[arg(long = "engine.state-provider-metrics", default_value_t = DefaultEngineValues::get_global().state_provider_metrics)]
418    pub state_provider_metrics: bool,
419
420    /// Configure the size of cross-block cache in megabytes
421    #[arg(long = "engine.cross-block-cache-size", default_value_t = DefaultEngineValues::get_global().cross_block_cache_size)]
422    pub cross_block_cache_size: usize,
423
424    /// Enables accepting requests hash instead of an array of requests in `engine_newPayloadV4`.
425    #[arg(long = "engine.accept-execution-requests-hash", default_value_t = DefaultEngineValues::get_global().accept_execution_requests_hash)]
426    pub accept_execution_requests_hash: bool,
427
428    /// Multiproof task chunk size for proof targets.
429    #[arg(long = "engine.multiproof-chunk-size", default_value_t = DefaultEngineValues::get_global().multiproof_chunk_size, value_parser = RangedU64ValueParser::<usize>::new().range(1..))]
430    pub multiproof_chunk_size: usize,
431
432    /// Configure the number of reserved CPU cores for non-reth processes
433    #[arg(long = "engine.reserved-cpu-cores", default_value_t = DefaultEngineValues::get_global().reserved_cpu_cores)]
434    pub reserved_cpu_cores: usize,
435
436    /// Override the available CPU count for node thread pools and parallel execution decisions.
437    /// Does not change CPU affinity. Explicit thread counts take precedence.
438    #[arg(long = "cpu-cores", value_name = "COUNT")]
439    pub cpu_cores: Option<NonZeroUsize>,
440
441    /// Disable precompile cache
442    #[arg(long = "engine.disable-precompile-cache", default_value_t = DefaultEngineValues::get_global().precompile_cache_disabled)]
443    pub precompile_cache_disabled: bool,
444
445    /// Enable state root fallback, useful for testing
446    #[arg(long = "engine.state-root-fallback", default_value_t = DefaultEngineValues::get_global().state_root_fallback)]
447    pub state_root_fallback: bool,
448
449    /// Always process payload attributes and begin a payload build process even if
450    /// `forkchoiceState.headBlockHash` is already the canonical head or an ancestor. See
451    /// `TreeConfig::always_process_payload_attributes_on_canonical_head` for more details.
452    ///
453    /// Note: This is a no-op on OP Stack.
454    #[arg(
455        long = "engine.always-process-payload-attributes-on-canonical-head",
456        default_value_t = DefaultEngineValues::get_global().always_process_payload_attributes_on_canonical_head
457    )]
458    pub always_process_payload_attributes_on_canonical_head: bool,
459
460    /// Allow unwinding canonical header to ancestor during forkchoice updates.
461    /// See `TreeConfig::unwind_canonical_header` for more details.
462    #[arg(long = "engine.allow-unwind-canonical-header", default_value_t = DefaultEngineValues::get_global().allow_unwind_canonical_header)]
463    pub allow_unwind_canonical_header: bool,
464
465    /// Configure the number of storage proof workers spawned for each block.
466    /// If not specified or zero, the count is derived from the block: 2x available parallelism,
467    /// halved for blocks with few transactions and doubled for blocks at or above 100M gas.
468    #[arg(long = "engine.storage-worker-count", default_value = Resettable::from(DefaultEngineValues::get_global().storage_worker_count.map(|v| v.to_string().into())))]
469    pub storage_worker_count: Option<usize>,
470
471    /// Configure the number of account proof workers spawned for each block.
472    /// If not specified or zero, the count is derived from the block the same way as for storage
473    /// workers.
474    #[arg(long = "engine.account-worker-count", default_value = Resettable::from(DefaultEngineValues::get_global().account_worker_count.map(|v| v.to_string().into())))]
475    pub account_worker_count: Option<usize>,
476
477    /// Configure the number of prewarming threads.
478    /// If not specified, defaults to available parallelism.
479    #[arg(long = "engine.prewarming-threads", default_value = Resettable::from(DefaultEngineValues::get_global().prewarming_threads.map(|v| v.to_string().into())))]
480    pub prewarming_threads: Option<usize>,
481
482    /// Disable cache metrics recording, which can take up to 50ms with large cached state.
483    #[arg(long = "engine.disable-cache-metrics", default_value_t = DefaultEngineValues::get_global().cache_metrics_disabled)]
484    pub cache_metrics_disabled: bool,
485
486    /// Configure the slow block logging threshold in milliseconds.
487    ///
488    /// When set, blocks that take longer than this threshold to execute will be logged
489    /// with detailed metrics including timing, state operations, and cache statistics.
490    ///
491    /// Set to 0 to log all blocks (useful for debugging/profiling).
492    ///
493    /// When not set, slow block logging is disabled (default).
494    #[arg(long = "engine.slow-block-threshold", value_parser = parse_duration_from_secs_or_ms, value_name = "DURATION", default_value = Resettable::from(DefaultEngineValues::get_global().slow_block_threshold.map(|threshold| format_duration_as_secs_or_ms(threshold).into())))]
495    pub slow_block_threshold: Option<Duration>,
496
497    /// Fully disable sparse trie cache pruning. When set, the cached sparse trie is preserved
498    /// without any node pruning or storage trie eviction between blocks. Useful for benchmarking
499    /// the effects of retaining the full trie cache.
500    #[arg(long = "engine.disable-sparse-trie-cache-pruning", default_value_t = DefaultEngineValues::get_global().disable_sparse_trie_cache_pruning)]
501    pub disable_sparse_trie_cache_pruning: bool,
502
503    /// Configure the timeout for the state root task before spawning a sequential fallback.
504    /// If the state root task takes longer than this, a sequential computation starts in
505    /// parallel and whichever finishes first is used.
506    ///
507    /// --engine.state-root-task-timeout 4s
508    /// --engine.state-root-task-timeout 400ms
509    ///
510    /// Set to 0s to disable.
511    #[arg(
512        long = "engine.state-root-task-timeout",
513        value_parser = parse_duration,
514        default_value = Resettable::from(DefaultEngineValues::get_global().state_root_task_timeout.as_ref().map(|v| v.as_str().into())),
515    )]
516    pub state_root_task_timeout: Option<Duration>,
517
518    /// Whether to share execution cache with the payload builder.
519    ///
520    /// When enabled, each payload job will get an instance of cross-block execution cache from the
521    /// engine.
522    ///
523    /// Note: this should only be enabled if node would not be requested to process any payloads in
524    /// parallel with payload building.
525    #[arg(
526        long = "engine.share-execution-cache-with-payload-builder",
527        default_value_t = DefaultEngineValues::get_global().share_execution_cache_with_payload_builder,
528    )]
529    pub share_execution_cache_with_payload_builder: bool,
530
531    /// Whether to share the sparse trie with the payload builder.
532    ///
533    /// Replaces the payload builder's blocking `state_root_with_updates()` call with the
534    /// sparse trie, computing the state root concurrently with transaction execution.
535    ///
536    /// The engine and payload builder contend for the same trie — if a builder task is
537    /// still running when `newPayload` arrives, the engine will block until the trie is
538    /// stored back.
539    ///
540    /// The builder also anchors the trie at the built block's state root, so if the next
541    /// `newPayload` is not on top of that block, the trie cache is invalidated and cleared.
542    #[arg(
543        long = "engine.share-sparse-trie-with-payload-builder",
544        default_value_t = DefaultEngineValues::get_global().share_sparse_trie_with_payload_builder,
545    )]
546    pub share_sparse_trie_with_payload_builder: bool,
547
548    /// Suppress persistence while building a payload.
549    ///
550    /// When enabled, persistence cycles are deferred while a payload build is active. Useful on
551    /// chains with short block times where persistence I/O can interfere with block building
552    /// latency.
553    #[arg(
554        long = "engine.suppress-persistence-during-build",
555        default_value_t = DefaultEngineValues::get_global().suppress_persistence_during_build,
556    )]
557    pub suppress_persistence_during_build: bool,
558
559    /// Disable BAL (Block Access List, EIP-7928) based parallel execution.
560    #[arg(long = "engine.disable-bal-parallel-execution", default_value_t = DefaultEngineValues::get_global().bal_parallel_execution_disabled)]
561    pub bal_parallel_execution_disabled: bool,
562
563    /// Disable BAL-driven parallel state root computation. This is only valid together with
564    /// `--engine.disable-bal-parallel-execution`.
565    #[arg(long = "engine.disable-bal-parallel-state-root", default_value_t = DefaultEngineValues::get_global().bal_parallel_state_root_disabled)]
566    pub bal_parallel_state_root_disabled: bool,
567
568    /// Disable BAL (Block Access List) storage prefetch IO during prewarming. When set, BAL
569    /// storage slots are not read into the execution cache.
570    #[arg(long = "engine.disable-bal-batch-io", default_value_t = false)]
571    pub disable_bal_batch_io: bool,
572
573    /// Reuse transaction prewarming results during block execution instead of executing
574    /// transactions again when their prewarm reads are still valid.
575    #[arg(
576        long = "engine.prewarm-reuse",
577        env = "RETH_ENGINE_PREWARM_REUSE",
578        default_value_t = false
579    )]
580    pub prewarm_reuse: bool,
581
582    /// Add random jitter before each proof computation (trie-debug only).
583    /// Each proof worker sleeps for a random duration up to this value before
584    /// starting work. Useful for stress-testing timing-sensitive proof logic.
585    ///
586    /// --engine.proof-jitter 100ms
587    /// --engine.proof-jitter 1s
588    #[cfg(feature = "trie-debug")]
589    #[arg(
590        long = "engine.proof-jitter",
591        value_parser = parse_duration,
592    )]
593    pub proof_jitter: Option<Duration>,
594}
595
596impl Default for EngineArgs {
597    fn default() -> Self {
598        let DefaultEngineValues {
599            persistence_threshold,
600            persistence_backpressure_threshold: _,
601            num_state_masking_blocks,
602            memory_block_buffer_target: _,
603            backfill_run_threshold,
604            invalid_header_hit_eviction_threshold,
605            state_cache_disabled,
606            prewarming_disabled,
607            txpool_prewarming_enabled,
608            sender_recovery_cache_enabled,
609            state_provider_metrics,
610            cross_block_cache_size,
611            accept_execution_requests_hash,
612            multiproof_chunk_size,
613            reserved_cpu_cores,
614            precompile_cache_disabled,
615            state_root_fallback,
616            always_process_payload_attributes_on_canonical_head,
617            allow_unwind_canonical_header,
618            storage_worker_count,
619            account_worker_count,
620            prewarming_threads,
621            cache_metrics_disabled,
622            slow_block_threshold,
623            disable_sparse_trie_cache_pruning,
624            state_root_task_timeout,
625            share_execution_cache_with_payload_builder,
626            share_sparse_trie_with_payload_builder,
627            suppress_persistence_during_build,
628            bal_parallel_execution_disabled,
629            bal_parallel_state_root_disabled,
630        } = DefaultEngineValues::get_global().clone();
631        Self {
632            persistence_threshold,
633            persistence_backpressure_threshold: None,
634            num_state_masking_blocks,
635            memory_block_buffer_target: None,
636            backfill_run_threshold,
637            invalid_header_hit_eviction_threshold,
638            state_cache_disabled,
639            prewarming_disabled,
640            txpool_prewarming_enabled,
641            sender_recovery_cache_enabled,
642            state_provider_metrics,
643            cross_block_cache_size,
644            accept_execution_requests_hash,
645            multiproof_chunk_size,
646            reserved_cpu_cores,
647            cpu_cores: None,
648            precompile_cache_disabled,
649            state_root_fallback,
650            always_process_payload_attributes_on_canonical_head,
651            allow_unwind_canonical_header,
652            storage_worker_count,
653            account_worker_count,
654            prewarming_threads,
655            cache_metrics_disabled,
656            slow_block_threshold,
657            disable_sparse_trie_cache_pruning,
658            state_root_task_timeout: state_root_task_timeout
659                .as_deref()
660                .map(|s| parse_duration(s).expect("valid default duration")),
661            share_execution_cache_with_payload_builder,
662            share_sparse_trie_with_payload_builder,
663            suppress_persistence_during_build,
664            bal_parallel_execution_disabled,
665            bal_parallel_state_root_disabled,
666            disable_bal_batch_io: false,
667            prewarm_reuse: false,
668            #[cfg(feature = "trie-debug")]
669            proof_jitter: None,
670        }
671    }
672}
673
674impl EngineArgs {
675    /// Returns the effective state masking window, disabled when persistence is immediate.
676    pub const fn num_state_masking_blocks(&self) -> u64 {
677        if self.persistence_threshold == 0 {
678            0
679        } else {
680            self.num_state_masking_blocks
681        }
682    }
683
684    /// Returns the effective memory block buffer target.
685    pub fn memory_block_buffer_target(&self) -> u64 {
686        self.memory_block_buffer_target.unwrap_or_else(|| {
687            self.persistence_threshold
688                .min(DefaultEngineValues::get_global().memory_block_buffer_target)
689        })
690    }
691
692    /// Returns the effective persistence backpressure threshold.
693    pub fn persistence_backpressure_threshold(&self) -> u64 {
694        self.persistence_backpressure_threshold.unwrap_or_else(|| {
695            default_persistence_backpressure_threshold(self.persistence_threshold)
696        })
697    }
698
699    /// Validates cross-field engine arguments.
700    pub fn validate(&self) -> eyre::Result<()> {
701        let persistence_backpressure_threshold = self.persistence_backpressure_threshold();
702        let memory_block_buffer_target = self.memory_block_buffer_target();
703        let num_state_masking_blocks = self.num_state_masking_blocks();
704        ensure!(
705            persistence_backpressure_threshold > self.persistence_threshold,
706            "--engine.persistence-backpressure-threshold ({}) must be greater than --engine.persistence-threshold ({})",
707            persistence_backpressure_threshold,
708            self.persistence_threshold
709        );
710        ensure!(
711            memory_block_buffer_target <= self.persistence_threshold,
712            "--engine.memory-block-buffer-target ({}) must be less than or equal to --engine.persistence-threshold ({})",
713            memory_block_buffer_target,
714            self.persistence_threshold,
715        );
716        ensure!(
717            num_state_masking_blocks == 0 ||
718                matches!(
719                    num_state_masking_blocks.checked_add(memory_block_buffer_target),
720                    Some(window) if window < self.persistence_threshold
721                ),
722            "--engine.num-state-masking-blocks ({}) + --engine.memory-block-buffer-target ({}) must be less than --engine.persistence-threshold ({})",
723            num_state_masking_blocks,
724            memory_block_buffer_target,
725            self.persistence_threshold,
726        );
727        ensure!(
728            !self.state_cache_disabled || !self.txpool_prewarming_enabled,
729            "--engine.txpool-prewarming conflicts with --engine.disable-state-cache"
730        );
731        ensure!(
732            self.bal_parallel_execution_disabled || !self.bal_parallel_state_root_disabled,
733            "--engine.disable-bal-parallel-state-root requires --engine.disable-bal-parallel-execution because BAL parallel execution depends on BAL prewarm state-root updates"
734        );
735        Ok(())
736    }
737
738    /// Creates a [`TreeConfig`] from the engine arguments.
739    pub fn tree_config(&self) -> TreeConfig {
740        let config = TreeConfig::default()
741            // Clear the default window before applying overrides that may be smaller than it.
742            .with_persistence_threshold(0)
743            .with_persistence_backpressure_threshold(self.persistence_backpressure_threshold())
744            .with_persistence_threshold(self.persistence_threshold)
745            .with_memory_block_buffer_target(self.memory_block_buffer_target())
746            .with_num_state_masking_blocks(self.num_state_masking_blocks())
747            .with_backfill_run_threshold(self.backfill_run_threshold)
748            .with_invalid_header_hit_eviction_threshold(self.invalid_header_hit_eviction_threshold)
749            .without_state_cache(self.state_cache_disabled)
750            .without_prewarming(self.prewarming_disabled)
751            .with_txpool_prewarming(self.txpool_prewarming_enabled)
752            .with_state_provider_metrics(self.state_provider_metrics)
753            .with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
754            .with_multiproof_chunk_size(self.multiproof_chunk_size)
755            .with_reserved_cpu_cores(self.reserved_cpu_cores)
756            .without_precompile_cache(self.precompile_cache_disabled)
757            .with_state_root_fallback(self.state_root_fallback)
758            .with_always_process_payload_attributes_on_canonical_head(
759                self.always_process_payload_attributes_on_canonical_head,
760            )
761            .with_unwind_canonical_header(self.allow_unwind_canonical_header)
762            .without_cache_metrics(self.cache_metrics_disabled)
763            .with_slow_block_threshold(self.slow_block_threshold)
764            .with_disable_sparse_trie_cache_pruning(self.disable_sparse_trie_cache_pruning)
765            .with_state_root_task_timeout(self.state_root_task_timeout.filter(|d| !d.is_zero()))
766            .with_share_execution_cache_with_payload_builder(
767                self.share_execution_cache_with_payload_builder,
768            )
769            .with_share_sparse_trie_with_payload_builder(
770                self.share_sparse_trie_with_payload_builder,
771            )
772            .with_suppress_persistence_during_build(self.suppress_persistence_during_build)
773            .without_bal_parallel_execution(self.bal_parallel_execution_disabled)
774            .without_bal_parallel_state_root(self.bal_parallel_state_root_disabled)
775            .without_bal_batch_io(self.disable_bal_batch_io)
776            .with_prewarm_reuse(self.prewarm_reuse);
777        #[cfg(feature = "trie-debug")]
778        let config = config.with_proof_jitter(self.proof_jitter);
779        if let Some(cpu_cores) = self.cpu_cores {
780            config.with_has_enough_parallelism(cpu_cores.get() >= 5)
781        } else {
782            config
783        }
784    }
785}
786
787#[cfg(test)]
788mod tests {
789    use super::*;
790    use clap::Parser;
791
792    /// A helper type to parse Args more easily
793    #[derive(Parser)]
794    struct CommandParser<T: Args> {
795        #[command(flatten)]
796        args: T,
797    }
798
799    #[test]
800    fn cpu_cores_override_controls_parallel_state_root() {
801        for (cores, enabled) in [(1, false), (4, false), (5, true), (8, true)] {
802            let args = CommandParser::<EngineArgs>::parse_from([
803                "reth",
804                "--cpu-cores",
805                &cores.to_string(),
806            ])
807            .args;
808            assert_eq!(args.cpu_cores.unwrap().get(), cores);
809            assert_eq!(args.tree_config().use_state_root_task(), enabled);
810        }
811    }
812
813    #[test]
814    fn cpu_cores_override_preserves_state_root_fallback() {
815        let args = CommandParser::<EngineArgs>::parse_from([
816            "reth",
817            "--cpu-cores",
818            "8",
819            "--engine.state-root-fallback",
820        ])
821        .args;
822        assert!(!args.tree_config().use_state_root_task());
823    }
824
825    #[test]
826    fn test_parse_engine_args() {
827        let default_args = EngineArgs::default();
828        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
829        assert_eq!(args, default_args);
830        assert_eq!(args.persistence_threshold, 50);
831        assert_eq!(args.num_state_masking_blocks, 30);
832        assert_eq!(args.memory_block_buffer_target, None);
833        assert_eq!(args.memory_block_buffer_target(), 5);
834        assert_eq!(args.persistence_backpressure_threshold(), 100);
835        args.validate().unwrap();
836        let config = args.tree_config();
837        assert_eq!(config.persistence_threshold(), 50);
838        assert_eq!(config.num_state_masking_blocks(), 30);
839        assert_eq!(config.persistence_backpressure_threshold(), 100);
840    }
841
842    #[test]
843    fn txpool_prewarming_is_disabled_by_default_and_can_be_enabled() {
844        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
845        assert!(!args.txpool_prewarming_enabled);
846        assert!(!args.tree_config().txpool_prewarming());
847
848        let args =
849            CommandParser::<EngineArgs>::parse_from(["reth", "--engine.txpool-prewarming"]).args;
850        assert!(args.txpool_prewarming_enabled);
851        assert!(args.tree_config().txpool_prewarming());
852    }
853
854    #[test]
855    fn validate_rejects_txpool_prewarming_with_disabled_state_cache() {
856        let args = EngineArgs {
857            state_cache_disabled: true,
858            txpool_prewarming_enabled: true,
859            ..EngineArgs::default()
860        };
861
862        let err = args.validate().unwrap_err().to_string();
863        assert!(err.contains("engine.txpool-prewarming"));
864        assert!(err.contains("engine.disable-state-cache"));
865    }
866
867    #[test]
868    fn default_backpressure_threshold_uses_parsed_persistence_args() {
869        let args = CommandParser::<EngineArgs>::parse_from([
870            "reth",
871            "--engine.persistence-threshold",
872            "100",
873            "--engine.memory-block-buffer-target",
874            "50",
875        ])
876        .args;
877
878        assert_eq!(args.persistence_backpressure_threshold(), 200);
879
880        let tree_config = args.tree_config();
881        assert_eq!(tree_config.persistence_threshold(), 100);
882        assert_eq!(tree_config.memory_block_buffer_target(), 50);
883        assert_eq!(tree_config.persistence_backpressure_threshold(), 200);
884    }
885
886    #[test]
887    fn default_backpressure_threshold_uses_minimum_when_larger() {
888        let args = CommandParser::<EngineArgs>::parse_from([
889            "reth",
890            "--engine.persistence-threshold",
891            "4",
892        ])
893        .args;
894
895        assert_eq!(
896            args.persistence_backpressure_threshold(),
897            DefaultEngineValues::get_global().persistence_backpressure_threshold
898        );
899        assert_eq!(args.persistence_backpressure_threshold(), 16);
900    }
901
902    #[test]
903    fn explicit_backpressure_threshold_overrides_calculated_default() {
904        let args = CommandParser::<EngineArgs>::parse_from([
905            "reth",
906            "--engine.persistence-threshold",
907            "100",
908            "--engine.memory-block-buffer-target",
909            "50",
910            "--engine.persistence-backpressure-threshold",
911            "101",
912        ])
913        .args;
914
915        assert_eq!(args.persistence_backpressure_threshold(), 101);
916    }
917
918    #[test]
919    fn sender_recovery_cache_is_enabled_by_default_and_can_be_disabled() {
920        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
921        assert!(args.sender_recovery_cache_enabled);
922
923        let args =
924            CommandParser::<EngineArgs>::parse_from(["reth", "--engine.sender-recovery-cache"])
925                .args;
926        assert!(args.sender_recovery_cache_enabled);
927
928        let args = CommandParser::<EngineArgs>::parse_from([
929            "reth",
930            "--engine.sender-recovery-cache=true",
931        ])
932        .args;
933        assert!(args.sender_recovery_cache_enabled);
934
935        let args = CommandParser::<EngineArgs>::parse_from([
936            "reth",
937            "--engine.sender-recovery-cache=false",
938        ])
939        .args;
940        assert!(!args.sender_recovery_cache_enabled);
941
942        let args = CommandParser::<EngineArgs>::parse_from([
943            "reth",
944            "--engine.sender-recovery-cache",
945            "false",
946        ])
947        .args;
948        assert!(!args.sender_recovery_cache_enabled);
949    }
950
951    #[test]
952    fn engine_args() {
953        let args = EngineArgs {
954            persistence_threshold: 100,
955            persistence_backpressure_threshold: Some(101),
956            num_state_masking_blocks: DEFAULT_NUM_STATE_MASKING_BLOCKS,
957            memory_block_buffer_target: Some(50),
958            backfill_run_threshold: 100,
959            invalid_header_hit_eviction_threshold: 7,
960            state_cache_disabled: true,
961            prewarming_disabled: true,
962            // conflicts with --engine.disable-state-cache, covered by its own test below
963            txpool_prewarming_enabled: false,
964            sender_recovery_cache_enabled: true,
965            state_provider_metrics: true,
966            cross_block_cache_size: 256,
967            accept_execution_requests_hash: true,
968            multiproof_chunk_size: 512,
969            reserved_cpu_cores: 4,
970            cpu_cores: Some(NonZeroUsize::new(8).unwrap()),
971            precompile_cache_disabled: true,
972            state_root_fallback: true,
973            always_process_payload_attributes_on_canonical_head: true,
974            allow_unwind_canonical_header: true,
975            storage_worker_count: Some(16),
976            account_worker_count: Some(8),
977            prewarming_threads: Some(4),
978            cache_metrics_disabled: true,
979            slow_block_threshold: None,
980            disable_sparse_trie_cache_pruning: true,
981            state_root_task_timeout: Some(Duration::from_secs(2)),
982            share_execution_cache_with_payload_builder: false,
983            share_sparse_trie_with_payload_builder: false,
984            suppress_persistence_during_build: false,
985            bal_parallel_execution_disabled: true,
986            bal_parallel_state_root_disabled: true,
987            disable_bal_batch_io: true,
988            prewarm_reuse: true,
989            #[cfg(feature = "trie-debug")]
990            proof_jitter: None,
991        };
992
993        let parsed_args = CommandParser::<EngineArgs>::parse_from([
994            "reth",
995            "--engine.persistence-threshold",
996            "100",
997            "--engine.persistence-backpressure-threshold",
998            "101",
999            "--engine.memory-block-buffer-target",
1000            "50",
1001            "--engine.backfill-threshold",
1002            "100",
1003            "--engine.invalid-header-cache-hit-eviction-threshold",
1004            "7",
1005            "--engine.disable-state-cache",
1006            "--engine.disable-prewarming",
1007            "--engine.sender-recovery-cache",
1008            "--engine.state-provider-metrics",
1009            "--engine.cross-block-cache-size",
1010            "256",
1011            "--engine.accept-execution-requests-hash",
1012            "--engine.multiproof-chunk-size",
1013            "512",
1014            "--engine.reserved-cpu-cores",
1015            "4",
1016            "--cpu-cores",
1017            "8",
1018            "--engine.disable-precompile-cache",
1019            "--engine.state-root-fallback",
1020            "--engine.always-process-payload-attributes-on-canonical-head",
1021            "--engine.allow-unwind-canonical-header",
1022            "--engine.storage-worker-count",
1023            "16",
1024            "--engine.account-worker-count",
1025            "8",
1026            "--engine.prewarming-threads",
1027            "4",
1028            "--engine.disable-cache-metrics",
1029            "--engine.disable-sparse-trie-cache-pruning",
1030            "--engine.state-root-task-timeout",
1031            "2s",
1032            "--engine.disable-bal-parallel-execution",
1033            "--engine.disable-bal-parallel-state-root",
1034            "--engine.disable-bal-batch-io",
1035            "--engine.prewarm-reuse",
1036        ])
1037        .args;
1038
1039        assert_eq!(parsed_args, args);
1040    }
1041
1042    #[test]
1043    fn validate_rejects_invalid_backpressure_threshold() {
1044        let args = EngineArgs {
1045            persistence_threshold: 4,
1046            persistence_backpressure_threshold: Some(4),
1047            ..EngineArgs::default()
1048        };
1049
1050        let err = args.validate().unwrap_err().to_string();
1051        assert!(err.contains("engine.persistence-backpressure-threshold"));
1052        assert!(err.contains("engine.persistence-threshold"));
1053    }
1054
1055    #[test]
1056    fn validate_memory_block_buffer_target() {
1057        let args = EngineArgs {
1058            persistence_threshold: 4,
1059            num_state_masking_blocks: 0,
1060            memory_block_buffer_target: Some(4),
1061            ..EngineArgs::default()
1062        };
1063        args.validate().unwrap();
1064
1065        let args = EngineArgs { memory_block_buffer_target: Some(5), ..args };
1066        let err = args.validate().unwrap_err().to_string();
1067        assert!(err.contains("engine.memory-block-buffer-target"));
1068        assert!(err.contains("engine.persistence-threshold"));
1069    }
1070
1071    #[test]
1072    fn test_parse_backfill_threshold() {
1073        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
1074        let config = args.tree_config();
1075        assert_eq!(config.backfill_run_threshold(), DEFAULT_BACKFILL_RUN_THRESHOLD);
1076
1077        for (threshold, expected) in [("500", 500), ("2048", 1024)] {
1078            let args = CommandParser::<EngineArgs>::parse_from([
1079                "reth",
1080                "--engine.backfill-threshold",
1081                threshold,
1082            ])
1083            .args;
1084            assert_eq!(args.tree_config().backfill_run_threshold(), expected);
1085        }
1086    }
1087
1088    #[test]
1089    fn validate_rejects_state_masking_window_at_or_above_threshold() {
1090        let args = EngineArgs {
1091            persistence_threshold: 4,
1092            num_state_masking_blocks: 2,
1093            memory_block_buffer_target: Some(2),
1094            ..EngineArgs::default()
1095        };
1096
1097        let err = args.validate().unwrap_err().to_string();
1098        assert!(err.contains("engine.num-state-masking-blocks"));
1099    }
1100
1101    #[test]
1102    fn validate_rejects_overflowing_state_masking_window() {
1103        let args = EngineArgs {
1104            persistence_threshold: 7,
1105            num_state_masking_blocks: u64::MAX,
1106            ..EngineArgs::default()
1107        };
1108
1109        let err = args.validate().unwrap_err().to_string();
1110        assert!(err.contains("engine.num-state-masking-blocks"));
1111    }
1112
1113    #[test]
1114    fn default_memory_block_buffer_target_is_bounded_by_persistence_threshold() {
1115        let args = CommandParser::<EngineArgs>::parse_from([
1116            "reth",
1117            "--engine.persistence-threshold",
1118            "4",
1119            "--engine.num-state-masking-blocks",
1120            "0",
1121        ])
1122        .args;
1123
1124        assert_eq!(args.memory_block_buffer_target, None);
1125        assert_eq!(args.memory_block_buffer_target(), 4);
1126        assert_eq!(args.tree_config().memory_block_buffer_target(), 4);
1127        args.validate().unwrap();
1128    }
1129
1130    #[test]
1131    fn explicit_persistence_settings_can_be_lower_than_defaults() {
1132        let args = CommandParser::<EngineArgs>::parse_from([
1133            "reth",
1134            "--engine.persistence-threshold",
1135            "0",
1136            "--engine.persistence-backpressure-threshold",
1137            "1",
1138        ])
1139        .args;
1140
1141        args.validate().unwrap();
1142        let config = args.tree_config();
1143        assert_eq!(config.persistence_threshold(), 0);
1144        assert_eq!(config.num_state_masking_blocks(), 0);
1145        assert_eq!(config.memory_block_buffer_target(), 0);
1146        assert_eq!(config.persistence_backpressure_threshold(), 1);
1147    }
1148
1149    #[test]
1150    fn parse_rejects_zero_multiproof_chunk_size() {
1151        let result = CommandParser::<EngineArgs>::try_parse_from([
1152            "reth",
1153            "--engine.multiproof-chunk-size",
1154            "0",
1155        ]);
1156
1157        assert!(result.is_err());
1158    }
1159
1160    #[test]
1161    fn validate_rejects_bal_parallel_execution_without_bal_parallel_state_root() {
1162        let args = EngineArgs {
1163            bal_parallel_execution_disabled: false,
1164            bal_parallel_state_root_disabled: true,
1165            ..EngineArgs::default()
1166        };
1167
1168        let err = args.validate().unwrap_err().to_string();
1169        assert!(err.contains("engine.disable-bal-parallel-state-root"));
1170        assert!(err.contains("engine.disable-bal-parallel-execution"));
1171    }
1172
1173    #[test]
1174    fn test_parse_slow_block_threshold() {
1175        // Test default value (None - disabled)
1176        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
1177        assert_eq!(args.slow_block_threshold, None);
1178
1179        // Test setting to 0 (log all blocks)
1180        let args =
1181            CommandParser::<EngineArgs>::parse_from(["reth", "--engine.slow-block-threshold", "0"])
1182                .args;
1183        assert_eq!(args.slow_block_threshold, Some(Duration::ZERO));
1184
1185        // Test setting to custom value
1186        let args = CommandParser::<EngineArgs>::parse_from([
1187            "reth",
1188            "--engine.slow-block-threshold",
1189            "500",
1190        ])
1191        .args;
1192        assert_eq!(args.slow_block_threshold, Some(Duration::from_secs(500)));
1193
1194        let args = CommandParser::<EngineArgs>::parse_from([
1195            "reth",
1196            "--engine.slow-block-threshold",
1197            "500ms",
1198        ])
1199        .args;
1200        assert_eq!(args.slow_block_threshold, Some(Duration::from_millis(500)));
1201    }
1202
1203    #[test]
1204    fn test_parse_invalid_header_hit_eviction_threshold() {
1205        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
1206        assert_eq!(
1207            args.invalid_header_hit_eviction_threshold,
1208            DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD
1209        );
1210        assert_eq!(
1211            args.tree_config().invalid_header_hit_eviction_threshold(),
1212            DEFAULT_INVALID_HEADER_HIT_EVICTION_THRESHOLD
1213        );
1214
1215        let args = CommandParser::<EngineArgs>::parse_from([
1216            "reth",
1217            "--engine.invalid-header-cache-hit-eviction-threshold",
1218            "0",
1219        ])
1220        .args;
1221        assert_eq!(args.invalid_header_hit_eviction_threshold, 0);
1222        assert_eq!(args.tree_config().invalid_header_hit_eviction_threshold(), 0);
1223    }
1224
1225    #[test]
1226    fn test_parse_share_sparse_trie_flag() {
1227        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
1228        assert!(!args.share_sparse_trie_with_payload_builder);
1229        assert!(!args.tree_config().share_sparse_trie_with_payload_builder());
1230
1231        let args = CommandParser::<EngineArgs>::parse_from([
1232            "reth",
1233            "--engine.share-sparse-trie-with-payload-builder",
1234        ])
1235        .args;
1236        assert!(args.share_sparse_trie_with_payload_builder);
1237        assert!(args.tree_config().share_sparse_trie_with_payload_builder());
1238    }
1239}