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", hide = true)]
30    #[deprecated]
31    pub caching_and_prewarming_enabled: bool,
32
33    /// Disable cross-block caching and parallel prewarming
34    #[arg(long = "engine.disable-caching-and-prewarming")]
35    pub caching_and_prewarming_disabled: bool,
36
37    /// CAUTION: This CLI flag has no effect anymore, use --engine.disable-parallel-sparse-trie
38    /// if you want to disable usage of the `ParallelSparseTrie`.
39    #[deprecated]
40    #[arg(long = "engine.parallel-sparse-trie", default_value = "true", hide = true)]
41    pub parallel_sparse_trie_enabled: bool,
42
43    /// Disable the parallel sparse trie in the engine.
44    #[arg(long = "engine.disable-parallel-sparse-trie", default_value = "false")]
45    pub parallel_sparse_trie_disabled: bool,
46
47    /// Enable state provider latency metrics. This allows the engine to collect and report stats
48    /// about how long state provider calls took during execution, but this does introduce slight
49    /// overhead to state provider calls.
50    #[arg(long = "engine.state-provider-metrics", default_value = "false")]
51    pub state_provider_metrics: bool,
52
53    /// Configure the size of cross-block cache in megabytes
54    #[arg(long = "engine.cross-block-cache-size", default_value_t = DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB)]
55    pub cross_block_cache_size: u64,
56
57    /// Enable comparing trie updates from the state root task to the trie updates from the regular
58    /// state root calculation.
59    #[arg(long = "engine.state-root-task-compare-updates")]
60    pub state_root_task_compare_updates: bool,
61
62    /// Enables accepting requests hash instead of an array of requests in `engine_newPayloadV4`.
63    #[arg(long = "engine.accept-execution-requests-hash")]
64    pub accept_execution_requests_hash: bool,
65
66    /// Configure the maximum number of concurrent proof tasks
67    #[arg(long = "engine.max-proof-task-concurrency", default_value_t = DEFAULT_MAX_PROOF_TASK_CONCURRENCY)]
68    pub max_proof_task_concurrency: u64,
69
70    /// Configure the number of reserved CPU cores for non-reth processes
71    #[arg(long = "engine.reserved-cpu-cores", default_value_t = DEFAULT_RESERVED_CPU_CORES)]
72    pub reserved_cpu_cores: usize,
73
74    /// CAUTION: This CLI flag has no effect anymore, use --engine.disable-precompile-cache
75    /// if you want to disable precompile cache
76    #[arg(long = "engine.precompile-cache", default_value = "true", hide = true)]
77    #[deprecated]
78    pub precompile_cache_enabled: bool,
79
80    /// Disable precompile cache
81    #[arg(long = "engine.disable-precompile-cache", default_value = "false")]
82    pub precompile_cache_disabled: bool,
83
84    /// Enable state root fallback, useful for testing
85    #[arg(long = "engine.state-root-fallback", default_value = "false")]
86    pub state_root_fallback: bool,
87
88    /// Always process payload attributes and begin a payload build process even if
89    /// `forkchoiceState.headBlockHash` is already the canonical head or an ancestor. See
90    /// `TreeConfig::always_process_payload_attributes_on_canonical_head` for more details.
91    ///
92    /// Note: This is a no-op on OP Stack.
93    #[arg(
94        long = "engine.always-process-payload-attributes-on-canonical-head",
95        default_value = "false"
96    )]
97    pub always_process_payload_attributes_on_canonical_head: bool,
98
99    /// Allow unwinding canonical header to ancestor during forkchoice updates.
100    /// See `TreeConfig::unwind_canonical_header` for more details.
101    #[arg(long = "engine.allow-unwind-canonical-header", default_value = "false")]
102    pub allow_unwind_canonical_header: bool,
103}
104
105#[allow(deprecated)]
106impl Default for EngineArgs {
107    fn default() -> Self {
108        Self {
109            persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
110            memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
111            legacy_state_root_task_enabled: false,
112            state_root_task_compare_updates: false,
113            caching_and_prewarming_enabled: true,
114            caching_and_prewarming_disabled: false,
115            parallel_sparse_trie_enabled: true,
116            parallel_sparse_trie_disabled: false,
117            state_provider_metrics: false,
118            cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB,
119            accept_execution_requests_hash: false,
120            max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
121            reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
122            precompile_cache_enabled: true,
123            precompile_cache_disabled: false,
124            state_root_fallback: false,
125            always_process_payload_attributes_on_canonical_head: false,
126            allow_unwind_canonical_header: false,
127        }
128    }
129}
130
131impl EngineArgs {
132    /// Creates a [`TreeConfig`] from the engine arguments.
133    pub fn tree_config(&self) -> TreeConfig {
134        TreeConfig::default()
135            .with_persistence_threshold(self.persistence_threshold)
136            .with_memory_block_buffer_target(self.memory_block_buffer_target)
137            .with_legacy_state_root(self.legacy_state_root_task_enabled)
138            .without_caching_and_prewarming(self.caching_and_prewarming_disabled)
139            .with_disable_parallel_sparse_trie(self.parallel_sparse_trie_disabled)
140            .with_state_provider_metrics(self.state_provider_metrics)
141            .with_always_compare_trie_updates(self.state_root_task_compare_updates)
142            .with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
143            .with_max_proof_task_concurrency(self.max_proof_task_concurrency)
144            .with_reserved_cpu_cores(self.reserved_cpu_cores)
145            .without_precompile_cache(self.precompile_cache_disabled)
146            .with_state_root_fallback(self.state_root_fallback)
147            .with_always_process_payload_attributes_on_canonical_head(
148                self.always_process_payload_attributes_on_canonical_head,
149            )
150            .with_unwind_canonical_header(self.allow_unwind_canonical_header)
151    }
152}
153
154#[cfg(test)]
155mod tests {
156    use super::*;
157    use clap::Parser;
158
159    /// A helper type to parse Args more easily
160    #[derive(Parser)]
161    struct CommandParser<T: Args> {
162        #[command(flatten)]
163        args: T,
164    }
165
166    #[test]
167    fn test_parse_engine_args() {
168        let default_args = EngineArgs::default();
169        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
170        assert_eq!(args, default_args);
171    }
172}