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)]
76    pub flashblocks_url: Option<Url>,
77}
78
79impl Default for RollupArgs {
80    fn default() -> Self {
81        Self {
82            sequencer: None,
83            disable_txpool_gossip: false,
84            compute_pending_block: false,
85            discovery_v4: false,
86            enable_tx_conditional: false,
87            supervisor_http: DEFAULT_SUPERVISOR_URL.to_string(),
88            supervisor_safety_level: SafetyLevel::CrossUnsafe,
89            sequencer_headers: Vec::new(),
90            historical_rpc: None,
91            min_suggested_priority_fee: 1_000_000,
92            flashblocks_url: None,
93        }
94    }
95}
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100    use clap::{Args, Parser};
101
102    /// A helper type to parse Args more easily
103    #[derive(Parser)]
104    struct CommandParser<T: Args> {
105        #[command(flatten)]
106        args: T,
107    }
108
109    #[test]
110    fn test_parse_optimism_default_args() {
111        let default_args = RollupArgs::default();
112        let args = CommandParser::<RollupArgs>::parse_from(["reth"]).args;
113        assert_eq!(args, default_args);
114    }
115
116    #[test]
117    fn test_parse_optimism_compute_pending_block_args() {
118        let expected_args = RollupArgs { compute_pending_block: true, ..Default::default() };
119        let args =
120            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.compute-pending-block"])
121                .args;
122        assert_eq!(args, expected_args);
123    }
124
125    #[test]
126    fn test_parse_optimism_discovery_v4_args() {
127        let expected_args = RollupArgs { discovery_v4: true, ..Default::default() };
128        let args = CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.discovery.v4"]).args;
129        assert_eq!(args, expected_args);
130    }
131
132    #[test]
133    fn test_parse_optimism_sequencer_http_args() {
134        let expected_args =
135            RollupArgs { sequencer: Some("http://host:port".into()), ..Default::default() };
136        let args = CommandParser::<RollupArgs>::parse_from([
137            "reth",
138            "--rollup.sequencer-http",
139            "http://host:port",
140        ])
141        .args;
142        assert_eq!(args, expected_args);
143    }
144
145    #[test]
146    fn test_parse_optimism_disable_txpool_args() {
147        let expected_args = RollupArgs { disable_txpool_gossip: true, ..Default::default() };
148        let args =
149            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.disable-tx-pool-gossip"])
150                .args;
151        assert_eq!(args, expected_args);
152    }
153
154    #[test]
155    fn test_parse_optimism_enable_tx_conditional() {
156        let expected_args = RollupArgs { enable_tx_conditional: true, ..Default::default() };
157        let args =
158            CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.enable-tx-conditional"])
159                .args;
160        assert_eq!(args, expected_args);
161    }
162
163    #[test]
164    fn test_parse_optimism_many_args() {
165        let expected_args = RollupArgs {
166            disable_txpool_gossip: true,
167            compute_pending_block: true,
168            enable_tx_conditional: true,
169            sequencer: Some("http://host:port".into()),
170            ..Default::default()
171        };
172        let args = CommandParser::<RollupArgs>::parse_from([
173            "reth",
174            "--rollup.disable-tx-pool-gossip",
175            "--rollup.compute-pending-block",
176            "--rollup.enable-tx-conditional",
177            "--rollup.sequencer-http",
178            "http://host:port",
179        ])
180        .args;
181        assert_eq!(args, expected_args);
182    }
183}