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    /// Enable state provider latency metrics. This allows the engine to collect and report stats
37    /// about how long state provider calls took during execution, but this does introduce slight
38    /// overhead to state provider calls.
39    #[arg(long = "engine.state-provider-metrics", default_value = "false")]
40    pub state_provider_metrics: bool,
41
42    /// Configure the size of cross-block cache in megabytes
43    #[arg(long = "engine.cross-block-cache-size", default_value_t = DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB)]
44    pub cross_block_cache_size: u64,
45
46    /// Enable comparing trie updates from the state root task to the trie updates from the regular
47    /// state root calculation.
48    #[arg(long = "engine.state-root-task-compare-updates")]
49    pub state_root_task_compare_updates: bool,
50
51    /// Enables accepting requests hash instead of an array of requests in `engine_newPayloadV4`.
52    #[arg(long = "engine.accept-execution-requests-hash")]
53    pub accept_execution_requests_hash: bool,
54
55    /// Configure the maximum number of concurrent proof tasks
56    #[arg(long = "engine.max-proof-task-concurrency", default_value_t = DEFAULT_MAX_PROOF_TASK_CONCURRENCY)]
57    pub max_proof_task_concurrency: u64,
58
59    /// Configure the number of reserved CPU cores for non-reth processes
60    #[arg(long = "engine.reserved-cpu-cores", default_value_t = DEFAULT_RESERVED_CPU_CORES)]
61    pub reserved_cpu_cores: usize,
62
63    /// Enable precompile cache
64    #[arg(long = "engine.precompile-cache", default_value = "false")]
65    pub precompile_cache_enabled: bool,
66}
67
68impl Default for EngineArgs {
69    fn default() -> Self {
70        Self {
71            persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
72            memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
73            legacy_state_root_task_enabled: false,
74            state_root_task_compare_updates: false,
75            caching_and_prewarming_enabled: true,
76            caching_and_prewarming_disabled: false,
77            state_provider_metrics: false,
78            cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB,
79            accept_execution_requests_hash: false,
80            max_proof_task_concurrency: DEFAULT_MAX_PROOF_TASK_CONCURRENCY,
81            reserved_cpu_cores: DEFAULT_RESERVED_CPU_CORES,
82            precompile_cache_enabled: false,
83        }
84    }
85}
86
87impl EngineArgs {
88    /// Creates a [`TreeConfig`] from the engine arguments.
89    pub fn tree_config(&self) -> TreeConfig {
90        TreeConfig::default()
91            .with_persistence_threshold(self.persistence_threshold)
92            .with_memory_block_buffer_target(self.memory_block_buffer_target)
93            .with_legacy_state_root(self.legacy_state_root_task_enabled)
94            .without_caching_and_prewarming(self.caching_and_prewarming_disabled)
95            .with_state_provider_metrics(self.state_provider_metrics)
96            .with_always_compare_trie_updates(self.state_root_task_compare_updates)
97            .with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
98            .with_max_proof_task_concurrency(self.max_proof_task_concurrency)
99            .with_reserved_cpu_cores(self.reserved_cpu_cores)
100            .with_precompile_cache_enabled(self.precompile_cache_enabled)
101    }
102}
103
104#[cfg(test)]
105mod tests {
106    use super::*;
107    use clap::Parser;
108
109    /// A helper type to parse Args more easily
110    #[derive(Parser)]
111    struct CommandParser<T: Args> {
112        #[command(flatten)]
113        args: T,
114    }
115
116    #[test]
117    fn test_parse_engine_args() {
118        let default_args = EngineArgs::default();
119        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
120        assert_eq!(args, default_args);
121    }
122}