--- 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 = [] --- 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 --- 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>>, _)> { + Ok(( + match config.chain_spec.runtime_id() { + #[cfg(feature = "unique-runtime")] + RuntimeId::Unique => Box::pin(cmd.run::(config)), + + #[cfg(feature = "quartz-runtime")] + RuntimeId::Quartz => Box::pin(cmd.run::(config)), + + RuntimeId::Opal => { + Box::pin(cmd.run::(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(); --- 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 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) + } + } } } } --- 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", --- a/runtime/quartz/Cargo.toml +++ b/runtime/quartz/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", --- 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",