Lines
56 %
Functions
12.07 %
Branches
100 %
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.
// Tanssi 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.
// Tanssi 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 Tanssi. If not, see <http://www.gnu.org/licenses/>.
use {
node_common::{cli::BuildSpecCmd, service::Sealing},
std::path::PathBuf,
tc_service_container_chain::cli::ContainerChainRunCmd,
};
/// Sub-commands supported by the collator.
#[derive(Debug, clap::Subcommand)]
#[allow(clippy::large_enum_variant)]
pub enum Subcommand {
/// Build a chain specification.
BuildSpec(BuildSpecCmdCollator),
/// Validate blocks.
CheckBlock(sc_cli::CheckBlockCmd),
/// Export blocks.
ExportBlocks(sc_cli::ExportBlocksCmd),
/// Export the state of a given block into a chain spec.
ExportState(sc_cli::ExportStateCmd),
/// Import blocks.
ImportBlocks(sc_cli::ImportBlocksCmd),
/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),
/// Remove the whole chain.
PurgeChain(cumulus_client_cli::PurgeChainCmd),
/// Export the genesis state of the parachain.
#[command(alias = "export-genesis-state")]
ExportGenesisHead(cumulus_client_cli::ExportGenesisHeadCommand),
/// Export the genesis wasm of the parachain.
ExportGenesisWasm(ExportGenesisWasmCommand),
/// Sub-commands concerned with benchmarking.
/// The pallet benchmarking moved to the `pallet` sub-command.
#[command(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
/// Key management cli utilities
Key(KeyCmd),
/// Precompile the WASM runtime into native code
PrecompileWasm(sc_cli::PrecompileWasmCmd),
/// Solochain collator mode
SoloChain(SoloChainCmd),
}
/// The `build-spec` command used to build a specification.
#[derive(Debug, clap::Parser)]
#[group(skip)]
pub struct SoloChainCmd {
#[command(flatten)]
pub run: ContainerChainRunCmd,
/// Disable automatic hardware benchmarks.
///
/// By default these benchmarks are automatically ran at startup and measure
/// the CPU speed, the memory bandwidth and the disk speed.
/// The results are then printed out in the logs, and also sent as part of
/// telemetry, if telemetry is enabled.
#[arg(long)]
pub no_hardware_benchmarks: bool,
/// Relay chain arguments
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,
#[derive(Debug, Clone, clap::Args)]
pub struct BuildSpecCmdExtraFields {
/// List of container chain chain spec paths to add to genesis.
pub add_container_chain: Option<Vec<String>>,
/// List of container chain chain spec mocks to add to genesis.
pub mock_container_chain: Option<Vec<u32>>,
/// List of invulnerable collators to write to pallet_invulnerables genesis.
pub invulnerable: Option<Vec<String>>,
pub parachain_id: Option<u32>,
pub type BuildSpecCmdCollator = BuildSpecCmd<BuildSpecCmdExtraFields>;
/// Command for exporting the genesis wasm file.
pub struct ExportGenesisWasmCommand {
/// Output file name or stdout if unspecified.
pub output: Option<PathBuf>,
/// Write output in binary. Default is to write in hex.
#[arg(short, long)]
pub raw: bool,
/// The name of the chain for that the genesis wasm file should be exported.
pub chain: Option<String>,
pub struct RunCmd {
#[clap(flatten)]
pub base: cumulus_client_cli::RunCmd,
/// Enable the development service to run without a backing relay chain
pub dev_service: bool,
/// When blocks should be sealed in the dev service.
/// Options are "instant", "manual", or timer interval in milliseconds
#[arg(long, default_value = "instant")]
pub sealing: Sealing,
/// Id of the parachain this collator collates for.
/// EXPERIMENTAL: This is meant to be used only if collator is overshooting the PoV size, and
/// building blocks that do not fit in the max_pov_size. It is a percentage of the max_pov_size
/// configuration of the relay-chain.
/// It will be removed once <https://github.com/paritytech/polkadot-sdk/issues/6020> is fixed.
pub experimental_max_pov_percentage: Option<u32>,
impl std::ops::Deref for RunCmd {
type Target = cumulus_client_cli::RunCmd;
fn deref(&self) -> &Self::Target {
&self.base
pub enum KeyCmd {
BaseCli(sc_cli::KeySubcommand),
impl KeyCmd {
/// run the key subcommands
pub fn run<C: sc_cli::SubstrateCli>(&self, cli: &C) -> Result<(), sc_cli::Error> {
match self {
KeyCmd::BaseCli(cmd) => cmd.run(cli),
#[command(
propagate_version = true,
args_conflicts_with_subcommands = true,
subcommand_negates_reqs = true
)]
pub struct Cli {
pub subcommand: Option<Subcommand>,
pub run: RunCmd,
/// Optional parachain id that should be used to build chain spec.
pub para_id: Option<u32>,
/// Extra arguments, `container-args -- relay-args` or `relay-args` if no `--`
extra_args: Vec<String>,
impl Cli {
pub fn relaychain_args(&self) -> &[String] {
let (relay_chain_args, _) = self.split_extra_args_at_first_dashdash();
relay_chain_args
pub fn container_chain_args(&self) -> &[String] {
let (_, container_chain_args) = self.split_extra_args_at_first_dashdash();
container_chain_args
fn split_extra_args_at_first_dashdash(&self) -> (&[String], &[String]) {
let index_of_dashdash = self.extra_args.iter().position(|x| *x == "--");
if let Some(i) = index_of_dashdash {
let (container_chain_args, extra_extra) = self.extra_args.split_at(i);
(&extra_extra[1..], container_chain_args)
} else {
// Only relay chain args
(&self.extra_args, &[])
#[derive(Debug)]
pub struct RelayChainCli {
/// The actual relay chain cli object.
pub base: polkadot_cli::RunCmd,
/// Optional chain id that should be passed to the relay chain.
pub chain_id: Option<String>,
/// The base path that should be used by the relay chain.
pub base_path: PathBuf,
impl RelayChainCli {
/// Parse the relay chain CLI parameters using the para chain `Configuration`.
pub fn new<'a>(
para_config: &sc_service::Configuration,
relay_chain_args: impl Iterator<Item = &'a String>,
) -> Self {
let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec);
let chain_id = extension.map(|e| e.relay_chain.clone());
let base_path = para_config.base_path.path().join("polkadot");
Self {
base_path,
chain_id,
base: clap::Parser::parse_from(relay_chain_args),