Skip to content

fix: skip tipset if it's part of current chain in chain follower#7019

Merged
hanabi1224 merged 1 commit intomainfrom
hm/chain-follower-fix
May 7, 2026
Merged

fix: skip tipset if it's part of current chain in chain follower#7019
hanabi1224 merged 1 commit intomainfrom
hm/chain-follower-fix

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented May 7, 2026

Summary of changes

Changes introduced in this pull request:

  • to not rewind the head when receiving old heads from laggy peers

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Bug Fixes
    • Optimized chain synchronization to eliminate redundant tipset processing when equivalent blocks already exist at the same height, improving sync efficiency.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack

Walkthrough

This PR optimizes chain synchronization by adding an early-exit check to SyncStateMachine::add_full_tipset that skips redundant insertion/merging when the chain index already contains an equivalent tipset at the same epoch height, queried via chain_index().tipset_by_height() with null-tipset resolution strategy.

Changes

Chain Follower Duplicate Tipset Avoidance

Layer / File(s) Summary
Imports
src/chain_sync/chain_follower.rs
ResolveNullTipset type imported from crate::chain::index to enable height-based tipset resolution with strategy selection.
Core Deduplication Logic
src/chain_sync/chain_follower.rs
Early-exit check added in SyncStateMachine::add_full_tipset that queries the chain index for a tipset at the incoming tipset's height and returns early if the resolved tipset key matches the incoming tipset key, preventing redundant insertion/merging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • ChainSafe/forest#6780: Early-return logic calls ChainIndex::tipset_by_height to avoid inserting duplicate tipsets, directly relating to that PR's modifications to tipset_by_height cache and semantics.
  • ChainSafe/forest#6880: Both PRs modify behavior around tipset_by_height; this PR calls it with ResolveNullTipset::TakeOlder to prevent redundant inserts while that PR changes the function's underlying cache and skip-interval logic.

Suggested reviewers

  • LesnyRumcajs
  • akaladarshi
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: skip tipset if it's part of current chain in chain follower' directly and clearly describes the main change: preventing insertion/merging of tipsets that are already in the current chain.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/chain-follower-fix
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/chain-follower-fix

Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 marked this pull request as ready for review May 7, 2026 14:49
@hanabi1224 hanabi1224 requested a review from a team as a code owner May 7, 2026 14:49
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team May 7, 2026 14:49
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/chain_sync/chain_follower.rs (1)

701-709: ⚡ Quick win

Reuse the existing heaviest snapshot in this guard.

Line 704 fetches head again even though heaviest was already read at Line 688. Reusing it avoids mixed-head decisions and an extra lookup.

Suggested diff
-        if let Ok(Some(ts)) = self.cs.chain_index().tipset_by_height(
+        if let Ok(Some(ts)) = self.cs.chain_index().tipset_by_height(
             tipset.epoch(),
-            self.cs.heaviest_tipset(),
+            heaviest.clone(),
             ResolveNullTipset::TakeOlder,
         ) && ts.key() == tipset.key()
         {
             return;
         }
🤖 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 701 - 709, The guard is
re-fetching the current head instead of reusing the previously read `heaviest`
snapshot, which can cause mixed-head decisions and an extra lookup; change the
call to `self.cs.chain_index().tipset_by_height(..., self.cs.heaviest_tipset(),
...)` to pass the existing `heaviest` variable (the one read at line 688) into
`self.cs.chain_index().tipset_by_height(tipset.epoch(), heaviest,
ResolveNullTipset::TakeOlder)` so the comparison `ts.key() == tipset.key()` uses
a consistent snapshot.
🤖 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 701-709: The guard is re-fetching the current head instead of
reusing the previously read `heaviest` snapshot, which can cause mixed-head
decisions and an extra lookup; change the call to
`self.cs.chain_index().tipset_by_height(..., self.cs.heaviest_tipset(), ...)` to
pass the existing `heaviest` variable (the one read at line 688) into
`self.cs.chain_index().tipset_by_height(tipset.epoch(), heaviest,
ResolveNullTipset::TakeOlder)` so the comparison `ts.key() == tipset.key()` uses
a consistent snapshot.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8f23e39d-42bb-4aff-a9d8-f01124f67f54

📥 Commits

Reviewing files that changed from the base of the PR and between 4cea4c5 and f92e280.

📒 Files selected for processing (1)
  • src/chain_sync/chain_follower.rs

@hanabi1224 hanabi1224 added this pull request to the merge queue May 7, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.22%. Comparing base (4cea4c5) to head (f92e280).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/chain_sync/chain_follower.rs 57.14% 2 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/chain_sync/chain_follower.rs 38.16% <57.14%> (+0.18%) ⬆️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cea4c5...f92e280. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Merged via the queue into main with commit 8f2b32b May 7, 2026
40 checks passed
@hanabi1224 hanabi1224 deleted the hm/chain-follower-fix branch May 7, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants