mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 16:48:13 -05:00
refactor: rename take children function (#2795)
This commit is contained in:
@@ -12,7 +12,7 @@ pub type BufferedBlocks = BTreeMap<BlockNumber, HashMap<BlockHash, SealedBlockWi
|
||||
///
|
||||
/// It has three main functionality:
|
||||
/// * [BlockBuffer::insert_block] for inserting blocks inside the buffer.
|
||||
/// * [BlockBuffer::take_all_children] for connecting blocks if the parent gets received and
|
||||
/// * [BlockBuffer::remove_with_children] for connecting blocks if the parent gets received and
|
||||
/// inserted.
|
||||
/// * [BlockBuffer::clean_old_blocks] to clear old blocks that are below finalized line.
|
||||
///
|
||||
@@ -63,12 +63,13 @@ impl BlockBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get all the children of the block and its child children.
|
||||
/// Removes the given block from the buffer and also all the children of the block.
|
||||
///
|
||||
/// This is used to get all the blocks that are dependent on the block that is included.
|
||||
///
|
||||
/// Note: that order of returned blocks is important and the blocks with lower block number
|
||||
/// in the chain will come first so that they can be executed in the correct order.
|
||||
pub fn take_all_children(&mut self, parent: BlockNumHash) -> Vec<SealedBlockWithSenders> {
|
||||
pub fn remove_with_children(&mut self, parent: BlockNumHash) -> Vec<SealedBlockWithSenders> {
|
||||
// remove parent block if present
|
||||
let mut taken = Vec::new();
|
||||
if let Some(block) = self.remove_from_blocks(&parent) {
|
||||
@@ -212,7 +213,7 @@ mod tests {
|
||||
buffer.insert_block(block4);
|
||||
|
||||
assert_eq!(buffer.len(), 4);
|
||||
assert_eq!(buffer.take_all_children(main_parent), vec![block1, block2, block3]);
|
||||
assert_eq!(buffer.remove_with_children(main_parent), vec![block1, block2, block3]);
|
||||
assert_eq!(buffer.len(), 1);
|
||||
}
|
||||
|
||||
@@ -234,7 +235,7 @@ mod tests {
|
||||
assert_eq!(buffer.len(), 4);
|
||||
assert_eq!(
|
||||
buffer
|
||||
.take_all_children(main_parent)
|
||||
.remove_with_children(main_parent)
|
||||
.into_iter()
|
||||
.map(|b| (b.hash, b))
|
||||
.collect::<HashMap<_, _>>(),
|
||||
@@ -266,7 +267,7 @@ mod tests {
|
||||
assert_eq!(buffer.len(), 4);
|
||||
assert_eq!(
|
||||
buffer
|
||||
.take_all_children(block1.num_hash())
|
||||
.remove_with_children(block1.num_hash())
|
||||
.into_iter()
|
||||
.map(|b| (b.hash, b))
|
||||
.collect::<HashMap<_, _>>(),
|
||||
|
||||
@@ -744,7 +744,7 @@ impl<DB: Database, C: Consensus, EF: ExecutorFactory> BlockchainTree<DB, C, EF>
|
||||
fn try_connect_buffered_blocks(&mut self, new_block: BlockNumHash) {
|
||||
trace!(target: "blockchain_tree", ?new_block, "try_connect_buffered_blocks");
|
||||
|
||||
let include_blocks = self.buffered_blocks.take_all_children(new_block);
|
||||
let include_blocks = self.buffered_blocks.remove_with_children(new_block);
|
||||
// insert block children
|
||||
for block in include_blocks.into_iter() {
|
||||
// dont fail on error, just ignore the block.
|
||||
|
||||
Reference in New Issue
Block a user