reth_optimism_node/
args.rs

1//! Additional Node command arguments.
2
3//! clap [Args](clap::Args) for optimism rollup configuration
4
5/// Parameters for rollup configuration
6#[derive(Debug, Clone, PartialEq, Eq, clap::Args)]
7#[command(next_help_heading = "Rollup")]
8pub struct RollupArgs {
9    /// HTTP endpoint for the sequencer mempool
10    #[arg(long = "rollup.sequencer-http", value_name = "HTTP_URL")]
11    pub sequencer_http: Option<String>,
12
13    /// Disable transaction pool gossip
14    #[arg(long = "rollup.disable-tx-pool-gossip")]
15    pub disable_txpool_gossip: bool,
16
17    /// Enable walkback to genesis on startup. This is useful for re-validating the existing DB
18    /// prior to beginning normal syncing.
19    #[arg(long = "rollup.enable-genesis-walkback")]
20    pub enable_genesis_walkback: bool,
21
22    /// By default the pending block equals the latest block
23    /// to save resources and not leak txs from the tx-pool,
24    /// this flag enables computing of the pending block
25    /// from the tx-pool instead.
26    ///
27    /// If `compute_pending_block` is not enabled, the payload builder
28    /// will use the payload attributes from the latest block. Note
29    /// that this flag is not yet functional.
30    #[arg(long = "rollup.compute-pending-block")]
31    pub compute_pending_block: bool,
32
33    /// enables discovery v4 if provided
34    #[arg(long = "rollup.discovery.v4", default_value = "false")]
35    pub discovery_v4: bool,
36
37    /// Enable transaction conditional support on sequencer
38    #[arg(long = "rollup.enable-tx-conditional", default_value = "false")]
39    pub enable_tx_conditional: bool,
40}
41
42#[allow(clippy::derivable_impls)]
43impl Default for RollupArgs {
44    fn default() -> Self {
45        Self {
46            sequencer_http: None,
47            disable_txpool_gossip: false,
48            enable_genesis_walkback: false,
49            compute_pending_block: false,
50            discovery_v4: false,
51            enable_tx_conditional: false,
52        }
53    }
54}
55
56#[cfg(test)]
57mod tests {
58    use super::*;
59    use clap::{Args, Parser};
60
61    /// A helper type to parse Args more easily
62    #[derive(Parser)]
63    struct CommandParser<T: Args> {
64        #[command(flatten)]
65        args: T,
66    }
67
68    #[test]
69    fn test_parse_optimism_default_args() {
70        let default_args = RollupArgs::default();
71        let args = CommandParser::<RollupArgs>::parse_from(["reth"]).args;
72        assert_eq!(args, default_args);
73    }
74
75    #[test]
76    fn test_parse_optimism_walkback_args() {
77        let expected_args = RollupArgs { enable_genesis_walkback: true, ..Default::default() };
78        let args =
79            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.enable-genesis-walkback"])
80                .args;
81        assert_eq!(args, expected_args);
82    }
83
84    #[test]
85    fn test_parse_optimism_compute_pending_block_args() {
86        let expected_args = RollupArgs { compute_pending_block: true, ..Default::default() };
87        let args =
88            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.compute-pending-block"])
89                .args;
90        assert_eq!(args, expected_args);
91    }
92
93    #[test]
94    fn test_parse_optimism_discovery_v4_args() {
95        let expected_args = RollupArgs { discovery_v4: true, ..Default::default() };
96        let args = CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.discovery.v4"]).args;
97        assert_eq!(args, expected_args);
98    }
99
100    #[test]
101    fn test_parse_optimism_sequencer_http_args() {
102        let expected_args =
103            RollupArgs { sequencer_http: Some("http://host:port".into()), ..Default::default() };
104        let args = CommandParser::<RollupArgs>::parse_from([
105            "reth",
106            "--rollup.sequencer-http",
107            "http://host:port",
108        ])
109        .args;
110        assert_eq!(args, expected_args);
111    }
112
113    #[test]
114    fn test_parse_optimism_disable_txpool_args() {
115        let expected_args = RollupArgs { disable_txpool_gossip: true, ..Default::default() };
116        let args =
117            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.disable-tx-pool-gossip"])
118                .args;
119        assert_eq!(args, expected_args);
120    }
121
122    #[test]
123    fn test_parse_optimism_enable_tx_conditional() {
124        let expected_args = RollupArgs { enable_tx_conditional: true, ..Default::default() };
125        let args =
126            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.enable-tx-conditional"])
127                .args;
128        assert_eq!(args, expected_args);
129    }
130
131    #[test]
132    fn test_parse_optimism_many_args() {
133        let expected_args = RollupArgs {
134            disable_txpool_gossip: true,
135            compute_pending_block: true,
136            enable_genesis_walkback: true,
137            enable_tx_conditional: true,
138            sequencer_http: Some("http://host:port".into()),
139            ..Default::default()
140        };
141        let args = CommandParser::<RollupArgs>::parse_from([
142            "reth",
143            "--rollup.disable-tx-pool-gossip",
144            "--rollup.compute-pending-block",
145            "--rollup.enable-genesis-walkback",
146            "--rollup.enable-tx-conditional",
147            "--rollup.sequencer-http",
148            "http://host:port",
149        ])
150        .args;
151        assert_eq!(args, expected_args);
152    }
153}