feat: add parent blockstate to blockstate (#9755)

This commit is contained in:
Matthias Seitz
2024-07-24 12:39:43 +02:00
committed by GitHub
parent 3eeca7650b
commit fa1bbe44d6

View File

@@ -260,18 +260,30 @@ impl CanonicalInMemoryState {
}
}
/// State after applying the given block.
/// State after applying the given block, this block is part of the canonical chain that partially
/// stored in memory and can be traced back to a canonical block on disk.
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct BlockState {
/// The executed block that determines the state.
pub block: ExecutedBlock,
/// The executed block that determines the state after this block has been executed.
block: ExecutedBlock,
/// The block's parent block if it exists.
parent: Option<Box<BlockState>>,
}
#[allow(dead_code)]
impl BlockState {
/// `BlockState` constructor.
pub const fn new(block: ExecutedBlock) -> Self {
Self { block }
Self { block, parent: None }
}
/// Returns the hash and block of the on disk block this state can be traced back to.
pub fn anchor(&self) -> BlockNumHash {
if let Some(parent) = &self.parent {
parent.anchor()
} else {
self.block.block().parent_num_hash()
}
}
/// Returns the executed block that determines the state.