Skip to content

refactor: inline MempoolState into MempoolManager#628

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
refactor/inline-mempool-state
Open

refactor: inline MempoolState into MempoolManager#628
xdustinface wants to merge 1 commit intov0.42-devfrom
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.

@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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 3, 2026
@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.80%. Comparing base (88e8a9a) to head (9731037).

Files with missing lines Patch % Lines
dash-spv/src/sync/mempool/manager.rs 98.43% 2 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #628      +/-   ##
=============================================
- Coverage      67.81%   67.80%   -0.02%     
=============================================
  Files            318      318              
  Lines          67976    67849     -127     
=============================================
- Hits           46100    46003      -97     
+ Misses         21876    21846      -30     
Flag Coverage Δ
core 75.21% <ø> (ø)
ffi 38.51% <ø> (+0.22%) ⬆️
rpc 19.92% <ø> (ø)
spv 85.13% <98.67%> (-0.10%) ⬇️
wallet 67.56% <ø> (ø)
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 19 files with indirect coverage changes

@xdustinface xdustinface closed this Apr 6, 2026
@xdustinface xdustinface reopened this Apr 6, 2026
Base automatically changed from fix/broadcast-tx-local-processing to v0.42-dev April 6, 2026 23:56
@xdustinface xdustinface dismissed coderabbitai[bot]’s stale review April 6, 2026 23:56

The base branch was changed.

@github-actions github-actions bot added the merge-conflict The PR conflicts with the target branch. label Apr 6, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

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.
@xdustinface xdustinface force-pushed the refactor/inline-mempool-state branch from c85bef9 to 9731037 Compare April 7, 2026 00:04
@xdustinface xdustinface marked this pull request as ready for review April 7, 2026 00:05
@github-actions github-actions bot removed the merge-conflict The PR conflicts with the target branch. label Apr 7, 2026
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