From 5045590582dcbea35a4d548770fb31c6947b2f15 Mon Sep 17 00:00:00 2001 From: Vladimir Stepanenko Date: Fri, 24 Mar 2023 12:37:00 +0300 Subject: [PATCH] Fix try-runtime build --- Cargo.lock | 1 + node/Cargo.toml | 1 + node/src/command.rs | 9 +++++-- pallets/farming/src/migrations.rs | 10 ++++---- pallets/hermes-governance-platform/Cargo.toml | 4 ++++ .../src/migrations/v1.rs | 8 ++++--- .../src/migrations/v2.rs | 15 ++++++------ runtime/Cargo.toml | 1 + runtime/src/lib.rs | 24 +++++++++---------- 9 files changed, 44 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75d3bc2697..ff97d8df12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13602,6 +13602,7 @@ source = "git+https://github.com/sora-xor/substrate.git?branch=polkadot-v0.9.38# dependencies = [ "clap 4.1.11", "frame-remote-externalities", + "frame-try-runtime", "hex", "log", "parity-scale-codec", diff --git a/node/Cargo.toml b/node/Cargo.toml index b9fdf5c538..210a29de19 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -147,5 +147,6 @@ runtime-benchmarks = [ try-runtime = [ "try-runtime-cli", + "try-runtime-cli/try-runtime", "framenode-runtime/try-runtime", ] diff --git a/node/src/command.rs b/node/src/command.rs index f0c0ff463f..5c1605ed63 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -214,6 +214,11 @@ pub fn run() -> sc_cli::Result<()> { } #[cfg(feature = "try-runtime")] Some(Subcommand::TryRuntime(cmd)) => { + use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; + type HostFunctionsOf = ExtendedHostFunctions< + sp_io::SubstrateHostFunctions, + ::ExtendHostFunctions, + >; let runner = cli.create_runner(cmd)?; set_default_ss58_version(); @@ -226,9 +231,9 @@ pub fn run() -> sc_cli::Result<()> { let task_manager = TaskManager::new(runner.config().tokio_handle.clone(), *registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - runner.async_run(|config| { + runner.async_run(|_config| { Ok(( - cmd.run::(config), + cmd.run::>(), task_manager, )) }) diff --git a/pallets/farming/src/migrations.rs b/pallets/farming/src/migrations.rs index efbda739a2..cedb7b22ae 100644 --- a/pallets/farming/src/migrations.rs +++ b/pallets/farming/src/migrations.rs @@ -72,17 +72,17 @@ pub mod v2 { } #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result<(), &'static str> { - ensure!( + fn pre_upgrade() -> Result, &'static str> { + frame_support::ensure!( StorageVersion::get::>() == StorageVersion::new(1), "Wrong storage version before upgrade" ); - Ok(()) + Ok(Vec::new()) } #[cfg(feature = "try-runtime")] - fn post_upgrade() -> Result<(), &'static str> { - ensure!( + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + frame_support::ensure!( StorageVersion::get::>() == StorageVersion::new(2), "Wrong storage version after upgrade" ); diff --git a/pallets/hermes-governance-platform/Cargo.toml b/pallets/hermes-governance-platform/Cargo.toml index 6880f7b1d9..b7ab547261 100644 --- a/pallets/hermes-governance-platform/Cargo.toml +++ b/pallets/hermes-governance-platform/Cargo.toml @@ -75,3 +75,7 @@ runtime-benchmarks = [ "frame-system/runtime-benchmarks", "frame-support/runtime-benchmarks", ] + +try-runtime = [ + "frame-support/try-runtime" +] \ No newline at end of file diff --git a/pallets/multicollateral-bonding-curve-pool/src/migrations/v1.rs b/pallets/multicollateral-bonding-curve-pool/src/migrations/v1.rs index 2898859527..facb6c3102 100644 --- a/pallets/multicollateral-bonding-curve-pool/src/migrations/v1.rs +++ b/pallets/multicollateral-bonding-curve-pool/src/migrations/v1.rs @@ -7,6 +7,8 @@ use frame_support::{ pallet_prelude::StorageVersion, traits::GetStorageVersion as _, }; +#[cfg(feature = "try-runtime")] +use sp_std::prelude::*; pub struct InitializeXSTPool(core::marker::PhantomData); @@ -36,16 +38,16 @@ where } #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result<(), &'static str> { + fn pre_upgrade() -> Result, &'static str> { frame_support::ensure!( Pallet::::on_chain_storage_version() == 0, "must upgrade linearly" ); - Ok(()) + Ok(Vec::new()) } #[cfg(feature = "try-runtime")] - fn post_upgrade() -> Result<(), &'static str> { + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { frame_support::ensure!( Pallet::::on_chain_storage_version() == 1, "should be upgraded to version 1" diff --git a/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs b/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs index 00d917601c..ab0faa5d4c 100644 --- a/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs +++ b/pallets/multicollateral-bonding-curve-pool/src/migrations/v2.rs @@ -10,6 +10,7 @@ use frame_support::{ traits::GetStorageVersion as _, }; use sp_runtime::traits::Zero; +use sp_std::prelude::*; pub const SORAMITSU_PAYMENT_ACCOUNT: [u8; 32] = hex_literal::hex!("34b9a44a2d3f681d8191815a6de986bf163d15f6d6b58d56aa1ab887313e1723"); @@ -92,27 +93,27 @@ where } #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result<(), &'static str> { + fn pre_upgrade() -> Result, &'static str> { frame_support::ensure!( - assets::Pallet::::ensure_asset_exists(TBCD.into()).is_err(), + assets::Pallet::::ensure_asset_exists(&TBCD.into()).is_err(), "TBCD asset already registered" ); frame_support::ensure!( - !crate::EnabledTargets::get().contains(&TBCD.into()), + !crate::EnabledTargets::::get().contains(&TBCD.into()), "TBCD pool already initialized" ); frame_support::ensure!( Pallet::::on_chain_storage_version() == 1, "must upgrade linearly" ); - Ok(()) + Ok(Vec::new()) } #[cfg(feature = "try-runtime")] - fn post_upgrade() -> Result<(), &'static str> { - assets::Pallet::::ensure_asset_exists(TBCD.into())?; + fn post_upgrade(_state: Vec) -> Result<(), &'static str> { + assets::Pallet::::ensure_asset_exists(&TBCD.into())?; frame_support::ensure!( - crate::EnabledTargets::get().contains(&TBCD.into()), + crate::EnabledTargets::::get().contains(&TBCD.into()), "TBCD pool is not initialized" ); frame_support::ensure!( diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b687cfbe04..4ef71763d2 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -368,6 +368,7 @@ try-runtime = [ "ceres-staking/try-runtime", "ceres-token-locker/try-runtime", "demeter-farming-platform/try-runtime", + "hermes-governance-platform/try-runtime", "dex-api/try-runtime", "dex-manager/try-runtime", "eth-bridge/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 890fc31200..c48e24cd5b 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -3062,21 +3062,21 @@ 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."); - let weight = Executive::try_runtime_upgrade().unwrap(); + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade"); + let weight = Executive::try_runtime_upgrade(checks).unwrap(); (weight, BlockWeights::get().max_block) } - fn execute_block(block: Block, state_root_check: bool, select: frame_try_runtime::TryStateSelect) -> Weight { - log::info!( - target: "runtime", "try-runtime: executing block #{} ({:?}) / root checks: {:?} / sanity-checks: {:?}", - block.header.number, - block.header.hash(), - state_root_check, - select, - ); - Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed") + fn execute_block( + block: Block, + state_root_check: bool, + signature_check: bool, + select: frame_try_runtime::TryStateSelect, + ) -> Weight { + // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to + // have a backtrace here. + Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() } } }