Skip to content

fix: broadcast head changes only when subscribed#6759

Merged
hanabi1224 merged 1 commit intomainfrom
hm/check-subscribers-before-publishing-head-changes
Mar 20, 2026
Merged

fix: broadcast head changes only when subscribed#6759
hanabi1224 merged 1 commit intomainfrom
hm/check-subscribers-before-publishing-head-changes

Conversation

@hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Mar 18, 2026

Summary of changes

Changes introduced in this pull request:

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

Release Notes

  • Performance

    • Optimized head-change notification publishing to occur only when active listeners are present.
    • Extracted shared subscriber detection utility for reuse across components.
  • Tests

    • Added tests validating subscriber status detection behavior.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d4baf59d-bfcd-428a-9a30-73184bee95ef

📥 Commits

Reviewing files that changed from the base of the PR and between bb3bf11 and 2121ef7.

📒 Files selected for processing (5)
  • src/chain/store/chain_store.rs
  • src/db/parity_db.rs
  • src/utils/broadcast/mod.rs
  • src/utils/broadcast/tests.rs
  • src/utils/mod.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/utils/broadcast/tests.rs
  • src/db/parity_db.rs

Walkthrough

This PR introduces a shared has_subscribers utility function to check for active broadcast channel subscribers and applies it to guard expensive path-change computations in the chain store and database layer, preventing unnecessary work when no subscribers are present.

Changes

Cohort / File(s) Summary
Broadcast Utility Module
src/utils/broadcast/mod.rs, src/utils/broadcast/tests.rs, src/utils/mod.rs
New broadcast utility module with public has_subscribers<T>() function for checking active subscribers on tokio broadcast channels, including comprehensive test coverage for subscriber lifecycle scenarios.
Chain Store Integration
src/chain/store/chain_store.rs
Applied subscriber guard around head-change path computation and broadcast; work is now performed only when has_subscribers confirms active subscribers exist.
Database Integration
src/db/parity_db.rs
Replaced local has_subscribers helper with imported centralized version from broadcast utility module, removing redundant code and unused import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • akaladarshi
  • sudo-shashank
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: broadcast head changes only when subscribed' accurately and concisely describes the main change: adding a subscriber check before publishing head changes to avoid unnecessary broadcast operations.

✏️ 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/check-subscribers-before-publishing-head-changes
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/check-subscribers-before-publishing-head-changes
📝 Coding Plan
  • Generate coding plan for human review comments

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

@hanabi1224 hanabi1224 marked this pull request as ready for review March 18, 2026 12:10
@hanabi1224 hanabi1224 requested a review from a team as a code owner March 18, 2026 12:10
@hanabi1224 hanabi1224 requested review from akaladarshi and sudo-shashank and removed request for a team March 18, 2026 12:10
@hanabi1224 hanabi1224 force-pushed the hm/check-subscribers-before-publishing-head-changes branch from bb3bf11 to 998ed48 Compare March 18, 2026 12:16
Copy link
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/utils/broadcast/tests.rs`:
- Around line 6-25: The test test_has_subscribers should assert the public
helper has_subscribers instead of inspecting tx.closed().now_or_never()
directly; replace each assertion that checks
tx.closed().now_or_never().is_none()/is_some() with the corresponding
has_subscribers(&tx) boolean check (e.g., assert!(has_subscribers(&tx)) or
assert!(!has_subscribers(&tx))) so the test verifies the has_subscribers
function contract rather than duplicating its implementation; update all four
occurrences and add any necessary use/import for has_subscribers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1d8ed2a1-da0f-4c22-9c65-ddd9ad65c6c7

📥 Commits

Reviewing files that changed from the base of the PR and between 37418a6 and bb3bf11.

📒 Files selected for processing (7)
  • src/chain/store/chain_store.rs
  • src/db/parity_db.rs
  • src/shim/executor.rs
  • src/state_manager/mod.rs
  • src/utils/broadcast/mod.rs
  • src/utils/broadcast/tests.rs
  • src/utils/mod.rs

@hanabi1224 hanabi1224 force-pushed the hm/check-subscribers-before-publishing-head-changes branch from 998ed48 to 2121ef7 Compare March 18, 2026 12:23
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 25.00000% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.60%. Comparing base (37418a6) to head (2121ef7).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/chain/store/chain_store.rs 7.69% 12 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/db/parity_db.rs 67.74% <ø> (-0.26%) ⬇️
src/utils/broadcast/mod.rs 100.00% <100.00%> (ø)
src/utils/mod.rs 82.45% <ø> (ø)
src/chain/store/chain_store.rs 67.33% <7.69%> (-3.07%) ⬇️

... and 14 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 37418a6...2121ef7. Read the comment docs.

@hanabi1224 hanabi1224 added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit aaafd1b Mar 20, 2026
35 checks passed
@hanabi1224 hanabi1224 deleted the hm/check-subscribers-before-publishing-head-changes branch March 20, 2026 11:00
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