reth_optimism_node/
args.rs

1//! Additional Node command arguments.
2
3//! clap [Args](clap::Args) for optimism rollup configuration
4
5use op_alloy_consensus::interop::SafetyLevel;
6use reth_optimism_txpool::supervisor::DEFAULT_SUPERVISOR_URL;
7use url::Url;
8
9/// Parameters for rollup configuration
10#[derive(Debug, Clone, PartialEq, Eq, clap::Args)]
11#[command(next_help_heading = "Rollup")]
12pub struct RollupArgs {
13    /// Endpoint for the sequencer mempool (can be both HTTP and WS)
14    #[arg(long = "rollup.sequencer", visible_aliases = ["rollup.sequencer-http", "rollup.sequencer-ws"])]
15    pub sequencer: Option<String>,
16
17    /// Disable transaction pool gossip
18    #[arg(long = "rollup.disable-tx-pool-gossip")]
19    pub disable_txpool_gossip: bool,
20
21    /// By default the pending block equals the latest block
22    /// to save resources and not leak txs from the tx-pool,
23    /// this flag enables computing of the pending block
24    /// from the tx-pool instead.
25    ///
26    /// If `compute_pending_block` is not enabled, the payload builder
27    /// will use the payload attributes from the latest block. Note
28    /// that this flag is not yet functional.
29    #[arg(long = "rollup.compute-pending-block")]
30    pub compute_pending_block: bool,
31
32    /// enables discovery v4 if provided
33    #[arg(long = "rollup.discovery.v4", default_value = "false")]
34    pub discovery_v4: bool,
35
36    /// Enable transaction conditional support on sequencer
37    #[arg(long = "rollup.enable-tx-conditional", default_value = "false")]
38    pub enable_tx_conditional: bool,
39
40    /// HTTP endpoint for the supervisor
41    #[arg(
42        long = "rollup.supervisor-http",
43        value_name = "SUPERVISOR_HTTP_URL",
44        default_value = DEFAULT_SUPERVISOR_URL
45    )]
46    pub supervisor_http: String,
47
48    /// Safety level for the supervisor
49    #[arg(
50        long = "rollup.supervisor-safety-level",
51        default_value_t = SafetyLevel::CrossUnsafe,
52    )]
53    pub supervisor_safety_level: SafetyLevel,
54
55    /// Optional headers to use when connecting to the sequencer.
56    #[arg(long = "rollup.sequencer-headers", requires = "sequencer")]
57    pub sequencer_headers: Vec<String>,
58
59    /// RPC endpoint for historical data.
60    #[arg(
61        long = "rollup.historicalrpc",
62        alias = "rollup.historical-rpc",
63        value_name = "HISTORICAL_HTTP_URL"
64    )]
65    pub historical_rpc: Option<String>,
66
67    /// Minimum suggested priority fee (tip) in wei, default `1_000_000`
68    #[arg(long, default_value_t = 1_000_000)]
69    pub min_suggested_priority_fee: u64,
70
71    /// A URL pointing to a secure websocket subscription that streams out flashblocks.
72    ///
73    /// If given, the flashblocks are received to build pending block. All request with "pending"
74    /// block tag will use the pending state based on flashblocks.
75    #[arg(long, alias = "websocket-url")]
76    pub flashblocks_url: Option<Url>,
77
78    /// Enable flashblock consensus client to drive the chain forward
79    ///
80    /// When enabled, the flashblock consensus client will process flashblock sequences and submit
81    /// them to the engine API to advance the chain.
82    /// Requires `flashblocks_url` to be set.
83    #[arg(long, default_value_t = false, requires = "flashblocks_url")]
84    pub flashblock_consensus: bool,
85}
86
87impl Default for RollupArgs {
88    fn default() -> Self {
89        Self {
90            sequencer: None,
91            disable_txpool_gossip: false,
92            compute_pending_block: false,
93            discovery_v4: false,
94            enable_tx_conditional: false,
95            supervisor_http: DEFAULT_SUPERVISOR_URL.to_string(),
96            supervisor_safety_level: SafetyLevel::CrossUnsafe,
97            sequencer_headers: Vec::new(),
98            historical_rpc: None,
99            min_suggested_priority_fee: 1_000_000,
100            flashblocks_url: None,
101            flashblock_consensus: false,
102        }
103    }
104}
105
106#[cfg(test)]
107mod tests {
108    use super::*;
109    use clap::{Args, Parser};
110
111    /// A helper type to parse Args more easily
112    #[derive(Parser)]
113    struct CommandParser<T: Args> {
114        #[command(flatten)]
115        args: T,
116    }
117
118    #[test]
119    fn test_parse_optimism_default_args() {
120        let default_args = RollupArgs::default();
121        let args = CommandParser::<RollupArgs>::parse_from(["reth"]).args;
122        assert_eq!(args, default_args);
123    }
124
125    #[test]
126    fn test_parse_optimism_compute_pending_block_args() {
127        let expected_args = RollupArgs { compute_pending_block: true, ..Default::default() };
128        let args =
129            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.compute-pending-block"])
130                .args;
131        assert_eq!(args, expected_args);
132    }
133
134    #[test]
135    fn test_parse_optimism_discovery_v4_args() {
136        let expected_args = RollupArgs { discovery_v4: true, ..Default::default() };
137        let args = CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.discovery.v4"]).args;
138        assert_eq!(args, expected_args);
139    }
140
141    #[test]
142    fn test_parse_optimism_sequencer_http_args() {
143        let expected_args =
144            RollupArgs { sequencer: Some("http://host:port".into()), ..Default::default() };
145        let args = CommandParser::<RollupArgs>::parse_from([
146            "reth",
147            "--rollup.sequencer-http",
148            "http://host:port",
149        ])
150        .args;
151        assert_eq!(args, expected_args);
152    }
153
154    #[test]
155    fn test_parse_optimism_disable_txpool_args() {
156        let expected_args = RollupArgs { disable_txpool_gossip: true, ..Default::default() };
157        let args =
158            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.disable-tx-pool-gossip"])
159                .args;
160        assert_eq!(args, expected_args);
161    }
162
163    #[test]
164    fn test_parse_optimism_enable_tx_conditional() {
165        let expected_args = RollupArgs { enable_tx_conditional: true, ..Default::default() };
166        let args =
167            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.enable-tx-conditional"])
168                .args;
169        assert_eq!(args, expected_args);
170    }
171
172    #[test]
173    fn test_parse_optimism_many_args() {
174        let expected_args = RollupArgs {
175            disable_txpool_gossip: true,
176            compute_pending_block: true,
177            enable_tx_conditional: true,
178            sequencer: Some("http://host:port".into()),
179            ..Default::default()
180        };
181        let args = CommandParser::<RollupArgs>::parse_from([
182            "reth",
183            "--rollup.disable-tx-pool-gossip",
184            "--rollup.compute-pending-block",
185            "--rollup.enable-tx-conditional",
186            "--rollup.sequencer-http",
187            "http://host:port",
188        ])
189        .args;
190        assert_eq!(args, expected_args);
191    }
192}