From d5419aa2389d53f4e6203fb88ff0755f4163fbfd Mon Sep 17 00:00:00 2001 From: linning Date: Tue, 29 Oct 2024 05:16:34 +0800 Subject: [PATCH 1/2] Remove the try-runtime feature It is broken, incomplete, and unused, we can add it back when we have use case. Signed-off-by: linning --- crates/pallet-domains/Cargo.toml | 1 - crates/pallet-history-seeding/Cargo.toml | 1 - crates/pallet-rewards/Cargo.toml | 1 - crates/pallet-runtime-configs/Cargo.toml | 1 - crates/pallet-subspace-mmr/Cargo.toml | 5 ---- crates/pallet-subspace/Cargo.toml | 1 - crates/pallet-transaction-fees/Cargo.toml | 1 - domains/pallets/auto-id/Cargo.toml | 1 - domains/pallets/block-fees/Cargo.toml | 5 ---- domains/pallets/domain-id/Cargo.toml | 5 ---- domains/pallets/domain-sudo/Cargo.toml | 5 ---- domains/pallets/evm_nonce_tracker/Cargo.toml | 5 ---- domains/pallets/executive/Cargo.toml | 1 - domains/pallets/executive/src/lib.rs | 26 -------------------- domains/pallets/messenger/Cargo.toml | 1 - domains/pallets/transporter/Cargo.toml | 1 - 16 files changed, 61 deletions(-) diff --git a/crates/pallet-domains/Cargo.toml b/crates/pallet-domains/Cargo.toml index 9f58a57b6c..3cdd59b4e0 100644 --- a/crates/pallet-domains/Cargo.toml +++ b/crates/pallet-domains/Cargo.toml @@ -64,7 +64,6 @@ std = [ "subspace-core-primitives/std", "subspace-runtime-primitives/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", diff --git a/crates/pallet-history-seeding/Cargo.toml b/crates/pallet-history-seeding/Cargo.toml index e5dbeab17b..0819d9b24d 100644 --- a/crates/pallet-history-seeding/Cargo.toml +++ b/crates/pallet-history-seeding/Cargo.toml @@ -37,7 +37,6 @@ std = [ "scale-info/std", "sp-std/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/crates/pallet-rewards/Cargo.toml b/crates/pallet-rewards/Cargo.toml index 4f80389d04..956374ce07 100644 --- a/crates/pallet-rewards/Cargo.toml +++ b/crates/pallet-rewards/Cargo.toml @@ -47,7 +47,6 @@ std = [ "sp-runtime/std", "subspace-runtime-primitives/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/crates/pallet-runtime-configs/Cargo.toml b/crates/pallet-runtime-configs/Cargo.toml index a8d61c7bac..99905dd16a 100644 --- a/crates/pallet-runtime-configs/Cargo.toml +++ b/crates/pallet-runtime-configs/Cargo.toml @@ -38,7 +38,6 @@ std = [ "sp-std?/std", "subspace-runtime-primitives/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/crates/pallet-subspace-mmr/Cargo.toml b/crates/pallet-subspace-mmr/Cargo.toml index 4a4dfe4781..8d2ddfd738 100644 --- a/crates/pallet-subspace-mmr/Cargo.toml +++ b/crates/pallet-subspace-mmr/Cargo.toml @@ -39,8 +39,3 @@ std = [ "sp-std/std", "sp-subspace-mmr/std" ] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/crates/pallet-subspace/Cargo.toml b/crates/pallet-subspace/Cargo.toml index 828ada518f..c9970547d4 100644 --- a/crates/pallet-subspace/Cargo.toml +++ b/crates/pallet-subspace/Cargo.toml @@ -67,7 +67,6 @@ std = [ "subspace-runtime-primitives/std", "subspace-verification/std" ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/crates/pallet-transaction-fees/Cargo.toml b/crates/pallet-transaction-fees/Cargo.toml index ece8de7bd1..e78aac6271 100644 --- a/crates/pallet-transaction-fees/Cargo.toml +++ b/crates/pallet-transaction-fees/Cargo.toml @@ -33,4 +33,3 @@ std = [ "scale-info/std", "subspace-runtime-primitives/std", ] -try-runtime = ["frame-support/try-runtime"] diff --git a/domains/pallets/auto-id/Cargo.toml b/domains/pallets/auto-id/Cargo.toml index ecc76c7abe..e82eaaa75f 100644 --- a/domains/pallets/auto-id/Cargo.toml +++ b/domains/pallets/auto-id/Cargo.toml @@ -44,7 +44,6 @@ std = [ "sp-runtime/std", "subspace-runtime-primitives/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/domains/pallets/block-fees/Cargo.toml b/domains/pallets/block-fees/Cargo.toml index 558293b4f1..dd97054a92 100644 --- a/domains/pallets/block-fees/Cargo.toml +++ b/domains/pallets/block-fees/Cargo.toml @@ -37,8 +37,3 @@ std = [ "sp-runtime/std", "sp-std/std", ] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/domains/pallets/domain-id/Cargo.toml b/domains/pallets/domain-id/Cargo.toml index dc31110ccc..1fc5e6bc15 100644 --- a/domains/pallets/domain-id/Cargo.toml +++ b/domains/pallets/domain-id/Cargo.toml @@ -36,8 +36,3 @@ std = [ ] runtime-benchmarks = [] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/domains/pallets/domain-sudo/Cargo.toml b/domains/pallets/domain-sudo/Cargo.toml index 3f54399915..baa759e383 100644 --- a/domains/pallets/domain-sudo/Cargo.toml +++ b/domains/pallets/domain-sudo/Cargo.toml @@ -32,8 +32,3 @@ std = [ "sp-runtime/std", "sp-domain-sudo/std" ] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/domains/pallets/evm_nonce_tracker/Cargo.toml b/domains/pallets/evm_nonce_tracker/Cargo.toml index 9299b6a461..557f856179 100644 --- a/domains/pallets/evm_nonce_tracker/Cargo.toml +++ b/domains/pallets/evm_nonce_tracker/Cargo.toml @@ -30,8 +30,3 @@ std = [ "sp-core/std", "sp-runtime/std", ] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/domains/pallets/executive/Cargo.toml b/domains/pallets/executive/Cargo.toml index 0eb028e311..3cbc1bee1c 100644 --- a/domains/pallets/executive/Cargo.toml +++ b/domains/pallets/executive/Cargo.toml @@ -48,7 +48,6 @@ std = [ "sp-std/std", "sp-tracing/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/domains/pallets/executive/src/lib.rs b/domains/pallets/executive/src/lib.rs index 47c68c8abe..60ccd83cc7 100644 --- a/domains/pallets/executive/src/lib.rs +++ b/domains/pallets/executive/src/lib.rs @@ -301,32 +301,6 @@ where >::execute_on_runtime_upgrade() } - /// Wrapped `frame_executive::Executive::execute_block_no_check`. - #[cfg(feature = "try-runtime")] - pub fn execute_block_no_check(block: BlockOf) -> Weight { - frame_executive::Executive::< - ExecutiveConfig, - BlockOf, - Context, - UnsignedValidator, - AllPalletsWithSystem, - COnRuntimeUpgrade, - >::execute_block_no_check(block) - } - - /// Wrapped `frame_executive::Executive::try_runtime_upgrade`. - #[cfg(feature = "try-runtime")] - pub fn try_runtime_upgrade() -> Result { - frame_executive::Executive::< - ExecutiveConfig, - BlockOf, - Context, - UnsignedValidator, - AllPalletsWithSystem, - COnRuntimeUpgrade, - >::try_runtime_upgrade() - } - /// Wrapped `frame_executive::Executive::initialize_block`. /// /// Note the storage root in the end. diff --git a/domains/pallets/messenger/Cargo.toml b/domains/pallets/messenger/Cargo.toml index 0ede1913c0..669bb6f51a 100644 --- a/domains/pallets/messenger/Cargo.toml +++ b/domains/pallets/messenger/Cargo.toml @@ -51,7 +51,6 @@ std = [ "sp-trie/std", "sp-subspace-mmr/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", diff --git a/domains/pallets/transporter/Cargo.toml b/domains/pallets/transporter/Cargo.toml index 09c16d5c8c..8761158eb4 100644 --- a/domains/pallets/transporter/Cargo.toml +++ b/domains/pallets/transporter/Cargo.toml @@ -46,7 +46,6 @@ std = [ "sp-runtime/std", "sp-std/std", ] -try-runtime = ["frame-support/try-runtime"] runtime-benchmarks = [ "frame-benchmarking", "frame-benchmarking/runtime-benchmarks", From 2da37f499eb528e0a5e661f8c7ffa1a3e36c0ca7 Mon Sep 17 00:00:00 2001 From: linning Date: Tue, 29 Oct 2024 06:47:16 +0800 Subject: [PATCH 2/2] Keep our customized executive pallet up-to-date with the upstream Signed-off-by: linning --- domains/pallets/executive/src/lib.rs | 62 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/domains/pallets/executive/src/lib.rs b/domains/pallets/executive/src/lib.rs index 60ccd83cc7..f4ebe82486 100644 --- a/domains/pallets/executive/src/lib.rs +++ b/domains/pallets/executive/src/lib.rs @@ -18,6 +18,7 @@ //! # Domain Executive Module //! //! This module is derived from frame_executive with some custom modifications for +//! including the failed extrinsic during `pre/post_dispatch` in the block and //! collecting the intermediate storage roots in the block execution required for //! the fraud proof of decoupled execution in Subspace. @@ -35,6 +36,7 @@ pub mod weights; extern crate alloc; use codec::{Codec, Encode}; +use frame_support::defensive_assert; use frame_support::dispatch::{ DispatchClass, DispatchErrorWithPostInfo, DispatchInfo, GetDispatchInfo, Pays, PostDispatchInfo, }; @@ -43,7 +45,7 @@ use frame_support::traits::fungible::{Inspect, Mutate}; use frame_support::traits::tokens::{Fortitude, Precision, Preservation}; use frame_support::traits::{ BeforeAllRuntimeMigrations, EnsureInherentsAreFirst, ExecuteBlock, Get, OffchainWorker, - OnFinalize, OnIdle, OnInitialize, OnPoll, OnRuntimeUpgrade, + OnFinalize, OnIdle, OnInitialize, OnPoll, OnRuntimeUpgrade, PostTransactions, }; use frame_support::weights::{Weight, WeightToFee}; use frame_system::pallet_prelude::*; @@ -316,7 +318,7 @@ where } // TODO: https://github.com/paritytech/substrate/issues/10711 - fn initial_checks(block: &BlockOf) { + fn initial_checks(block: &BlockOf) -> u32 { sp_tracing::enter_span!(sp_tracing::Level::TRACE, "initial_checks"); let header = block.header(); @@ -330,37 +332,56 @@ where "Parent hash should be valid.", ); - if let Err(i) = ExecutiveConfig::ensure_inherents_are_first(block) { - panic!("Invalid inherent position for extrinsic at index {i}"); + match ExecutiveConfig::ensure_inherents_are_first(block) { + Ok(num) => num, + Err(i) => panic!("Invalid inherent position for extrinsic at index {}", i), } } /// Wrapped `frame_executive::Executive::execute_block`. /// - /// The purpose is to use our custom [`Executive::initialize_block`] and - /// [`Executive::apply_extrinsic`]. + /// The purpose is to use our custom [`Executive::apply_extrinsic`] and + /// the [`Executive::finalize_block`] logic. pub fn execute_block(block: BlockOf) { sp_io::init_tracing(); sp_tracing::within_span! { sp_tracing::info_span!("execute_block", ?block); + // Execute `on_runtime_upgrade` and `on_initialize`. + let mode = Self::initialize_block(block.header()); + let num_inherents = Self::initial_checks(&block) as usize; + let (header, extrinsics) = block.deconstruct(); + let num_extrinsics = extrinsics.len(); - Self::initialize_block(block.header()); + if mode == ExtrinsicInclusionMode::OnlyInherents && num_extrinsics > num_inherents { + // Invalid block + panic!("Only inherents are allowed in this block") + } - Self::initial_checks(&block); + Self::apply_extrinsics(extrinsics.into_iter()); + + // In this case there were no transactions to trigger this state transition: + if !>::inherents_applied() { + defensive_assert!(num_inherents == num_extrinsics); + frame_executive::Executive::< + ExecutiveConfig, + BlockOf, + Context, + UnsignedValidator, + AllPalletsWithSystem, + COnRuntimeUpgrade, + >::inherents_applied(); + } - // execute extrinsics - let (header, extrinsics) = block.deconstruct(); - Self::execute_extrinsics_with_book_keeping(extrinsics, *header.number()); + >::note_finished_extrinsics(); + ::PostTransactions::post_transactions(); + Self::idle_and_finalize_hook(*header.number()); Self::final_checks(&header); } } - /// Exactly same with `frame_executive::executive::execute_extrinsics_with_book_keeping`. - fn execute_extrinsics_with_book_keeping( - extrinsics: Vec>, - block_number: NumberFor>, - ) { + /// Wrapped `frame_executive::Executive::apply_extrinsics`. + fn apply_extrinsics(extrinsics: impl Iterator>) { extrinsics.into_iter().for_each(|e| { if let Err(e) = Self::apply_extrinsic(e) { let err: &'static str = e.into(); @@ -372,11 +393,6 @@ where // syncing process produces the same storage root with the one processed based on // the consensus block. Pallet::::push_root(Self::storage_root()); - - // post-extrinsics book-keeping - >::note_finished_extrinsics(); - - Self::idle_and_finalize_hook(block_number); } /// Wrapped `frame_executive::Executive::finalize_block`. @@ -392,7 +408,7 @@ where >::finalize_block() } - // TODO: https://github.com/paritytech/substrate/issues/10711 + /// Wrapped `frame_executive::Executive::on_idle_hook` and `frame_executive::Executive::on_finalize_hook` fn idle_and_finalize_hook(block_number: NumberFor>) { let weight = >::block_weight(); let max_weight = <::BlockWeights as frame_support::traits::Get<_>>::get().max_block; @@ -411,7 +427,7 @@ where /// Wrapped `frame_executive::Executive::apply_extrinsic`. /// - /// Note the storage root in the end. + /// Note the storage root in the beginning. pub fn apply_extrinsic(uxt: ExtrinsicOf) -> ApplyExtrinsicResult { Pallet::::push_root(Self::storage_root());