astar_collator/
cli.rs

1// This file is part of Astar.
2
3// Copyright (C) Stake Technologies Pte.Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6// Astar is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// Astar is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with Astar. If not, see <http://www.gnu.org/licenses/>.
18
19use clap::Parser;
20use std::path::PathBuf;
21
22use crate::evm_tracing_types::EthApiOptions;
23
24/// An overarching CLI command definition.
25#[derive(Debug, clap::Parser)]
26pub struct Cli {
27    /// Possible subcommand with parameters.
28    #[clap(subcommand)]
29    pub subcommand: Option<Subcommand>,
30
31    #[allow(missing_docs)]
32    #[clap(flatten)]
33    pub run: cumulus_client_cli::RunCmd,
34
35    #[allow(missing_docs)]
36    #[clap(flatten)]
37    pub eth_api_options: EthApiOptions,
38
39    /// Enable Ethereum compatible JSON-RPC servers (disabled by default).
40    #[clap(name = "enable-evm-rpc", long)]
41    pub enable_evm_rpc: bool,
42
43    /// Relaychain arguments
44    #[clap(raw = true)]
45    pub relaychain_args: Vec<String>,
46
47    /// Proposer's maximum block size limit in bytes
48    #[clap(long, default_value = sc_basic_authorship::DEFAULT_BLOCK_SIZE_LIMIT.to_string())]
49    pub proposer_block_size_limit: usize,
50
51    /// Proposer's soft deadline in percents of block size
52    #[clap(long, default_value = "50")]
53    pub proposer_soft_deadline_percent: u8,
54
55    /// Disable automatic hardware benchmarks.
56    ///
57    /// By default these benchmarks are automatically ran at startup and measure
58    /// the CPU speed, the memory bandwidth and the disk speed.
59    ///
60    /// The results are then printed out in the logs, and also sent as part of
61    /// telemetry, if telemetry is enabled.
62    #[arg(long)]
63    pub no_hardware_benchmarks: bool,
64}
65
66/// Possible subcommands of the main binary.
67#[derive(Debug, clap::Subcommand)]
68pub enum Subcommand {
69    /// Key management cli utilities
70    #[clap(subcommand)]
71    Key(sc_cli::KeySubcommand),
72
73    /// Verify a signature for a message, provided on STDIN, with a given (public or secret) key.
74    Verify(sc_cli::VerifyCmd),
75
76    /// Generate a seed that provides a vanity address.
77    Vanity(sc_cli::VanityCmd),
78
79    /// Sign a message, with a given (secret) key.
80    Sign(sc_cli::SignCmd),
81
82    /// Build a chain specification.
83    BuildSpec(sc_cli::BuildSpecCmd),
84
85    /// Validate blocks.
86    CheckBlock(sc_cli::CheckBlockCmd),
87
88    /// Export blocks.
89    ExportBlocks(sc_cli::ExportBlocksCmd),
90
91    /// Export the state of a given block into a chain spec.
92    ExportState(sc_cli::ExportStateCmd),
93
94    /// Import blocks.
95    ImportBlocks(sc_cli::ImportBlocksCmd),
96
97    /// Remove the whole chain.
98    PurgeChain(cumulus_client_cli::PurgeChainCmd),
99
100    /// Revert the chain to a previous state.
101    Revert(sc_cli::RevertCmd),
102
103    /// Export the genesis state of the parachain.
104    ExportGenesisState(cumulus_client_cli::ExportGenesisHeadCommand),
105
106    /// Export the genesis wasm of the parachain.
107    ExportGenesisWasm(cumulus_client_cli::ExportGenesisWasmCommand),
108
109    /// The custom benchmark subcommmand benchmarking runtime pallets.
110    #[cfg(feature = "runtime-benchmarks")]
111    #[clap(name = "benchmark", about = "Benchmark runtime pallets.")]
112    #[clap(subcommand)]
113    Benchmark(frame_benchmarking_cli::BenchmarkCmd),
114}
115
116#[derive(Debug)]
117#[allow(missing_docs)]
118pub struct RelayChainCli {
119    /// The actual relay chain cli object.
120    pub base: polkadot_cli::RunCmd,
121
122    /// Optional chain id that should be passed to the relay chain.
123    pub chain_id: Option<String>,
124
125    /// The base path that should be used by the relay chain.
126    pub base_path: Option<PathBuf>,
127}
128
129impl RelayChainCli {
130    /// Parse the relay chain CLI parameters using the para chain `Configuration`.
131    pub fn new<'a>(
132        para_config: &sc_service::Configuration,
133        relay_chain_args: impl Iterator<Item = &'a String>,
134    ) -> Self {
135        let extension = crate::parachain::chain_spec::Extensions::try_get(&*para_config.chain_spec);
136        let chain_id = extension.map(|e| e.relay_chain.clone());
137        let base_path = para_config.base_path.path().join("polkadot");
138        Self {
139            base: polkadot_cli::RunCmd::parse_from(relay_chain_args),
140            chain_id,
141            base_path: Some(base_path),
142        }
143    }
144}