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.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use crate::chain_spec;18use std::{path::PathBuf, env};19use clap::Parser;2021const NODE_NAME_ENV: &str = "UNIQUE_NODE_NAME";2223/// Sub-commands supported by the collator.24#[derive(Debug, Parser)]25pub enum Subcommand {26 /// Export the genesis state of the parachain.27 #[clap(name = "export-genesis-state")]28 ExportGenesisState(ExportGenesisStateCommand),2930 /// Export the genesis wasm of the parachain.31 #[clap(name = "export-genesis-wasm")]32 ExportGenesisWasm(ExportGenesisWasmCommand),3334 /// Build a chain specification.35 BuildSpec(sc_cli::BuildSpecCmd),3637 /// Validate blocks.38 CheckBlock(sc_cli::CheckBlockCmd),3940 /// Export blocks.41 ExportBlocks(sc_cli::ExportBlocksCmd),4243 /// Export the state of a given block into a chain spec.44 ExportState(sc_cli::ExportStateCmd),4546 /// Import blocks.47 ImportBlocks(sc_cli::ImportBlocksCmd),4849 /// Remove the whole chain.50 PurgeChain(cumulus_client_cli::PurgeChainCmd),5152 /// Revert the chain to a previous state.53 Revert(sc_cli::RevertCmd),5455 /// The custom benchmark subcommmand benchmarking runtime pallets.56 #[clap(subcommand)]57 Benchmark(frame_benchmarking_cli::BenchmarkCmd),58}5960/// Command for exporting the genesis state of the parachain61#[derive(Debug, Parser)]62pub struct ExportGenesisStateCommand {63 /// Output file name or stdout if unspecified.64 #[clap(parse(from_os_str))]65 pub output: Option<PathBuf>,6667 /// Id of the parachain this state is for.68 ///69 /// Default: 10070 #[clap(long, conflicts_with = "chain")]71 pub parachain_id: Option<u32>,7273 /// Write output in binary. Default is to write in hex.74 #[clap(short, long)]75 pub raw: bool,7677 /// The name of the chain for that the genesis state should be exported.78 #[clap(long, conflicts_with = "parachain-id")]79 pub chain: Option<String>,80}8182/// Command for exporting the genesis wasm file.83#[derive(Debug, Parser)]84pub struct ExportGenesisWasmCommand {85 /// Output file name or stdout if unspecified.86 #[clap(parse(from_os_str))]87 pub output: Option<PathBuf>,8889 /// Write output in binary. Default is to write in hex.90 #[clap(short, long)]91 pub raw: bool,9293 /// The name of the chain for that the genesis wasm file should be exported.94 #[clap(long)]95 pub chain: Option<String>,96}9798#[derive(Debug, Parser)]99#[clap(args_conflicts_with_subcommands = true, subcommand_negates_reqs = true)]100pub struct Cli {101 #[structopt(subcommand)]102 pub subcommand: Option<Subcommand>,103104 #[structopt(flatten)]105 pub run: cumulus_client_cli::RunCmd,106107 /// When running the node in the `--dev` mode and108 /// there is no transaction in the transaction pool,109 /// an empty block will be sealed automatically110 /// after the `--idle-autoseal-interval` milliseconds.111 ///112 /// The default interval is 500 milliseconds113 #[structopt(default_value = "500", long)]114 pub idle_autoseal_interval: u64,115116 /// Relaychain arguments117 #[structopt(raw = true)]118 pub relaychain_args: Vec<String>,119}120121impl Cli {122 pub fn node_name() -> String {123 match env::var(NODE_NAME_ENV).ok() {124 Some(name) => name,125 None => {126 if cfg!(feature = "unique-runtime") {127 "Unique"128 } else if cfg!(feature = "quartz-runtime") {129 "Quartz"130 } else {131 "Opal"132 }133 }134 .into(),135 }136 }137}138139#[derive(Debug)]140pub struct RelayChainCli {141 /// The actual relay chain cli object.142 pub base: polkadot_cli::RunCmd,143144 /// Optional chain id that should be passed to the relay chain.145 pub chain_id: Option<String>,146147 /// The base path that should be used by the relay chain.148 pub base_path: Option<PathBuf>,149}150151impl RelayChainCli {152 /// Parse the relay chain CLI parameters using the para chain `Configuration`.153 pub fn new<'a>(154 para_config: &sc_service::Configuration,155 relay_chain_args: impl Iterator<Item = &'a String>,156 ) -> Self {157 let extension = chain_spec::Extensions::try_get(&*para_config.chain_spec);158 let chain_id = extension.map(|e| e.relay_chain.clone());159 let base_path = para_config160 .base_path161 .as_ref()162 .map(|x| x.path().join("polkadot"));163 Self {164 base_path,165 chain_id,166 base: polkadot_cli::RunCmd::parse_from(relay_chain_args),167 }168 }169}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.tomldiffbeforeafterboth--- 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",
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",