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