Skip to content

fix(wallet): schedule CoinJoin auto-denomination per wallet and guard an empty round list - #8113

Merged
PastaPastaPasta merged 2 commits into
dashpay:developfrom
PastaPastaPasta:fix/coinjoin-wallet-message-delivery
Nov 13, 2026
Merged

PastaPastaPasta merged 2 commits into
dashpay:developfrom
PastaPastaPasta:fix/coinjoin-wallet-message-delivery

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

CCoinJoinClientManager::DoMaintenance keeps its tick counter and next-run tick in function statics, so every wallet's client manager shares them. With several mixing wallets loaded, the shared counter advances once per wallet per scheduler tick. Only the wallet whose call happens to land on the scheduled tick runs DoAutomaticDenominating. Which wallet mixes is effectively arbitrary, a wallet can skip many cycles, and the configured interval is divided by the number of wallets.

A second, smaller bug in the same file: SubmitDenominate reads vecInputsByRounds.begin()->first without checking that the vector has an entry. Input selection excludes fully mixed coins using the rounds setting at selection time, while the dry-run loop that fills the vector reads GetRounds() again. SetRounds (the setcoinjoinrounds RPC or the GUI) does not take cs_wallet, so lowering the target between the two can leave every selected input outside the loop's range. The vector then stays empty and the dereference is undefined behaviour.

What was done?

Two commits:

  • Keep the maintenance tick and next-run tick as members of each CCoinJoinClientManager. Initial values and trigger logic are unchanged. DoMaintenance is only called from the scheduler, so the members need no lock.
  • Skip the per-round attempt when no round count prepared, so the existing all-rounds fallback runs and fails cleanly.

How Has This Been Tested?

On macOS arm64:

  • A debug build with warnings as errors.
  • ./src/test/test_dash --run_test='coinjoin_*'.
  • rpc_coinjoin.py --legacy-wallet and --descriptors (on the earlier revision; the CoinJoin code paths they exercise are unchanged since).

The new coinjoin_tests/coinjoin_maintenance_runs_for_every_wallet test uses the existing wallet fixture and public client methods. With automatic backups disabled, each wallet must stop mixing at its first automatic attempt after five maintenance calls. Applied to unmodified develop, it fails: one wallet runs early and the other misses its deadline. It passes with the fix.

The empty-vector guard has no test: reaching it needs a rounds change racing with SubmitDenominate, which can't be made deterministic. It was checked by reading the selection and dry-run paths.

Breaking Changes

None.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation (no options or interfaces changed)
  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 46 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0a8eecb-5d4e-46e7-b0c8-618ccf0c6381
Commits

Reviewing files that changed from the base of the PR and between 5c34dcf and 51134ab.

Files selected for processing: 3

  • src/coinjoin/client.cpp
  • src/coinjoin/client.h
  • src/wallet/test/coinjoin_tests.cpp
Pre-merge checks: Inconclusive 2

Failed Failed checks: 2 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Description check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@thepastaclaw

thepastaclaw commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 51134ab) · triage: normal · Phase 2 only (queue backlog)

@PastaPastaPasta PastaPastaPasta added this to the 24.1 milestone Nov 11, 2026
@PastaPastaPasta PastaPastaPasta changed the title fix(coinjoin): deliver pool messages to every wallet and session fix: deliver CoinJoin pool messages to every wallet and session Nov 11, 2026
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/coinjoin-wallet-message-delivery branch from b288f3b to 01aab22 Compare November 11, 2026 18:27
@PastaPastaPasta PastaPastaPasta changed the title fix: deliver CoinJoin pool messages to every wallet and session fix(wallet): schedule CoinJoin auto-denomination per wallet and harden client sessions Nov 11, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 2 only (queue backlog)

