Integrate try-runtime into cumulus (#793)

* almost integrate

* revert branch changes

* remove extra deps

* some review comments'

* Fix a bunch of stuff

* Update parachain-template/node/Cargo.toml

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Fix

* Fix

* fix benchmark

* fmt

* Remove wrong bench test

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
This commit is contained in:
Kian Paimani
2021-12-02 14:00:54 +01:00
committed by GitHub
parent ca81203b83
commit e70f7fd016
23 changed files with 189 additions and 10 deletions
+16
View File
@@ -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:
Generated
+7
View File
@@ -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",
+1 -1
View File
@@ -38,4 +38,4 @@ members = [
]
[profile.release]
panic = "unwind"
panic = "unwind"
+1 -1
View File
@@ -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
+2
View File
@@ -60,3 +60,5 @@ std = [
"pallet-authorship/std",
"pallet-session/std",
]
try-runtime = [ "frame-support/try-runtime" ]
@@ -88,7 +88,7 @@ fn register_validators<T: Config + session::Config>(count: u32) {
let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();
for (who, keys) in validators {
<session::Module<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();
}
}
+1 -3
View File
@@ -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<T: Config>(pallet_session::Pallet<T>);
@@ -39,6 +39,4 @@ benchmarks! {
let proof: Vec<u8> = vec![0,1,2,3];
let _t = pallet_session::Pallet::<T>::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,);
+3
View File
@@ -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" }
+3
View File
@@ -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
+20 -1
View File
@@ -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::<Block, TemplateRuntimeExecutor>(config), task_manager))
})
} else {
Err("Try-runtime must be enabled by `--features try-runtime`.".into())
},
None => {
let runner = cli.create_runner(&cli.run.normalize())?;
@@ -35,3 +35,4 @@ std = [
"frame-system/std",
"frame-benchmarking/std",
]
try-runtime = [ "frame-support/try-runtime" ]
+6
View File
@@ -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",
]
+12 -1
View File
@@ -732,6 +732,18 @@ impl_runtime_apis! {
}
}
#[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 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<Block> for Runtime {
@@ -788,7 +800,6 @@ impl_runtime_apis! {
add_benchmark!(params, batches, pallet_session, SessionBench::<Runtime>);
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)
+9
View File
@@ -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',
]
+7
View File
@@ -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",
]
+3
View File
@@ -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),
}
+35 -1
View File
@@ -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::<Block, StatemineRuntimeExecutor>(config), task_manager))
})
} else if runner.config().chain_spec.is_westmint() {
runner.async_run(|config| {
Ok((cmd.run::<Block, WestmintRuntimeExecutor>(config), task_manager))
})
} else if runner.config().chain_spec.is_statemint() {
runner.async_run(|config| {
Ok((cmd.run::<Block, StatemintRuntimeExecutor>(config), task_manager))
})
} else if runner.config().chain_spec.is_shell() {
runner.async_run(|config| {
Ok((cmd.run::<Block, ShellRuntimeExecutor>(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())?;
+7
View File
@@ -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",
+13
View File
@@ -889,6 +889,19 @@ impl_runtime_apis! {
}
}
#[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 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<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
+7
View File
@@ -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",
+13
View File
@@ -890,6 +890,19 @@ impl_runtime_apis! {
}
}
#[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 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<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
+8 -1
View File
@@ -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",
+13
View File
@@ -887,6 +887,19 @@ impl_runtime_apis! {
}
}
#[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 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<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (