Skip to content

refactor: inline MempoolState into MempoolManager#628

Draft
xdustinface wants to merge 1 commit intofix/broadcast-tx-local-processingfrom
refactor/inline-mempool-state
Draft

refactor: inline MempoolState into MempoolManager#628
xdustinface wants to merge 1 commit intofix/broadcast-tx-local-processingfrom
refactor/inline-mempool-state

Conversation

@xdustinface
Copy link
Copy Markdown
Collaborator

@xdustinface xdustinface commented Apr 3, 2026

Move transactions and recent_sends directly into MempoolManager as plain fields, removing the MempoolState struct and its Arc<RwLock<...>> wrapper. The dead pending_balance and pending_instant_balance tracking is dropped entirely since no code outside of the struct itself ever read those values.

remove_confirmed and prune_expired are no longer async since they no longer need to acquire a lock.

Based on:

Summary by CodeRabbit

  • Refactor
    • Improved internal architecture of mempool transaction tracking system. Mempool monitoring and transaction pruning continue to operate transparently without affecting user experience.

Move `transactions` and `recent_sends` directly into `MempoolManager`
as plain fields, removing the `MempoolState` struct and its
`Arc<RwLock<...>>` wrapper. The dead `pending_balance` and
`pending_instant_balance` tracking is dropped entirely since no code
outside of the struct itself ever read those values.

`remove_confirmed` and `prune_expired` are no longer async since they
no longer need to acquire a lock.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: dab6e585-5cc2-49fa-be0b-d623d8175d05

📥 Commits

Reviewing files that changed from the base of the PR and between b707e28 and c85bef9.

📒 Files selected for processing (4)
  • dash-spv/src/client/lifecycle.rs
  • dash-spv/src/sync/mempool/manager.rs
  • dash-spv/src/sync/mempool/sync_manager.rs
  • dash-spv/src/types.rs
💤 Files with no reviewable changes (2)
  • dash-spv/src/client/lifecycle.rs
  • dash-spv/src/types.rs

📝 Walkthrough

Walkthrough

The pull request removes the shared MempoolState struct and transfers mempool tracking ownership directly into MempoolManager. Previously passed as an Arc<RwLock<...>> parameter, mempool transactions and send history are now owned fields. Async methods for confirmed-transaction removal and expiration pruning become synchronous, and all call sites are updated accordingly.

Changes

Cohort / File(s) Summary
Mempool State Type Removal
dash-spv/src/types.rs
Deleted the MempoolState public struct and all associated methods (add_transaction, remove_transaction, prune_expired, record_send, is_recent_send, total_pending_balance), consolidating mempool tracking logic into MempoolManager.
MempoolManager Refactoring
dash-spv/src/sync/mempool/manager.rs
Replaced Arc<RwLock<MempoolState>> field with owned HashMap fields for transactions and recent_sends. Constructor signature removes mempool_state parameter. Methods remove_confirmed and prune_expired changed from async to synchronous. All state reads/writes redirected to internal maps. Tests converted from async to sync where applicable.
Constructor & Call Site Updates
dash-spv/src/client/lifecycle.rs, dash-spv/src/sync/mempool/sync_manager.rs
Removed mempool_state construction and parameter passing in DashSpvClient::new. Updated sync_manager.rs calls to remove_confirmed and prune_expired to remove .await, and refactored test setup to work with manager's owned fields instead of external state.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 Hops of joy! The mempool's now all mine,
No shared locks to tangle in a line,
Fresh hashMaps hold the pending txs true,
Synchronous pruning—swift and new!
StateMonad? Gone! But cleaner is the way.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: inline MempoolState into MempoolManager' accurately describes the primary change: moving mempool state tracking from a separate struct into the manager itself, removing the shared state wrapper, and simplifying the API.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 refactor/inline-mempool-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@xdustinface
Copy link
Copy Markdown
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 98.67550% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.60%. Comparing base (b707e28) to head (c85bef9).

Files with missing lines Patch % Lines
dash-spv/src/sync/mempool/manager.rs 98.43% 2 Missing ⚠️
Additional details and impacted files
@@                          Coverage Diff                          @@
##           fix/broadcast-tx-local-processing     #628      +/-   ##
=====================================================================
- Coverage                              67.73%   67.60%   -0.14%     
=====================================================================
  Files                                    318      318              
  Lines                                  67914    67889      -25     
=====================================================================
- Hits                                   46001    45895     -106     
- Misses                                 21913    21994      +81     
Flag Coverage Δ
core 75.21% <ø> (ø)
ffi 38.09% <ø> (ø)
rpc 19.92% <ø> (ø)
spv 84.42% <98.67%> (-0.62%) ⬇️
wallet 67.57% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/client/lifecycle.rs 65.98% <ø> (-0.35%) ⬇️
dash-spv/src/sync/mempool/sync_manager.rs 98.72% <100.00%> (-0.04%) ⬇️
dash-spv/src/types.rs 88.11% <ø> (-1.68%) ⬇️
dash-spv/src/sync/mempool/manager.rs 97.19% <98.43%> (-0.43%) ⬇️

... and 7 files with indirect coverage changes

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.

1 participant