diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index 7888e87a56..65120ee7e9 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -58,7 +58,7 @@ impl InMemoryState { /// Returns the pending state corresponding to the current head plus one, /// from the payload received in newPayload that does not have a FCU yet. pub(crate) fn pending_state(&self) -> Option> { - self.pending.read().as_ref().map(|state| Arc::new(BlockState(state.0.clone()))) + self.pending.read().as_ref().map(|state| Arc::new(BlockState::new(state.block.clone()))) } } @@ -255,39 +255,42 @@ impl CanonicalInMemoryState { /// State after applying the given block. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct BlockState(pub ExecutedBlock); +pub struct BlockState { + /// The executed block that determines the state. + pub block: ExecutedBlock, +} #[allow(dead_code)] impl BlockState { /// `BlockState` constructor. - pub const fn new(executed_block: ExecutedBlock) -> Self { - Self(executed_block) + pub const fn new(block: ExecutedBlock) -> Self { + Self { block } } /// Returns the executed block that determines the state. pub fn block(&self) -> ExecutedBlock { - self.0.clone() + self.block.clone() } /// Returns the hash of executed block that determines the state. pub fn hash(&self) -> B256 { - self.0.block().hash() + self.block.block().hash() } /// Returns the block number of executed block that determines the state. pub fn number(&self) -> u64 { - self.0.block().number + self.block.block().number } /// Returns the state root after applying the executed block that determines /// the state. pub fn state_root(&self) -> B256 { - self.0.block().header.state_root + self.block.block().header.state_root } /// Returns the `Receipts` of executed block that determines the state. pub fn receipts(&self) -> &Receipts { - &self.0.execution_outcome().receipts + &self.block.execution_outcome().receipts } /// Returns a vector of `Receipt` of executed block that determines the state. @@ -440,8 +443,8 @@ mod tests { let result = in_memory_state.pending_state(); assert!(result.is_some()); let actual_pending_state = result.unwrap(); - assert_eq!(actual_pending_state.0.block().hash(), pending_hash); - assert_eq!(actual_pending_state.0.block().number, pending_number); + assert_eq!(actual_pending_state.block.block().hash(), pending_hash); + assert_eq!(actual_pending_state.block.block().number, pending_number); } #[tokio::test] diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index dab5d2bb56..a895a04ad7 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -1467,7 +1467,7 @@ mod tests { let number = sealed_block.number; blocks_by_hash.insert(hash, block.clone()); blocks_by_number.entry(number).or_insert_with(Vec::new).push(block.clone()); - state_by_hash.insert(hash, Arc::new(BlockState(block.clone()))); + state_by_hash.insert(hash, Arc::new(BlockState::new(block.clone()))); hash_by_number.insert(number, hash); } let tree_state = TreeState { blocks_by_hash, blocks_by_number, ..Default::default() };