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

Commit

Permalink
Companion for paritytech/cumulus#1759
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong committed Jan 3, 2023
1 parent b02c851 commit 341a001
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
5 changes: 4 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ sp-timestamp = { git = "https://github.com/paritytech/substrat
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33", optional = true}

[features]
default = []
Expand All @@ -118,6 +118,9 @@ runtime-benchmarks = [
try-runtime = [
# darwinia
"darwinia-runtime/try-runtime",

# substrate
"try-runtime-cli/try-runtime",
]

all-native = [
Expand Down
5 changes: 5 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ pub enum Subcommand {
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Try some testing command against a specified runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),

/// Errors since the binary was not build with `--features try-runtime`.
#[cfg(not(feature = "try-runtime"))]
TryRuntime,
}

#[derive(Debug, clap::Parser)]
Expand Down
46 changes: 23 additions & 23 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,35 +496,35 @@ pub fn run() -> Result<()> {
_ => Err("Benchmarking sub-command unsupported".into()),
}
},
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
if cfg!(feature = "try-runtime") {
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;

set_default_ss58_version(chain_spec);
// grab the task manager.
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager =
TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?;
set_default_ss58_version(chain_spec);
// grab the task manager.
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?;

if chain_spec.is_crab() {
runner.async_run(|config| {
Ok((cmd.run::<Block, CrabRuntimeExecutor>(config), task_manager))
})
} else if chain_spec.is_pangolin() {
runner.async_run(|config| {
Ok((cmd.run::<Block, PangolinRuntimeExecutor>(config), task_manager))
})
} else {
runner.async_run(|config| {
Ok((cmd.run::<Block, DarwiniaRuntimeExecutor>(config), task_manager))
})
}
if chain_spec.is_crab() {
runner.async_run(|config| {
Ok((cmd.run::<Block, CrabRuntimeExecutor>(config), task_manager))
})
} else if chain_spec.is_pangolin() {
runner.async_run(|config| {
Ok((cmd.run::<Block, PangolinRuntimeExecutor>(config), task_manager))
})
} else {
Err("Try-runtime must be enabled by `--features try-runtime`.".into())
runner.async_run(|config| {
Ok((cmd.run::<Block, DarwiniaRuntimeExecutor>(config), task_manager))
})
}
},
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => Err("Try-runtime was not enabled when building the node. \
You can enable it with `--features try-runtime`."
.into()),
None => {
let runner = cli.create_runner(&cli.run.normalize())?;
let collator_options = cli.run.collator_options();
Expand Down
2 changes: 1 addition & 1 deletion runtime/crab/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,5 @@ try-runtime = [
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
# substrate optional
"frame-try-runtime",
"frame-try-runtime/try-runtime",
]
2 changes: 1 addition & 1 deletion runtime/darwinia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,5 @@ try-runtime = [
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
# substrate optional
"frame-try-runtime",
"frame-try-runtime/try-runtime",
]
2 changes: 1 addition & 1 deletion runtime/pangolin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,5 @@ try-runtime = [
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
# substrate optional
"frame-try-runtime",
"frame-try-runtime/try-runtime",
]

0 comments on commit 341a001

Please sign in to comment.