Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 135 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fvm_ipld_encoding = "0.5.3"
fvm_shared2 = { package = "fvm_shared", version = "~2.11" }
fvm_shared3 = { package = "fvm_shared", version = "~3.13", features = ["proofs"] }
fvm_shared4 = { package = "fvm_shared", version = "~4.7", features = ["proofs"] }
get-size2 = { version = "0.5", features = ["derive"] }
gethostname = "1"
git-version = "0.3"
group = "0.13"
Expand Down
17 changes: 10 additions & 7 deletions src/chain_sync/bad_block_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
use std::num::NonZeroUsize;

use cid::Cid;
use lru::LruCache;
use nonzero_ext::nonzero;
use parking_lot::Mutex;

use crate::utils::{cache::SizeTrackingLruCache, get_size};

/// Thread-safe cache for tracking bad blocks.
/// This cache is checked before validating a block, to ensure no duplicate
/// work.
#[derive(Debug)]
pub struct BadBlockCache {
cache: Mutex<LruCache<Cid, ()>>,
cache: SizeTrackingLruCache<get_size::CidWrapper, ()>,
}

impl Default for BadBlockCache {
Expand All @@ -25,17 +25,20 @@ impl Default for BadBlockCache {
impl BadBlockCache {
pub fn new(cap: NonZeroUsize) -> Self {
Self {
cache: Mutex::new(LruCache::new(cap)),
cache: SizeTrackingLruCache::new_with_default_metrics_registry(
"bad_block_cache".into(),
cap,
),
}
}

pub fn put(&self, c: Cid) {
self.cache.lock().put(c, ());
pub fn push(&self, c: Cid) {
self.cache.push(c.into(), ());
}

/// Returns `Some` if the block CID is in bad block cache.
/// This function does not update the head position of the `Cid` key.
pub fn peek(&self, c: &Cid) -> Option<()> {
self.cache.lock().peek(c).cloned()
self.cache.peek_cloned(&(*c).into())
}
}
2 changes: 1 addition & 1 deletion src/chain_sync/chain_follower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ impl<DB: Blockstore> SyncStateMachine<DB> {
// Mark all blocks in the tipset as bad
if let Some(bad_block_cache) = &self.bad_block_cache {
for block in tipset.blocks() {
bad_block_cache.put(*block.cid());
bad_block_cache.push(*block.cid());
}
}

Expand Down
Loading
Loading