From ce4e9aa1263779c4a6fd76fce775746a54eeb98f Mon Sep 17 00:00:00 2001 From: Miguel <64885598+MiguelDD1@users.noreply.github.com> Date: Fri, 24 Feb 2023 13:11:59 +0100 Subject: [PATCH] Re-enable `try-runtime` (#139) * Add `try-runtime` & fix `avail-core` versions * Toolchain to nightly-2022-11-25 --- .github/workflows/default.yml | 17 +++++++---------- Cargo.lock | 1 + avail-subxt/Cargo.toml | 2 +- node/Cargo.toml | 4 +++- node/src/command.rs | 9 ++++++++- pallets/dactr/Cargo.toml | 5 ++++- pallets/executive/Cargo.toml | 7 ++++++- pallets/executive/src/lib.rs | 4 +++- pallets/mocked_runtime/Cargo.toml | 1 + pallets/mocked_runtime/src/test_xt.rs | 8 ++++++++ pallets/nomad/da-bridge/Cargo.toml | 5 ++++- pallets/nomad/home/Cargo.toml | 5 ++++- pallets/nomad/updater-manager/Cargo.toml | 5 ++++- pallets/system/Cargo.toml | 5 ++++- pallets/system/src/mock.rs | 3 +++ runtime/Cargo.toml | 1 + runtime/src/lib.rs | 7 ++++--- 17 files changed, 66 insertions(+), 23 deletions(-) diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index a8c987340..9e63061af 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -9,7 +9,7 @@ on: - main - develop env: - BUILD_TOOLCHAIN: nightly-2022-09-22 + BUILD_TOOLCHAIN: nightly-2022-11-15 CARGO_SCCACHE_COMMIT: bed5571c SCCACHE_DIR: /home/runner/.cache/cargo-sccache-bed5571c SCCACHE_BIN: /home/runner/.cache/cargo-sccache-bed5571c/bin/sccache @@ -60,9 +60,8 @@ jobs: run: | curl https://sh.rustup.rs -sSf | sh -s -- -y source "$HOME/.cargo/env" - rustup toolchain install nightly - rustup default nightly - rustup target add wasm32-unknown-unknown --toolchain nightly + rustup default ${{ env.BUILD_TOOLCHAIN }} + rustup target add wasm32-unknown-unknown --toolchain ${{ env.BUILD_TOOLCHAIN }} - name: SCCache run: | @@ -119,9 +118,8 @@ jobs: run: | curl https://sh.rustup.rs -sSf | sh -s -- -y source "$HOME/.cargo/env" - rustup toolchain install nightly - rustup default nightly - rustup target add wasm32-unknown-unknown --toolchain nightly + rustup default ${{ env.BUILD_TOOLCHAIN }} + rustup target add wasm32-unknown-unknown --toolchain ${{ env.BUILD_TOOLCHAIN }} - name: SCCache run: | @@ -181,9 +179,8 @@ jobs: run: | curl https://sh.rustup.rs -sSf | sh -s -- -y source "$HOME/.cargo/env" - rustup toolchain install nightly - rustup default nightly - rustup target add wasm32-unknown-unknown --toolchain nightly + rustup default ${{ env.BUILD_TOOLCHAIN }} + rustup target add wasm32-unknown-unknown --toolchain ${{ env.BUILD_TOOLCHAIN }} - name: SCCache run: | diff --git a/Cargo.lock b/Cargo.lock index b353356e5..3bdf8b36e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1787,6 +1787,7 @@ dependencies = [ "sp-core", "sp-finality-grandpa", "sp-inherents", + "sp-io", "sp-keyring", "sp-keystore", "sp-rpc", diff --git a/avail-subxt/Cargo.toml b/avail-subxt/Cargo.toml index ce12f8d7f..7ba42b504 100644 --- a/avail-subxt/Cargo.toml +++ b/avail-subxt/Cargo.toml @@ -29,7 +29,7 @@ num_enum = "0.5.9" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes", "tokio1"] } -sp-keyring = "7.0.0" +sp-keyring = "6.0.0" futures = "0.3.13" hex-literal = "0.3.4" test-case = "1.2.3" diff --git a/node/Cargo.toml b/node/Cargo.toml index ac7fca68c..f5f3af9f9 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -43,6 +43,7 @@ hex-literal = "0.3.4" # Substrate ## Primitives sc-cli = "0.10.0-dev" +sp-io = "7.0.0" sp-core = "7.0.0" sc-executor = "0.10.0-dev" sc-service = "0.10.0-dev" @@ -135,7 +136,8 @@ runtime-benchmarks = [ # in the near future. try-runtime = [ "da-runtime/try-runtime", - "try-runtime-cli/try-runtime" + "try-runtime-cli/try-runtime", + "da-primitives/try-runtime" ] diff --git a/node/src/command.rs b/node/src/command.rs index c7245ffa5..a2a714303 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -246,6 +246,7 @@ pub fn run() -> Result<()> { }, #[cfg(feature = "try-runtime")] Some(Subcommand::TryRuntime(cmd)) => { + use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch}; let runner = cli.create_runner(cmd)?; runner.async_run(|config| { // we don't need any of the components of new_partial, just a runtime, or a task @@ -255,7 +256,13 @@ pub fn run() -> Result<()> { sc_service::TaskManager::new(config.tokio_handle.clone(), registry) .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - Ok((cmd.run::(config), task_manager)) + Ok(( + cmd.run::::ExtendHostFunctions, + >>(), + task_manager, + )) }) }, #[cfg(not(feature = "try-runtime"))] diff --git a/pallets/dactr/Cargo.toml b/pallets/dactr/Cargo.toml index 204d7cdf8..1c5cc1144 100644 --- a/pallets/dactr/Cargo.toml +++ b/pallets/dactr/Cargo.toml @@ -54,4 +54,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "da-primitives/try-runtime" +] diff --git a/pallets/executive/Cargo.toml b/pallets/executive/Cargo.toml index ada55857e..4bbebdf49 100644 --- a/pallets/executive/Cargo.toml +++ b/pallets/executive/Cargo.toml @@ -55,4 +55,9 @@ std = [ "sp-tracing/std", "da-primitives/std", ] -try-runtime = ["frame-support/try-runtime", "frame-try-runtime/try-runtime" ] +try-runtime = [ + "frame-support/try-runtime", + "frame-try-runtime/try-runtime" , + "da-primitives/try-runtime", + "mocked-runtime/try-runtime" +] diff --git a/pallets/executive/src/lib.rs b/pallets/executive/src/lib.rs index c399df7b0..c79bbc37c 100644 --- a/pallets/executive/src/lib.rs +++ b/pallets/executive/src/lib.rs @@ -117,6 +117,8 @@ #![cfg_attr(not(feature = "std"), no_std)] use codec::{Codec, Encode}; +#[cfg(feature = "try-runtime")] +use da_primitives::asdr::AppId; use da_primitives::asdr::GetAppId; use frame_support::{ dispatch::{DispatchClass, DispatchInfo, GetDispatchInfo, PostDispatchInfo}, @@ -265,7 +267,7 @@ where } else { uxt.unchecked_into_checked_i_know_what_i_am_doing(&Default::default()) }?; - >::note_extrinsic(encoded); + >::note_extrinsic(AppId::default(), encoded); let dispatch_info = xt.get_dispatch_info(); let r = Applyable::apply::(xt, &dispatch_info, encoded_len)?; diff --git a/pallets/mocked_runtime/Cargo.toml b/pallets/mocked_runtime/Cargo.toml index 8b3875fc9..27d76a3c0 100644 --- a/pallets/mocked_runtime/Cargo.toml +++ b/pallets/mocked_runtime/Cargo.toml @@ -41,3 +41,4 @@ pallet-staking = "4.0.0-dev" [features] default = ["std"] std = [ ] +try-runtime = [] diff --git a/pallets/mocked_runtime/src/test_xt.rs b/pallets/mocked_runtime/src/test_xt.rs index 58a12b17b..75e314585 100644 --- a/pallets/mocked_runtime/src/test_xt.rs +++ b/pallets/mocked_runtime/src/test_xt.rs @@ -49,6 +49,14 @@ impl Checkable for TestXt Result { Ok(self) } + + #[cfg(feature = "try-runtime")] + fn unchecked_into_checked_i_know_what_i_am_doing( + self, + _: &Context, + ) -> Result { + unreachable!() + } } impl Extrinsic for TestXt { diff --git a/pallets/nomad/da-bridge/Cargo.toml b/pallets/nomad/da-bridge/Cargo.toml index d2fabc144..0e3599b3b 100644 --- a/pallets/nomad/da-bridge/Cargo.toml +++ b/pallets/nomad/da-bridge/Cargo.toml @@ -61,4 +61,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "da-primitives/try-runtime" +] diff --git a/pallets/nomad/home/Cargo.toml b/pallets/nomad/home/Cargo.toml index 1e5a75c39..f2fb3dd53 100644 --- a/pallets/nomad/home/Cargo.toml +++ b/pallets/nomad/home/Cargo.toml @@ -61,4 +61,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "da-primitives/try-runtime" +] diff --git a/pallets/nomad/updater-manager/Cargo.toml b/pallets/nomad/updater-manager/Cargo.toml index 717516bd9..3d123de7f 100644 --- a/pallets/nomad/updater-manager/Cargo.toml +++ b/pallets/nomad/updater-manager/Cargo.toml @@ -50,4 +50,7 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "da-primitives/try-runtime" +] diff --git a/pallets/system/Cargo.toml b/pallets/system/Cargo.toml index 9f58e48d6..b49810f4d 100644 --- a/pallets/system/Cargo.toml +++ b/pallets/system/Cargo.toml @@ -66,7 +66,10 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "sp-runtime/runtime-benchmarks", ] -try-runtime = ["frame-support/try-runtime"] +try-runtime = [ + "frame-support/try-runtime", + "da-primitives/try-runtime" +] force-rs-merkle = [ "rs_merkle" ] # For testing backward/forward header compatibility. diff --git a/pallets/system/src/mock.rs b/pallets/system/src/mock.rs index c805d2687..09fb4d9b4 100644 --- a/pallets/system/src/mock.rs +++ b/pallets/system/src/mock.rs @@ -116,13 +116,16 @@ impl Config for Test { type Version = Version; } +#[allow(dead_code)] pub type SysEvent = frame_system::Event; /// A simple call, which one doesn't matter. +#[allow(dead_code)] pub const CALL: &::RuntimeCall = &RuntimeCall::System(frame_system::Call::set_heap_pages { pages: 0u64 }); /// Create new externalities for `System` module tests. +#[allow(dead_code)] pub fn new_test_ext() -> sp_io::TestExternalities { let mut ext: sp_io::TestExternalities = GenesisConfig::default() .system diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index c91a5bb62..c42a3ea70 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -236,4 +236,5 @@ try-runtime = [ "pallet-nomination-pools/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-tips/try-runtime", + "da-primitives/try-runtime", ] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index bf408b619..b241158e9 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -1618,17 +1618,18 @@ impl_runtime_apis! { #[cfg(feature = "try-runtime")] impl frame_try_runtime::TryRuntime for Runtime { - fn on_runtime_upgrade() -> (Weight, Weight) { + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { // NOTE: intentional unwrap: we don't want to propagate the error backwards, and want to // have a backtrace here. If any of the pre/post migration checks fail, we shall stop // right here and right now. - let weight = Executive::try_runtime_upgrade().unwrap(); + let weight = Executive::try_runtime_upgrade(checks).unwrap(); (weight, RuntimeBlockWeights::get().max_block) } fn execute_block( block: Block, state_root_check: bool, + signature_check: bool, select: frame_try_runtime::TryStateSelect ) -> Weight { log::info!( @@ -1640,7 +1641,7 @@ impl_runtime_apis! { ); // 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, select).unwrap() + Executive::try_execute_block(block, state_root_check, signature_check, select).unwrap() } }