diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5b7a9c85c5a..31b2eae0c6d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -107,6 +107,22 @@ test-linux-stable: fi - sccache -s +check-runtime-benchmarks: + stage: test + <<: *docker-env + script: + # Check that the node will compile with `runtime-benchmarks` feature flag. + - time cargo check --features runtime-benchmarks + - sccache -s + +cargo-check-try-runtime: + stage: test + <<: *docker-env + script: + # Check that the node will compile with `try-runtime` feature flag. + - time cargo check --features try-runtime + - sccache -s + #### stage: publish publish-s3: diff --git a/Cargo.lock b/Cargo.lock index 741c696b79b..0ee7e4c9f96 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6055,6 +6055,7 @@ dependencies = [ "substrate-build-script-utils", "substrate-frame-rpc-system", "substrate-prometheus-endpoint", + "try-runtime-cli", ] [[package]] @@ -6076,6 +6077,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal 0.3.4", "log", "pallet-aura", @@ -6699,6 +6701,7 @@ dependencies = [ "substrate-frame-rpc-system", "substrate-prometheus-endpoint", "tempfile", + "try-runtime-cli", "westmint-runtime", ] @@ -9816,6 +9819,7 @@ dependencies = [ "frame-executive", "frame-support", "frame-system", + "frame-try-runtime", "log", "parachain-info", "parity-scale-codec", @@ -10712,6 +10716,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal 0.3.4", "log", "node-primitives", @@ -10777,6 +10782,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal 0.3.4", "log", "node-primitives", @@ -12170,6 +12176,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal 0.3.4", "log", "node-primitives", diff --git a/Cargo.toml b/Cargo.toml index f677317b2f6..241e54fd609 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,4 +38,4 @@ members = [ ] [profile.release] -panic = "unwind" \ No newline at end of file +panic = "unwind" diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index d9545f191ad..f0d9b0b1063 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -133,7 +133,7 @@ pub struct RunCmd { } /// A non-redundant version of the `RunCmd` that sets the `validator` field when the -/// original `RunCmd` had the `colaltor` field. +/// original `RunCmd` had the `collator` field. /// This is how we make `--collator` imply `--validator`. pub struct NormalizedRunCmd { /// The cumulus RunCmd inherents from sc_cli's diff --git a/pallets/collator-selection/Cargo.toml b/pallets/collator-selection/Cargo.toml index 94211b53a37..7150905240c 100644 --- a/pallets/collator-selection/Cargo.toml +++ b/pallets/collator-selection/Cargo.toml @@ -60,3 +60,5 @@ std = [ "pallet-authorship/std", "pallet-session/std", ] + +try-runtime = [ "frame-support/try-runtime" ] diff --git a/pallets/collator-selection/src/benchmarking.rs b/pallets/collator-selection/src/benchmarking.rs index e9c50e3df6e..cc91fd88ecd 100644 --- a/pallets/collator-selection/src/benchmarking.rs +++ b/pallets/collator-selection/src/benchmarking.rs @@ -88,7 +88,7 @@ fn register_validators(count: u32) { let validators = (0..count).map(|c| validator::(c)).collect::>(); for (who, keys) in validators { - >::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap(); + >::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap(); } } diff --git a/pallets/session-benchmarking/src/lib.rs b/pallets/session-benchmarking/src/lib.rs index 533cc01d3c9..453c50d341e 100644 --- a/pallets/session-benchmarking/src/lib.rs +++ b/pallets/session-benchmarking/src/lib.rs @@ -18,7 +18,7 @@ #![cfg(feature = "runtime-benchmarks")] use sp_std::{prelude::*, vec}; -use frame_benchmarking::{benchmarks, impl_benchmark_test_suite, whitelisted_caller}; +use frame_benchmarking::{benchmarks, whitelisted_caller}; use frame_system::RawOrigin; use pallet_session::*; pub struct Pallet(pallet_session::Pallet); @@ -39,6 +39,4 @@ benchmarks! { let proof: Vec = vec![0,1,2,3]; let _t = pallet_session::Pallet::::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof); }: _(RawOrigin::Signed(caller)) - } -impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test, extra = false,); diff --git a/parachain-template/node/Cargo.toml b/parachain-template/node/Cargo.toml index 9e6508437d0..661ed9d75d7 100644 --- a/parachain-template/node/Cargo.toml +++ b/parachain-template/node/Cargo.toml @@ -21,6 +21,7 @@ path = "src/main.rs" [features] runtime-benchmarks = ["parachain-template-runtime/runtime-benchmarks"] +try-runtime = [ "parachain-template-runtime/try-runtime" ] [dependencies] derive_more = "0.99.2" @@ -39,6 +40,7 @@ parachain-template-runtime = { path = "../runtime" } # Substrate Dependencies frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -92,3 +94,4 @@ polkadot-cli = { git = "https://github.com/paritytech/polkadot", branch = "maste polkadot-parachain = { git = "https://github.com/paritytech/polkadot", branch = "master" } polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "master" } polkadot-service = { git = "https://github.com/paritytech/polkadot", branch = "master" } + diff --git a/parachain-template/node/src/cli.rs b/parachain-template/node/src/cli.rs index 1ed730984d2..53040d7c581 100644 --- a/parachain-template/node/src/cli.rs +++ b/parachain-template/node/src/cli.rs @@ -37,6 +37,9 @@ pub enum Subcommand { /// The custom benchmark subcommmand benchmarking runtime pallets. #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")] Benchmark(frame_benchmarking_cli::BenchmarkCmd), + + /// Try some testing command against a specified runtime state. + TryRuntime(try_runtime_cli::TryRuntimeCmd), } /// Command for exporting the genesis state of the parachain diff --git a/parachain-template/node/src/command.rs b/parachain-template/node/src/command.rs index 59fb46e3a20..b03e83fcf96 100644 --- a/parachain-template/node/src/command.rs +++ b/parachain-template/node/src/command.rs @@ -13,7 +13,10 @@ use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, }; -use sc_service::config::{BasePath, PrometheusConfig}; +use sc_service::{ + config::{BasePath, PrometheusConfig}, + TaskManager, +}; use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::Block as BlockT; use std::{io::Write, net::SocketAddr}; @@ -237,6 +240,22 @@ pub fn run() -> Result<()> { You can enable it with `--features runtime-benchmarks`." .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 = + TaskManager::new(runner.config().tokio_handle.clone(), *registry) + .map_err(|e| format!("Error: {:?}", e))?; + + runner.async_run(|config| { + Ok((cmd.run::(config), task_manager)) + }) + } else { + Err("Try-runtime must be enabled by `--features try-runtime`.".into()) + }, None => { let runner = cli.create_runner(&cli.run.normalize())?; diff --git a/parachain-template/pallets/template/Cargo.toml b/parachain-template/pallets/template/Cargo.toml index 8ad0825b0c1..aa67b725bbd 100644 --- a/parachain-template/pallets/template/Cargo.toml +++ b/parachain-template/pallets/template/Cargo.toml @@ -35,3 +35,4 @@ std = [ "frame-system/std", "frame-benchmarking/std", ] +try-runtime = [ "frame-support/try-runtime" ] diff --git a/parachain-template/runtime/Cargo.toml b/parachain-template/runtime/Cargo.toml index 673a5ffde8d..beb9b87a75e 100644 --- a/parachain-template/runtime/Cargo.toml +++ b/parachain-template/runtime/Cargo.toml @@ -42,6 +42,7 @@ sp-version = { git = "https://github.com/paritytech/substrate", default-features ## Substrate FRAME Dependencies frame-benchmarking = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "master" } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "master" } frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" } frame-support = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false , branch = "master" } @@ -144,3 +145,8 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "cumulus-pallet-session-benchmarking/runtime-benchmarks", ] + +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", +] diff --git a/parachain-template/runtime/src/lib.rs b/parachain-template/runtime/src/lib.rs index 23ebd91b2f5..d2459f17d80 100644 --- a/parachain-template/runtime/src/lib.rs +++ b/parachain-template/runtime/src/lib.rs @@ -732,6 +732,18 @@ impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade parachain-template."); + 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) + } + } #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { @@ -788,7 +800,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_session, SessionBench::); add_benchmark!(params, batches, pallet_timestamp, Timestamp); add_benchmark!(params, batches, pallet_collator_selection, CollatorSelection); - add_benchmark!(params, batches, pallet_session, Session); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/polkadot-parachains/Cargo.toml b/polkadot-parachains/Cargo.toml index e26fbacd3f6..4a317b3a5f6 100644 --- a/polkadot-parachains/Cargo.toml +++ b/polkadot-parachains/Cargo.toml @@ -57,6 +57,9 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "master" } substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" } +# try-runtime stuff. +try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master" } + # RPC related dependencies jsonrpc-core = "18.0.0" sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -95,3 +98,9 @@ runtime-benchmarks = [ "statemine-runtime/runtime-benchmarks", "westmint-runtime/runtime-benchmarks", ] +try-runtime = [ + 'statemint-runtime/try-runtime', + 'statemine-runtime/try-runtime', + 'westmint-runtime/try-runtime', + 'shell-runtime/try-runtime', +] diff --git a/polkadot-parachains/shell/Cargo.toml b/polkadot-parachains/shell/Cargo.toml index 955e47004da..80071086ab9 100644 --- a/polkadot-parachains/shell/Cargo.toml +++ b/polkadot-parachains/shell/Cargo.toml @@ -28,6 +28,9 @@ frame-support = { git = "https://github.com/paritytech/substrate", default-featu frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +# try-runtime stuff. +frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } + # Cumulus dependencies cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false } cumulus-primitives-core = { path = "../../primitives/core", default-features = false } @@ -72,3 +75,7 @@ std = [ "xcm-builder/std", "xcm-executor/std", ] +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", +] diff --git a/polkadot-parachains/src/cli.rs b/polkadot-parachains/src/cli.rs index e0a98be20f2..900335fb94f 100644 --- a/polkadot-parachains/src/cli.rs +++ b/polkadot-parachains/src/cli.rs @@ -55,6 +55,9 @@ pub enum Subcommand { #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")] Benchmark(frame_benchmarking_cli::BenchmarkCmd), + /// Try some testing command against a specified runtime state. + TryRuntime(try_runtime_cli::TryRuntimeCmd), + /// Key management CLI utilities Key(sc_cli::KeySubcommand), } diff --git a/polkadot-parachains/src/command.rs b/polkadot-parachains/src/command.rs index e9b2952bf97..5a9e4eacae1 100644 --- a/polkadot-parachains/src/command.rs +++ b/polkadot-parachains/src/command.rs @@ -31,7 +31,10 @@ use sc_cli::{ ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams, NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli, }; -use sc_service::config::{BasePath, PrometheusConfig}; +use sc_service::{ + config::{BasePath, PrometheusConfig}, + TaskManager, +}; use sp_core::hexdisplay::HexDisplay; use sp_runtime::traits::Block as BlockT; use std::{io::Write, net::SocketAddr}; @@ -391,6 +394,37 @@ pub fn run() -> Result<()> { You can enable it with `--features runtime-benchmarks`." .into()) }, + Some(Subcommand::TryRuntime(cmd)) => + if cfg!(feature = "try-runtime") { + // grab the task manager. + let runner = cli.create_runner(cmd)?; + 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 runner.config().chain_spec.is_statemine() { + runner.async_run(|config| { + Ok((cmd.run::(config), task_manager)) + }) + } else if runner.config().chain_spec.is_westmint() { + runner.async_run(|config| { + Ok((cmd.run::(config), task_manager)) + }) + } else if runner.config().chain_spec.is_statemint() { + runner.async_run(|config| { + Ok((cmd.run::(config), task_manager)) + }) + } else if runner.config().chain_spec.is_shell() { + runner.async_run(|config| { + Ok((cmd.run::(config), task_manager)) + }) + } else { + Err("Chain doesn't support try-runtime".into()) + } + } else { + Err("Try-runtime must be enabled by `--features try-runtime`.".into()) + }, Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?), None => { let runner = cli.create_runner(&cli.run.normalize())?; diff --git a/polkadot-parachains/statemine/Cargo.toml b/polkadot-parachains/statemine/Cargo.toml index b6d816bb274..1983f618610 100644 --- a/polkadot-parachains/statemine/Cargo.toml +++ b/polkadot-parachains/statemine/Cargo.toml @@ -73,6 +73,9 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +# Try-runtime stuff +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "master" } + [dev-dependencies] hex-literal = "0.3.1" @@ -100,6 +103,10 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", ] +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", +] std = [ "codec/std", "scale-info/std", diff --git a/polkadot-parachains/statemine/src/lib.rs b/polkadot-parachains/statemine/src/lib.rs index e82e6a853a3..24acd5d1af3 100644 --- a/polkadot-parachains/statemine/src/lib.rs +++ b/polkadot-parachains/statemine/src/lib.rs @@ -889,6 +889,19 @@ impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade statemine."); + 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) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/polkadot-parachains/statemint/Cargo.toml b/polkadot-parachains/statemint/Cargo.toml index 6076eb86833..eddf78a20b5 100644 --- a/polkadot-parachains/statemint/Cargo.toml +++ b/polkadot-parachains/statemint/Cargo.toml @@ -73,6 +73,9 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +# Try-runtime stuff +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "master" } + [dev-dependencies] hex-literal = "0.3.1" @@ -100,6 +103,10 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", ] +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", +] std = [ "codec/std", "scale-info/std", diff --git a/polkadot-parachains/statemint/src/lib.rs b/polkadot-parachains/statemint/src/lib.rs index 58483a0e6d1..cb716dc3ced 100644 --- a/polkadot-parachains/statemint/src/lib.rs +++ b/polkadot-parachains/statemint/src/lib.rs @@ -890,6 +890,19 @@ impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade statemint."); + 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) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/polkadot-parachains/westmint/Cargo.toml b/polkadot-parachains/westmint/Cargo.toml index 82c334130a6..3c405d7a841 100644 --- a/polkadot-parachains/westmint/Cargo.toml +++ b/polkadot-parachains/westmint/Cargo.toml @@ -34,7 +34,7 @@ frame-support = { git = "https://github.com/paritytech/substrate", default-featu frame-executive = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } -pallet-asset-tx-payment = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } +pallet-asset-tx-payment = { git = 'https://github.com/paritytech/substrate', default-features = false, branch = "master" } pallet-assets = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -73,6 +73,9 @@ xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "master" } +# Try-runtime stuff +frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, optional = true , branch = "master" } + [dev-dependencies] hex-literal = "0.3.1" @@ -100,6 +103,10 @@ runtime-benchmarks = [ "pallet-xcm/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", ] +try-runtime = [ + "frame-try-runtime", + "frame-executive/try-runtime", +] std = [ "codec/std", "scale-info/std", diff --git a/polkadot-parachains/westmint/src/lib.rs b/polkadot-parachains/westmint/src/lib.rs index 2c2e1c5b78c..27766c69a50 100644 --- a/polkadot-parachains/westmint/src/lib.rs +++ b/polkadot-parachains/westmint/src/lib.rs @@ -887,6 +887,19 @@ impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade westmint."); + 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) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> (