-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathcommand.rs
More file actions
327 lines (304 loc) · 9.71 KB
/
command.rs
File metadata and controls
327 lines (304 loc) · 9.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// This file is part of Substrate.
// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use std::sync::Arc;
use avail_node::chains;
use da_runtime::Block;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use sc_cli::{Result, SubstrateCli};
use sc_service::PartialComponents;
#[cfg(feature = "try-runtime")]
use {
crate::service::ExecutorDispatch, da_runtime::constants::time::SLOT_DURATION,
try_runtime_cli::block_building_info::substrate_info,
};
use crate::{
cli::{Cli, Subcommand},
service::{self, new_partial, FullClient},
};
use avail_node::NODE_VERSION;
impl SubstrateCli for Cli {
fn impl_name() -> String {
"Avail Node".into()
}
fn impl_version() -> String {
let commit_hash = env!("SUBSTRATE_CLI_COMMIT_HASH");
format!("{NODE_VERSION}-{commit_hash}")
}
fn description() -> String {
env!("CARGO_PKG_DESCRIPTION").into()
}
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}
fn support_url() -> String {
"https://github.com/availproject/avail/issues/new/choose".into()
}
fn copyright_start_year() -> i32 {
// Notice
2017
}
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
let spec = match id {
"" => {
return Err(
"Please specify which chain you want to run, e.g. --chain mainnet".into(),
)
},
"dev" => Box::new(chains::dev::chain_spec(self.network_name.clone())),
"dev.tri" => Box::new(chains::dev_tri::chain_spec(self.network_name.clone())),
"devnet0" => Box::new(chains::devnet0::chain_spec()?),
"mainnet" => Box::new(chains::mainnet::chain_spec()?),
"turing" => Box::new(chains::turing::chain_spec()?),
path => Box::new(chains::ChainSpec::from_json_file(
std::path::PathBuf::from(path),
)?),
};
Ok(spec)
}
}
/// Parse command line arguments into service configuration.
pub fn run() -> Result<()> {
let cli = Cli::from_args();
// Validate configuration before starting any services
// This catches errors early and provides clear feedback to users
cli.validate()
.map_err(|e| sc_cli::Error::Input(e))?;
match &cli.subcommand {
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
service::new_full(config, cli).map_err(sc_cli::Error::Service)
})
},
/*Some(Subcommand::Inspect(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block, RuntimeApi, ExecutorDispatch>(config))
},*/
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
// This switch needs to be in the client, since the client decides
// which sub-commands it wants to support.
match cmd {
BenchmarkCmd::Pallet(cmd) => {
if !cfg!(feature = "runtime-benchmarks") {
return Err(
"Runtime benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into(),
);
}
cmd.run::<Block, (
frame_system::native::hosted_header_builder::hosted_header_builder::HostFunctions,
avail_base::mem_tmp_storage::hosted_mem_tmp_storage::HostFunctions,
da_runtime::kate::native::hosted_kate::HostFunctions,
)>(config)
},
BenchmarkCmd::Block(_cmd) => {
unimplemented!();
/*
// ensure that we keep the task manager alive
let partial = new_partial(&config, cli.unsafe_da_sync)?;
cmd.run(partial.client)
*/
},
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) => Err(
"Storage benchmarking can be enabled with `--features runtime-benchmarks`."
.into(),
),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(_cmd) => {
unimplemented!();
/*
// ensure that we keep the task manager alive
let partial = new_partial(&config, cli.unsafe_da_sync)?;
let db = partial.backend.expose_db();
let storage = partial.backend.expose_storage();
cmd.run(config, partial.client, db, storage)
*/
},
BenchmarkCmd::Overhead(_cmd) => {
unimplemented!();
/*
// ensure that we keep the task manager alive
let partial = new_partial(&config, cli.unsafe_da_sync)?;
let ext_builder = RemarkBuilder::new(partial.client.clone());
cmd.run(
config,
partial.client,
inherent_benchmark_data()?,
Vec::new(),
&ext_builder,
)
*/
},
BenchmarkCmd::Extrinsic(_cmd) => {
unimplemented!();
/*
// ensure that we keep the task manager alive
let partial = service::new_partial(&config, cli.unsafe_da_sync)?;
// Register the *Remark* and *TKA* builders.
let ext_factory = ExtrinsicFactory(vec![
Box::new(RemarkBuilder::new(partial.client.clone())),
Box::new(TransferKeepAliveBuilder::new(
partial.client.clone(),
Sr25519Keyring::Alice.to_account_id(),
ExistentialDeposit::get(),
)),
]);
cmd.run(
partial.client,
inherent_benchmark_data()?,
Vec::new(),
&ext_factory,
)*/
},
BenchmarkCmd::Machine(cmd) => {
cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())
},
}
})
},
Some(Subcommand::Key(cmd)) => cmd.run(&cli),
Some(Subcommand::Sign(cmd)) => cmd.run(),
Some(Subcommand::Verify(cmd)) => cmd.run(),
Some(Subcommand::Vanity(cmd)) => cmd.run(),
Some(Subcommand::BuildSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
},
Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
import_queue,
..
} = new_partial(
&config,
cli.unsafe_da_sync,
kate_rpc::Deps::default(),
cli.grandpa_justification_period,
)?;
Ok((cmd.run(client, import_queue), task_manager))
})
},
Some(Subcommand::ExportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
..
} = new_partial(
&config,
cli.unsafe_da_sync,
kate_rpc::Deps::default(),
cli.grandpa_justification_period,
)?;
Ok((cmd.run(client, config.database), task_manager))
})
},
Some(Subcommand::ExportState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
..
} = new_partial(
&config,
cli.unsafe_da_sync,
kate_rpc::Deps::default(),
cli.grandpa_justification_period,
)?;
Ok((cmd.run(client, config.chain_spec), task_manager))
})
},
Some(Subcommand::ImportBlocks(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
import_queue,
..
} = new_partial(
&config,
cli.unsafe_da_sync,
kate_rpc::Deps::default(),
cli.grandpa_justification_period,
)?;
Ok((cmd.run(client, import_queue), task_manager))
})
},
Some(Subcommand::PurgeChain(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.database))
},
Some(Subcommand::Revert(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let PartialComponents {
client,
task_manager,
backend,
..
} = new_partial(
&config,
cli.unsafe_da_sync,
kate_rpc::Deps::default(),
cli.grandpa_justification_period,
)?;
let aux_revert = Box::new(|client: Arc<FullClient>, backend, blocks| {
sc_consensus_babe::revert(client.clone(), backend, blocks)?;
sc_consensus_grandpa::revert(client, blocks)?;
Ok(())
});
Ok((cmd.run(client, backend, Some(aux_revert)), task_manager))
})
},
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
// we don't need any of the components of new_partial, just a runtime, or a task
// manager to do `async_run`.
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
let info_provider = substrate_info(SLOT_DURATION);
Ok((
cmd.run::<Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
>, _>(Some(info_provider)),
task_manager,
))
})
},
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
You can enable it with `--features try-runtime`."
.into()),
Some(Subcommand::ChainInfo(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block>(&config))
},
}
}