mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore(engine): make block buffer pub (#14298)
This commit is contained in:
@ -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<B: Block> {
|
||||
pub struct BlockBuffer<B: Block> {
|
||||
/// All blocks in the buffer stored by their block hash.
|
||||
pub(crate) blocks: HashMap<BlockHash, RecoveredBlock<B>>,
|
||||
/// Map of any parent block hash (even the ones not currently in the buffer)
|
||||
@ -38,7 +38,7 @@ pub(super) struct BlockBuffer<B: Block> {
|
||||
|
||||
impl<B: Block> BlockBuffer<B> {
|
||||
/// 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<B: Block> BlockBuffer<B> {
|
||||
}
|
||||
|
||||
/// Return reference to the requested block.
|
||||
pub(super) fn block(&self, hash: &BlockHash) -> Option<&RecoveredBlock<B>> {
|
||||
pub fn block(&self, hash: &BlockHash) -> Option<&RecoveredBlock<B>> {
|
||||
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<B>> {
|
||||
pub fn lowest_ancestor(&self, hash: &BlockHash) -> Option<&RecoveredBlock<B>> {
|
||||
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<B: Block> BlockBuffer<B> {
|
||||
}
|
||||
|
||||
/// Insert a correct block inside the buffer.
|
||||
pub(super) fn insert_block(&mut self, block: RecoveredBlock<B>) {
|
||||
pub fn insert_block(&mut self, block: RecoveredBlock<B>) {
|
||||
let hash = block.hash();
|
||||
|
||||
self.parent_to_child.entry(block.parent_hash()).or_default().insert(hash);
|
||||
@ -98,7 +98,7 @@ impl<B: Block> BlockBuffer<B> {
|
||||
///
|
||||
/// 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<RecoveredBlock<B>> {
|
||||
@ -112,7 +112,7 @@ impl<B: Block> BlockBuffer<B> {
|
||||
}
|
||||
|
||||
/// 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.
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user