Refactor service to allow building full (and light) node matching chain spec (#1467)

This commit is contained in:
Cecile Tonglet
2020-07-27 07:54:24 +02:00
committed by GitHub
parent fa598f176b
commit 1cb92aa83e
3 changed files with 101 additions and 74 deletions
+28 -51
View File
@@ -106,8 +106,8 @@ pub fn run() -> Result<()> {
match &cli.subcommand {
None => {
let runtime = cli.create_runner(&cli.run.base)?;
let chain_spec = &runtime.config().chain_spec;
let runner = cli.create_runner(&cli.run.base)?;
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
@@ -124,55 +124,32 @@ pub fn run() -> Result<()> {
info!(" endorsed by the ");
info!(" KUSAMA FOUNDATION ");
info!("----------------------------");
runtime.run_node_until_exit(|config| match config.role {
Role::Light => service::kusama_new_light(config)
.map(|(components, _)| components),
_ => service::kusama_new_full(
config,
None,
None,
authority_discovery_disabled,
6000,
grandpa_pause,
).map(|(components, _, _)| components)
})
} else if chain_spec.is_westend() {
runtime.run_node_until_exit(|config| match config.role {
Role::Light => service::westend_new_light(config)
.map(|(components, _)| components),
_ => service::westend_new_full(
config,
None,
None,
authority_discovery_disabled,
6000,
grandpa_pause,
).map(|(components, _, _)| components)
})
} else {
runtime.run_node_until_exit(|config| match config.role {
Role::Light => service::polkadot_new_light(config)
.map(|(components, _)| components),
_ => service::polkadot_new_full(
config,
None,
None,
authority_discovery_disabled,
6000,
grandpa_pause,
).map(|(components, _, _)| components)
})
}
runner.run_node_until_exit(|config| {
let role = config.role.clone();
let builder = service::NodeBuilder::new(config);
match role {
Role::Light => builder.build_light().map(|(task_manager, _)| task_manager),
_ => builder.build_full(
None,
None,
authority_discovery_disabled,
6000,
grandpa_pause,
),
}
})
},
Some(Subcommand::Base(subcommand)) => {
let runtime = cli.create_runner(subcommand)?;
let chain_spec = &runtime.config().chain_spec;
let runner = cli.create_runner(subcommand)?;
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
if chain_spec.is_kusama() {
runtime.run_subcommand(subcommand, |config|
runner.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::kusama_runtime::RuntimeApi,
service::KusamaExecutor,
@@ -180,7 +157,7 @@ pub fn run() -> Result<()> {
>(config)
)
} else if chain_spec.is_westend() {
runtime.run_subcommand(subcommand, |config|
runner.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::westend_runtime::RuntimeApi,
service::WestendExecutor,
@@ -188,7 +165,7 @@ pub fn run() -> Result<()> {
>(config)
)
} else {
runtime.run_subcommand(subcommand, |config|
runner.run_subcommand(subcommand, |config|
service::new_chain_ops::<
service::polkadot_runtime::RuntimeApi,
service::PolkadotExecutor,
@@ -209,21 +186,21 @@ pub fn run() -> Result<()> {
}
},
Some(Subcommand::Benchmark(cmd)) => {
let runtime = cli.create_runner(cmd)?;
let chain_spec = &runtime.config().chain_spec;
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
if chain_spec.is_kusama() {
runtime.sync_run(|config| {
runner.sync_run(|config| {
cmd.run::<service::kusama_runtime::Block, service::KusamaExecutor>(config)
})
} else if chain_spec.is_westend() {
runtime.sync_run(|config| {
runner.sync_run(|config| {
cmd.run::<service::westend_runtime::Block, service::WestendExecutor>(config)
})
} else {
runtime.sync_run(|config| {
runner.sync_run(|config| {
cmd.run::<service::polkadot_runtime::Block, service::PolkadotExecutor>(config)
})
}