mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
dev: block_with_senders on BlockState (#11363)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -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};
|
||||
@ -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()
|
||||
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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,
|
||||
)
|
||||
}
|
||||
@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user