referrerpolicy=no-referrer-when-downgrade

undying_collator/
cli.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Polkadot CLI library.
18
19use clap::Parser;
20use sc_cli::SubstrateCli;
21use std::path::PathBuf;
22
23/// Sub-commands supported by the collator.
24#[derive(Debug, Parser)]
25pub enum Subcommand {
26	/// Export the genesis state of the parachain.
27	#[command(name = "export-genesis-state")]
28	ExportGenesisState(ExportGenesisHeadCommand),
29
30	/// Export the genesis wasm of the parachain.
31	#[command(name = "export-genesis-wasm")]
32	ExportGenesisWasm(ExportGenesisWasmCommand),
33}
34
35/// Command for exporting the genesis head data of the parachain
36#[derive(Debug, Parser)]
37pub struct ExportGenesisHeadCommand {
38	/// Output file name or stdout if unspecified.
39	#[arg()]
40	pub output: Option<PathBuf>,
41
42	/// Id of the parachain this collator collates for.
43	#[arg(long, default_value_t = 100)]
44	pub parachain_id: u32,
45
46	/// The target raw PoV size in bytes. Minimum value is 64.
47	#[arg(long, default_value_t = 1024)]
48	pub pov_size: usize,
49
50	/// The PVF execution complexity. Actually specifies how  many iterations/signatures
51	/// we compute per block.
52	#[arg(long, default_value_t = 1)]
53	pub pvf_complexity: u32,
54}
55
56/// Command for exporting the genesis wasm file.
57#[derive(Debug, Parser)]
58pub struct ExportGenesisWasmCommand {
59	/// Output file name or stdout if unspecified.
60	#[arg()]
61	pub output: Option<PathBuf>,
62}
63
64/// Enum representing different types of malicious behaviors for collators.
65#[derive(Debug, Parser, Clone, PartialEq, clap::ValueEnum)]
66pub enum MalusType {
67	/// No malicious behavior.
68	None,
69	/// Submit the same collations to all assigned cores.
70	DuplicateCollations,
71}
72
73#[allow(missing_docs)]
74#[derive(Debug, Parser)]
75#[group(skip)]
76pub struct RunCmd {
77	#[allow(missing_docs)]
78	#[clap(flatten)]
79	pub base: sc_cli::RunCmd,
80
81	/// Id of the parachain this collator collates for.
82	#[arg(long, default_value_t = 2000)]
83	pub parachain_id: u32,
84
85	/// The target raw PoV size in bytes. Minimum value is 64.
86	#[arg(long, default_value_t = 1024)]
87	pub pov_size: usize,
88
89	/// The PVF execution complexity. Actually specifies how many iterations/signatures
90	/// we compute per block.
91	#[arg(long, default_value_t = 1)]
92	pub pvf_complexity: u32,
93
94	/// Specifies the malicious behavior of the collator.
95	#[arg(long, value_enum, default_value_t = MalusType::None)]
96	pub malus_type: MalusType,
97
98	/// Whether or not the collator should send the experimental ApprovedPeer UMP signal.
99	#[arg(long)]
100	pub experimental_send_approved_peer: bool,
101}
102
103#[allow(missing_docs)]
104#[derive(Debug, Parser)]
105pub struct Cli {
106	#[command(subcommand)]
107	pub subcommand: Option<Subcommand>,
108
109	#[clap(flatten)]
110	pub run: RunCmd,
111}
112
113impl SubstrateCli for Cli {
114	fn impl_name() -> String {
115		"Parity Zombienet/Undying".into()
116	}
117
118	fn impl_version() -> String {
119		env!("CARGO_PKG_VERSION").into()
120	}
121
122	fn description() -> String {
123		env!("CARGO_PKG_DESCRIPTION").into()
124	}
125
126	fn author() -> String {
127		env!("CARGO_PKG_AUTHORS").into()
128	}
129
130	fn support_url() -> String {
131		"https://github.com/paritytech/polkadot-sdk/issues/new".into()
132	}
133
134	fn copyright_start_year() -> i32 {
135		2022
136	}
137
138	fn executable_name() -> String {
139		"undying-collator".into()
140	}
141
142	fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
143		let id = if id.is_empty() { "rococo" } else { id };
144		Ok(match id {
145			"rococo-staging" =>
146				Box::new(polkadot_service::chain_spec::rococo_staging_testnet_config()?),
147			"rococo-local" =>
148				Box::new(polkadot_service::chain_spec::rococo_local_testnet_config()?),
149			"rococo" => Box::new(polkadot_service::chain_spec::rococo_config()?),
150			path => {
151				let path = std::path::PathBuf::from(path);
152				Box::new(polkadot_service::RococoChainSpec::from_json_file(path)?)
153			},
154		})
155	}
156}