Skip to content

fix(mpool): run_head_change in select message to only simulate the head change#7182

Merged
akaladarshi merged 1 commit into
mainfrom
akaladarshi/fix-selection-remove-msg
Jun 17, 2026
Merged

fix(mpool): run_head_change in select message to only simulate the head change#7182
akaladarshi merged 1 commit into
mainfrom
akaladarshi/fix-selection-remove-msg

Conversation

@akaladarshi

@akaladarshi akaladarshi commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Summary of changes

Changes introduced in this pull request:

  • The run_head_change now only simulates the head change instead of removing the pending messages from the pending store

Reference issue to close (if applicable)

Closes #6975

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

  • Bug Fixes
    • Fixed Filecoin.MpoolSelect to no longer remove messages from the live message pool when performing selection simulations. The operation now safely simulates head changes without mutating the actual pool state.

@akaladarshi akaladarshi requested a review from a team as a code owner June 16, 2026 15:52
@akaladarshi akaladarshi requested review from LesnyRumcajs and hanabi1224 and removed request for a team June 16, 2026 15:52
@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label Jun 16, 2026
@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

run_head_change in the message-pool selection path is narrowed to remove the pending_store and key_cache parameters. A new remove_from_selected_msgs helper in utils.rs mutates only the local rmsgs scratch map. A regression test and changelog entry confirm Filecoin.MpoolSelect no longer side-effects the live pool.

Changes

MpoolSelect live-pool isolation

Layer / File(s) Summary
remove_from_selected_msgs helper and run_head_change signature
src/message_pool/msgpool/utils.rs, src/message_pool/msgpool/selection.rs
Adds remove_from_selected_msgs to utils (removes an entry from the nested rmsgs map by address and sequence), then drops pending_store and key_cache from run_head_change's signature so the function can only touch the local scratch map.
Right-chain removal and call-site update
src/message_pool/msgpool/selection.rs
run_head_change's right-chain loop replaces the old pending-store removal flow with a direct call to utils::remove_from_selected_msgs; get_pending_messages call site updated to match the narrowed signature.
Regression test and changelog
src/message_pool/msgpool/selection.rs, CHANGELOG.md
New async test select_messages_on_non_current_tipset_should_not_update_mpool_state asserts live pool contents, pool size, and MpoolUpdate events are unchanged after select_messages on a non-current tipset; changelog records the fix.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • ChainSafe/forest#6965: Directly modified the same run_head_change/pending-store interaction in selection.rs that this PR further refactors.
  • ChainSafe/forest#7006: Touched get_pending_messages/run_head_change call signatures in selection.rs, the exact call site updated here.
  • ChainSafe/forest#7033: Worked on the head-change simulation/reorg logic in selection.rs that this PR builds on for the right-chain removal change.

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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 accurately captures the main change: modifying run_head_change to only simulate head change rather than mutate the live pool.
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 akaladarshi/fix-selection-remove-msg
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch akaladarshi/fix-selection-remove-msg

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

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.05882% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.41%. Comparing base (71cc220) to head (2d63816).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/message_pool/msgpool/selection.rs 96.61% 1 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/message_pool/msgpool/utils.rs 80.59% <100.00%> (+3.01%) ⬆️
src/message_pool/msgpool/selection.rs 87.45% <96.61%> (+1.17%) ⬆️

... and 17 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 71cc220...2d63816. 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: 1

🧹 Nitpick comments (1)
src/message_pool/msgpool/selection.rs (1)

1095-1097: ⚡ Quick win

Assert the simulated selection result too.

This test verifies no live-pool side effects, but it would still pass if the scratch rmsgs simulation failed to remove the message already included in ts2. Capture the return value and assert it does not include pending_msg.

Suggested assertion
-        let _ = mpool.select_messages(&ts2, 1.0).unwrap();
+        let selected = mpool.select_messages(&ts2, 1.0).unwrap();
+        assert!(
+            !selected.iter().any(|msg| msg.cid() == pending_msg.cid()),
+            "selection for the target tipset must not return a message already applied there"
+        );
🤖 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/message_pool/msgpool/selection.rs` around lines 1095 - 1097, The test
currently discards the return value from the mpool.select_messages(&ts2,
1.0).unwrap() call by using let _. To ensure the simulated selection is working
correctly, capture the returned value in a variable instead of discarding it,
then add an assertion to verify that the returned selection does not include the
pending_msg that was already included in the ts2 tipset. This ensures the test
catches cases where the scratch rmsgs simulation fails to properly exclude
messages.
🤖 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/message_pool/msgpool/utils.rs`:
- Around line 75-76: The issue is that rmsgs may be keyed by resolved sender
addresses from the pending snapshot while the from parameter could be an ID
address, causing get_mut(from) to fail to locate the correct message set.
Instead of directly calling rmsgs.get_mut(from), you need to look up the message
set using the actual stored sender address key. Determine the resolved sender
address that corresponds to the message being removed and use that to access the
correct set in rmsgs before calling set.remove(&sequence), ensuring messages are
properly removed regardless of whether from is an ID address or resolved
address.

---

Nitpick comments:
In `@src/message_pool/msgpool/selection.rs`:
- Around line 1095-1097: The test currently discards the return value from the
mpool.select_messages(&ts2, 1.0).unwrap() call by using let _. To ensure the
simulated selection is working correctly, capture the returned value in a
variable instead of discarding it, then add an assertion to verify that the
returned selection does not include the pending_msg that was already included in
the ts2 tipset. This ensures the test catches cases where the scratch rmsgs
simulation fails to properly exclude messages.
🪄 Autofix (Beta)

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: b99dbbb2-7e17-4dd9-abf6-0b3a05fd0ca2

📥 Commits

Reviewing files that changed from the base of the PR and between 2d7b230 and 2d63816.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/message_pool/msgpool/selection.rs
  • src/message_pool/msgpool/utils.rs
🔗 Linked repositories identified

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

  • filecoin-project/lotus (manual)

Comment thread src/message_pool/msgpool/utils.rs
@akaladarshi akaladarshi marked this pull request as draft June 16, 2026 16:41
@akaladarshi akaladarshi marked this pull request as ready for review June 16, 2026 17:31
@akaladarshi akaladarshi added this pull request to the merge queue Jun 17, 2026
Merged via the queue into main with commit d590f15 Jun 17, 2026
70 of 94 checks passed
@akaladarshi akaladarshi deleted the akaladarshi/fix-selection-remove-msg branch June 17, 2026 10:23
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.

fix: make run_head_change() side-effect free in message selection

2 participants