reth_optimism_node/
args.rs
1use op_alloy_consensus::interop::SafetyLevel;
6use reth_optimism_txpool::supervisor::DEFAULT_SUPERVISOR_URL;
7
8#[derive(Debug, Clone, PartialEq, Eq, clap::Args)]
10#[command(next_help_heading = "Rollup")]
11pub struct RollupArgs {
12 #[arg(long = "rollup.sequencer", visible_aliases = ["rollup.sequencer-http", "rollup.sequencer-ws"])]
14 pub sequencer: Option<String>,
15
16 #[arg(long = "rollup.disable-tx-pool-gossip")]
18 pub disable_txpool_gossip: bool,
19
20 #[arg(long = "rollup.enable-genesis-walkback")]
23 pub enable_genesis_walkback: bool,
24
25 #[arg(long = "rollup.compute-pending-block")]
34 pub compute_pending_block: bool,
35
36 #[arg(long = "rollup.discovery.v4", default_value = "false")]
38 pub discovery_v4: bool,
39
40 #[arg(long = "rollup.enable-tx-conditional", default_value = "false")]
42 pub enable_tx_conditional: bool,
43
44 #[arg(
46 long = "rollup.supervisor-http",
47 value_name = "SUPERVISOR_HTTP_URL",
48 default_value = DEFAULT_SUPERVISOR_URL
49 )]
50 pub supervisor_http: String,
51
52 #[arg(
54 long = "rollup.supervisor-safety-level",
55 default_value_t = SafetyLevel::CrossUnsafe,
56 )]
57 pub supervisor_safety_level: SafetyLevel,
58}
59
60impl Default for RollupArgs {
61 fn default() -> Self {
62 Self {
63 sequencer: None,
64 disable_txpool_gossip: false,
65 enable_genesis_walkback: false,
66 compute_pending_block: false,
67 discovery_v4: false,
68 enable_tx_conditional: false,
69 supervisor_http: DEFAULT_SUPERVISOR_URL.to_string(),
70 supervisor_safety_level: SafetyLevel::CrossUnsafe,
71 }
72 }
73}
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78 use clap::{Args, Parser};
79
80 #[derive(Parser)]
82 struct CommandParser<T: Args> {
83 #[command(flatten)]
84 args: T,
85 }
86
87 #[test]
88 fn test_parse_optimism_default_args() {
89 let default_args = RollupArgs::default();
90 let args = CommandParser::<RollupArgs>::parse_from(["reth"]).args;
91 assert_eq!(args, default_args);
92 }
93
94 #[test]
95 fn test_parse_optimism_walkback_args() {
96 let expected_args = RollupArgs { enable_genesis_walkback: true, ..Default::default() };
97 let args =
98 CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.enable-genesis-walkback"])
99 .args;
100 assert_eq!(args, expected_args);
101 }
102
103 #[test]
104 fn test_parse_optimism_compute_pending_block_args() {
105 let expected_args = RollupArgs { compute_pending_block: true, ..Default::default() };
106 let args =
107 CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.compute-pending-block"])
108 .args;
109 assert_eq!(args, expected_args);
110 }
111
112 #[test]
113 fn test_parse_optimism_discovery_v4_args() {
114 let expected_args = RollupArgs { discovery_v4: true, ..Default::default() };
115 let args = CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.discovery.v4"]).args;
116 assert_eq!(args, expected_args);
117 }
118
119 #[test]
120 fn test_parse_optimism_sequencer_http_args() {
121 let expected_args =
122 RollupArgs { sequencer: Some("http://host:port".into()), ..Default::default() };
123 let args = CommandParser::<RollupArgs>::parse_from([
124 "reth",
125 "--rollup.sequencer-http",
126 "http://host:port",
127 ])
128 .args;
129 assert_eq!(args, expected_args);
130 }
131
132 #[test]
133 fn test_parse_optimism_disable_txpool_args() {
134 let expected_args = RollupArgs { disable_txpool_gossip: true, ..Default::default() };
135 let args =
136 CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.disable-tx-pool-gossip"])
137 .args;
138 assert_eq!(args, expected_args);
139 }
140
141 #[test]
142 fn test_parse_optimism_enable_tx_conditional() {
143 let expected_args = RollupArgs { enable_tx_conditional: true, ..Default::default() };
144 let args =
145 CommandParser::<RollupArgs>::parse_from(["reth", "--rollup.enable-tx-conditional"])
146 .args;
147 assert_eq!(args, expected_args);
148 }
149
150 #[test]
151 fn test_parse_optimism_many_args() {
152 let expected_args = RollupArgs {
153 disable_txpool_gossip: true,
154 compute_pending_block: true,
155 enable_genesis_walkback: true,
156 enable_tx_conditional: true,
157 sequencer: Some("http://host:port".into()),
158 ..Default::default()
159 };
160 let args = CommandParser::<RollupArgs>::parse_from([
161 "reth",
162 "--rollup.disable-tx-pool-gossip",
163 "--rollup.compute-pending-block",
164 "--rollup.enable-genesis-walkback",
165 "--rollup.enable-tx-conditional",
166 "--rollup.sequencer-http",
167 "http://host:port",
168 ])
169 .args;
170 assert_eq!(args, expected_args);
171 }
172}