From 563827278c05883fa4f81636c369fffc086602d2 Mon Sep 17 00:00:00 2001 From: Gregory Edison Date: Tue, 1 Oct 2024 09:06:38 +0200 Subject: [PATCH] add block_with_senders and sealed_block_with_senders on BlockState --- crates/chain-state/src/in_memory.rs | 18 +++++++++-- .../src/providers/blockchain_provider.rs | 32 ++++++------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/crates/chain-state/src/in_memory.rs b/crates/chain-state/src/in_memory.rs index cc56056cdab4..40a659800a1e 100644 --- a/crates/chain-state/src/in_memory.rs +++ b/crates/chain-state/src/in_memory.rs @@ -11,8 +11,8 @@ use reth_chainspec::ChainInfo; use reth_execution_types::{Chain, ExecutionOutcome}; use reth_metrics::{metrics::Gauge, Metrics}; use reth_primitives::{ - Header, Receipt, Receipts, SealedBlock, SealedBlockWithSenders, SealedHeader, TransactionMeta, - TransactionSigned, + BlockWithSenders, Header, Receipt, Receipts, SealedBlock, SealedBlockWithSenders, SealedHeader, + TransactionMeta, TransactionSigned, }; use reth_storage_api::StateProviderBox; use reth_trie::{updates::TrieUpdates, HashedPostState}; @@ -613,6 +613,20 @@ impl BlockState { self.block.clone() } + /// Returns the block with senders for the state. + pub fn block_with_senders(&self) -> BlockWithSenders { + let block = self.block.block().clone(); + let senders = self.block.senders().clone(); + BlockWithSenders { block: block.unseal(), senders } + } + + /// Returns the sealed block with senders for the state. + pub fn sealed_block_with_senders(&self) -> SealedBlockWithSenders { + let block = self.block.block().clone(); + let senders = self.block.senders().clone(); + SealedBlockWithSenders { block, senders } + } + /// Returns the hash of executed block that determines the state. pub fn hash(&self) -> B256 { self.block.block().hash() diff --git a/crates/storage/provider/src/providers/blockchain_provider.rs b/crates/storage/provider/src/providers/blockchain_provider.rs index e1a28e1e5ba8..6039f1d47c50 100644 --- a/crates/storage/provider/src/providers/blockchain_provider.rs +++ b/crates/storage/provider/src/providers/blockchain_provider.rs @@ -554,16 +554,12 @@ impl BlockReader for BlockchainProvider2 { match id { BlockHashOrNumber::Hash(hash) => { if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(BlockWithSenders { block: block.unseal(), senders })); + return Ok(Some(block_state.block_with_senders())); } } BlockHashOrNumber::Number(num) => { if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(BlockWithSenders { block: block.unseal(), senders })); + return Ok(Some(block_state.block_with_senders())); } } } @@ -578,16 +574,12 @@ impl BlockReader for BlockchainProvider2 { match id { BlockHashOrNumber::Hash(hash) => { if let Some(block_state) = self.canonical_in_memory_state.state_by_hash(hash) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(SealedBlockWithSenders { block, senders })); + return Ok(Some(block_state.sealed_block_with_senders())); } } BlockHashOrNumber::Number(num) => { if let Some(block_state) = self.canonical_in_memory_state.state_by_number(num) { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - return Ok(Some(SealedBlockWithSenders { block, senders })); + return Ok(Some(block_state.sealed_block_with_senders())); } } } @@ -615,11 +607,9 @@ impl BlockReader for BlockchainProvider2 { range, |range, _| self.database.block_with_senders_range(range), |num, _| { - self.canonical_in_memory_state.state_by_number(num).map(|block_state| { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - BlockWithSenders { block: block.unseal(), senders } - }) + self.canonical_in_memory_state + .state_by_number(num) + .map(|block_state| block_state.block_with_senders()) }, |_| true, ) @@ -633,11 +623,9 @@ impl BlockReader for BlockchainProvider2 { range, |range, _| self.database.sealed_block_with_senders_range(range), |num, _| { - self.canonical_in_memory_state.state_by_number(num).map(|block_state| { - let block = block_state.block().block().clone(); - let senders = block_state.block().senders().clone(); - SealedBlockWithSenders { block, senders } - }) + self.canonical_in_memory_state + .state_by_number(num) + .map(|block_state| block_state.sealed_block_with_senders()) }, |_| true, )