Skip to content

fix: disable overflow in head change broadcast channel - #7462

Open
hanabi1224 wants to merge 13 commits into
mainfrom
hm/no-head-change-overflow
Open

fix: disable overflow in head change broadcast channel#7462
hanabi1224 wants to merge 13 commits into
mainfrom
hm/no-head-change-overflow

Conversation

@hanabi1224

@hanabi1224 hanabi1224 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #7442

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

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • 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

    • Improved reliability and delivery of chain head-change notifications across indexing, messaging, state management, and RPC subscriptions.
    • Prevented unnecessary notifications and path-change responses when no changes occur or chain points match.
    • Improved subscription behavior when notification sources or subscribers close.
  • Tests

    • Added coverage for ordered notification delivery, duplicate suppression, and the absence of extra events.

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The PR migrates chain head-change notifications from Tokio broadcast to async-broadcast. It configures non-dropping publication, updates subscription contracts and consumers, and handles identical chain-path keys.

Changes

Head-change broadcast migration

Layer / File(s) Summary
Configure head-change publication
Cargo.toml, src/chain/store/chain_store.rs
Adds async-broadcast. ChainStore uses a capacity-1000 channel, disables overflow drops, publishes non-empty changes with broadcast_blocking, and tests ordered delivery and duplicate suppression.
Update subscription contracts and test provider
src/message_pool/msgpool/provider.rs, src/message_pool/msgpool/test_provider.rs, src/rpc/methods/eth/pubsub.rs
Provider and test APIs use async_broadcast::Receiver. Test channels use capacity 100 and broadcast_blocking. RPC feeds consume receivers directly.
Process head-change streams
src/daemon/db_util.rs, src/daemon/mod.rs, src/lib.rs, src/message_pool/msgpool/msg_pool.rs, src/rpc/methods/chain.rs, src/state_manager/message_search.rs
Consumers use stream iteration for head changes. They retain existing processing behavior and stop when streams close. Tokio broadcast polling and lagged-event handling are removed.
Handle empty chain paths
src/rpc/methods/chain.rs
chain_get_path returns empty changes when both tipset keys match. PathChanges exposes is_empty.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ChainStore
  participant Indexer
  participant MessagePool
  participant RPCSubscriber
  ChainStore->>Indexer: publish head-change stream events
  ChainStore->>MessagePool: publish head-change stream events
  ChainStore->>RPCSubscriber: publish head-change stream events
  Indexer-->>Indexer: process applied tipsets
  MessagePool-->>MessagePool: apply head changes
  RPCSubscriber-->>RPCSubscriber: publish feed updates
Loading

Suggested reviewers: lesnyrumcajs, sudo-shashank

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The migration and consumer updates are present [#7442], but the summary lacks a slow-consumer overflow test and SQLite indexer coverage. Add a test that exceeds channel capacity without loss, verify the SQLite indexer consumer, and test clean shutdown for blocked senders and receivers.
✅ 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 clearly identifies the primary change: disabling overflow in the head-change broadcast channel.
Out of Scope Changes check ✅ Passed The changes remain focused on migrating head-change notifications, updating consumers, and validating ordered delivery [#7442].
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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/no-head-change-overflow
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/no-head-change-overflow

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

@hanabi1224
hanabi1224 marked this pull request as ready for review August 7, 2026 06:47
@hanabi1224
hanabi1224 requested a review from a team as a code owner August 7, 2026 06:47
@hanabi1224
hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team August 7, 2026 06:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@src/chain/store/chain_store.rs`:
- Around line 258-259: Update the active-subscriber check in the head-change
publication logic to use self.head_changes_tx.receiver_count() > 0. Remove the
comparison with inactive_receiver_count() so inactive receivers cannot suppress
publication to active receivers.
- Around line 144-146: Retain a deactivated InactiveReceiver for the broadcast
channel lifetime in ChainStore at src/chain/store/chain_store.rs:144-146, and in
both TestApi constructors at src/message_pool/msgpool/test_provider.rs:42 and
:56; configure the TestApi senders with await_active disabled, handle
broadcast_blocking send errors instead of unwrapping when no active receiver
exists, and add a regression test proving subscribers created after construction
receive head changes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 04beca37-e23d-4ec4-817e-f05d2501f9cf

📥 Commits

Reviewing files that changed from the base of the PR and between 9c30523 and b19d888.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (10)
  • Cargo.toml
  • src/chain/store/chain_store.rs
  • src/daemon/db_util.rs
  • src/daemon/mod.rs
  • src/message_pool/msgpool/msg_pool.rs
  • src/message_pool/msgpool/provider.rs
  • src/message_pool/msgpool/test_provider.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/eth/pubsub.rs
  • src/state_manager/message_search.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread src/chain/store/chain_store.rs Outdated
Comment thread src/chain/store/chain_store.rs Outdated
@hanabi1224
hanabi1224 force-pushed the hm/no-head-change-overflow branch from b19d888 to 8a6626a Compare August 7, 2026 06:55
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@hanabi1224
hanabi1224 force-pushed the hm/no-head-change-overflow branch from 8a6626a to aa2d402 Compare August 7, 2026 07:03
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@hanabi1224
hanabi1224 force-pushed the hm/no-head-change-overflow branch from aa2d402 to e4de3e2 Compare August 7, 2026 07:04
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.63889% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.16%. Comparing base (9199a82) to head (582fbd3).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/daemon/db_util.rs 0.00% 18 Missing ⚠️
src/state_manager/message_search.rs 53.84% 16 Missing and 2 partials ⚠️
src/rpc/methods/chain.rs 23.07% 10 Missing ⚠️
src/daemon/mod.rs 0.00% 7 Missing ⚠️
src/chain/store/chain_store.rs 94.23% 3 Missing ⚠️
src/message_pool/msgpool/msg_pool.rs 25.00% 2 Missing and 1 partial ⚠️
src/rpc/methods/eth/pubsub.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/message_pool/msgpool/provider.rs 69.84% <100.00%> (-1.59%) ⬇️
src/message_pool/msgpool/test_provider.rs 99.05% <100.00%> (+<0.01%) ⬆️
src/rpc/methods/eth/pubsub.rs 58.80% <0.00%> (ø)
src/chain/store/chain_store.rs 76.53% <94.23%> (+2.84%) ⬆️
src/message_pool/msgpool/msg_pool.rs 88.90% <25.00%> (+0.09%) ⬆️
src/daemon/mod.rs 24.39% <0.00%> (+0.10%) ⬆️
src/rpc/methods/chain.rs 48.34% <23.07%> (-0.21%) ⬇️
src/daemon/db_util.rs 54.70% <0.00%> (-0.18%) ⬇️
src/state_manager/message_search.rs 88.30% <53.84%> (+0.32%) ⬆️

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9199a82...582fbd3. 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/rpc/methods/chain.rs (1)

2061-2063: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add rustdoc for PathChanges::is_empty.

PathChanges::is_empty is a new public function without a rustdoc comment. Document that it returns true when both reverts and applies are empty.

As per coding guidelines, public functions and structs must have doc comments.

Proposed documentation
 impl<T> PathChanges<T> {
+    /// Returns `true` when both revert and apply lists are empty.
     pub fn is_empty(&self) -> bool {
🤖 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/rpc/methods/chain.rs` around lines 2061 - 2063, Add a rustdoc comment
directly above PathChanges::is_empty describing that it returns true only when
both reverts and applies are empty, following the project’s documentation style
for public functions.

Source: Coding guidelines

🤖 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.

Inline comments:
In `@src/chain/store/chain_store.rs`:
- Around line 981-1024: Extend test_head_changes to publish more than
HEAD_CHANGE_BROADCAST_CHANNEL_CAP changes while the receiver is paused, then
drain and assert all changes arrive in order, including the expected behavior
for retained unread changes. Add a separate shutdown scenario that leaves
publication blocked by a full channel, drops or closes the receiver, and
verifies the publisher task exits cleanly.
- Around line 281-285: Update set_heaviest_tipset to avoid calling
broadcast_blocking on the Tokio worker. Route non-empty changes through a single
ordered asynchronous publisher with shutdown cancellation, preserving lossless
delivery and existing receiver checks; do not replace it with a dropping or
best-effort send.

In `@src/rpc/methods/chain.rs`:
- Around line 1142-1147: Update chain_get_path to load and validate the tipset
key before the from == to empty-path shortcut, so an unknown identical key
returns the appropriate error while valid identical keys still return an empty
path. Add a regression test covering an unknown key used for both from and to.

---

Nitpick comments:
In `@src/rpc/methods/chain.rs`:
- Around line 2061-2063: Add a rustdoc comment directly above
PathChanges::is_empty describing that it returns true only when both reverts and
applies are empty, following the project’s documentation style for public
functions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 280f51ff-72b1-4f71-a6cb-02b7904b03bb

📥 Commits

Reviewing files that changed from the base of the PR and between e4de3e2 and c8d8c70.

📒 Files selected for processing (2)
  • src/chain/store/chain_store.rs
  • src/rpc/methods/chain.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Comment thread src/chain/store/chain_store.rs
Comment thread src/chain/store/chain_store.rs
Comment thread src/rpc/methods/chain.rs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent head-change broadcast overflow by migrating to async-broadcast

1 participant