Verified head 01aab22 against the Phase-2 assessment and found no actionable defects: scheduling is now per wallet, empty preparation results safely reach the fallback, and cleanup preserves successful-session pending-input locks. The regression test exercises each wallet's initial maintenance deadline, and the supplied base-drift evidence shows no conflicts or overlapping changes. This was a static review only; current CI reports ClangFormat, lint, cppcheck, and the TSAN build passing, with remaining builds and TSAN tests pending and no failed checks.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff makes three small, contained client-side fixes to per-wallet scheduling, empty-map handling, and coin unlocking, with a focused regression test and no large or intricate changes.
  • Phase 1 reviewers: not run (skipped for throughput: 12 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 11, 2026
DoMaintenance kept its tick counter and next-run tick in function statics
shared by every wallet's CCoinJoinClientManager. With several mixing wallets
the shared counter advanced once per wallet per scheduler tick, so only the
wallet whose call happened to land on the scheduled tick ran
DoAutomaticDenominating. Keep the counters per manager.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@PastaPastaPasta PastaPastaPasta changed the title fix(wallet): schedule CoinJoin auto-denomination per wallet and harden client sessions fix(coinjoin): schedule auto-denomination per wallet and guard an empty round list Nov 13, 2026
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/coinjoin-wallet-message-delivery branch from 01aab22 to 8105ae0 Compare November 13, 2026 05:59
@thepastaclaw thepastaclaw removed the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 13, 2026
Input selection excludes fully mixed coins using the rounds setting at
selection time, while the dry-run loop reads GetRounds() again. SetRounds
(the setcoinjoinrounds RPC or the GUI) does not take cs_wallet, so lowering
the target between the two can leave every selected input outside the
loop's range. vecInputsByRounds then stays empty and begin()->first is
undefined behaviour. Skip the per-round attempt in that case and fall
through to the existing all-rounds attempt, which fails cleanly.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@PastaPastaPasta PastaPastaPasta changed the title fix(coinjoin): schedule auto-denomination per wallet and guard an empty round list fix(wallet): schedule CoinJoin auto-denomination per wallet and guard an empty round list Nov 13, 2026
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/coinjoin-wallet-message-delivery branch from 8105ae0 to 51134ab Compare November 13, 2026 06:03

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 2 only (queue backlog)

The reviewed changes correctly isolate CoinJoin maintenance timing per wallet and guard the empty denomination-round result before dereferencing it. The fallback path clears and repopulates its temporary output vector, and the maintenance scheduler is the sole production caller under the wallet-manager map lock. Successful build, lint, ClangFormat, and cppcheck checks provide no regression signal; remaining test checks were queued or in progress at the snapshot.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — The change modifies CoinJoin wallet maintenance scheduling and input-selection control flow across implementation, state, and tests, but it does not directly alter a critical surface such as consensus, cryptography, key handling, or storage migration.
  • Phase 1 reviewers: not run (skipped for throughput: 17 PRs queued, above the 10 limit)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 13, 2026

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Approved

PastaPastaPasta added a commit that referenced this pull request Nov 14, 2026
…let and guard an empty round list

51134ab fix(coinjoin): don't dereference an empty round list in SubmitDenominate (pasta)
7dc17f6 fix(coinjoin): schedule auto-denomination per wallet (pasta)

Pull request description:

  ## Issue being fixed or feature implemented

  `CCoinJoinClientManager::DoMaintenance` keeps its tick counter and next-run tick in function statics, so every wallet's client manager shares them. With several mixing wallets loaded, the shared counter advances once per wallet per scheduler tick. Only the wallet whose call happens to land on the scheduled tick runs `DoAutomaticDenominating`. Which wallet mixes is effectively arbitrary, a wallet can skip many cycles, and the configured interval is divided by the number of wallets.

  A second, smaller bug in the same file: `SubmitDenominate` reads `vecInputsByRounds.begin()->first` without checking that the vector has an entry. Input selection excludes fully mixed coins using the rounds setting at selection time, while the dry-run loop that fills the vector reads `GetRounds()` again. `SetRounds` (the `setcoinjoinrounds` RPC or the GUI) does not take `cs_wallet`, so lowering the target between the two can leave every selected input outside the loop's range. The vector then stays empty and the dereference is undefined behaviour.

  ## What was done?

  Two commits:
  - Keep the maintenance tick and next-run tick as members of each `CCoinJoinClientManager`. Initial values and trigger logic are unchanged. `DoMaintenance` is only called from the scheduler, so the members need no lock.
  - Skip the per-round attempt when no round count prepared, so the existing all-rounds fallback runs and fails cleanly.

  ## How Has This Been Tested?

  On macOS arm64:
  - A debug build with warnings as errors.
  - `./src/test/test_dash --run_test='coinjoin_*'`.
  - `rpc_coinjoin.py --legacy-wallet` and `--descriptors` (on the earlier revision; the CoinJoin code paths they exercise are unchanged since).

  The new `coinjoin_tests/coinjoin_maintenance_runs_for_every_wallet` test uses the existing wallet fixture and public client methods. With automatic backups disabled, each wallet must stop mixing at its first automatic attempt after five maintenance calls. Applied to unmodified develop, it fails: one wallet runs early and the other misses its deadline. It passes with the fix.

  The empty-vector guard has no test: reaching it needs a rounds change racing with `SubmitDenominate`, which can't be made deterministic. It was checked by reading the selection and dry-run paths.

  ## Breaking Changes

  None.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have made corresponding changes to the documentation (no options or interfaces changed)
  - [x] I have assigned this pull request to a milestone

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: 3d98748396b8348044b63aac4d0a21602659e8d9104719f679e09f1c81325057c7bfb9a2a6e5d9703857c95c4454a85798b54e81228ad902c00f4b4fc9692836
(cherry picked from commit f464016)
PastaPastaPasta added a commit that referenced this pull request Nov 14, 2026
b534385 chore: prepare v24.0.2 release (pasta)
70e06ae Merge #8117: fix: races in watch-connection seed, partial sig-share batches, and ChainLock shutdown (merge-script)
d50ea34 Merge #8115: fix: free pooled secure allocations with their allocated size (merge-script)
824e58a Merge #8113: fix(wallet): schedule CoinJoin auto-denomination per wallet and guard an empty round list (merge-script)
068529f Merge #8112: fix: answer govsync only to the requesting peer and index replayed orphan votes (merge-script)
484ec63 Merge #8119: fix(stats): wrong inputValue gauge, counter data race, and null-tip crash (merge-script)
28d5711 Merge #8120: fix(utils): accept -printcrashinfo in dash-cli and dash-tx (merge-script)
578b914 Merge bitcoin-core/gui#770: Revert "gui: provide wallet controller context to wallet actions" (Konstantin Akimov)
d6902fa Merge bitcoin-core/gui#765: Fix wallet list hover crash on shutdown (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented

  Backports and release prep for v24.0.2, on top of `v24.0.x` at 137d999 (v24.0.1). One PR carries both, so the release branch gets a single merge.

  Two fixes are the reason for the release:

  - **Memory leak (#8115).** Since v24.0.0 a node's locked-memory use grows for as long as it runs. On `v24.0.x` BLS still uses relic, where a G2 element is 296 bytes; the pooled secure allocator frees such an allocation with one chunk fewer than it allocated. The batch-verification weighting added in v24.0.0 makes one such allocation per verified message, so the pool keeps growing until restart. On develop (blst, 288-byte elements) the same code path does not leak, which is why #8115 describes the bug as latent.
  - **macOS crash on close (#8073's bitcoin-core/gui#765 and gui#770).** On macOS the menu bar stays usable after the main window is hidden for shutdown. `File > Open Wallet`, `Close Wallet` and the other wallet items then call the wallet controller after it has been deleted.

  The rest are small fixes that were already merged on develop and are low risk to carry.

  ## What was done?

  ### Picked

  In develop merge order. The Dash PRs are picked from their develop merge commits with `git cherry-pick -m1 -x`; the two GUI backports are picked with `-x` from the commits #8073 merged, like earlier partial picks on this branch.

  - bitcoin-core/gui#765 Fix wallet list hover crash on shutdown, and bitcoin-core/gui#770, which reverts its first commit (from #8073). Together they leave one change: `appMenuBar->clear()` when shutdown starts.
  - #8120 fix(utils): accept -printcrashinfo in dash-cli and dash-tx
  - #8119 fix(stats): wrong inputValue gauge, counter data race, and null-tip crash
  - #8112 fix: answer govsync only to the requesting peer and index replayed orphan votes
  - #8113 fix(wallet): schedule CoinJoin auto-denomination per wallet and guard an empty round list
  - #8115 fix: free pooled secure allocations with their allocated size
  - #8117 fix: races in watch-connection seed, partial sig-share batches, and ChainLock shutdown

  Then one commit, `chore: prepare v24.0.2 release`:

  - `configure.ac`: `_CLIENT_VERSION_BUILD` 1 → 2.
  - `doc/release-notes.md`: v24.0.2 notes. The v24.0.1 notes are archived verbatim to `doc/release-notes/dash/release-notes-24.0.1.md` and added to "Older releases".
  - `contrib/flatpak/org.dash.dash-core.metainfo.xml`: `24.0.2` entry dated 2026-11-13. The date needs changing if the tag is cut on another day.
  - `doc/man/*.1`: version string only. `-printcrashinfo` (#8120) is a hidden option, so no help text changed.

  ### Adaptations

  Every pick changes the same lines as its develop counterpart except:

  - **#8073:** only the two GUI commits are taken. The other two backports in that PR (bitcoin#28629, partial bitcoin#28639) are test and refactor changes for code `v24.0.x` doesn't need.
  - **#8112:** `test/functional/feature_governance.py` differs on `v24.0.x` (no pruned node from #7860). The `v24.0.x` file is kept and only #8112's additions are applied: the imports it needs, `GovernanceSyncPeer`, `check_govsync_is_peer_local()` and its call. The source change is identical.
  - **#8113:** one line of the new unit test. `v24.0.x` has the five-argument `CWallet` constructor and `CreateMockWalletDatabase()`, so the second wallet is built the way the fixture in the same file builds the first. The source change is identical.
  - **#8117:** in `src/llmq/utils.cpp` the neighbouring includes differ; the pick removes `<atomic>` and adds nothing. The source change is otherwise identical.

  ### Not picked

  - #8111 (check every BIP39 checksum bit): it can refuse a mnemonic that v24.0.1 accepts, so it should come with a major or minor release and a release note, not a patch release.
  - #8118 (RPC argument and locking fixes): changes RPC error behaviour and needs a hand-port to `rpc/masternode.cpp`.
  - #8122 (CacheMultiMap): the use-after-free can't be reached on `v24.0.x`, and the capacity part is hardening with no behaviour change.
  - #8047 (index startup after an unclean stop): on `v24.0.x` a synced node never records the uncommitted tip it handles, and the governance index it mainly covers doesn't exist here.
  - #8092 (wording): changes two translatable strings.
  - #8101, #8102, #8098, #8095 with #8121, #8116 with #7815, #8085: unchanged from the v24.0.1 decision in #8128.
  - Features, refactors, Bitcoin Core backports, CI and test-only changes merged since the branch point.

  #8103 (EvoDB left ahead of the coins DB after a reindex) is a candidate that is still open on develop. If it merges before this PR does, its pick will be added here.

  ## How Has This Been Tested?

  Linux x86_64, depends build with `--enable-debug --enable-werror`, GUI enabled. Head is b534385.

  - `dashd`, `dash-qt`, `test_dash` and `test_dash-qt` build cleanly; `dashd -version` reports `v24.0.2`.
  - `test_dash` (1106 cases), `test_dash-qt` and `test/util/test_runner.py` pass. That includes the picked unit tests: `allocator_tests/mt_pooled_secure_allocator_reuses_all_chunks` (#8115), `coinjoin_tests/coinjoin_maintenance_runs_for_every_wallet` (#8113) and the orphan-vote case in `governance_vote_processing_tests` (#8112).
  - The full functional suite (`test_runner.py -j14`): 312 passed, 12 skipped, 1 failed. The skipped ones are the usual environment-dependent tests (`feature_bind_port_*`, `rpc_bind.py --ipv6`, `interface_usdt_*`, previous-release compatibility and `feature_unsupported_utxo_db.py`). The run includes the scenarios the picks add or extend: `feature_governance.py` (#8112), `feature_stats.py` (#8119) and `interface_bitcoin_cli.py` (#8120).
  - The failure was `feature_llmq_is_cl_conflicts.py`, in `mine_cycle_quorum`: the node logs show the block for the final commitments being built about 40 ms before the second quorum's final commitment reached the mining node, so that quorum was not mined. It is a timing race in the test helper under load, in code none of the picks touch (develop reworked those waits in #7892). Run again on its own four times in parallel, it passed all four.
  - **Leak, end to end.** A regtest script (not part of the tree) mines a single-member InstantSend quorum, sends InstantSend-locked transactions and reads `getmemoryinfo` `locked.used` on each node every 50 locks.
    - The published v24.0.1 Linux binary: the four non-masternode nodes go from 39,568 bytes to 467,664 bytes over 600 locks, and are still growing at the end.
    - This branch: the same nodes stay at 20,096 bytes for all 600 locks.
  - The man pages were regenerated with `contrib/devtools/gen-manpages.py` from this build. They are byte-identical to the committed ones except for the `lock` debug category in `dashd.1` and `dash-qt.1`, which only an `--enable-debug` build lists.
  - The archived v24.0.1 notes are byte-identical to the previous `doc/release-notes.md`.

  Not tested: the macOS shutdown crash itself. The GUI change is the upstream one-liner and was built and run through `test_dash-qt` on Linux only.

  ## Breaking Changes

  None. No consensus change, and no change to which P2P messages a node accepts or how it scores peers. A node that syncs governance from a v24.0.2 node receives the same inventories as before; other peers of that node no longer receive them.

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(if you have permission to set one)_

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: 6d9861f4a8c2341889bb0ce5dd500a7083ea59395777a21c5e5d01e70ec8e8b489cf6425bc26ca79f15b1919610ceab10baada361043322dc689b7dfcae7cb5d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants