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
    BuildSpec(BuildSpecCmd),
33

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
157
    /// Override the maximum number of pvf execute workers.
158
    ///
159
    ///  **Dangerous!** Do not touch unless explicitly advised to.
160
    #[arg(long)]
161
    pub execute_workers_max_num: Option<usize>,
162
    /// Override the maximum number of pvf workers that can be spawned in the pvf prepare
163
    /// pool for tasks with the priority below critical.
164
    ///
165
    ///  **Dangerous!** Do not touch unless explicitly advised to.
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
    /// How long finalized data should be kept in the availability store (in hours).
189
    /// Only used for testnets. If not specified, set to 1 hour. Always set to 25 hours for live
190
    /// networks.
191
    #[arg(long)]
192
    pub keep_finalized_for: Option<u32>,
193
}
194

            
195
#[allow(missing_docs)]
196
#[derive(Debug, Parser)]
197
pub struct Cli {
198
    #[command(subcommand)]
199
    pub subcommand: Option<Subcommand>,
200

            
201
    #[clap(flatten)]
202
    pub run: RunCmd,
203

            
204
    #[clap(flatten)]
205
    pub storage_monitor: sc_storage_monitor::StorageMonitorParams,
206
}