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
#[allow(clippy::large_enum_variant)]
29
#[derive(Debug, Parser)]
30
pub enum Subcommand {
31
    /// Build a chain specification.
32
    #[deprecated(
33
        note = "build-spec command will be removed after 1/04/2026. Use export-chain-spec command instead"
34
    )]
35
    BuildSpec(BuildSpecCmd),
36

            
37
    /// Export the chain specification.
38
    ExportChainSpec(ExportChainSpecCmd),
39

            
40
    /// Validate blocks.
41
    CheckBlock(sc_cli::CheckBlockCmd),
42

            
43
    /// Export blocks.
44
    ExportBlocks(sc_cli::ExportBlocksCmd),
45

            
46
    /// Export the state of a given block into a chain spec.
47
    ExportState(sc_cli::ExportStateCmd),
48

            
49
    /// Import blocks.
50
    ImportBlocks(sc_cli::ImportBlocksCmd),
51

            
52
    /// Remove the whole chain.
53
    PurgeChain(sc_cli::PurgeChainCmd),
54

            
55
    /// Revert the chain to a previous state.
56
    Revert(sc_cli::RevertCmd),
57

            
58
    /// Sub-commands concerned with benchmarking.
59
    /// The pallet benchmarking moved to the `pallet` sub-command.
60
    #[command(subcommand)]
61
    Benchmark(frame_benchmarking_cli::BenchmarkCmd),
62

            
63
    /// Key management CLI utilities
64
    #[command(subcommand)]
65
    Key(sc_cli::KeySubcommand),
66

            
67
    /// Precompile the WASM runtime into native code
68
    PrecompileWasm(sc_cli::PrecompileWasmCmd),
69

            
70
    /// Db meta columns information.
71
    ChainInfo(sc_cli::ChainInfoCmd),
