diff --git a/polkadot/Cargo.lock b/polkadot/Cargo.lock index 61953d91e7..845c58b4bf 100644 --- a/polkadot/Cargo.lock +++ b/polkadot/Cargo.lock @@ -1778,6 +1778,18 @@ dependencies = [ "sp-api", ] +[[package]] +name = "frame-try-runtime" +version = "0.9.0" +source = "git+https://github.com/paritytech/substrate?branch=master#904495bc14eff5171fca5912247e772948439411" +dependencies = [ + "frame-support", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std", +] + [[package]] name = "fs-swap" version = "0.2.5" @@ -2634,6 +2646,7 @@ checksum = "489b9c612e60c766f751ab40fcb43cbb55a1e10bb44a9b4307ed510ca598cbd7" dependencies = [ "failure", "futures 0.1.29", + "hyper 0.12.35", "jsonrpc-core", "jsonrpc-pubsub", "log", @@ -2775,6 +2788,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal", "libsecp256k1", "log", @@ -5137,6 +5151,7 @@ dependencies = [ "substrate-build-script-utils", "thiserror", "tracing-futures", + "try-runtime-cli", "wasm-bindgen", "wasm-bindgen-futures", ] @@ -5709,6 +5724,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal", "libsecp256k1", "log", @@ -6714,6 +6730,24 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "remote-externalities" +version = "0.9.0" +source = "git+https://github.com/paritytech/substrate?branch=master#904495bc14eff5171fca5912247e772948439411" +dependencies = [ + "bincode", + "env_logger 0.8.2", + "futures 0.1.29", + "hex-literal", + "jsonrpc-core-client", + "log", + "sc-rpc", + "sc-rpc-api", + "sp-core", + "sp-io", + "tokio 0.1.22", +] + [[package]] name = "remove_dir_all" version = "0.5.3" @@ -9834,6 +9868,28 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +[[package]] +name = "try-runtime-cli" +version = "0.9.0" +source = "git+https://github.com/paritytech/substrate?branch=master#904495bc14eff5171fca5912247e772948439411" +dependencies = [ + "frame-try-runtime", + "log", + "parity-scale-codec", + "remote-externalities", + "sc-cli", + "sc-client-api", + "sc-executor", + "sc-service", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-externalities", + "sp-runtime", + "sp-state-machine", + "structopt", +] + [[package]] name = "twox-hash" version = "1.5.0" @@ -10447,6 +10503,7 @@ dependencies = [ "frame-system", "frame-system-benchmarking", "frame-system-rpc-runtime-api", + "frame-try-runtime", "hex-literal", "libsecp256k1", "log", diff --git a/polkadot/Cargo.toml b/polkadot/Cargo.toml index 6fd9162ff1..e073800c83 100644 --- a/polkadot/Cargo.toml +++ b/polkadot/Cargo.toml @@ -92,6 +92,7 @@ panic = "unwind" runtime-benchmarks=["cli/runtime-benchmarks"] real-overseer=["cli/real-overseer"] approval-checking=["real-overseer", "service/approval-checking"] +try-runtime = ["cli/try-runtime"] # Configuration for building a .deb package - for use with `cargo-deb` [package.metadata.deb] diff --git a/polkadot/cli/Cargo.toml b/polkadot/cli/Cargo.toml index 4e29c3dc85..ad4a22b59a 100644 --- a/polkadot/cli/Cargo.toml +++ b/polkadot/cli/Cargo.toml @@ -27,6 +27,7 @@ polkadot-parachain = { path = "../parachain", optional = true } sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" } tracing-futures = "0.2.4" frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } +try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } browser-utils = { package = "substrate-browser-utils", git = "https://github.com/paritytech/substrate", branch = "master", optional = true } @@ -47,6 +48,7 @@ cli = [ "sc-cli", "sc-service", "frame-benchmarking-cli", + "try-runtime-cli", ] browser = [ "wasm-bindgen", @@ -58,3 +60,4 @@ runtime-benchmarks = [ "service/runtime-benchmarks" ] trie-memory-tracker = [ "sp-trie/memory-tracker" ] full-node = [ "service/full-node" ] real-overseer = [ "service/real-overseer" ] +try-runtime = [ "service/try-runtime" ] diff --git a/polkadot/cli/src/cli.rs b/polkadot/cli/src/cli.rs index c7520eee12..2dd56bc1ad 100644 --- a/polkadot/cli/src/cli.rs +++ b/polkadot/cli/src/cli.rs @@ -46,13 +46,17 @@ pub enum Subcommand { #[structopt(name = "validation-worker", setting = structopt::clap::AppSettings::Hidden)] ValidationWorker(ValidationWorkerCommand), - /// The custom benchmark subcommmand benchmarking runtime pallets. + /// The custom benchmark subcommand benchmarking runtime pallets. #[structopt( name = "benchmark", about = "Benchmark runtime pallets." )] Benchmark(frame_benchmarking_cli::BenchmarkCmd), + /// Testing subcommand for runtime testing and trying. + #[cfg(feature = "try-runtime")] + TryRuntime(try_runtime_cli::TryRuntimeCmd), + /// Key management cli utilities Key(sc_cli::KeySubcommand), } diff --git a/polkadot/cli/src/command.rs b/polkadot/cli/src/command.rs index 8b7e135fff..cb9e1bba2f 100644 --- a/polkadot/cli/src/command.rs +++ b/polkadot/cli/src/command.rs @@ -245,7 +245,7 @@ pub fn run() -> Result<()> { Ok(runner.async_run(|mut config| { let (client, backend, _, task_manager) = service::new_chain_ops(&mut config, None)?; - Ok((cmd.run(client, backend).map_err(Error::SubstrateCli),task_manager)) + Ok((cmd.run(client, backend).map_err(Error::SubstrateCli), task_manager)) })?) }, Some(Subcommand::ValidationWorker(cmd)) => { @@ -276,6 +276,31 @@ pub fn run() -> Result<()> { })?) }, Some(Subcommand::Key(cmd)) => Ok(cmd.run(&cli)?), + #[cfg(feature = "try-runtime")] + Some(Subcommand::TryRuntime(cmd)) => { + let runner = cli.create_runner(cmd)?; + let chain_spec = &runner.config().chain_spec; + set_default_ss58_version(chain_spec); + + runner.async_run(|config| { + use sc_service::TaskManager; + let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); + let task_manager = TaskManager::new( + config.task_executor.clone(), + registry, + ).map_err(|e| Error::SubstrateService(sc_service::Error::Prometheus(e)))?; + + Ok(( + cmd.run::< + service::kusama_runtime::Block, + service::KusamaExecutor, + >(config).map_err(Error::SubstrateCli), + task_manager + )) + // NOTE: we fetch only the block number from the block type, the chance of disparity + // between kusama's and polkadot's block number is small enough to overlook this. + }) + } }?; Ok(()) } diff --git a/polkadot/node/service/Cargo.toml b/polkadot/node/service/Cargo.toml index 47c2928462..9022f483c4 100644 --- a/polkadot/node/service/Cargo.toml +++ b/polkadot/node/service/Cargo.toml @@ -117,6 +117,11 @@ runtime-benchmarks = [ "westend-runtime/runtime-benchmarks", "rococo-runtime/runtime-benchmarks" ] +try-runtime = [ + "polkadot-runtime/try-runtime", + "kusama-runtime/try-runtime", + "westend-runtime/try-runtime", +] real-overseer = [ "polkadot-availability-bitfield-distribution", diff --git a/polkadot/runtime/kusama/Cargo.toml b/polkadot/runtime/kusama/Cargo.toml index f4660b6b3a..1637b773dc 100644 --- a/polkadot/runtime/kusama/Cargo.toml +++ b/polkadot/runtime/kusama/Cargo.toml @@ -58,7 +58,7 @@ pallet-session = { git = "https://github.com/paritytech/substrate", branch = "ma pallet-society = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-staking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } -pallet-staking-reward-curve = { package = "pallet-staking-reward-curve", git = "https://github.com/paritytech/substrate", branch = "master" } +pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-system = {git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } @@ -68,6 +68,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "ma pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } @@ -182,7 +183,10 @@ runtime-benchmarks = [ "frame-system-benchmarking", "hex-literal", ] - +try-runtime = [ + "frame-executive/try-runtime", + "frame-try-runtime", +] # When enabled, the runtime api will not be build. # # This is required by Cumulus to access certain types of the diff --git a/polkadot/runtime/kusama/src/lib.rs b/polkadot/runtime/kusama/src/lib.rs index 639d6a9a9d..ff1a1c3ad6 100644 --- a/polkadot/runtime/kusama/src/lib.rs +++ b/polkadot/runtime/kusama/src/lib.rs @@ -1067,7 +1067,6 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllModules, - () >; /// The payload being signed in the transactions. pub type SignedPayload = generic::SignedPayload; @@ -1316,6 +1315,15 @@ sp_api::impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> { + frame_support::debug::RuntimeLogger::init(); + let weight = Executive::try_runtime_upgrade()?; + Ok((weight, BlockWeights::get().max_block)) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn dispatch_benchmark( diff --git a/polkadot/runtime/polkadot/Cargo.toml b/polkadot/runtime/polkadot/Cargo.toml index ad4049acd4..2660f448d1 100644 --- a/polkadot/runtime/polkadot/Cargo.toml +++ b/polkadot/runtime/polkadot/Cargo.toml @@ -66,6 +66,7 @@ pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "ma pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } @@ -177,7 +178,10 @@ runtime-benchmarks = [ "frame-system-benchmarking", "hex-literal", ] - +try-runtime = [ + "frame-executive/try-runtime", + "frame-try-runtime", +] # When enabled, the runtime api will not be build. # # This is required by Cumulus to access certain types of the diff --git a/polkadot/runtime/polkadot/src/lib.rs b/polkadot/runtime/polkadot/src/lib.rs index 5c66a23dc6..83502543a2 100644 --- a/polkadot/runtime/polkadot/src/lib.rs +++ b/polkadot/runtime/polkadot/src/lib.rs @@ -1311,6 +1311,15 @@ sp_api::impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> { + frame_support::debug::RuntimeLogger::init(); + let weight = Executive::try_runtime_upgrade()?; + Ok((weight, BlockWeights::get().max_block)) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn dispatch_benchmark( diff --git a/polkadot/runtime/westend/Cargo.toml b/polkadot/runtime/westend/Cargo.toml index 992b235c5e..cc1b4a359a 100644 --- a/polkadot/runtime/westend/Cargo.toml +++ b/polkadot/runtime/westend/Cargo.toml @@ -67,6 +67,7 @@ pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "ma pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +frame-try-runtime = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } frame-system-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-offences-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } pallet-session-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } @@ -179,7 +180,10 @@ runtime-benchmarks = [ "frame-system-benchmarking", "hex-literal", ] - +try-runtime = [ + "frame-executive/try-runtime", + "frame-try-runtime", +] # When enabled, the runtime api will not be build. # # This is required by Cumulus to access certain types of the diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index c6f43a598a..cd503410c8 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -774,7 +774,6 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllModules, - () >; /// The payload being signed in transactions. pub type SignedPayload = generic::SignedPayload; @@ -1031,6 +1030,15 @@ sp_api::impl_runtime_apis! { } } + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> { + frame_support::debug::RuntimeLogger::init(); + let weight = Executive::try_runtime_upgrade()?; + Ok((weight, BlockWeights::get().max_block)) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn dispatch_benchmark(