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_MEMORY_BLOCK_BUFFER_TARGET,
8    DEFAULT_PERSISTENCE_THRESHOLD,
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    /// Enable cross-block caching and parallel prewarming
28    #[arg(long = "engine.caching-and-prewarming")]
29    pub caching_and_prewarming_enabled: bool,
30
31    /// Configure the size of cross-block cache in megabytes
32    #[arg(long = "engine.cross-block-cache-size", default_value_t = DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB)]
33    pub cross_block_cache_size: u64,
34
35    /// Enable comparing trie updates from the state root task to the trie updates from the regular
36    /// state root calculation.
37    #[arg(long = "engine.state-root-task-compare-updates")]
38    pub state_root_task_compare_updates: bool,
39}
40
41impl Default for EngineArgs {
42    fn default() -> Self {
43        Self {
44            persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD,
45            memory_block_buffer_target: DEFAULT_MEMORY_BLOCK_BUFFER_TARGET,
46            legacy_state_root_task_enabled: false,
47            state_root_task_compare_updates: false,
48            caching_and_prewarming_enabled: false,
49            cross_block_cache_size: DEFAULT_CROSS_BLOCK_CACHE_SIZE_MB,
50        }
51    }
52}
53
54impl EngineArgs {
55    /// Creates a [`TreeConfig`] from the engine arguments.
56    pub fn tree_config(&self) -> TreeConfig {
57        TreeConfig::default()
58            .with_persistence_threshold(self.persistence_threshold)
59            .with_memory_block_buffer_target(self.memory_block_buffer_target)
60            .with_legacy_state_root(self.legacy_state_root_task_enabled)
61            .with_caching_and_prewarming(self.caching_and_prewarming_enabled)
62            .with_always_compare_trie_updates(self.state_root_task_compare_updates)
63            .with_cross_block_cache_size(self.cross_block_cache_size * 1024 * 1024)
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70    use clap::Parser;
71
72    /// A helper type to parse Args more easily
73    #[derive(Parser)]
74    struct CommandParser<T: Args> {
75        #[command(flatten)]
76        args: T,
77    }
78
79    #[test]
80    fn test_parse_engine_args() {
81        let default_args = EngineArgs::default();
82        let args = CommandParser::<EngineArgs>::parse_from(["reth"]).args;
83        assert_eq!(args, default_args);
84    }
85}