72
}
73

            
74
/// The `build-spec` command used to build a specification.
75
#[derive(Debug, Clone, clap::Parser)]
76
pub struct BuildSpecCmd {
77
    /// Base cmd.
78
    #[clap(flatten)]
79
    pub base: sc_cli::BuildSpecCmd,
80

            
81
    /// List of container chain chain spec paths to add to genesis.
82
    #[arg(long)]
83
    pub add_container_chain: Option<Vec<String>>,
84

            
85
    /// List of container chain chain spec mocks to add to genesis.
86
    #[arg(long)]
87
    pub mock_container_chain: Option<Vec<u32>>,
88

            
89
    /// List of invulnerable collators to write to pallet_invulnerables genesis.
90
    #[arg(long)]
91
    pub invulnerable: Option<Vec<String>>,
92

            
93
    /// List of authority validators to write to genesis.
94
    #[arg(long)]
95
    pub authority: Option<Vec<String>>,
96
}
97

            
98
/// The `export-chain-spec` command used to export a chain-spec.
99
#[derive(Debug, Clone, clap::Parser)]
100
pub struct ExportChainSpecCmd {
101
    /// Base cmd.
102
    #[clap(flatten)]
103
    pub base: sc_cli::ExportChainSpecCmd,
104

            
105
    /// List of container chain chain spec paths to add to genesis.
106
    #[arg(long)]
107
    pub add_container_chain: Option<Vec<String>>,
108

            
109
    /// List of container chain chain spec mocks to add to genesis.
110
    #[arg(long)]
111
    pub mock_container_chain: Option<Vec<u32>>,
112

            
113
    /// List of invulnerable collators to write to pallet_invulnerables genesis.
114
    #[arg(long)]
115
    pub invulnerable: Option<Vec<String>>,
116

            
117
    /// List of authority validators to write to genesis.
118
    #[arg(long)]
119
    pub authority: Option<Vec<String>>,
120
}
121

            
122
impl CliConfiguration for BuildSpecCmd {
123
    fn shared_params(&self) -> &SharedParams {
124
        &self.base.shared_params
125
    }
126

            
127
    fn node_key_params(&self) -> Option<&NodeKeyParams> {
128
        Some(&self.base.node_key_params)
129
    }
130
}
131

            
132
#[allow(missing_docs)]
133
#[derive(Debug, Parser)]
134
#[group(skip)]
135
pub struct RunCmd {
136
    #[clap(flatten)]
137
    pub base: sc_cli::RunCmd,
138

            
139
    /// Force using Dancelight native runtime.
140
    #[arg(long = "force-dancelight")]
141
    pub force_dancelight: bool,
142

            
143
    /// Disable the BEEFY gadget.
144
    ///
145
    /// Currently enabled by default on 'Dancelight'.
146
    #[arg(long)]
147
    pub no_beefy: bool,
148

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

            
155
    /// Enable the block authoring backoff that is triggered when finality is lagging.
156
    #[arg(long)]
157
    pub force_authoring_backoff: bool,
158

            
159
    /// Add the destination address to the `pyroscope` agent.
160
    ///
161
    /// Must be valid socket address, of format `IP:Port` (commonly `127.0.0.1:4040`).
162
    #[arg(long)]
163
    pub pyroscope_server: Option<String>,
164

            
165
    /// Disable automatic hardware benchmarks.
166
    ///
167
    /// By default these benchmarks are automatically ran at startup and measure
168
    /// the CPU speed, the memory bandwidth and the disk speed.
169
    ///
170
    /// The results are then printed out in the logs, and also sent as part of
171
    /// telemetry, if telemetry is enabled.
172
    #[arg(long)]
173
    pub no_hardware_benchmarks: bool,
174

            
175
    /// Overseer message capacity override.
176
    ///
177
    /// **Dangerous!** Do not touch unless explicitly advised to.
178
    #[arg(long)]
179
    pub overseer_channel_capacity_override: Option<usize>,
180

            
181
    /// Path to the directory where auxiliary worker binaries reside.
182
    ///
183
    /// If not specified, the main binary's directory is searched first, then
184
    /// `/usr/lib/polkadot` is searched.
185
    ///
186
    /// TESTING ONLY: if the path points to an executable rather then directory,
187
    /// that executable is used both as preparation and execution worker.
188
    #[arg(long, value_name = "PATH")]
189
    pub workers_path: Option<PathBuf>,
190

            
191
    /// Override the maximum number of pvf execute workers.
192
    ///
193
    ///  **Dangerous!** Do not touch unless explicitly advised to.
194
    #[arg(long)]
195
    pub execute_workers_max_num: Option<usize>,
196
    /// Override the maximum number of pvf workers that can be spawned in the pvf prepare
197
    /// pool for tasks with the priority below critical.
198
    ///
199
    ///  **Dangerous!** Do not touch unless explicitly advised to.
200
    #[arg(long)]
201
    pub prepare_workers_soft_max_num: Option<usize>,
202
    /// Override the absolute number of pvf workers that can be spawned in the pvf prepare pool.
203
    ///
204
    ///  **Dangerous!** Do not touch unless explicitly advised to.
205
    #[arg(long)]
206
    pub prepare_workers_hard_max_num: Option<usize>,
207
    /// TESTING ONLY: disable the version check between nodes and workers.
208
    #[arg(long, hide = true)]
209
    pub disable_worker_version_check: bool,
210

            
211
    /// Enable approval-voting message processing in parallel.
212
    ///
213
    ///**Dangerous!** This is an experimental feature and should not be used in production, unless
214
    /// explicitly advised to.
215
    #[arg(long)]
216
    pub enable_approval_voting_parallel: bool,
217

            
218
    // Enable the development service
219
    #[arg(long)]
220
    pub dev_service: bool,
221

            
222
    /// How long finalized data should be kept in the availability store (in hours).
223
    /// Only used for testnets. If not specified, set to 1 hour. Always set to 25 hours for live
224
    /// networks.
225
    #[arg(long)]
226
    pub keep_finalized_for: Option<u32>,
227
}
228

            
229
#[allow(missing_docs)]
230
#[derive(Debug, Parser)]
231
pub struct Cli {
232
    #[command(subcommand)]
233
    pub subcommand: Option<Subcommand>,
234

            
235
    #[clap(flatten)]
236
    pub run: RunCmd,
237

            
238
    #[clap(flatten)]
239
    pub storage_monitor: sc_storage_monitor::StorageMonitorParams,
240
}