1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi 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
// Tanssi 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 Tanssi.  If not, see <http://www.gnu.org/licenses/>
16

            
17
//! Polkadot CLI library.
18

            
19
pub use polkadot_node_primitives::NODE_VERSION;
20

            
21
use {
22
    clap::Parser,
23
    sc_cli::{CliConfiguration, NodeKeyParams, SharedParams},
24
    std::path::PathBuf,
25
};
26

            
27
#[allow(missing_docs)]
28
#[derive(Debug, Parser)]
29
pub enum Subcommand {
30
    /// Build a chain specification.
31
    BuildSpec(BuildSpecCmd),
32

            
33
    /// Validate blocks.
34
    CheckBlock(sc_cli::CheckBlockCmd),
35

            
36
    /// Export blocks.
37
    ExportBlocks(sc_cli::ExportBlocksCmd),
38

            
39
    /// Export the state of a given block into a chain spec.
40
    ExportState(sc_cli::ExportStateCmd),
41

            
42
    /// Import blocks.
43
    ImportBlocks(sc_cli::ImportBlocksCmd),
44

            
45
    /// Remove the whole chain.
46
    PurgeChain(sc_cli::PurgeChainCmd),
47

            
48
    /// Revert the chain to a previous state.
49
    Revert(sc_cli::RevertCmd),
50

            
51
    /// Sub-commands concerned with benchmarking.
52
    /// The pallet benchmarking moved to the `pallet` sub-command.
53
    #[command(subcommand)]
54
    Benchmark(frame_benchmarking_cli::BenchmarkCmd),
55

            
56
    /// Key management CLI utilities
57
    #[command(subcommand)]
58
    Key(sc_cli::KeySubcommand),
59

            
60
    /// Precompile the WASM runtime into native code
61
    PrecompileWasm(sc_cli::PrecompileWasmCmd),
62

            
63
    /// Db meta columns information.
64
    ChainInfo(sc_cli::ChainInfoCmd),
65
}
66

            
67
/// The `build-spec` command used to build a specification.
68
#[derive(Debug, Clone, clap::Parser)]
69
pub struct BuildSpecCmd {
70
    /// Base cmd.
71
    #[clap(flatten)]
72
    pub base: sc_cli::BuildSpecCmd,
73

            
74
    /// List of container chain chain spec paths to add to genesis.
75
    #[arg(long)]
76
    pub add_container_chain: Option<Vec<String>>,
77

            
78
    /// List of container chain chain spec mocks to add to genesis.
79
    #[arg(long)]
80
12
    pub mock_container_chain: Option<Vec<u32>>,
81

            
82
    /// List of invulnerable collators to write to pallet_invulnerables genesis.
83
    #[arg(long)]
84
    pub invulnerable: Option<Vec<String>>,
85
}
86

            
87
impl CliConfiguration for BuildSpecCmd {
88
264
    fn shared_params(&self) -> &SharedParams {
89
264
        &self.base.shared_params
90
264
    }
91

            
92
24
    fn node_key_params(&self) -> Option<&NodeKeyParams> {
93
24
        Some(&self.base.node_key_params)
94
24
    }
95
}
96

            
97
#[allow(missing_docs)]
98
#[derive(Debug, Parser)]
99
#[group(skip)]
100
pub struct RunCmd {
101
    #[clap(flatten)]
102
    pub base: sc_cli::RunCmd,
103

            
104
    /// Force using Dancelight native runtime.
105
    #[arg(long = "force-dancelight")]
106
    pub force_dancelight: bool,
107

            
108
    /// Disable the BEEFY gadget.
109
    ///
110
    /// Currently enabled by default on 'Dancelight'.
111
    #[arg(long)]
112
    pub no_beefy: bool,
113

            
114
    /// Allows a validator to run insecurely outside of Secure Validator Mode. Security features
115
    /// are still enabled on a best-effort basis, but missing features are no longer required. For
116
    /// more information see <https://github.com/w3f/polkadot-wiki/issues/4881>.
117
    #[arg(long = "insecure-validator-i-know-what-i-do", requires = "validator")]
118
    pub insecure_validator: bool,
119

            
120
    /// Enable the block authoring backoff that is triggered when finality is lagging.
121
    #[arg(long)]
122
    pub force_authoring_backoff: bool,
123

            
124
    /// Add the destination address to the `pyroscope` agent.
125
    ///
126
    /// Must be valid socket address, of format `IP:Port` (commonly `127.0.0.1:4040`).
127
    #[arg(long)]
128
    pub pyroscope_server: Option<String>,
129

            
130
    /// Disable automatic hardware benchmarks.
131
    ///
132
    /// By default these benchmarks are automatically ran at startup and measure
133
    /// the CPU speed, the memory bandwidth and the disk speed.
134
    ///
135
    /// The results are then printed out in the logs, and also sent as part of
136
    /// telemetry, if telemetry is enabled.
137
    #[arg(long)]
138
    pub no_hardware_benchmarks: bool,
139

            
140
    /// Overseer message capacity override.
141
    ///
142
    /// **Dangerous!** Do not touch unless explicitly advised to.
143
    #[arg(long)]
144
    pub overseer_channel_capacity_override: Option<usize>,
145

            
146
    /// Path to the directory where auxiliary worker binaries reside.
147
    ///
148
    /// If not specified, the main binary's directory is searched first, then
149
    /// `/usr/lib/polkadot` is searched.
150
    ///
151
    /// TESTING ONLY: if the path points to an executable rather then directory,
152
    /// that executable is used both as preparation and execution worker.
153
    #[arg(long, value_name = "PATH")]
154
    pub workers_path: Option<PathBuf>,
155

            
156
    /// Override the maximum number of pvf execute workers.
157
    ///
158
    ///  **Dangerous!** Do not touch unless explicitly advised to.
159
    #[arg(long)]
160
    pub execute_workers_max_num: Option<usize>,
161
    /// Override the maximum number of pvf workers that can be spawned in the pvf prepare
162
    /// pool for tasks with the priority below critical.
163
    ///
164
    ///  **Dangerous!** Do not touch unless explicitly advised to.
165

            
166
    #[arg(long)]
167
    pub prepare_workers_soft_max_num: Option<usize>,
168
    /// Override the absolute number of pvf workers that can be spawned in the pvf prepare pool.
169
    ///
170
    ///  **Dangerous!** Do not touch unless explicitly advised to.
171
    #[arg(long)]
172
    pub prepare_workers_hard_max_num: Option<usize>,
173
    /// TESTING ONLY: disable the version check between nodes and workers.
174
    #[arg(long, hide = true)]
175
    pub disable_worker_version_check: bool,
176

            
177
    /// Enable approval-voting message processing in parallel.
178
    ///
179
    ///**Dangerous!** This is an experimental feature and should not be used in production, unless
180
    /// explicitly advised to.
181
    #[arg(long)]
182
    pub enable_approval_voting_parallel: bool,
183

            
184
    // Enable the development service
185
    #[arg(long)]
186
    pub dev_service: bool,
187
}
188

            
189
#[allow(missing_docs)]
190
#[derive(Debug, Parser)]
191
pub struct Cli {
192
    #[command(subcommand)]
193
    pub subcommand: Option<Subcommand>,
194

            
195
    #[clap(flatten)]
196
    pub run: RunCmd,
197

            
198
    #[clap(flatten)]
199
    pub storage_monitor: sc_storage_monitor::StorageMonitorParams,
200
}