Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Reduce parachain template cognitive complexity (#1777)
Browse files Browse the repository at this point in the history
* Removed some not required generics
* Type aliases for some verbose types
  • Loading branch information
davxy authored Oct 19, 2022
1 parent 5e63a1d commit 18c01ee
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 385 deletions.
27 changes: 7 additions & 20 deletions parachain-template/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cumulus_client_cli::generate_genesis_block;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use log::{info, warn};
use parachain_template_runtime::{Block, RuntimeApi};
use parachain_template_runtime::Block;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
Expand All @@ -20,7 +20,7 @@ use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
use crate::{
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::{new_partial, TemplateRuntimeExecutor},
service::{new_partial, ParachainNativeExecutor},
};

fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Expand Down Expand Up @@ -116,14 +116,7 @@ macro_rules! construct_async_run {
(|$components:ident, $cli:ident, $cmd:ident, $config:ident| $( $code:tt )* ) => {{
let runner = $cli.create_runner($cmd)?;
runner.async_run(|$config| {
let $components = new_partial::<
RuntimeApi,
TemplateRuntimeExecutor,
_
>(
&$config,
crate::service::parachain_build_import_queue,
)?;
let $components = new_partial(&$config)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
Expand Down Expand Up @@ -204,17 +197,14 @@ pub fn run() -> Result<()> {
match cmd {
BenchmarkCmd::Pallet(cmd) =>
if cfg!(feature = "runtime-benchmarks") {
runner.sync_run(|config| cmd.run::<Block, TemplateRuntimeExecutor>(config))
runner.sync_run(|config| cmd.run::<Block, ParachainNativeExecutor>(config))
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
.into())
},
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
let partials = new_partial::<RuntimeApi, TemplateRuntimeExecutor, _>(
&config,
crate::service::parachain_build_import_queue,
)?;
let partials = new_partial(&config)?;
cmd.run(partials.client)
}),
#[cfg(not(feature = "runtime-benchmarks"))]
Expand All @@ -227,10 +217,7 @@ pub fn run() -> Result<()> {
.into()),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials = new_partial::<RuntimeApi, TemplateRuntimeExecutor, _>(
&config,
crate::service::parachain_build_import_queue,
)?;
let partials = new_partial(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

Expand All @@ -255,7 +242,7 @@ pub fn run() -> Result<()> {
.map_err(|e| format!("Error: {:?}", e))?;

runner.async_run(|config| {
Ok((cmd.run::<Block, TemplateRuntimeExecutor>(config), task_manager))
Ok((cmd.run::<Block, ParachainNativeExecutor>(config), task_manager))
})
} else {
Err("Try-runtime must be enabled by `--features try-runtime`.".into())
Expand Down
Loading

0 comments on commit 18c01ee

Please sign in to comment.