Co #12341: Use try-runtime feature (#1759)

* Add try-runtime feature

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* More feature gates

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Add dummy command

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* update lockfile for {"polkadot", "substrate"}

* Fix code

* Remove unused import

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Imports...

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: parity-processbot <>
This commit is contained in:
Oliver Tale-Yazdi
2022-10-20 15:17:36 +02:00
committed by GitHub
parent ee30bcd3f9
commit 9a2f343526
15 changed files with 345 additions and 318 deletions
+267 -254
View File
File diff suppressed because it is too large Load Diff
+6 -2
View File
@@ -51,7 +51,7 @@ sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "mast
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
# Polkadot # Polkadot
polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master" } polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "master" }
@@ -78,7 +78,11 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
[features] [features]
default = [] default = []
runtime-benchmarks = [ runtime-benchmarks = [
"try-runtime-cli/try-runtime",
"parachain-template-runtime/runtime-benchmarks", "parachain-template-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks", "polkadot-cli/runtime-benchmarks",
] ]
try-runtime = ["parachain-template-runtime/try-runtime"] try-runtime = [
"try-runtime-cli/try-runtime",
"parachain-template-runtime/try-runtime"
]
@@ -36,7 +36,12 @@ pub enum Subcommand {
Benchmark(frame_benchmarking_cli::BenchmarkCmd), Benchmark(frame_benchmarking_cli::BenchmarkCmd),
/// Try some testing command against a specified runtime state. /// Try some testing command against a specified runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd), 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)] #[derive(Debug, clap::Parser)]
@@ -10,10 +10,7 @@ use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
}; };
use sc_service::{ use sc_service::config::{BasePath, PrometheusConfig};
config::{BasePath, PrometheusConfig},
TaskManager,
};
use sp_core::hexdisplay::HexDisplay; use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
@@ -231,23 +228,24 @@ pub fn run() -> Result<()> {
_ => Err("Benchmarking sub-command unsupported".into()), _ => Err("Benchmarking sub-command unsupported".into()),
} }
}, },
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => { Some(Subcommand::TryRuntime(cmd)) => {
if cfg!(feature = "try-runtime") {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
// grab the task manager. // grab the task manager.
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry); let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = let task_manager =
TaskManager::new(runner.config().tokio_handle.clone(), *registry) sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?; .map_err(|e| format!("Error: {:?}", e))?;
runner.async_run(|config| { runner.async_run(|config| {
Ok((cmd.run::<Block, ParachainNativeExecutor>(config), task_manager)) Ok((cmd.run::<Block, ParachainNativeExecutor>(config), task_manager))
}) })
} else {
Err("Try-runtime must be enabled by `--features try-runtime`.".into())
}
}, },
#[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 => { None => {
let runner = cli.create_runner(&cli.run.normalize())?; let runner = cli.create_runner(&cli.run.normalize())?;
let collator_options = cli.run.collator_options(); let collator_options = cli.run.collator_options();
@@ -148,7 +148,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
"pallet-authorship/try-runtime", "pallet-authorship/try-runtime",
"pallet-balances/try-runtime", "pallet-balances/try-runtime",
@@ -109,7 +109,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-asset-tx-payment/try-runtime", "pallet-asset-tx-payment/try-runtime",
"pallet-assets/try-runtime", "pallet-assets/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
@@ -108,7 +108,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-asset-tx-payment/try-runtime", "pallet-asset-tx-payment/try-runtime",
"pallet-assets/try-runtime", "pallet-assets/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
@@ -108,7 +108,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-asset-tx-payment/try-runtime", "pallet-asset-tx-payment/try-runtime",
"pallet-assets/try-runtime", "pallet-assets/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
@@ -104,7 +104,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-alliance/try-runtime", "pallet-alliance/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
"pallet-authorship/try-runtime", "pallet-authorship/try-runtime",
@@ -157,7 +157,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
"pallet-authorship/try-runtime", "pallet-authorship/try-runtime",
"pallet-balances/try-runtime", "pallet-balances/try-runtime",
@@ -68,5 +68,5 @@ std = [
] ]
try-runtime = [ try-runtime = [
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
] ]
@@ -150,7 +150,7 @@ try-runtime = [
"cumulus-pallet-xcmp-queue/try-runtime", "cumulus-pallet-xcmp-queue/try-runtime",
"frame-executive/try-runtime", "frame-executive/try-runtime",
"frame-system/try-runtime", "frame-system/try-runtime",
"frame-try-runtime", "frame-try-runtime/try-runtime",
"pallet-aura/try-runtime", "pallet-aura/try-runtime",
"pallet-authorship/try-runtime", "pallet-authorship/try-runtime",
"pallet-balances/try-runtime", "pallet-balances/try-runtime",
+2 -1
View File
@@ -60,7 +60,7 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch =
sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-sysinfo = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-serializer = { git = "https://github.com/paritytech/substrate", branch = "master" }
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" } frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -110,4 +110,5 @@ try-runtime = [
"statemine-runtime/try-runtime", "statemine-runtime/try-runtime",
"westmint-runtime/try-runtime", "westmint-runtime/try-runtime",
"shell-runtime/try-runtime", "shell-runtime/try-runtime",
"try-runtime-cli/try-runtime",
] ]
+5
View File
@@ -56,7 +56,12 @@ pub enum Subcommand {
Benchmark(frame_benchmarking_cli::BenchmarkCmd), Benchmark(frame_benchmarking_cli::BenchmarkCmd),
/// Try some testing command against a specified runtime state. /// Try some testing command against a specified runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd), 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)] #[derive(Debug, clap::Parser)]
+13 -12
View File
@@ -18,8 +18,8 @@ use crate::{
chain_spec, chain_spec,
cli::{Cli, RelayChainCli, Subcommand}, cli::{Cli, RelayChainCli, Subcommand},
service::{ service::{
new_partial, Block, CollectivesPolkadotRuntimeExecutor, ShellRuntimeExecutor, new_partial, Block, CollectivesPolkadotRuntimeExecutor, StatemineRuntimeExecutor,
StatemineRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor, StatemintRuntimeExecutor, WestmintRuntimeExecutor,
}, },
}; };
use codec::Encode; use codec::Encode;
@@ -32,10 +32,7 @@ use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
}; };
use sc_service::{ use sc_service::config::{BasePath, PrometheusConfig};
config::{BasePath, PrometheusConfig},
TaskManager,
};
use sp_core::hexdisplay::HexDisplay; use sp_core::hexdisplay::HexDisplay;
use sp_runtime::traits::{AccountIdConversion, Block as BlockT}; use sp_runtime::traits::{AccountIdConversion, Block as BlockT};
use std::{net::SocketAddr, path::PathBuf}; use std::{net::SocketAddr, path::PathBuf};
@@ -597,13 +594,13 @@ pub fn run() -> Result<()> {
_ => Err("Benchmarking sub-command unsupported".into()), _ => Err("Benchmarking sub-command unsupported".into()),
} }
}, },
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => { Some(Subcommand::TryRuntime(cmd)) => {
if cfg!(feature = "try-runtime") {
// grab the task manager. // grab the task manager.
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry); let registry = &runner.config().prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager = let task_manager =
TaskManager::new(runner.config().tokio_handle.clone(), *registry) sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?; .map_err(|e| format!("Error: {:?}", e))?;
match runner.config().chain_spec.runtime() { match runner.config().chain_spec.runtime() {
@@ -624,14 +621,18 @@ pub fn run() -> Result<()> {
)) ))
}), }),
Runtime::Shell => runner.async_run(|config| { Runtime::Shell => runner.async_run(|config| {
Ok((cmd.run::<Block, ShellRuntimeExecutor>(config), task_manager)) Ok((
cmd.run::<Block, crate::service::ShellRuntimeExecutor>(config),
task_manager,
))
}), }),
_ => Err("Chain doesn't support try-runtime".into()), _ => Err("Chain doesn't support try-runtime".into()),
} }
} else {
Err("Try-runtime must be enabled by `--features try-runtime`.".into())
}
}, },
#[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()),
Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?), Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?),
None => { None => {
let runner = cli.create_runner(&cli.run.normalize())?; let runner = cli.create_runner(&cli.run.normalize())?;