fix: cleanup dangling forks in chain follower#7179
Conversation
Walkthrough
ChangesDangling Fork Pruning in Chain Follower
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 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 |
7b0e4af to
d469577
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/chain_sync/chain_follower.rs (1)
906-924: 💤 Low valueConsider calling
shrink_to_fit()after bulk removal.After removing potentially many tipsets from dangling forks, the
tipsetsHashMap may have excess capacity. For consistency withadd_full_tipset(line 777) which callsshrink_to_fit(), consider adding the same call here to reclaim memory after cleanup.♻️ Suggested change
pub fn cleanup_dangling_forks(&mut self) { let finalized_epoch = self.cs.ec_calculator_finalized_epoch(); for chain in self.chains() { // Cleanup dangling fork when its target epoch is finalized if let Some(target) = chain.last() && target.epoch() < finalized_epoch { chain.iter().for_each(|ts| { self.tipsets.remove(ts.key()); }); tracing::info!( "Cleaned up dangling fork from epoch {} to {}", chain.first().map(|ts| ts.epoch()).unwrap_or_default(), chain.last().map(|ts| ts.epoch()).unwrap_or_default(), ); } } + self.tipsets.shrink_to_fit(); }🤖 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 906 - 924, After the bulk removal of tipsets in the cleanup_dangling_forks method (where chain.iter().for_each removes multiple tipsets from self.tipsets), add a call to self.tipsets.shrink_to_fit() to reclaim the excess capacity left by the HashMap after deletion. This maintains consistency with the approach already used in the add_full_tipset method for memory efficiency during cleanup operations.
🤖 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 906-924: After the bulk removal of tipsets in the
cleanup_dangling_forks method (where chain.iter().for_each removes multiple
tipsets from self.tipsets), add a call to self.tipsets.shrink_to_fit() to
reclaim the excess capacity left by the HashMap after deletion. This maintains
consistency with the approach already used in the add_full_tipset method for
memory efficiency during cleanup operations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: e1699663-311d-48a7-acef-94bfae5dff97
📒 Files selected for processing (1)
src/chain_sync/chain_follower.rs
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
filecoin-project/lotus(manual)
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 4 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
|
As discussed, let's let it run for a bit. |
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #7177
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit