From f99c9042150b5d9c5228912fc7769c4d5d1419cb Mon Sep 17 00:00:00 2001 From: vedhavyas Date: Fri, 26 Jan 2024 12:24:25 +0530 Subject: [PATCH] add confirmed domain block storage and update storage when a domain block is confirmed --- crates/pallet-domains/src/block_tree.rs | 36 ++++++++++++++++++++++--- crates/pallet-domains/src/lib.rs | 14 ++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/crates/pallet-domains/src/block_tree.rs b/crates/pallet-domains/src/block_tree.rs index b2626655291..bdc3eaeca97 100644 --- a/crates/pallet-domains/src/block_tree.rs +++ b/crates/pallet-domains/src/block_tree.rs @@ -2,11 +2,12 @@ use crate::pallet::StateRoots; use crate::{ - BalanceOf, BlockTree, BlockTreeNodes, Config, ConsensusBlockHash, DomainBlockNumberFor, - DomainHashingFor, ExecutionInbox, ExecutionReceiptOf, HeadReceiptExtended, HeadReceiptNumber, - InboxedBundleAuthor, LatestConfirmedDomainBlockNumber, ReceiptHashFor, + BalanceOf, BlockTree, BlockTreeNodes, Config, ConfirmedDomainBlocks, ConsensusBlockHash, + DomainBlockNumberFor, DomainHashingFor, ExecutionInbox, ExecutionReceiptOf, + HeadReceiptExtended, HeadReceiptNumber, InboxedBundleAuthor, LatestConfirmedDomainBlockNumber, + ReceiptHashFor, }; -use codec::{Decode, Encode}; +use codec::{Codec, Decode, Encode}; use frame_support::{ensure, PalletError}; use scale_info::TypeInfo; use sp_core::Get; @@ -36,6 +37,21 @@ pub enum Error { InvalidStateRoot, } +/// Type holding the block details of confirmed domain block. +#[derive(TypeInfo, Encode, Decode, Debug, Clone, PartialEq, Eq)] +pub struct ConfirmedDomainBlock { + /// Block number of the confirmed domain block. + pub block_number: DomainBlockNumber, + /// Block hash of the confirmed domain block. + pub block_hash: DomainHash, + /// Parent block hash of the confirmed domain block. + pub parent_block_receipt_hash: DomainHash, + /// State root of the domain block. + pub state_root: DomainHash, + /// Extrinsic root of the domain block. + pub extrinsics_root: DomainHash, +} + #[derive(TypeInfo, Debug, Encode, Decode, Clone, PartialEq, Eq)] pub struct BlockTreeNode { /// The full ER for this block. @@ -342,6 +358,18 @@ pub(crate) fn process_execution_receipt( execution_receipt.consensus_block_number, ); + ConfirmedDomainBlocks::::insert( + domain_id, + ConfirmedDomainBlock { + block_number: to_prune, + block_hash: execution_receipt.domain_block_hash, + parent_block_receipt_hash: execution_receipt + .parent_domain_block_receipt_hash, + state_root: execution_receipt.final_state_root, + extrinsics_root: execution_receipt.domain_block_extrinsic_root, + }, + ); + return Ok(Some(ConfirmedDomainBlockInfo { domain_block_number: to_prune, operator_ids, diff --git a/crates/pallet-domains/src/lib.rs b/crates/pallet-domains/src/lib.rs index 517c43313ad..1a9052e7fcb 100644 --- a/crates/pallet-domains/src/lib.rs +++ b/crates/pallet-domains/src/lib.rs @@ -115,8 +115,8 @@ mod pallet { #![allow(clippy::large_enum_variant)] use crate::block_tree::{ - execution_receipt_type, process_execution_receipt, BlockTreeNode, Error as BlockTreeError, - ReceiptType, + execution_receipt_type, process_execution_receipt, BlockTreeNode, ConfirmedDomainBlock, + Error as BlockTreeError, ReceiptType, }; use crate::domain_registry::{ do_instantiate_domain, do_update_domain_allow_list, DomainConfig, DomainObject, @@ -558,6 +558,16 @@ mod pallet { pub(super) type LastEpochStakingDistribution = StorageMap<_, Identity, DomainId, ElectionVerificationParams>, OptionQuery>; + /// Storage to hold all the domain's latest confirmed block. + #[pallet::storage] + pub(super) type ConfirmedDomainBlocks = StorageMap< + _, + Identity, + DomainId, + ConfirmedDomainBlock, T::DomainHash>, + OptionQuery, + >; + #[derive(TypeInfo, Encode, Decode, PalletError, Debug, PartialEq)] pub enum BundleError { /// Can not find the operator for given operator id.