From 5a714cda79b6217e3f9c9878f86fdf58fb53ed8c Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Fri, 7 Feb 2025 13:16:31 +0100 Subject: [PATCH] chore(engine): make block buffer pub (#14298) --- crates/engine/tree/src/tree/block_buffer.rs | 14 +++++++------- crates/engine/tree/src/tree/metrics.rs | 2 +- crates/engine/tree/src/tree/mod.rs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/engine/tree/src/tree/block_buffer.rs b/crates/engine/tree/src/tree/block_buffer.rs index 58a4c6b362..4a0fede28f 100644 --- a/crates/engine/tree/src/tree/block_buffer.rs +++ b/crates/engine/tree/src/tree/block_buffer.rs @@ -17,7 +17,7 @@ use std::collections::{BTreeMap, HashMap, HashSet}; /// Note: Buffer is limited by number of blocks that it can contain and eviction of the block /// is done by last recently used block. #[derive(Debug)] -pub(super) struct BlockBuffer { +pub struct BlockBuffer { /// All blocks in the buffer stored by their block hash. pub(crate) blocks: HashMap>, /// Map of any parent block hash (even the ones not currently in the buffer) @@ -38,7 +38,7 @@ pub(super) struct BlockBuffer { impl BlockBuffer { /// Create new buffer with max limit of blocks - pub(super) fn new(limit: u32) -> Self { + pub fn new(limit: u32) -> Self { Self { blocks: Default::default(), parent_to_child: Default::default(), @@ -49,12 +49,12 @@ impl BlockBuffer { } /// Return reference to the requested block. - pub(super) fn block(&self, hash: &BlockHash) -> Option<&RecoveredBlock> { + pub fn block(&self, hash: &BlockHash) -> Option<&RecoveredBlock> { self.blocks.get(hash) } /// Return a reference to the lowest ancestor of the given block in the buffer. - pub(super) fn lowest_ancestor(&self, hash: &BlockHash) -> Option<&RecoveredBlock> { + pub fn lowest_ancestor(&self, hash: &BlockHash) -> Option<&RecoveredBlock> { let mut current_block = self.blocks.get(hash)?; while let Some(parent) = self.blocks.get(¤t_block.parent_hash()) { current_block = parent; @@ -63,7 +63,7 @@ impl BlockBuffer { } /// Insert a correct block inside the buffer. - pub(super) fn insert_block(&mut self, block: RecoveredBlock) { + pub fn insert_block(&mut self, block: RecoveredBlock) { let hash = block.hash(); self.parent_to_child.entry(block.parent_hash()).or_default().insert(hash); @@ -98,7 +98,7 @@ impl BlockBuffer { /// /// 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(super) fn remove_block_with_children( + pub fn remove_block_with_children( &mut self, parent_hash: &BlockHash, ) -> Vec> { @@ -112,7 +112,7 @@ impl BlockBuffer { } /// Discard all blocks that precede block number from the buffer. - pub(super) fn remove_old_blocks(&mut self, block_number: BlockNumber) { + pub fn remove_old_blocks(&mut self, block_number: BlockNumber) { let mut block_hashes_to_remove = Vec::new(); // discard all blocks that are before the finalized number. diff --git a/crates/engine/tree/src/tree/metrics.rs b/crates/engine/tree/src/tree/metrics.rs index 816458d0b8..757e595d06 100644 --- a/crates/engine/tree/src/tree/metrics.rs +++ b/crates/engine/tree/src/tree/metrics.rs @@ -91,7 +91,7 @@ impl BlockValidationMetrics { /// Metrics for the blockchain tree block buffer #[derive(Metrics)] #[metrics(scope = "blockchain_tree.block_buffer")] -pub(super) struct BlockBufferMetrics { +pub(crate) struct BlockBufferMetrics { /// Total blocks in the block buffer pub blocks: Gauge, } diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 243380c4bc..5971342f61 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -18,7 +18,6 @@ use alloy_primitives::{ use alloy_rpc_types_engine::{ ForkchoiceState, PayloadStatus, PayloadStatusEnum, PayloadValidationError, }; -use block_buffer::BlockBuffer; use cached_state::{ProviderCaches, SavedCache}; use error::{InsertBlockError, InsertBlockErrorKind, InsertBlockFatalError}; use persistence_state::CurrentPersistenceAction; @@ -91,6 +90,7 @@ pub mod root; mod trie_updates; use crate::tree::{config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError}; +pub use block_buffer::BlockBuffer; pub use config::TreeConfig; pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook}; pub use invalid_headers::InvalidHeaderCache;