Skip to content

Commit

Permalink
dev: block_with_senders on BlockState (#11363)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
greged93 and mattsse authored Oct 1, 2024
1 parent 6b3a759 commit 15e3e0e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
18 changes: 16 additions & 2 deletions crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -618,6 +618,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()
Expand Down
28 changes: 6 additions & 22 deletions crates/storage/provider/src/providers/blockchain_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,16 +596,12 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
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()));
}
}
}
Expand All @@ -620,16 +616,12 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
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()));
}
}
}
Expand All @@ -652,11 +644,7 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
self.fetch_db_mem_range_while(
range,
|db_provider, range, _| db_provider.block_with_senders_range(range),
|block_state, _| {
let block = block_state.block().block().clone();
let senders = block_state.block().senders().clone();
Some(BlockWithSenders { block: block.unseal(), senders })
},
|block_state, _| Some(block_state.block_with_senders()),
|_| true,
)
}
Expand All @@ -668,11 +656,7 @@ impl<N: ProviderNodeTypes> BlockReader for BlockchainProvider2<N> {
self.fetch_db_mem_range_while(
range,
|db_provider, range, _| db_provider.sealed_block_with_senders_range(range),
|block_state, _| {
let block = block_state.block().block().clone();
let senders = block_state.block().senders().clone();
Some(SealedBlockWithSenders { block, senders })
},
|block_state, _| Some(block_state.sealed_block_with_senders()),
|_| true,
)
}
Expand Down

0 comments on commit 15e3e0e

Please sign in to comment.