Skip to content

refactor: msg pool to make more structured#6965

Open
akaladarshi wants to merge 5 commits intomainfrom
akaladarshi/msgpool-refactor
Open

refactor: msg pool to make more structured#6965
akaladarshi wants to merge 5 commits intomainfrom
akaladarshi/msgpool-refactor

Conversation

@akaladarshi
Copy link
Copy Markdown
Collaborator

@akaladarshi akaladarshi commented Apr 23, 2026

Summary of changes

Changes introduced in this pull request:

  • Part 1 one of the refactor of the msg_pool, this mostly contains the structural refactor such as combining methods and creating new files etc.:
    • Introduced a new pending_store that holds all the pending related data for the mempool
    • Moved the mset related changes into it's own file to reduce the bloat on msgpool

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

  • New Features

    • Real-time pending-message events and a subscription API to receive add/remove notifications.
  • Improvements

    • Replaced in-memory pending map with a snapshot-capable store for safer concurrent access and more efficient reads.
    • Tighter, clearer replace-by-fee and nonce-gap handling for more robust transaction behavior and capacity enforcement.
  • Tests

    • Updated and expanded tests for snapshots, event emission, capacity/RBF, and nonce-gap scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 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: cd0c8ac7-e135-416b-9500-194e66a696ef

📥 Commits

Reviewing files that changed from the base of the PR and between 48cdcbe and 0d66af3.

📒 Files selected for processing (3)
  • src/message_pool/msgpool/events.rs
  • src/message_pool/msgpool/mod.rs
  • src/message_pool/msgpool/msg_set.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/message_pool/msgpool/events.rs

Walkthrough

Replaces the per-address in-memory pending HashMap with a crate-scoped PendingStore, extracts per-sender logic into MsgSet, and adds MpoolUpdate broadcast events; updates insertion/removal/read paths, threads pending_store through selection/republish/head-change, and adjusts tests to use snapshot APIs and event subscriptions.

Changes

Cohort / File(s) Summary
Event Infrastructure
src/message_pool/msgpool/events.rs
Adds MpoolUpdate enum (Add, Remove) and MPOOL_UPDATE_CHANNEL_CAPACITY constant for pending-pool broadcast events.
Pending Store
src/message_pool/msgpool/pending_store.rs
Introduces PendingStore (crate-visible) with new, insert, remove, snapshot, snapshot_for, has_subscribers, and subscribe/broadcast emission semantics; emits MpoolUpdate on real mutations.
Per-sender Message Set
src/message_pool/msgpool/msg_set.rs
Adds MsgSet, MsgSetLimits, StrictnessPolicy, MAX_NONCE_GAP, and add/rm logic implementing nonce-gap rules, gap-filling, replace-by-fee, capacity limits, and metrics updates.
MessagePool Core
src/message_pool/msgpool/msg_pool.rs, src/message_pool/msgpool/mod.rs
Replaces pending: SyncRwLock<HashMap> with pending_store: PendingStore; threads pending_store through contexts; adds subscribe_to_updates(); tightens head_change visibility; updates callers to use pending_store APIs.
Selection & Republish
src/message_pool/msgpool/selection.rs, src/message_pool/msgpool/mod.rs
Refactors selection and republish paths to use pending_store.snapshot() / snapshot_for(...); constructs MpoolCtx with pending_store; updates tests to assert via snapshots.
Exports & Tests
src/message_pool/msgpool/...
Adds crate-visible submodules events, msg_set, pending_store; re-exports MpoolUpdate; updates tests to use PendingStore snapshots and subscription behavior; removes some MsgSet-specific tests now validated via store snapshots.

Sequence Diagram(s)

sequenceDiagram
    participant Client as "MessagePool API"
    participant Store as "PendingStore"
    participant MsgSet as "MsgSet (per-sender)"
    participant Sub as "Subscriber (broadcast::Receiver)"
    Client->>Store: insert(resolved_from, msg, sequence, trust, strictness)
    Store->>MsgSet: get_or_create(resolved_from)
    MsgSet-->>Store: add(msg, strictness, trust, limits) -> Result
    alt insert succeeded
        Store->>Store: persist into map
        Store->>Sub: broadcast MpoolUpdate::Add(msg)
    else insert failed
        Store-->>Client: return Error
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • sudo-shashank
  • LesnyRumcajs
  • hanabi1224
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: a structural refactor of the message pool codebase that improves organization by introducing pending_store and separating concerns into new modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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/msgpool-refactor
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch akaladarshi/msgpool-refactor

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

