frequency_cli/
cli.rs

1//! Frequency CLI library.
2
3// File originally from https://github.com/paritytech/cumulus/blob/master/parachain-template/node/src/cli.rs
4
5use crate::{ExportMetadataCmd, ExportRuntimeVersionCmd};
6use std::path::PathBuf;
7
8#[cfg(feature = "frequency-no-relay")]
9use std::num::NonZeroU16;
10
11#[cfg(feature = "frequency-no-relay")]
12use cli_opt::SealingMode;
13
14/// Sub-commands supported by the collator.
15#[derive(Debug, clap::Subcommand)]
16pub enum Subcommand {
17	/// Key management cli utilities
18	#[command(subcommand)]
19	Key(sc_cli::KeySubcommand),
20	/// Build a chain specification.
21	BuildSpec(sc_cli::BuildSpecCmd),
22
23	/// Validate blocks.
24	CheckBlock(sc_cli::CheckBlockCmd),
25
26	/// Export blocks.
27	ExportBlocks(sc_cli::ExportBlocksCmd),
28
29	/// Export the state of a given block into a chain spec.
30	ExportState(sc_cli::ExportStateCmd),
31
32	/// Import blocks.
33	ImportBlocks(sc_cli::ImportBlocksCmd),
34
35	/// Export metadata.
36	ExportMetadata(ExportMetadataCmd),
37
38	/// Revert the chain to a previous state.
39	Revert(sc_cli::RevertCmd),
40
41	/// Remove the whole chain.
42	PurgeChain(cumulus_client_cli::PurgeChainCmd),
43
44	/// Export the genesis state of the parachain.
45	#[command(alias = "export-genesis-state")]
46	ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),
47
48	/// Export the genesis wasm of the parachain.
49	ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
50
51	/// Sub-commands concerned with benchmarking.
52	/// The pallet benchmarking moved to the `pallet` sub-command.
53	#[clap(subcommand)]
54	Benchmark(frame_benchmarking_cli::BenchmarkCmd),
55
56	/// Get current runtime spec version.
57	ExportRuntimeVersion(ExportRuntimeVersionCmd),
58}
59
60#[derive(Debug, clap::Parser)]
61#[clap(
62	propagate_version = true,
63	args_conflicts_with_subcommands = true,
64	subcommand_negates_reqs = true
65)]
66pub struct Cli {
67	#[clap(subcommand)]
68	pub subcommand: Option<Subcommand>,
69
70	#[clap(flatten)]
71	pub run: cumulus_client_cli::RunCmd,
72
73	/// Disable automatic hardware benchmarks.
74	///
75	/// By default these benchmarks are automatically ran at startup and measure
76	/// the CPU speed, the memory bandwidth and the disk speed.
77	///
78	/// The results are then printed out in the logs, and also sent as part of
79	/// telemetry, if telemetry is enabled.
80	#[clap(long)]
81	pub no_hardware_benchmarks: bool,
82
83	/// Relay chain arguments
84	#[clap(raw = true)]
85	pub relay_chain_args: Vec<String>,
86
87	/// Instant block sealing
88	/// Blocks are triggered to be formed each time a transaction hits the validated transaction pool
89	/// Empty blocks can also be formed using the `engine_createBlock` RPC
90	#[cfg(feature = "frequency-no-relay")]
91	#[clap(long, value_enum, help = "The sealing mode", default_value_t=SealingMode::Instant)]
92	pub sealing: SealingMode,
93
94	/// Interval in seconds for interval sealing.
95	#[cfg(feature = "frequency-no-relay")]
96	#[clap(long, help = "The interval in seconds", default_value = "6", value_name = "SECONDS")]
97	pub sealing_interval: NonZeroU16,
98
99	/// Whether to create empty blocks in manual and interval sealing modes.
100	#[cfg(feature = "frequency-no-relay")]
101	#[clap(long, help = "Create empty blocks in interval sealing modes", default_value = "false")]
102	pub sealing_create_empty_blocks: bool,
103}
104
105#[derive(Debug)]
106pub struct RelayChainCli {
107	/// The actual relay chain cli object.
108	pub base: polkadot_cli::RunCmd,
109
110	/// Optional chain id that should be passed to the relay chain.
111	pub chain_id: Option<String>,
112
113	/// The base path that should be used by the relay chain.
114	pub base_path: Option<PathBuf>,
115}
116
117impl RelayChainCli {
118	/// Parse the relay chain CLI parameters using the para chain `Configuration`.
119	pub fn new<'a>(
120		para_config: &sc_service::Configuration,
121		relay_chain_args: impl Iterator<Item = &'a String>,
122	) -> Self {
123		let extension =
124			frequency_service::chain_spec::Extensions::try_get(&*para_config.chain_spec);
125		let chain_id = extension.map(|e| e.relay_chain.clone());
126		let base_path = para_config.base_path.path().join("polkadot");
127		Self {
128			base_path: Some(base_path),
129			chain_id,
130			base: clap::Parser::parse_from(relay_chain_args),
131		}
132	}
133}