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
    /// Db meta columns information.
61
    ChainInfo(sc_cli::ChainInfoCmd),
62
}
63

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

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

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

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

            
84
impl CliConfiguration for BuildSpecCmd {
85
    fn shared_params(&self) -> &SharedParams {
86
        &self.base.shared_params
87
    }
88

            
89
    fn node_key_params(&self) -> Option<&NodeKeyParams> {
90
        Some(&self.base.node_key_params)
91
    }
92
}
93

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

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

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

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

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

            
121
    /// Add the destination address to the 'Jaeger' agent.
122
    ///
123
    /// Must be valid socket address, of format `IP:Port` (commonly `127.0.0.1:6831`).
124
    #[arg(long)]
125
    pub jaeger_agent: Option<String>,
126

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

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

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

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

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

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

            
180
    // Enable the development service
181
    #[arg(long)]
182
    pub dev_service: bool,
183
}
184

            
185
#[allow(missing_docs)]
186
#[derive(Debug, Parser)]
187
pub struct Cli {
188
    #[command(subcommand)]
189
    pub subcommand: Option<Subcommand>,
190

            
191
    #[clap(flatten)]
192
    pub run: RunCmd,
193

            
194
    #[clap(flatten)]
195
    pub storage_monitor: sc_storage_monitor::StorageMonitorParams,
196
}