fix: make validated block cache bounded#7135
Conversation
WalkthroughChainStore replaces validated-blocks tracking from Mutex-guarded ChangesValidated Blocks Cache Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/chain/store/chain_store.rs (1)
154-157: ⚡ Quick winAdd a regression test for the bounded behavior.
This constructor is the core behavior change in the PR, but the visible coverage still only exercises insert/lookup. A small-capacity test that overfills the cache and asserts eviction or cap enforcement would make the “bounded” part much harder to regress.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/chain/store/chain_store.rs` around lines 154 - 157, Add a regression test that verifies the bounded eviction behavior of the validated_blocks cache created via SizeTrackingCache::new_with_metrics (the constructor change in this PR): instantiate a SizeTrackingCache with a very small capacity (override VALIDATED_BLOCKS_CACHE_SIZE or construct directly with a small cap), insert more entries than the capacity, then assert the cache enforces the bound (e.g., size() <= capacity) and that older/expected entries have been evicted (lookup for the earliest-inserted keys returns miss while recent keys hit); place the test near the chain_store tests and name it something like validated_blocks_bounded_eviction_test so future regressions are obvious.src/chain_sync/chain_follower.rs (1)
153-157: ⚡ Quick winHide validated-block clearing behind
ChainStore.
reset()now depends on the concretevalidated_blocksfield andSizeTrackingCacheAPI. A smallChainStore::clear_validated_blocks()helper would keep the sync layer insulated from future storage changes.♻️ Suggested refactor
// src/chain/store/chain_store.rs + pub(crate) fn clear_validated_blocks(&self) { + self.validated_blocks.clear(); + } // src/chain_sync/chain_follower.rs - self.state_manager.chain_store().validated_blocks.clear(); + self.state_manager.chain_store().clear_validated_blocks();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/chain_sync/chain_follower.rs` around lines 153 - 157, The reset logic in ChainFollower is reaching into ChainStore internals by clearing validated_blocks directly, so add a ChainStore::clear_validated_blocks() helper and call that from ChainFollower::reset() instead. Keep the sync layer using the ChainStore API only, and move any SizeTrackingCache-specific clearing behavior behind that new helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/chain_sync/chain_follower.rs`:
- Around line 153-157: The reset logic in ChainFollower is reaching into
ChainStore internals by clearing validated_blocks directly, so add a
ChainStore::clear_validated_blocks() helper and call that from
ChainFollower::reset() instead. Keep the sync layer using the ChainStore API
only, and move any SizeTrackingCache-specific clearing behavior behind that new
helper.
In `@src/chain/store/chain_store.rs`:
- Around line 154-157: Add a regression test that verifies the bounded eviction
behavior of the validated_blocks cache created via
SizeTrackingCache::new_with_metrics (the constructor change in this PR):
instantiate a SizeTrackingCache with a very small capacity (override
VALIDATED_BLOCKS_CACHE_SIZE or construct directly with a small cap), insert more
entries than the capacity, then assert the cache enforces the bound (e.g.,
size() <= capacity) and that older/expected entries have been evicted (lookup
for the earliest-inserted keys returns miss while recent keys hit); place the
test near the chain_store tests and name it something like
validated_blocks_bounded_eviction_test so future regressions are obvious.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 7447ddb8-00b1-48b8-bc5b-eb0a3453a861
📒 Files selected for processing (2)
src/chain/store/chain_store.rssrc/chain_sync/chain_follower.rs
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 13 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit