mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
block_with_senders in ethstatecache (#5302)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -71,9 +71,12 @@ impl Chain {
|
||||
|
||||
/// Returns the block with matching hash.
|
||||
pub fn block(&self, block_hash: BlockHash) -> Option<&SealedBlock> {
|
||||
self.blocks
|
||||
.iter()
|
||||
.find_map(|(_num, block)| (block.hash() == block_hash).then_some(&block.block))
|
||||
self.block_with_senders(block_hash).map(|block| &block.block)
|
||||
}
|
||||
|
||||
/// Returns the block with matching hash.
|
||||
pub fn block_with_senders(&self, block_hash: BlockHash) -> Option<&SealedBlockWithSenders> {
|
||||
self.blocks.iter().find_map(|(_num, block)| (block.hash() == block_hash).then_some(block))
|
||||
}
|
||||
|
||||
/// Return post state of the block at the `block_number` or None if block is not known
|
||||
|
||||
@ -15,9 +15,9 @@ use reth_primitives::{
|
||||
snapshot::HighestSnapshots,
|
||||
stage::{StageCheckpoint, StageId},
|
||||
Address, Block, BlockHash, BlockHashOrNumber, BlockNumber, BlockWithSenders, ChainInfo,
|
||||
ChainSpec, Header, PruneCheckpoint, PruneSegment, Receipt, SealedBlock, SealedHeader,
|
||||
TransactionMeta, TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber, Withdrawal,
|
||||
B256, U256,
|
||||
ChainSpec, Header, PruneCheckpoint, PruneSegment, Receipt, SealedBlock, SealedBlockWithSenders,
|
||||
SealedHeader, TransactionMeta, TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber,
|
||||
Withdrawal, B256, U256,
|
||||
};
|
||||
use revm::primitives::{BlockEnv, CfgEnv};
|
||||
use std::{
|
||||
@ -290,6 +290,10 @@ impl<DB: Database> BlockReader for ProviderFactory<DB> {
|
||||
self.provider()?.pending_block()
|
||||
}
|
||||
|
||||
fn pending_block_with_senders(&self) -> ProviderResult<Option<SealedBlockWithSenders>> {
|
||||
self.provider()?.pending_block_with_senders()
|
||||
}
|
||||
|
||||
fn pending_block_and_receipts(&self) -> ProviderResult<Option<(SealedBlock, Vec<Receipt>)>> {
|
||||
self.provider()?.pending_block_and_receipts()
|
||||
}
|
||||
|
||||
@ -1073,6 +1073,10 @@ impl<TX: DbTx> BlockReader for DatabaseProvider<TX> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn pending_block_with_senders(&self) -> ProviderResult<Option<SealedBlockWithSenders>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn pending_block_and_receipts(&self) -> ProviderResult<Option<(SealedBlock, Vec<Receipt>)>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@ -252,6 +252,10 @@ where
|
||||
Ok(self.tree.pending_block())
|
||||
}
|
||||
|
||||
fn pending_block_with_senders(&self) -> ProviderResult<Option<SealedBlockWithSenders>> {
|
||||
Ok(self.tree.pending_block_with_senders())
|
||||
}
|
||||
|
||||
fn pending_block_and_receipts(&self) -> ProviderResult<Option<(SealedBlock, Vec<Receipt>)>> {
|
||||
Ok(self.tree.pending_block_and_receipts())
|
||||
}
|
||||
@ -637,6 +641,10 @@ where
|
||||
self.tree.block_by_hash(block_hash)
|
||||
}
|
||||
|
||||
fn block_with_senders_by_hash(&self, block_hash: BlockHash) -> Option<SealedBlockWithSenders> {
|
||||
self.tree.block_with_senders_by_hash(block_hash)
|
||||
}
|
||||
|
||||
fn buffered_block_by_hash(&self, block_hash: BlockHash) -> Option<SealedBlock> {
|
||||
self.tree.buffered_block_by_hash(block_hash)
|
||||
}
|
||||
|
||||
@ -12,8 +12,8 @@ use reth_interfaces::provider::{ProviderError, ProviderResult};
|
||||
use reth_primitives::{
|
||||
keccak256, trie::AccountProof, Account, Address, Block, BlockHash, BlockHashOrNumber, BlockId,
|
||||
BlockNumber, BlockWithSenders, Bytecode, Bytes, ChainInfo, ChainSpec, Header, Receipt,
|
||||
SealedBlock, SealedHeader, StorageKey, StorageValue, TransactionMeta, TransactionSigned,
|
||||
TransactionSignedNoHash, TxHash, TxNumber, B256, U256,
|
||||
SealedBlock, SealedBlockWithSenders, SealedHeader, StorageKey, StorageValue, TransactionMeta,
|
||||
TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber, B256, U256,
|
||||
};
|
||||
use reth_trie::updates::TrieUpdates;
|
||||
use revm::primitives::{BlockEnv, CfgEnv};
|
||||
@ -438,6 +438,10 @@ impl BlockReader for MockEthProvider {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn pending_block_with_senders(&self) -> ProviderResult<Option<SealedBlockWithSenders>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn pending_block_and_receipts(&self) -> ProviderResult<Option<(SealedBlock, Vec<Receipt>)>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@ use reth_primitives::{
|
||||
trie::AccountProof,
|
||||
Account, Address, Block, BlockHash, BlockHashOrNumber, BlockId, BlockNumber, Bytecode,
|
||||
ChainInfo, ChainSpec, Header, PruneCheckpoint, PruneSegment, Receipt, SealedBlock,
|
||||
SealedHeader, StorageKey, StorageValue, TransactionMeta, TransactionSigned,
|
||||
TransactionSignedNoHash, TxHash, TxNumber, B256, MAINNET, U256,
|
||||
SealedBlockWithSenders, SealedHeader, StorageKey, StorageValue, TransactionMeta,
|
||||
TransactionSigned, TransactionSignedNoHash, TxHash, TxNumber, B256, MAINNET, U256,
|
||||
};
|
||||
use reth_trie::updates::TrieUpdates;
|
||||
use revm::primitives::{BlockEnv, CfgEnv};
|
||||
@ -85,6 +85,10 @@ impl BlockReader for NoopProvider {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn pending_block_with_senders(&self) -> ProviderResult<Option<SealedBlockWithSenders>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
fn pending_block_and_receipts(&self) -> ProviderResult<Option<(SealedBlock, Vec<Receipt>)>> {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@ -85,6 +85,12 @@ pub trait BlockReader:
|
||||
/// and the caller does not know the hash.
|
||||
fn pending_block(&self) -> ProviderResult<Option<SealedBlock>>;
|
||||
|
||||
/// Returns the pending block if available
|
||||
///
|
||||
/// Note: This returns a [SealedBlockWithSenders] because it's expected that this is sealed by
|
||||
/// the provider and the caller does not know the hash.
|
||||
fn pending_block_with_senders(&self) -> ProviderResult<Option<SealedBlockWithSenders>>;
|
||||
|
||||
/// Returns the pending block and receipts if available.
|
||||
fn pending_block_and_receipts(&self) -> ProviderResult<Option<(SealedBlock, Vec<Receipt>)>>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user