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
|
/// Note: Buffer is limited by number of blocks that it can contain and eviction of the block
|
||||||
/// is done by last recently used block.
|
/// is done by last recently used block.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct BlockBuffer<B: Block> {
|
pub struct BlockBuffer<B: Block> {
|
||||||
/// All blocks in the buffer stored by their block hash.
|
/// All blocks in the buffer stored by their block hash.
|
||||||
pub(crate) blocks: HashMap<BlockHash, RecoveredBlock<B>>,
|
pub(crate) blocks: HashMap<BlockHash, RecoveredBlock<B>>,
|
||||||
/// Map of any parent block hash (even the ones not currently in the buffer)
|
/// 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> {
|
impl<B: Block> BlockBuffer<B> {
|
||||||
/// Create new buffer with max limit of blocks
|
/// Create new buffer with max limit of blocks
|
||||||
pub(super) fn new(limit: u32) -> Self {
|
pub fn new(limit: u32) -> Self {
|
||||||
Self {
|
Self {
|
||||||
blocks: Default::default(),
|
blocks: Default::default(),
|
||||||
parent_to_child: Default::default(),
|
parent_to_child: Default::default(),
|
||||||
@ -49,12 +49,12 @@ impl<B: Block> BlockBuffer<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return reference to the requested block.
|
/// 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)
|
self.blocks.get(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a reference to the lowest ancestor of the given block in the buffer.
|
/// 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)?;
|
let mut current_block = self.blocks.get(hash)?;
|
||||||
while let Some(parent) = self.blocks.get(¤t_block.parent_hash()) {
|
while let Some(parent) = self.blocks.get(¤t_block.parent_hash()) {
|
||||||
current_block = parent;
|
current_block = parent;
|
||||||
@ -63,7 +63,7 @@ impl<B: Block> BlockBuffer<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a correct block inside the buffer.
|
/// 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();
|
let hash = block.hash();
|
||||||
|
|
||||||
self.parent_to_child.entry(block.parent_hash()).or_default().insert(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
|
/// 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.
|
/// 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,
|
&mut self,
|
||||||
parent_hash: &BlockHash,
|
parent_hash: &BlockHash,
|
||||||
) -> Vec<RecoveredBlock<B>> {
|
) -> Vec<RecoveredBlock<B>> {
|
||||||
@ -112,7 +112,7 @@ impl<B: Block> BlockBuffer<B> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Discard all blocks that precede block number from the buffer.
|
/// 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();
|
let mut block_hashes_to_remove = Vec::new();
|
||||||
|
|
||||||
// discard all blocks that are before the finalized number.
|
// discard all blocks that are before the finalized number.
|
||||||
|
|||||||
@ -91,7 +91,7 @@ impl BlockValidationMetrics {
|
|||||||
/// Metrics for the blockchain tree block buffer
|
/// Metrics for the blockchain tree block buffer
|
||||||
#[derive(Metrics)]
|
#[derive(Metrics)]
|
||||||
#[metrics(scope = "blockchain_tree.block_buffer")]
|
#[metrics(scope = "blockchain_tree.block_buffer")]
|
||||||
pub(super) struct BlockBufferMetrics {
|
pub(crate) struct BlockBufferMetrics {
|
||||||
/// Total blocks in the block buffer
|
/// Total blocks in the block buffer
|
||||||
pub blocks: Gauge,
|
pub blocks: Gauge,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,6 @@ use alloy_primitives::{
|
|||||||
use alloy_rpc_types_engine::{
|
use alloy_rpc_types_engine::{
|
||||||
ForkchoiceState, PayloadStatus, PayloadStatusEnum, PayloadValidationError,
|
ForkchoiceState, PayloadStatus, PayloadStatusEnum, PayloadValidationError,
|
||||||
};
|
};
|
||||||
use block_buffer::BlockBuffer;
|
|
||||||
use cached_state::{ProviderCaches, SavedCache};
|
use cached_state::{ProviderCaches, SavedCache};
|
||||||
use error::{InsertBlockError, InsertBlockErrorKind, InsertBlockFatalError};
|
use error::{InsertBlockError, InsertBlockErrorKind, InsertBlockFatalError};
|
||||||
use persistence_state::CurrentPersistenceAction;
|
use persistence_state::CurrentPersistenceAction;
|
||||||
@ -91,6 +90,7 @@ pub mod root;
|
|||||||
mod trie_updates;
|
mod trie_updates;
|
||||||
|
|
||||||
use crate::tree::{config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError};
|
use crate::tree::{config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError};
|
||||||
|
pub use block_buffer::BlockBuffer;
|
||||||
pub use config::TreeConfig;
|
pub use config::TreeConfig;
|
||||||
pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook};
|
pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook};
|
||||||
pub use invalid_headers::InvalidHeaderCache;
|
pub use invalid_headers::InvalidHeaderCache;
|
||||||
|
|||||||
Reference in New Issue
Block a user