block_with_senders in ethstatecache (#5302)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Supernovahs.eth
2023-11-20 20:26:08 +05:30
committed by GitHub
parent 1cc68fcca6
commit 3c7989c541
18 changed files with 239 additions and 82 deletions

View File

@@ -209,10 +209,22 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTree<DB, EF> {
/// Returns the block with matching hash from any side-chain.
///
/// Caution: This will not return blocks from the canonical chain.
#[inline]
pub fn block_by_hash(&self, block_hash: BlockHash) -> Option<&SealedBlock> {
self.state.block_by_hash(block_hash)
}
/// Returns the block with matching hash from any side-chain.
///
/// Caution: This will not return blocks from the canonical chain.
#[inline]
pub fn block_with_senders_by_hash(
&self,
block_hash: BlockHash,
) -> Option<&SealedBlockWithSenders> {
self.state.block_with_senders_by_hash(block_hash)
}
/// Returns the block's receipts with matching hash from any side-chain.
///
/// Caution: This will not return blocks from the canonical chain.

View File

@@ -74,6 +74,10 @@ impl BlockchainTreeViewer for NoopBlockchainTree {
None
}
fn block_with_senders_by_hash(&self, _hash: BlockHash) -> Option<SealedBlockWithSenders> {
None
}
fn buffered_block_by_hash(&self, _block_hash: BlockHash) -> Option<SealedBlock> {
None
}

View File

@@ -117,6 +117,11 @@ impl<DB: Database, EF: ExecutorFactory> BlockchainTreeViewer for ShareableBlockc
self.tree.read().block_by_hash(block_hash).cloned()
}
fn block_with_senders_by_hash(&self, block_hash: BlockHash) -> Option<SealedBlockWithSenders> {
trace!(target: "blockchain_tree", ?block_hash, "Returning block by hash");
self.tree.read().block_with_senders_by_hash(block_hash).cloned()
}
fn buffered_block_by_hash(&self, block_hash: BlockHash) -> Option<SealedBlock> {
self.tree.read().get_buffered_block(&block_hash).map(|b| b.block.clone())
}

View File

@@ -56,10 +56,21 @@ impl TreeState {
/// Returns the block with matching hash from any side-chain.
///
/// Caution: This will not return blocks from the canonical chain.
#[inline]
pub(crate) fn block_by_hash(&self, block_hash: BlockHash) -> Option<&SealedBlock> {
self.block_with_senders_by_hash(block_hash).map(|block| &block.block)
}
/// Returns the block with matching hash from any side-chain.
///
/// Caution: This will not return blocks from the canonical chain.
#[inline]
pub(crate) fn block_with_senders_by_hash(
&self,
block_hash: BlockHash,
) -> Option<&SealedBlockWithSenders> {
let id = self.block_indices.get_blocks_chain_id(&block_hash)?;
let chain = self.chains.get(&id)?;
chain.block(block_hash)
chain.block_with_senders(block_hash)
}
/// Returns the block's receipts with matching hash from any side-chain.