@akaladarshi akaladarshi changed the title refactor: msg pool to make more structured [skip ci] refactor: msg pool to make more structured Apr 27, 2026
@akaladarshi akaladarshi added the RPC requires calibnet RPC checks to run on CI label Apr 27, 2026
@akaladarshi akaladarshi marked this pull request as ready for review April 27, 2026 15:07
@akaladarshi akaladarshi requested a review from a team as a code owner April 27, 2026 15:07
@akaladarshi akaladarshi requested review from LesnyRumcajs and sudo-shashank and removed request for a team April 27, 2026 15:07
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.

Actionable comments posted: 3

🤖 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/message_pool/msgpool/msg_pool.rs`:
- Around line 449-453: The public method subscribe_to_updates currently returns
broadcast::Receiver<MpoolUpdate> but MpoolUpdate is crate-private (declared
pub(in crate::message_pool) in events.rs), so callers outside
crate::message_pool cannot name the type; either re-export MpoolUpdate from a
public module (add a pub use crate::message_pool::msgpool::events::MpoolUpdate
in a public mod) so the type is publicly reachable, or reduce
subscribe_to_updates() visibility to match MpoolUpdate (make
subscribe_to_updates pub(crate) or pub(in crate::message_pool)) so the declared
signature and type visibility align; update the signature or re-export
accordingly and adjust any callers.

In `@src/message_pool/msgpool/msg_set.rs`:
- Around line 183-188: The applied=true branch in msg_set.rs only sets
self.next_sequence = sequence + 1 which can leave already-buffered higher nonces
unaccounted for; change the branch to advance next_sequence past any buffered
successors the same way the unknown-message branch does: set next_sequence =
sequence + 1 and then loop while self.msgs.contains_key(&self.next_sequence) (or
the equivalent buffered map/set used in this struct) incrementing next_sequence
until no buffered message exists, so callers are not told they can reuse a
still-pending nonce.

In `@src/message_pool/msgpool/selection.rs`:
- Around line 853-857: The simulated path run_head_change() is mutating the live
PendingStore because MpoolCtx is constructed with the real pending_store; change
the helper to be side-effect free by giving MpoolCtx a simulation-only context
or snapshot: either construct MpoolCtx with a read-only/snapshot PendingStore
clone or introduce a SimulationPendingStore (or a flag on MpoolCtx) that makes
remove_from_selected_msgs() operate only on the local rmsgs/result map rather
than calling pending_store.remove(...). Update the MpoolCtx construction in
run_head_change() and ensure MpoolCtx::remove_from_selected_msgs() checks the
simulation mode or uses the snapshot store so select_messages() against
non-current tipsets cannot delete entries from the live mempool.
🪄 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: 3914d600-4744-47e8-8b77-311223afc188

📥 Commits

Reviewing files that changed from the base of the PR and between 65c39a0 and c515b49.

📒 Files selected for processing (6)
  • src/message_pool/msgpool/events.rs
  • src/message_pool/msgpool/mod.rs
  • src/message_pool/msgpool/msg_pool.rs
  • src/message_pool/msgpool/msg_set.rs
  • src/message_pool/msgpool/pending_store.rs
  • src/message_pool/msgpool/selection.rs

Comment thread src/message_pool/msgpool/msg_pool.rs
Comment thread src/message_pool/msgpool/msg_set.rs
Comment thread src/message_pool/msgpool/selection.rs
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
2044 1 2043 0
View the top 1 failed test(s) by shortest run time
forest-filecoin::lint::lint
Stack Traces | 1.29s run time
thread 'lint' (47948) panicked at tests/lint.rs:174:17:
found 1 violations in 633 files
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's ease up on the comments; ideally documentation should explain things high-level, and not repeat the implementation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

@LesnyRumcajs
Copy link
Copy Markdown
Member

@akaladarshi Anything with 🐰 comments to address? If not, mark them as resolved.

@akaladarshi akaladarshi force-pushed the akaladarshi/msgpool-refactor branch from c515b49 to 48cdcbe Compare April 28, 2026 12:53
@akaladarshi akaladarshi force-pushed the akaladarshi/msgpool-refactor branch from 48cdcbe to 0d66af3 Compare April 28, 2026 13:06
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.

2 participants