mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 17:18:08 -05:00
feat: add another distance check (#3501)
This commit is contained in:
@@ -592,7 +592,7 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
|
||||
}
|
||||
|
||||
/// Checks the block buffer for the given block.
|
||||
pub fn get_buffered_block(&mut self, hash: &BlockHash) -> Option<&SealedBlockWithSenders> {
|
||||
pub fn get_buffered_block(&self, hash: &BlockHash) -> Option<&SealedBlockWithSenders> {
|
||||
self.buffered_blocks.block_by_hash(hash)
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +109,14 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTreeViewer
|
||||
self.tree.read().block_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())
|
||||
}
|
||||
|
||||
fn buffered_header_by_hash(&self, block_hash: BlockHash) -> Option<SealedHeader> {
|
||||
self.tree.read().get_buffered_block(&block_hash).map(|b| b.header.clone())
|
||||
}
|
||||
|
||||
fn canonical_blocks(&self) -> BTreeMap<BlockNumber, BlockHash> {
|
||||
trace!(target: "blockchain_tree", "Returning canonical blocks in tree");
|
||||
self.tree.read().block_indices().canonical_chain().inner().clone()
|
||||
|
||||
@@ -1082,6 +1082,15 @@ where
|
||||
canonical_tip_num,
|
||||
downloaded_num_hash.number,
|
||||
);
|
||||
} else if let Some(buffered_finalized) =
|
||||
self.blockchain.buffered_header_by_hash(state.finalized_block_hash)
|
||||
{
|
||||
// if we have buffered the finalized block, we should check how far
|
||||
// we're off
|
||||
requires_pipeline = self.exceeds_pipeline_run_threshold(
|
||||
canonical_tip_num,
|
||||
buffered_finalized.number,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -172,9 +172,24 @@ pub trait BlockchainTreeViewer: Send + Sync {
|
||||
|
||||
/// Returns the block with matching hash from the tree, if it exists.
|
||||
///
|
||||
/// Caution: This will not return blocks from the canonical chain.
|
||||
/// Caution: This will not return blocks from the canonical chain or buffered blocks that are
|
||||
/// disconnected from the canonical chain.
|
||||
fn block_by_hash(&self, hash: BlockHash) -> Option<SealedBlock>;
|
||||
|
||||
/// Returns the _buffered_ (disconnected) block with matching hash from the internal buffer if
|
||||
/// it exists.
|
||||
///
|
||||
/// Caution: Unlike [Self::block_by_hash] this will only return blocks that are currently
|
||||
/// disconnected from the canonical chain.
|
||||
fn buffered_block_by_hash(&self, block_hash: BlockHash) -> Option<SealedBlock>;
|
||||
|
||||
/// Returns the _buffered_ (disconnected) header with matching hash from the internal buffer if
|
||||
/// it exists.
|
||||
///
|
||||
/// Caution: Unlike [Self::block_by_hash] this will only return headers that are currently
|
||||
/// disconnected from the canonical chain.
|
||||
fn buffered_header_by_hash(&self, block_hash: BlockHash) -> Option<SealedHeader>;
|
||||
|
||||
/// Returns true if the tree contains the block with matching hash.
|
||||
fn contains(&self, hash: BlockHash) -> bool {
|
||||
self.block_by_hash(hash).is_some()
|
||||
|
||||
@@ -608,6 +608,14 @@ where
|
||||
self.tree.block_by_hash(block_hash)
|
||||
}
|
||||
|
||||
fn buffered_block_by_hash(&self, block_hash: BlockHash) -> Option<SealedBlock> {
|
||||
self.tree.buffered_block_by_hash(block_hash)
|
||||
}
|
||||
|
||||
fn buffered_header_by_hash(&self, block_hash: BlockHash) -> Option<SealedHeader> {
|
||||
self.tree.buffered_header_by_hash(block_hash)
|
||||
}
|
||||
|
||||
fn canonical_blocks(&self) -> BTreeMap<BlockNumber, BlockHash> {
|
||||
self.tree.canonical_blocks()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user