Skip to content

Commit

Permalink
add confirmed domain block storage and update storage when a domain b…
Browse files Browse the repository at this point in the history
…lock is confirmed
  • Loading branch information
vedhavyas committed Feb 1, 2024
1 parent 148922f commit f99c904
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
36 changes: 32 additions & 4 deletions crates/pallet-domains/src/block_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<DomainBlockNumber: Codec, DomainHash: Codec> {
/// 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<Number, Hash, DomainNumber, DomainHash, Balance> {
/// The full ER for this block.
Expand Down Expand Up @@ -342,6 +358,18 @@ pub(crate) fn process_execution_receipt<T: Config>(
execution_receipt.consensus_block_number,
);

ConfirmedDomainBlocks::<T>::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,
Expand Down
14 changes: 12 additions & 2 deletions crates/pallet-domains/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -558,6 +558,16 @@ mod pallet {
pub(super) type LastEpochStakingDistribution<T: Config> =
StorageMap<_, Identity, DomainId, ElectionVerificationParams<BalanceOf<T>>, OptionQuery>;

/// Storage to hold all the domain's latest confirmed block.
#[pallet::storage]
pub(super) type ConfirmedDomainBlocks<T: Config> = StorageMap<
_,
Identity,
DomainId,
ConfirmedDomainBlock<DomainBlockNumberFor<T>, T::DomainHash>,
OptionQuery,
>;

#[derive(TypeInfo, Encode, Decode, PalletError, Debug, PartialEq)]
pub enum BundleError {
/// Can not find the operator for given operator id.
Expand Down

0 comments on commit f99c904

Please sign in to comment.