From fa4fce98b19484e671e6a71eb00f7f2c25da9099 Mon Sep 17 00:00:00 2001 From: vedhavyas Date: Thu, 9 Jan 2025 17:19:56 +0530 Subject: [PATCH] remove Intermediate roots from pallet executive --- crates/sp-domains/src/core_api.rs | 3 -- .../client/block-builder/src/custom_api.rs | 22 ----------- domains/pallets/executive/src/lib.rs | 39 +------------------ domains/runtime/auto-id/src/lib.rs | 4 -- domains/runtime/evm/src/lib.rs | 4 -- domains/test/runtime/auto-id/src/lib.rs | 4 -- domains/test/runtime/evm/src/lib.rs | 4 -- 7 files changed, 2 insertions(+), 78 deletions(-) diff --git a/crates/sp-domains/src/core_api.rs b/crates/sp-domains/src/core_api.rs index 90a07c3a76..f17219f287 100644 --- a/crates/sp-domains/src/core_api.rs +++ b/crates/sp-domains/src/core_api.rs @@ -28,9 +28,6 @@ sp_api::decl_runtime_apis! { tx_range: &U256, ) -> bool; - /// Returns the intermediate storage roots in an encoded form. - fn intermediate_roots() -> Vec<[u8; 32]>; - /// Returns the storage root after initializing the block. fn initialize_block_with_post_state_root(header: &Block::Header) -> Vec; diff --git a/domains/client/block-builder/src/custom_api.rs b/domains/client/block-builder/src/custom_api.rs index ec9533db94..ae73f735ab 100644 --- a/domains/client/block-builder/src/custom_api.rs +++ b/domains/client/block-builder/src/custom_api.rs @@ -1,8 +1,5 @@ //! Custom API that is efficient to collect storage roots. -// TODO: remove in later commits -#![allow(dead_code)] - use codec::{Codec, Decode, Encode}; use hash_db::{HashDB, Hasher, Prefix}; use sc_client_api::{backend, ExecutorProvider, StateBackend}; @@ -26,9 +23,6 @@ pub(crate) type TrieDeltaBackendFor<'a, State, Block> = TrieBackend< HashingFor, >; -type TrieBackendFor = - TrieBackend, HashingFor>; - /// Storage changes are the collected throughout the execution. pub struct CollectedStorageChanges { /// Storage changes that are captured during the execution. @@ -102,22 +96,6 @@ where } } -impl<'a, S, H> DeltaBackend<'a, S, H> -where - S: 'a + TrieBackendStorage, - H: 'a + Hasher, -{ - fn consolidate_delta(&mut self, db: BackendTransaction) { - let delta = if let Some(mut delta) = self.delta.take() { - delta.consolidate(db); - delta - } else { - db - }; - self.delta = Some(delta); - } -} - pub(crate) struct TrieBackendApi, Exec> { parent_hash: Block::Hash, parent_number: NumberFor, diff --git a/domains/pallets/executive/src/lib.rs b/domains/pallets/executive/src/lib.rs index f4ebe82486..c7b6de62a7 100644 --- a/domains/pallets/executive/src/lib.rs +++ b/domains/pallets/executive/src/lib.rs @@ -182,26 +182,10 @@ mod pallet { #[pallet::hooks] impl Hooks> for Pallet { fn on_initialize(_block_number: BlockNumberFor) -> Weight { - // Reset the intermediate storage roots from last block. - IntermediateRoots::::kill(); // TODO: Probably needs a different value Weight::from_parts(1, 0) } } - - /// Intermediate storage roots collected during the block execution. - #[pallet::storage] - #[pallet::getter(fn intermediate_roots)] - pub(super) type IntermediateRoots = StorageValue<_, Vec<[u8; 32]>, ValueQuery>; -} - -impl Pallet { - pub(crate) fn push_root(root: Vec) { - IntermediateRoots::::append( - TryInto::<[u8; 32]>::try_into(root) - .expect("root is a SCALE encoded hash which uses H256; qed"), - ); - } } /// Same semantics with `frame_executive::Executive`. @@ -388,16 +372,10 @@ where panic!("{}", err) } }); - - // Note the storage root before finalizing the block so that the block imported during the - // syncing process produces the same storage root with the one processed based on - // the consensus block. - Pallet::::push_root(Self::storage_root()); } /// Wrapped `frame_executive::Executive::finalize_block`. pub fn finalize_block() -> HeaderFor { - Pallet::::push_root(Self::storage_root()); frame_executive::Executive::< ExecutiveConfig, BlockOf, @@ -429,8 +407,6 @@ where /// /// Note the storage root in the beginning. pub fn apply_extrinsic(uxt: ExtrinsicOf) -> ApplyExtrinsicResult { - Pallet::::push_root(Self::storage_root()); - // apply the extrinsic within another transaction so that changes can be reverted. let res = with_storage_layer(|| { frame_executive::Executive::< @@ -455,7 +431,7 @@ where // - Pre and Post dispatch fails. Check the test `test_domain_block_builder_include_ext_with_failed_predispatch` // why this could happen. If it fail due to this, then we revert the inner storage changes // but still include extrinsic so that we can clear inconsistency between block body and trace roots. - let res = match res { + match res { Ok(dispatch_outcome) => Ok(dispatch_outcome), Err(err) => { let encoded = uxt.encode(); @@ -509,18 +485,7 @@ where >::note_applied_extrinsic(&r, dispatch_info); Ok(Err(err)) } - }; - - // TODO: Critical!!! https://github.com/paritytech/substrate/pull/10922#issuecomment-1068997467 - log::debug!( - target: "domain::runtime::executive", - "[apply_extrinsic] after: {:?}", - { - use codec::Decode; - BlockHashOf::::decode(&mut Self::storage_root().as_slice()).unwrap() - } - ); - res + } } // TODO: https://github.com/paritytech/substrate/issues/10711 diff --git a/domains/runtime/auto-id/src/lib.rs b/domains/runtime/auto-id/src/lib.rs index ade1200f0c..0559a139a4 100644 --- a/domains/runtime/auto-id/src/lib.rs +++ b/domains/runtime/auto-id/src/lib.rs @@ -758,10 +758,6 @@ impl_runtime_apis! { } } - fn intermediate_roots() -> Vec<[u8; 32]> { - ExecutivePallet::intermediate_roots() - } - fn initialize_block_with_post_state_root(header: &::Header) -> Vec { Executive::initialize_block(header); Executive::storage_root() diff --git a/domains/runtime/evm/src/lib.rs b/domains/runtime/evm/src/lib.rs index 965573b918..ff73735e9a 100644 --- a/domains/runtime/evm/src/lib.rs +++ b/domains/runtime/evm/src/lib.rs @@ -1169,10 +1169,6 @@ impl_runtime_apis! { } } - fn intermediate_roots() -> Vec<[u8; 32]> { - ExecutivePallet::intermediate_roots() - } - fn initialize_block_with_post_state_root(header: &::Header) -> Vec { Executive::initialize_block(header); Executive::storage_root() diff --git a/domains/test/runtime/auto-id/src/lib.rs b/domains/test/runtime/auto-id/src/lib.rs index 0f77507876..018f347322 100644 --- a/domains/test/runtime/auto-id/src/lib.rs +++ b/domains/test/runtime/auto-id/src/lib.rs @@ -749,10 +749,6 @@ impl_runtime_apis! { } } - fn intermediate_roots() -> Vec<[u8; 32]> { - ExecutivePallet::intermediate_roots() - } - fn initialize_block_with_post_state_root(header: &::Header) -> Vec { Executive::initialize_block(header); Executive::storage_root() diff --git a/domains/test/runtime/evm/src/lib.rs b/domains/test/runtime/evm/src/lib.rs index 26dce324a9..1d50a4a141 100644 --- a/domains/test/runtime/evm/src/lib.rs +++ b/domains/test/runtime/evm/src/lib.rs @@ -1124,10 +1124,6 @@ impl_runtime_apis! { } } - fn intermediate_roots() -> Vec<[u8; 32]> { - ExecutivePallet::intermediate_roots() - } - fn initialize_block_with_post_state_root(header: &::Header) -> Vec { Executive::initialize_block(header); Executive::storage_root()