referrerpolicy=no-referrer-when-downgrade

polkadot_omni_node_lib/
cli.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17//! CLI options of the omni-node. See [`Command`].
18
19/// Default block time for dev mode when using `--dev` flag.
20const DEFAULT_DEV_BLOCK_TIME_MS: u64 = 3000;
21
22use crate::{
23	chain_spec::DiskChainSpecLoader,
24	common::{
25		chain_spec::{Extensions, LoadSpec},
26		NodeExtraArgs,
27	},
28};
29use chain_spec_builder::ChainSpecBuilder;
30use clap::{Command, CommandFactory, FromArgMatches, ValueEnum};
31use sc_chain_spec::ChainSpec;
32use sc_cli::{
33	CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams,
34	RpcEndpoint, SharedParams, SubstrateCli,
35};
36use sc_service::{config::PrometheusConfig, BasePath};
37use sc_storage_monitor::StorageMonitorParams;
38use std::{
39	fmt::{Display, Formatter},
40	marker::PhantomData,
41	path::PathBuf,
42};
43/// Trait that can be used to customize some of the customer-facing info related to the node binary
44/// that is being built using this library.
45///
46/// The related info is shown to the customer as part of logs or help messages.
47/// It does not impact functionality.
48pub trait CliConfig {
49	/// The version of the resulting node binary.
50	fn impl_version() -> String;
51
52	/// The description of the resulting node binary.
53	fn description(executable_name: String) -> String {
54		format!(
55			"The command-line arguments provided first will be passed to the parachain node, \n\
56			and the arguments provided after -- will be passed to the relay chain node. \n\
57			\n\
58			Example: \n\
59			\n\
60			{} [parachain-args] -- [relay-chain-args]",
61			executable_name
62		)
63	}
64
65	/// The author of the resulting node binary.
66	fn author() -> String;
67
68	/// The support URL for the resulting node binary.
69	fn support_url() -> String;
70
71	/// The starting copyright year of the resulting node binary.
72	fn copyright_start_year() -> u16;
73}
74
75/// Sub-commands supported by the collator.
76#[derive(Debug, clap::Subcommand)]
77pub enum Subcommand {
78	/// Key management CLI utilities
79	#[command(subcommand)]
80	Key(sc_cli::KeySubcommand),
81
82	/// Validate blocks.
83	CheckBlock(sc_cli::CheckBlockCmd),
84
85	/// Export blocks.
86	ExportBlocks(sc_cli::ExportBlocksCmd),
87
88	/// Export the state of a given block into a chain spec.
89	ExportState(sc_cli::ExportStateCmd),
90
91	/// Import blocks.
92	ImportBlocks(sc_cli::ImportBlocksCmd),
93
94	/// Revert the chain to a previous state.
95	Revert(sc_cli::RevertCmd),
96
97	/// Subcommand for generating and managing chain specifications.
98	///
99	/// A `chain-spec-builder` subcommand corresponds to the existing `chain-spec-builder` tool
100	/// (<https://crates.io/crates/staging-chain-spec-builder>), which can be used already standalone.
101	/// It provides the same functionality as the tool but bundled with `polkadot-omni-node` to
102	/// enable easier access to chain-spec generation, patching, converting to raw or validation,
103	/// from a single binary, which can be used as a parachain node tool
104	/// For a detailed usage guide please check out the standalone tool's crates.io or docs.rs
105	/// pages:
106	/// - <https://crates.io/crates/staging-chain-spec-builder>
107	/// - <https://docs.rs/staging-chain-spec-builder/latest/staging_chain_spec_builder/>
108	ChainSpecBuilder(ChainSpecBuilder),
109
110	/// Remove the whole chain.
111	PurgeChain(cumulus_client_cli::PurgeChainCmd),
112	/// Export the genesis state of the parachain.
113	#[command(alias = "export-genesis-state")]
114	ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),
115
116	/// Export the genesis wasm of the parachain.
117	ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
118
119	/// Sub-commands concerned with benchmarking.
120	/// The pallet benchmarking moved to the `pallet` sub-command.
121	#[command(subcommand)]
122	Benchmark(frame_benchmarking_cli::BenchmarkCmd),
123}
124
125/// CLI Options shipped with `polkadot-omni-node`.
126#[derive(clap::Parser)]
127#[command(
128	propagate_version = true,
129	args_conflicts_with_subcommands = true,
130	subcommand_negates_reqs = true
131)]
132pub struct Cli<Config: CliConfig> {
133	#[arg(skip)]
134	pub(crate) chain_spec_loader: Option<Box<dyn LoadSpec>>,
135
136	/// Possible subcommands. See [`Subcommand`].
137	#[command(subcommand)]
138	pub subcommand: Option<Subcommand>,
139
140	/// The shared parameters with all cumulus-based parachain nodes.
141	#[command(flatten)]
142	pub run: cumulus_client_cli::RunCmd,
143
144	/// Parameters for storage monitoring.
145	#[command(flatten)]
146	pub storage_monitor: StorageMonitorParams,
147
148	/// Start a dev node that produces a block each `dev_block_time` ms.
149	///
150	/// This is a dev option. It enables a manual sealing, meaning blocks are produced manually
151	/// rather than being part of an actual network consensus process. Using the option won't
152	/// result in starting or connecting to a parachain network. The resulting node will work on
153	/// its own, running the wasm blob and artificially producing a block each `dev_block_time` ms,
154	/// as if it was part of a parachain.
155	///
156	/// The `--dev` flag sets the `dev_block_time` to a default value of 3000ms unless explicitly
157	/// provided.
158	#[arg(long, conflicts_with = "instant_seal")]
159	pub dev_block_time: Option<u64>,
160
161	/// Start a dev node with instant seal.
162	///
163	/// This is a dev option that enables instant sealing, meaning blocks are produced
164	/// immediately when transactions are received, rather than at fixed intervals.
165	/// Using this option won't result in starting or connecting to a parachain network.
166	/// The resulting node will work on its own, running the wasm blob and producing blocks
167	/// instantly upon receiving transactions.
168	#[arg(long, conflicts_with = "dev_block_time")]
169	pub instant_seal: bool,
170
171	/// Authoring style to use.
172	#[arg(long, default_value_t = AuthoringPolicy::Lookahead)]
173	pub authoring: AuthoringPolicy,
174
175	/// Disable automatic hardware benchmarks.
176	///
177	/// By default these benchmarks are automatically ran at startup and measure
178	/// the CPU speed, the memory bandwidth and the disk speed.
179	///
180	/// The results are then printed out in the logs, and also sent as part of
181	/// telemetry, if telemetry is enabled.
182	#[arg(long)]
183	pub no_hardware_benchmarks: bool,
184
185	/// Export all `PoVs` build by this collator to the given folder.
186	///
187	/// This is useful for debugging issues that are occurring while validating these `PoVs` on the
188	/// relay chain.
189	#[arg(long)]
190	pub export_pov_to_path: Option<PathBuf>,
191
192	/// Relay chain arguments
193	#[arg(raw = true)]
194	pub relay_chain_args: Vec<String>,
195
196	/// Enable the statement store.
197	///
198	/// The statement store reads the storage of the chain to determine if users are allowed to
199	/// store statements or not.
200	#[arg(long)]
201	pub enable_statement_store: bool,
202
203	/// Route statements through the DHT instead of gossiping them to every peer.
204	///
205	/// Only relevant when `--enable-statement-store` is used.
206	#[arg(long, hide = true)]
207	pub statement_v2_dht: bool,
208
209	/// Number of concurrent workers for statement validation from the network.
210	///
211	/// Only relevant when `--enable-statement-store` is used.
212	#[arg(long, default_value_t = sc_statement_store::DEFAULT_NETWORK_WORKERS)]
213	pub statement_network_workers: usize,
214
215	/// Maximum statements per second per peer before rate limiting kicks in.
216	///
217	/// Uses a token bucket algorithm that allows short bursts up to this limit
218	/// while enforcing the average rate over time.
219	///
220	/// Only relevant when `--enable-statement-store` is used.
221	#[arg(long, default_value_t = sc_statement_store::DEFAULT_RATE_LIMIT)]
222	pub statement_rate_limit: u32,
223
224	/// Maximum number of statements the statement store can hold.
225	///
226	/// Once this limit is reached, lower-priority statements may be evicted.
227	///
228	/// Only relevant when `--enable-statement-store` is used.
229	#[arg(long, default_value_t = sc_statement_store::DEFAULT_MAX_TOTAL_STATEMENTS)]
230	pub statement_store_max_total_statements: usize,
231
232	/// Maximum total data size (in bytes) the statement store can hold.
233	///
234	/// Once this limit is reached, lower-priority statements may be evicted.
235	///
236	/// Only relevant when `--enable-statement-store` is used.
237	#[arg(long, default_value_t = sc_statement_store::DEFAULT_MAX_TOTAL_SIZE)]
238	pub statement_store_max_total_size: usize,
239
240	/// Number of seconds for which removed statements won't be allowed to be added back.
241	///
242	/// This prevents old statements from being re-propagated on the network.
243	///
244	/// Only relevant when `--enable-statement-store` is used.
245	#[arg(long, default_value_t = sc_statement_store::DEFAULT_PURGE_AFTER_SEC)]
246	pub statement_store_purge_after_sec: u64,
247
248	/// Affinity topic advertised by this node. Repeatable; each value is a 32-byte hex
249	/// hash.
250	///
251	/// Makes the node responsible for finding and storing all statements with topics in this
252	/// list.
253	///
254	/// Only relevant when `--enable-statement-store` is used.
255	///
256	/// Hidden: takes effect only with `--statement-v2-dht`.
257	#[arg(long = "statement-affinity-topic", value_name = "TOPIC", hide = true)]
258	pub statement_affinity_topics: Vec<sc_statement_store::Topic>,
259
260	/// File with affinity topics advertised by this node, one 32-byte hex topic per line.
261	/// Blank lines and lines starting with `#` are skipped. Adds to `--statement-affinity-topic`.
262	///
263	/// Only relevant when `--enable-statement-store` is used.
264	///
265	/// Hidden: takes effect only with `--statement-v2-dht`.
266	#[arg(long = "statement-affinity-topics-file", value_name = "PATH", hide = true)]
267	pub statement_affinity_topics_file: Option<sc_statement_store::AffinityTopicsFile>,
268
269	/// Number of K-closest peers (replication factor) used for DHT-affinity statement routing.
270	///
271	/// Only relevant when `--enable-statement-store` is used.
272	///
273	/// Hidden: takes effect only with `--statement-v2-dht`.
274	#[arg(
275		long,
276		value_name = "K",
277		default_value_t = sc_statement_store::DEFAULT_REPLICATION_FACTOR,
278		hide = true
279	)]
280	pub statement_replication_factor: std::num::NonZeroUsize,
281
282	/// Inbound slots for full peers on the statement protocol. Light peers get `--in-peers-light`
283	/// on top.
284	///
285	/// Only relevant when `--enable-statement-store` is used.
286	///
287	/// Hidden: takes effect only with `--statement-v2-dht`.
288	#[arg(
289		long,
290		value_name = "COUNT",
291		default_value_t = sc_statement_store::DEFAULT_IN_PEERS,
292		hide = true
293	)]
294	pub statement_in_peers: u32,
295
296	/// Number of peers to gossip a statement to in addition to DHT-affinity routing targets.
297	///
298	/// Only relevant when `--enable-statement-store` is used.
299	///
300	/// Hidden: takes effect only with `--statement-v2-dht`.
301	#[arg(
302		long,
303		value_name = "N",
304		default_value_t = sc_statement_store::DEFAULT_GOSSIP_TARGET,
305		hide = true
306	)]
307	pub statement_gossip_target: std::num::NonZeroUsize,
308
309	/// False-positive rate of the topic-affinity bloom filter this node advertises.
310	///
311	/// Only relevant when `--enable-statement-store` is used.
312	///
313	/// Hidden: takes effect only with `--statement-v2-dht`.
314	#[arg(
315		long,
316		value_name = "RATE",
317		default_value_t = sc_statement_store::DEFAULT_BLOOM_FALSE_POS_RATE,
318		hide = true
319	)]
320	pub statement_bloom_false_positive_rate: f64,
321
322	/// Seed of the topic-affinity bloom filter this node advertises. Defaults to a random
323	/// value per node.
324	///
325	/// Only relevant when `--enable-statement-store` is used.
326	///
327	/// Hidden: takes effect only with `--statement-v2-dht`.
328	#[arg(long, value_name = "SEED", hide = true)]
329	pub statement_bloom_seed: Option<u128>,
330
331	/// Maximum total data size (in bytes) of the statements the store keeps for DHT affinity.
332	/// Defaults to `--statement-store-max-total-size`.
333	///
334	/// Only relevant when `--enable-statement-store` is used.
335	///
336	/// Hidden: takes effect only with `--statement-v2-dht`.
337	#[arg(long, value_name = "BYTES", hide = true)]
338	pub statement_store_max_dht_affinity_size: Option<usize>,
339
340	/// Maximum total data size (in bytes) of the transient statements, kept only until
341	/// propagated. Defaults to `--statement-store-max-total-size`.
342	///
343	/// Only relevant when `--enable-statement-store` is used.
344	///
345	/// Hidden: takes effect only with `--statement-v2-dht`.
346	#[arg(long, value_name = "BYTES", hide = true)]
347	pub statement_store_max_transient_size: Option<usize>,
348
349	/// Upper bound on collator reserved-peer slots.
350	#[arg(long, value_name = "N", default_value_t = 32)]
351	pub collator_reserved_slots: usize,
352
353	/// HOP (Hand-Off Protocol) configuration parameters.
354	#[command(flatten)]
355	pub hop: sc_hop::HopParams,
356
357	#[arg(skip)]
358	pub(crate) _phantom: PhantomData<Config>,
359}
360
361/// Development sealing mode.
362#[derive(Debug, Clone, Copy)]
363pub(crate) enum DevSealMode {
364	/// Produces blocks immediately upon receiving transactions.
365	InstantSeal,
366	/// Produces blocks at fixed time intervals.
367	/// The u64 parameter represents the block time in milliseconds.
368	ManualSeal(u64),
369}
370
371/// Collator implementation to use.
372#[derive(PartialEq, Debug, ValueEnum, Clone, Copy)]
373pub enum AuthoringPolicy {
374	/// Use the lookahead collator. Builds a block once per imported relay chain block and
375	/// on relay chain forks. Default for asynchronous backing chains.
376	Lookahead,
377	/// Use the slot-based collator. Builds a block based on time. Can utilize multiple cores,
378	/// always builds on the best relay chain block available. Should be used with elastic-scaling
379	/// chains.
380	SlotBased,
381}
382
383impl Display for AuthoringPolicy {
384	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
385		match self {
386			AuthoringPolicy::Lookahead => write!(f, "lookahead"),
387			AuthoringPolicy::SlotBased => write!(f, "slot-based"),
388		}
389	}
390}
391
392impl<Config: CliConfig> Cli<Config> {
393	pub(crate) fn node_extra_args(&self) -> NodeExtraArgs {
394		NodeExtraArgs {
395			authoring_policy: self.authoring,
396			export_pov: self.export_pov_to_path.clone(),
397			max_pov_percentage: self.run.experimental_max_pov_percentage,
398			statement_store_config: self.enable_statement_store.then_some(
399				sc_statement_store::Config {
400					max_total_statements: self.statement_store_max_total_statements,
401					max_total_size: self.statement_store_max_total_size,
402					purge_after_sec: self.statement_store_purge_after_sec,
403					network_workers: self.statement_network_workers,
404					rate_limit: self.statement_rate_limit,
405					v2dht: sc_network_statement::v2dht_enabled().then(|| {
406						sc_statement_store::V2DhtConfig {
407							affinity_topics: self.statement_affinity_topics.clone(),
408							affinity_topics_file: self.statement_affinity_topics_file.clone(),
409							bloom_false_pos_rate: self.statement_bloom_false_positive_rate,
410							bloom_seed: self.statement_bloom_seed,
411							replication_factor: self.statement_replication_factor,
412							gossip_target: self.statement_gossip_target,
413							dht_affinity_max_size: self.statement_store_max_dht_affinity_size,
414							transient_max_size: self.statement_store_max_transient_size,
415							in_peers: self.statement_in_peers,
416						}
417					}),
418				},
419			),
420			storage_monitor: self.storage_monitor.clone(),
421			collator_reserved_slots: self.collator_reserved_slots,
422			hop: self.hop.enabled.then(|| self.hop.clone()),
423		}
424	}
425
426	/// Returns the dev seal mode if the node is in dev mode.
427	pub(crate) fn dev_mode(&self) -> Option<DevSealMode> {
428		if self.instant_seal {
429			Some(DevSealMode::InstantSeal)
430		} else if let Some(dev_block_time) = self.dev_block_time {
431			Some(DevSealMode::ManualSeal(dev_block_time))
432		} else if self.run.base.is_dev().unwrap_or(false) {
433			Some(DevSealMode::ManualSeal(DEFAULT_DEV_BLOCK_TIME_MS))
434		} else {
435			None
436		}
437	}
438}
439
440impl<Config: CliConfig> SubstrateCli for Cli<Config> {
441	fn impl_name() -> String {
442		Self::executable_name()
443	}
444
445	fn impl_version() -> String {
446		Config::impl_version()
447	}
448
449	fn description() -> String {
450		Config::description(Self::executable_name())
451	}
452
453	fn author() -> String {
454		Config::author()
455	}
456
457	fn support_url() -> String {
458		Config::support_url()
459	}
460
461	fn copyright_start_year() -> i32 {
462		Config::copyright_start_year() as i32
463	}
464
465	fn load_spec(&self, id: &str) -> Result<Box<dyn ChainSpec>, String> {
466		match &self.chain_spec_loader {
467			Some(chain_spec_loader) => chain_spec_loader.load_spec(id),
468			None => DiskChainSpecLoader.load_spec(id),
469		}
470	}
471}
472
473/// The relay chain CLI flags. These are passed in after a `--` at the end.
474#[derive(Debug)]
475pub struct RelayChainCli<Config: CliConfig> {
476	/// The actual relay chain cli object.
477	pub base: polkadot_cli::RunCmd,
478
479	/// Optional chain id that should be passed to the relay chain.
480	pub chain_id: Option<String>,
481
482	/// The base path that should be used by the relay chain.
483	pub base_path: Option<PathBuf>,
484
485	_phantom: PhantomData<Config>,
486}
487
488impl<Config: CliConfig> RelayChainCli<Config> {
489	fn polkadot_cmd() -> Command {
490		let help_template = color_print::cformat!(
491			"The arguments that are passed to the relay chain node. \n\
492			\n\
493			<bold><underline>RELAY_CHAIN_ARGS:</></> \n\
494			{{options}}",
495		);
496
497		polkadot_cli::RunCmd::command()
498			.no_binary_name(true)
499			.help_template(help_template)
500	}
501
502	/// Parse the relay chain CLI parameters using the parachain `Configuration`.
503	pub fn new<'a>(
504		para_config: &sc_service::Configuration,
505		relay_chain_args: impl Iterator<Item = &'a String>,
506	) -> Self {
507		let polkadot_cmd = Self::polkadot_cmd();
508		let matches = polkadot_cmd.get_matches_from(relay_chain_args);
509		let base = FromArgMatches::from_arg_matches(&matches).unwrap_or_else(|e| e.exit());
510
511		let extension = Extensions::try_get(&*para_config.chain_spec);
512		let chain_id = extension.map(|e| e.relay_chain());
513
514		let base_path = para_config.base_path.path().join("polkadot");
515		Self { base, chain_id, base_path: Some(base_path), _phantom: Default::default() }
516	}
517}
518
519impl<Config: CliConfig> SubstrateCli for RelayChainCli<Config> {
520	fn impl_name() -> String {
521		Cli::<Config>::impl_name()
522	}
523
524	fn impl_version() -> String {
525		Cli::<Config>::impl_version()
526	}
527
528	fn description() -> String {
529		Cli::<Config>::description()
530	}
531
532	fn author() -> String {
533		Cli::<Config>::author()
534	}
535
536	fn support_url() -> String {
537		Cli::<Config>::support_url()
538	}
539
540	fn copyright_start_year() -> i32 {
541		Cli::<Config>::copyright_start_year()
542	}
543
544	fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
545		polkadot_cli::Cli::from_iter([Self::executable_name()].iter()).load_spec(id)
546	}
547}
548
549impl<Config: CliConfig> DefaultConfigurationValues for RelayChainCli<Config> {
550	fn p2p_listen_port() -> u16 {
551		30334
552	}
553
554	fn rpc_listen_port() -> u16 {
555		9945
556	}
557
558	fn prometheus_listen_port() -> u16 {
559		9616
560	}
561}
562
563impl<Config: CliConfig> CliConfiguration<Self> for RelayChainCli<Config> {
564	fn shared_params(&self) -> &SharedParams {
565		self.base.base.shared_params()
566	}
567
568	fn import_params(&self) -> Option<&ImportParams> {
569		self.base.base.import_params()
570	}
571
572	fn network_params(&self) -> Option<&NetworkParams> {
573		self.base.base.network_params()
574	}
575
576	fn keystore_params(&self) -> Option<&KeystoreParams> {
577		self.base.base.keystore_params()
578	}
579
580	fn base_path(&self) -> sc_cli::Result<Option<BasePath>> {
581		Ok(self
582			.shared_params()
583			.base_path()?
584			.or_else(|| self.base_path.clone().map(Into::into)))
585	}
586
587	fn rpc_addr(&self, default_listen_port: u16) -> sc_cli::Result<Option<Vec<RpcEndpoint>>> {
588		self.base.base.rpc_addr(default_listen_port)
589	}
590
591	fn prometheus_config(
592		&self,
593		default_listen_port: u16,
594		chain_spec: &Box<dyn ChainSpec>,
595	) -> sc_cli::Result<Option<PrometheusConfig>> {
596		self.base.base.prometheus_config(default_listen_port, chain_spec)
597	}
598
599	fn init<F>(
600		&self,
601		_support_url: &String,
602		_impl_version: &String,
603		_logger_hook: F,
604	) -> sc_cli::Result<()>
605	where
606		F: FnOnce(&mut sc_cli::LoggerBuilder),
607	{
608		unreachable!("PolkadotCli is never initialized; qed");
609	}
610
611	fn chain_id(&self, is_dev: bool) -> sc_cli::Result<String> {
612		let chain_id = self.base.base.chain_id(is_dev)?;
613
614		Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id })
615	}
616
617	fn role(&self, is_dev: bool) -> sc_cli::Result<sc_service::Role> {
618		self.base.base.role(is_dev)
619	}
620
621	fn transaction_pool(
622		&self,
623		is_dev: bool,
624	) -> sc_cli::Result<sc_service::config::TransactionPoolOptions> {
625		self.base.base.transaction_pool(is_dev)
626	}
627
628	fn trie_cache_maximum_size(&self) -> sc_cli::Result<Option<usize>> {
629		self.base.base.trie_cache_maximum_size()
630	}
631
632	fn rpc_methods(&self) -> sc_cli::Result<sc_service::config::RpcMethods> {
633		self.base.base.rpc_methods()
634	}
635
636	fn rpc_max_connections(&self) -> sc_cli::Result<u32> {
637		self.base.base.rpc_max_connections()
638	}
639
640	fn rpc_cors(&self, is_dev: bool) -> sc_cli::Result<Option<Vec<String>>> {
641		self.base.base.rpc_cors(is_dev)
642	}
643
644	fn default_heap_pages(&self) -> sc_cli::Result<Option<u64>> {
645		self.base.base.default_heap_pages()
646	}
647
648	fn force_authoring(&self) -> sc_cli::Result<bool> {
649		self.base.base.force_authoring()
650	}
651
652	fn disable_grandpa(&self) -> sc_cli::Result<bool> {
653		self.base.base.disable_grandpa()
654	}
655
656	fn max_runtime_instances(&self) -> sc_cli::Result<Option<usize>> {
657		self.base.base.max_runtime_instances()
658	}
659
660	fn announce_block(&self) -> sc_cli::Result<bool> {
661		self.base.base.announce_block()
662	}
663
664	fn telemetry_endpoints(
665		&self,
666		chain_spec: &Box<dyn ChainSpec>,
667	) -> sc_cli::Result<Option<sc_telemetry::TelemetryEndpoints>> {
668		self.base.base.telemetry_endpoints(chain_spec)
669	}
670
671	fn node_name(&self) -> sc_cli::Result<String> {
672		self.base.base.node_name()
673	}
674}
675
676#[cfg(test)]
677mod tests {
678	use super::*;
679	use clap::{CommandFactory, FromArgMatches};
680
681	struct TestCliConfig;
682	impl CliConfig for TestCliConfig {
683		fn impl_version() -> String {
684			"0.0.0".into()
685		}
686		fn author() -> String {
687			"test".into()
688		}
689		fn support_url() -> String {
690			"https://example.invalid".into()
691		}
692		fn copyright_start_year() -> u16 {
693			2025
694		}
695	}
696
697	#[test]
698	fn statement_affinity_topics_accumulate_repeated_flags() {
699		let topic_a = "11".repeat(32);
700		let topic_b = "22".repeat(32);
701		// `propagate_version = true` on the command requires a version; the binary injects one via
702		// `SubstrateCli` at runtime, so set one here to drive clap directly.
703		let matches = Cli::<TestCliConfig>::command().version("0.0.0").get_matches_from([
704			"polkadot-omni-node",
705			"--statement-affinity-topic",
706			&format!("0x{topic_a}"),
707			"--statement-affinity-topic",
708			&format!("0x{topic_b}"),
709		]);
710		let cli = Cli::<TestCliConfig>::from_arg_matches(&matches).expect("args parse");
711		assert_eq!(
712			cli.statement_affinity_topics,
713			vec![sc_statement_store::Topic([0x11; 32]), sc_statement_store::Topic([0x22; 32])]
714		);
715	}
716
717	#[test]
718	fn statement_bloom_flags_parse() {
719		let matches = Cli::<TestCliConfig>::command().version("0.0.0").get_matches_from([
720			"polkadot-omni-node",
721			"--statement-bloom-false-positive-rate",
722			"0.001",
723			"--statement-bloom-seed",
724			"12345678901234567890123456789012345678",
725		]);
726		let cli = Cli::<TestCliConfig>::from_arg_matches(&matches).expect("args parse");
727		assert_eq!(cli.statement_bloom_false_positive_rate, 0.001);
728		assert_eq!(cli.statement_bloom_seed, Some(12345678901234567890123456789012345678));
729
730		let matches = Cli::<TestCliConfig>::command()
731			.version("0.0.0")
732			.get_matches_from(["polkadot-omni-node"]);
733		let cli = Cli::<TestCliConfig>::from_arg_matches(&matches).expect("args parse");
734		assert_eq!(
735			cli.statement_bloom_false_positive_rate,
736			sc_statement_store::DEFAULT_BLOOM_FALSE_POS_RATE
737		);
738		assert_eq!(cli.statement_bloom_seed, None);
739	}
740}