reth_node_core/args/
engine.rs

1//! clap [Args](clap::Args) for engine purposes
2
3use clap::Args;
4use reth_engine_primitives::TreeConfig;
5
6use crate::node_config::{
7    DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB, DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
8    DEFAULT_MEMORY_BLOCK_BUFFER_TARGET, DEFAULT_PERSISTENCE_THRESHOLD, DEFAULT_RESERVED_CPU_CORES,
9};
10
11/// Parameters for configuring the engine driver.
12#[derive(Debug, Clone, Args, PartialEq, Eq)]
13#[command(next_help_heading = "Engine")]
14pub struct EngineArgs {
15    /// Configure persistence threshold for engine experimental.
16    #[arg(long = "engine.persistence-threshold", default_value_t = DEFAULT_PERSISTENCE_THRESHOLD)]
17    pub persistence_threshold: u64,
18
19    /// Configure the target number of blocks to keep in memory.
20    #[arg(long = "engine.memory-block-buffer-target", default_value_t = DEFAULT_MEMORY_BLOCK_BUFFER_TARGET)]
21    pub memory_block_buffer_target: u64,
22
23    /// Enable legacy state root
24    #[arg(long = "engine.legacy-state-root", default_value = "false")]
25    pub legacy_state_root_task_enabled: bool,
26
27    /// CAUTION: This CLI flag has no effect anymore, use --engine.disable-caching-and-prewarming
28    /// if you want to disable caching and prewarming.
29    #[arg(long = "engine.caching-and-prewarming", default_value = "true")]
30    pub caching_and_prewarming_enabled: bool,
31
32    /// Disable cross-block caching and parallel prewarming
33    #[arg(long = "engine.disable-caching-and-prewarming")]
34    pub caching_and_prewarming_disabled: bool,
35
36    /// Configure the size of cross-block cache in megabytes
37    #[arg(long = "engine.cross-block-cache-size", default_value_t = DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB)]
38    pub cross_block_cache_size: u64,
39
40    /// Enable comparing trie updates from the state root task to the trie updates from the regular
41    /// state root calculation.
42    #[arg(long = "engine.state-root-task-compare-updates")]
43    pub state_root_task_compare_updates: bool,
44
45    /// Enables accepting requests hash instead of an array of requests in `engine_newPayloadV4`.
46    #[arg(long = "engine.accept-execution-requests-hash")]
47    pub accept_execution_requests_hash: bool,
48
49    /// Configure the maximum number of concurrent proof tasks
50    #[arg(long = "engine.max-proof-task-concurrency", default_value_t = DEFAULT_MAX_PROOF_TASK_CONCURRENCY)]
51    pub max_proof_task_concurrency: u64,
52
53    /// Configure the number of reserved CPU cores for non-reth processes
54    #[arg(long = "engine.reserved-cpu-cores", default_value_t = DEFAULT_RESERVED_CPU_CORES)]
55    pub reserved_cpu_cores: usize,
56}
57
58impl Default for EngineArgs {
59    fn default() -> Self {
60        Self {
61            persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
62            memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
63            legacy_state_root_task_enabled: false,
64            state_root_task_compare_updates: false,
65            caching_and_prewarming_enabled: true,
66            caching_and_prewarming_disabled: false,
67            cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB,
68            accept_execution_requests_hash: false,
69            max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
70            reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
71        }
72    }
73}
74
75impl EngineArgs {
76    /// Creates a [`TreeConfig`] from the engine arguments.
77    pub fn tree_config(&self) -> TreeConfig {
78        TreeConfig::default()
79            .with_persistence_threshold(self.persistence_threshold)
80            .with_memory_block_buffer_target(self.memory_block_buffer_target)
81            .with_legacy_state_root(self.legacy_state_root_task_enabled)
82            .without_caching_and_prewarming(self.caching_and_prewarming_disabled)
83            .with_always_compare_trie_updates(self.state_root_task_compare_updates)
84            .with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
85            .with_max_proof_task_concurrency(self.max_proof_task_concurrency)
86            .with_reserved_cpu_cores(self.reserved_cpu_cores)
87    }
88}
89
90#[cfg(test)]
91mod tests {
92    use super::*;
93    use clap::Parser;
94
95    /// A helper type to parse Args more easily
96    #[derive(Parser)]
97    struct CommandParser<T: Args> {
98        #[command(flatten)]
99        args: T,
100    }
101
102    #[test]
103    fn test_parse_engine_args() {
104        let default_args = EngineArgs::default();
105        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
106        assert_eq!(args, default_args);
107    }
108}