2022-07-15 04:05:00 +00:00
|
|
|
use sc_service::PartialComponents;
|
2022-08-16 21:43:46 +00:00
|
|
|
use frame_benchmarking_cli::{ExtrinsicFactory, BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
|
2022-07-15 04:05:00 +00:00
|
|
|
use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli};
|
|
|
|
|
|
|
|
use serai_runtime::Block;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
chain_spec,
|
|
|
|
cli::{Cli, Subcommand},
|
2022-08-16 21:43:46 +00:00
|
|
|
command_helper::{RemarkBuilder, inherent_benchmark_data},
|
2022-07-15 05:26:07 +00:00
|
|
|
service,
|
2022-07-15 04:05:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
impl SubstrateCli for Cli {
|
|
|
|
fn impl_name() -> String {
|
|
|
|
"Serai Node".into()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn impl_version() -> String {
|
|
|
|
env!("SUBSTRATE_CLI_IMPL_VERSION").to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn description() -> String {
|
|
|
|
env!("CARGO_PKG_DESCRIPTION").to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn author() -> String {
|
|
|
|
env!("CARGO_PKG_AUTHORS").to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn support_url() -> String {
|
|
|
|
"serai.exchange".to_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn copyright_start_year() -> i32 {
|
|
|
|
2022
|
|
|
|
}
|
|
|
|
|
|
|
|
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
|
|
|
|
match id {
|
|
|
|
"dev" => Ok(Box::new(chain_spec::development_config()?)),
|
2022-07-15 05:26:07 +00:00
|
|
|
_ => panic!("Unknown network ID"),
|
2022-07-15 04:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn native_runtime_version(_: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
|
|
|
|
&serai_runtime::VERSION
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn run() -> sc_cli::Result<()> {
|
|
|
|
let cli = Cli::from_args();
|
|
|
|
|
|
|
|
match &cli.subcommand {
|
|
|
|
Some(Subcommand::Key(cmd)) => cmd.run(&cli),
|
|
|
|
|
|
|
|
Some(Subcommand::BuildSpec(cmd)) => {
|
|
|
|
cli.create_runner(cmd)?.sync_run(|config| cmd.run(config.chain_spec, config.network))
|
2022-07-15 05:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Some(Subcommand::CheckBlock(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
|
|
|
let PartialComponents { client, task_manager, import_queue, .. } =
|
|
|
|
service::new_partial(&config)?;
|
|
|
|
Ok((cmd.run(client, import_queue), task_manager))
|
|
|
|
}),
|
|
|
|
|
|
|
|
Some(Subcommand::ExportBlocks(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
|
|
|
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
|
|
|
|
Ok((cmd.run(client, config.database), task_manager))
|
|
|
|
}),
|
|
|
|
|
|
|
|
Some(Subcommand::ExportState(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
|
|
|
let PartialComponents { client, task_manager, .. } = service::new_partial(&config)?;
|
|
|
|
Ok((cmd.run(client, config.chain_spec), task_manager))
|
|
|
|
}),
|
|
|
|
|
|
|
|
Some(Subcommand::ImportBlocks(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
|
|
|
let PartialComponents { client, task_manager, import_queue, .. } =
|
|
|
|
service::new_partial(&config)?;
|
|
|
|
Ok((cmd.run(client, import_queue), task_manager))
|
|
|
|
}),
|
2022-07-15 04:05:00 +00:00
|
|
|
|
|
|
|
Some(Subcommand::PurgeChain(cmd)) => {
|
|
|
|
cli.create_runner(cmd)?.sync_run(|config| cmd.run(config.database))
|
2022-07-15 05:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Some(Subcommand::Revert(cmd)) => cli.create_runner(cmd)?.async_run(|config| {
|
|
|
|
let PartialComponents { client, task_manager, backend, .. } = service::new_partial(&config)?;
|
|
|
|
Ok((cmd.run(client, backend, None), task_manager))
|
|
|
|
}),
|
|
|
|
|
|
|
|
Some(Subcommand::Benchmark(cmd)) => cli.create_runner(cmd)?.sync_run(|config| match cmd {
|
|
|
|
BenchmarkCmd::Pallet(cmd) => cmd.run::<Block, service::ExecutorDispatch>(config),
|
|
|
|
|
|
|
|
BenchmarkCmd::Block(cmd) => cmd.run(service::new_partial(&config)?.client),
|
|
|
|
|
|
|
|
BenchmarkCmd::Storage(cmd) => {
|
|
|
|
let PartialComponents { client, backend, .. } = service::new_partial(&config)?;
|
|
|
|
cmd.run(config, client, backend.expose_db(), backend.expose_storage())
|
|
|
|
}
|
|
|
|
|
|
|
|
BenchmarkCmd::Overhead(cmd) => {
|
|
|
|
let client = service::new_partial(&config)?.client;
|
2022-08-16 21:43:46 +00:00
|
|
|
cmd.run(config, client.clone(), inherent_benchmark_data()?, &RemarkBuilder::new(client))
|
|
|
|
}
|
|
|
|
|
|
|
|
BenchmarkCmd::Extrinsic(cmd) => {
|
|
|
|
let PartialComponents { client, .. } = service::new_partial(&config)?;
|
2022-07-15 05:26:07 +00:00
|
|
|
cmd.run(
|
|
|
|
client.clone(),
|
|
|
|
inherent_benchmark_data()?,
|
2022-08-16 21:43:46 +00:00
|
|
|
&ExtrinsicFactory(vec![Box::new(RemarkBuilder::new(client))]),
|
2022-07-15 05:26:07 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
BenchmarkCmd::Machine(cmd) => cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()),
|
|
|
|
}),
|
2022-07-15 04:05:00 +00:00
|
|
|
|
|
|
|
Some(Subcommand::ChainInfo(cmd)) => {
|
|
|
|
cli.create_runner(cmd)?.sync_run(|config| cmd.run::<Block>(&config))
|
|
|
|
}
|
2022-07-15 05:26:07 +00:00
|
|
|
|
|
|
|
None => cli.create_runner(&cli.run)?.run_node_until_exit(|config| async {
|
|
|
|
service::new_full(config).map_err(sc_cli::Error::Service)
|
|
|
|
}),
|
2022-07-15 04:05:00 +00:00
|
|
|
}
|
|
|
|
}
|