difftreelog
feat try-runtime subcommand
in: master
7 files changed
node/cli/Cargo.tomldiffbeforeafterboth--- a/node/cli/Cargo.toml
+++ b/node/cli/Cargo.toml
@@ -22,6 +22,10 @@
git = "https://github.com/paritytech/substrate"
branch = "polkadot-v0.9.20"
+[dependencies.try-runtime-cli]
+git = 'https://github.com/paritytech/substrate.git'
+branch = 'polkadot-v0.9.17'
+
[dependencies.pallet-transaction-payment-rpc]
git = "https://github.com/paritytech/substrate"
branch = "polkadot-v0.9.20"
@@ -318,3 +322,4 @@
'unique-runtime/runtime-benchmarks',
'polkadot-service/runtime-benchmarks',
]
+try-runtime = []
node/cli/src/cli.rsdiffbeforeafterboth--- a/node/cli/src/cli.rs
+++ b/node/cli/src/cli.rs
@@ -55,6 +55,9 @@
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[clap(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
+
+ /// Try runtime
+ TryRuntime(try_runtime_cli::TryRuntimeCmd),
}
/// Command for exporting the genesis state of the parachain
node/cli/src/command.rsdiffbeforeafterboth--- a/node/cli/src/command.rs
+++ b/node/cli/src/command.rs
@@ -49,6 +49,7 @@
use codec::Encode;
use cumulus_primitives_core::ParaId;
use cumulus_client_service::genesis::generate_genesis_block;
+use std::{future::Future, pin::Pin};
use log::info;
use polkadot_parachain::primitives::AccountIdConversion;
use sc_cli::{
@@ -413,6 +414,41 @@
Some(Subcommand::Benchmark(..)) => {
Err("benchmarking is only available with unique runtime enabled".into())
}
+ Some(Subcommand::TryRuntime(cmd)) => {
+ if cfg!(feature = "try-runtime") {
+ let runner = cli.create_runner(cmd)?;
+
+ // grab the task manager.
+ let registry = &runner
+ .config()
+ .prometheus_config
+ .as_ref()
+ .map(|cfg| &cfg.registry);
+ let task_manager =
+ sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
+ .map_err(|e| format!("Error: {:?}", e))?;
+
+ runner.async_run(|config| -> Result<(Pin<Box<dyn Future<Output = _>>>, _)> {
+ Ok((
+ match config.chain_spec.runtime_id() {
+ #[cfg(feature = "unique-runtime")]
+ RuntimeId::Unique => Box::pin(cmd.run::<Block, UniqueRuntimeExecutor>(config)),
+
+ #[cfg(feature = "quartz-runtime")]
+ RuntimeId::Quartz => Box::pin(cmd.run::<Block, QuartzRuntimeExecutor>(config)),
+
+ RuntimeId::Opal => {
+ Box::pin(cmd.run::<Block, OpalRuntimeExecutor>(config))
+ }
+ RuntimeId::Unknown(chain) => return Err(no_runtime_err!(chain).into()),
+ },
+ task_manager,
+ ))
+ })
+ } else {
+ Err("Try-runtime must be enabled by `--features try-runtime`.".into())
+ }
+ }
None => {
let runner = cli.create_runner(&cli.run.normalize())?;
let collator_options = cli.run.collator_options();
runtime/common/src/runtime_apis.rsdiffbeforeafterboth--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -425,6 +425,19 @@
Ok(batches)
}
}
+
+ #[cfg(feature = "try-runtime")]
+ impl frame_try_runtime::TryRuntime<Block> for Runtime {
+ fn on_runtime_upgrade() -> (Weight, Weight) {
+ log::info!("try-runtime::on_runtime_upgrade unique-chain.");
+ let weight = Executive::try_runtime_upgrade().unwrap();
+ (weight, RuntimeBlockWeights::get().max_block)
+ }
+
+ fn execute_block_no_check(block: Block) -> Weight {
+ Executive::execute_block_no_check(block)
+ }
+ }
}
}
}
runtime/opal/Cargo.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -38,6 +38,11 @@
'sp-runtime/runtime-benchmarks',
'xcm-builder/runtime-benchmarks',
]
+try-runtime = [
+ 'frame-try-runtime',
+ 'frame-executive/try-runtime',
+ 'frame-system/try-runtime',
+]
std = [
'codec/std',
'cumulus-pallet-aura-ext/std',
@@ -46,6 +51,7 @@
'cumulus-pallet-xcmp-queue/std',
'cumulus-primitives-core/std',
'cumulus-primitives-utility/std',
+ 'frame-try-runtime/std',
'frame-executive/std',
'frame-support/std',
'frame-system/std',
@@ -121,6 +127,12 @@
optional = true
branch = "polkadot-v0.9.20"
+[dependencies.frame-try-runtime]
+default-features = false
+git = 'https://github.com/paritytech/substrate.git'
+optional = true
+branch = 'polkadot-v0.9.17'
+
[dependencies.frame-executive]
default-features = false
git = "https://github.com/paritytech/substrate"
@@ -375,6 +387,7 @@
# local dependencies
[dependencies]
+log = { version = "0.4.16", default-features = false }
unique-runtime-common = { path = "../common", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
runtime/quartz/Cargo.tomldiffbeforeafterboth38 'sp-runtime/runtime-benchmarks',38 'sp-runtime/runtime-benchmarks',39 'xcm-builder/runtime-benchmarks',39 'xcm-builder/runtime-benchmarks',40]40]41try-runtime = [42 'frame-try-runtime',43 'frame-executive/try-runtime',44 'frame-system/try-runtime',45]41std = [46std = [42 'codec/std',47 'codec/std',43 'cumulus-pallet-aura-ext/std',48 'cumulus-pallet-aura-ext/std',46 'cumulus-pallet-xcmp-queue/std',51 'cumulus-pallet-xcmp-queue/std',47 'cumulus-primitives-core/std',52 'cumulus-primitives-core/std',48 'cumulus-primitives-utility/std',53 'cumulus-primitives-utility/std',54 'frame-try-runtime/std',49 'frame-executive/std',55 'frame-executive/std',50 'frame-support/std',56 'frame-support/std',51 'frame-system/std',57 'frame-system/std',121optional = true127optional = true122branch = "polkadot-v0.9.20"128branch = "polkadot-v0.9.20"129130[dependencies.frame-try-runtime]131default-features = false132git = 'https://github.com/paritytech/substrate.git'133optional = true134branch = 'polkadot-v0.9.17'123135124[dependencies.frame-executive]136[dependencies.frame-executive]125default-features = false137default-features = false375# local dependencies387# local dependencies376388377[dependencies]389[dependencies]390log = { version = "0.4.16", default-features = false }378unique-runtime-common = { path = "../common", default-features = false }391unique-runtime-common = { path = "../common", default-features = false }379scale-info = { version = "2.0.1", default-features = false, features = [392scale-info = { version = "2.0.1", default-features = false, features = [380 "derive",393 "derive",runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -38,6 +38,11 @@
'sp-runtime/runtime-benchmarks',
'xcm-builder/runtime-benchmarks',
]
+try-runtime = [
+ 'frame-try-runtime',
+ 'frame-executive/try-runtime',
+ 'frame-system/try-runtime',
+]
std = [
'codec/std',
'cumulus-pallet-aura-ext/std',
@@ -46,6 +51,7 @@
'cumulus-pallet-xcmp-queue/std',
'cumulus-primitives-core/std',
'cumulus-primitives-utility/std',
+ 'frame-try-runtime/std',
'frame-executive/std',
'frame-support/std',
'frame-system/std',
@@ -121,6 +127,12 @@
optional = true
branch = "polkadot-v0.9.20"
+[dependencies.frame-try-runtime]
+default-features = false
+git = 'https://github.com/paritytech/substrate.git'
+optional = true
+branch = 'polkadot-v0.9.17'
+
[dependencies.frame-executive]
default-features = false
git = "https://github.com/paritytech/substrate"
@@ -375,6 +387,7 @@
# local dependencies
[dependencies]
+log = { version = "0.4.16", default-features = false }
unique-runtime-common = { path = "../common", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",