From 8f01951891c58ea8d79c1bed49ac801318d243bf Mon Sep 17 00:00:00 2001 From: Roman Krasiuk Date: Fri, 7 Feb 2025 11:55:15 +0100 Subject: [PATCH] chore(engine): make invalid headers cache pub (#14297) --- crates/engine/tree/src/tree/invalid_headers.rs | 10 +++++----- crates/engine/tree/src/tree/mod.rs | 6 ++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/crates/engine/tree/src/tree/invalid_headers.rs b/crates/engine/tree/src/tree/invalid_headers.rs index 40303355a8..d349901a19 100644 --- a/crates/engine/tree/src/tree/invalid_headers.rs +++ b/crates/engine/tree/src/tree/invalid_headers.rs @@ -16,7 +16,7 @@ const INVALID_HEADER_HIT_EVICTION_THRESHOLD: u8 = 128; /// Keeps track of invalid headers. #[derive(Debug)] -pub(super) struct InvalidHeaderCache { +pub struct InvalidHeaderCache { /// This maps a header hash to a reference to its invalid ancestor. headers: LruMap, /// Metrics for the cache. @@ -25,7 +25,7 @@ pub(super) struct InvalidHeaderCache { impl InvalidHeaderCache { /// Invalid header cache constructor. - pub(super) fn new(max_length: u32) -> Self { + pub fn new(max_length: u32) -> Self { Self { headers: LruMap::new(ByLength::new(max_length)), metrics: Default::default() } } @@ -37,7 +37,7 @@ impl InvalidHeaderCache { /// /// If this is called, the hit count for the entry is incremented. /// If the hit count exceeds the threshold, the entry is evicted and `None` is returned. - pub(super) fn get(&mut self, hash: &B256) -> Option { + pub fn get(&mut self, hash: &B256) -> Option { { let entry = self.headers.get(hash)?; entry.hit_count += 1; @@ -52,7 +52,7 @@ impl InvalidHeaderCache { } /// Inserts an invalid block into the cache, with a given invalid ancestor. - pub(super) fn insert_with_invalid_ancestor( + pub fn insert_with_invalid_ancestor( &mut self, header_hash: B256, invalid_ancestor: BlockWithParent, @@ -68,7 +68,7 @@ impl InvalidHeaderCache { } /// Inserts an invalid ancestor into the map. - pub(super) fn insert(&mut self, invalid_ancestor: BlockWithParent) { + pub fn insert(&mut self, invalid_ancestor: BlockWithParent) { if self.get(&invalid_ancestor.block.hash).is_none() { warn!(target: "consensus::engine", ?invalid_ancestor, "Bad block with hash"); self.insert_entry(invalid_ancestor.block.hash, invalid_ancestor); diff --git a/crates/engine/tree/src/tree/mod.rs b/crates/engine/tree/src/tree/mod.rs index 59f7b8e972..243380c4bc 100644 --- a/crates/engine/tree/src/tree/mod.rs +++ b/crates/engine/tree/src/tree/mod.rs @@ -90,12 +90,10 @@ mod persistence_state; pub mod root; mod trie_updates; -use crate::tree::{ - config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError, - invalid_headers::InvalidHeaderCache, -}; +use crate::tree::{config::MIN_BLOCKS_FOR_PIPELINE_RUN, error::AdvancePersistenceError}; pub use config::TreeConfig; pub use invalid_block_hook::{InvalidBlockHooks, NoopInvalidBlockHook}; +pub use invalid_headers::InvalidHeaderCache; pub use persistence_state::PersistenceState; use trie_updates::compare_trie_updates;