Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: block_with_senders on BlockState #11363

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading