Skip to content

Commit fd0230b

Browse files
committed
f correct + constify header cache limit
1 parent 0a9b8a1 commit fd0230b

File tree

1 file changed

+5
-2
lines changed
  • lightning-block-sync/src

1 file changed

+5
-2
lines changed

lightning-block-sync/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,12 @@ pub(crate) trait Cache {
204204
fn blocks_disconnected(&mut self, fork_point: &ValidatedBlockHeader);
205205
}
206206

207+
/// The maximum number of [`ValidatedBlockHeader`]s stored in a [`HeaderCache`].
208+
pub const HEADER_CACHE_LIMIT: u32 = 6 * 24 * 7;
209+
207210
/// Bounded cache of block headers keyed by block hash.
208211
///
209-
/// Retains only the last `ANTI_REORG_DELAY * 2` block headers based on height.
212+
/// Retains only the latest [`HEADER_CACHE_LIMIT`] block headers based on height.
210213
pub struct HeaderCache(std::collections::HashMap<BlockHash, ValidatedBlockHeader>);
211214

212215
impl HeaderCache {
@@ -225,7 +228,7 @@ impl Cache for HeaderCache {
225228
self.0.insert(block_hash, block_header);
226229

227230
// Remove headers older than a week.
228-
let cutoff_height = block_header.height.saturating_sub(6 * 24 * 7);
231+
let cutoff_height = block_header.height.saturating_sub(HEADER_CACHE_LIMIT);
229232
self.0.retain(|_, header| header.height >= cutoff_height);
230233
}
231234

0 commit comments

Comments
 (0)