refactor: msg pool to make more structured#6965
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughReplaces the per-address in-memory pending HashMap with a crate-scoped PendingStore, extracts per-sender logic into MsgSet, and adds MpoolUpdate broadcast events; threads PendingStore through selection/republish/head-change, updates MessagePool APIs, and adjusts tests to use snapshot/subscribe APIs. ChangesPending store + MsgSet + wiring
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
Client->>Store: remove(from, sequence, applied)
Store->>MsgSet: rm(sequence, applied) -> Option<msg>
alt removal occurred
Store->>Sub: broadcast MpoolUpdate::Remove(msg)
else no-op
Store-->>Client: None
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
src/message_pool/msgpool/events.rssrc/message_pool/msgpool/mod.rssrc/message_pool/msgpool/msg_pool.rssrc/message_pool/msgpool/msg_set.rssrc/message_pool/msgpool/pending_store.rssrc/message_pool/msgpool/selection.rs
Codecov Report❌ Patch coverage is Additional details and impacted files
... and 8 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
@akaladarshi Anything with 🐰 comments to address? If not, mark them as resolved. |
48cdcbe to
0d66af3
Compare
|
Coverage check is failing dues to |
The lint was removed in #6977. |
0d66af3 to
4ba6458
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/mod.rs`:
- Around line 14-16: Remove the "TODO" marker in the comment above the pub use
to avoid failing the TODO lint: either delete the entire comment line "// TODO:
This will be used in https://github.com/ChainSafe/forest/pull/6941" or rewrite
it as a non-TODO remark (e.g., "// Will be used in PR ...") so the file still
exposes events::MpoolUpdate but no TODO token remains in
src/message_pool/msgpool/mod.rs.
🪄 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: 78cd95d6-c294-4f15-8004-e891c682cf26
📒 Files selected for processing (6)
src/message_pool/msgpool/events.rssrc/message_pool/msgpool/mod.rssrc/message_pool/msgpool/msg_pool.rssrc/message_pool/msgpool/msg_set.rssrc/message_pool/msgpool/pending_store.rssrc/message_pool/msgpool/selection.rs
✅ Files skipped from review due to trivial changes (2)
- src/message_pool/msgpool/pending_store.rs
- src/message_pool/msgpool/msg_set.rs
🚧 Files skipped from review as they are similar to previous changes (2)
- src/message_pool/msgpool/events.rs
- src/message_pool/msgpool/msg_pool.rs
Summary of changes
Changes introduced in this pull request:
pending_storethat holds all the pending related data for the mempoolmsetrelated changes into it's own file to reduce the bloat onmsgpoolReference issue to close (if applicable)
Part of #7010
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit
New Features
Improvements
Tests