Repository navigation
fix(history): correct CoinJoin mixing nets and keep the Mixing rows in step - #1599
Conversation
When a restore processes a mixing round before the transactions that funded its inputs, the SDK stores the round with netAmount = +(our outputs) instead of the true net (0 for a pure denomination round). rust-dashcore#979 fixes this in the engine; stores without it keep the wrong value (236 of 5,070 rounds, +84.41 DASH, on Wallet A; 52 of 1,526, +4.79 DASH, on Wallet B). For every CoinJoin row, funded - spent over the TXO mirror equals the correct net. reattributed() now also flags CoinJoin rows (transactionTypeKind 1, direction COINJOIN) with confirmed spent evidence and corrects only their net to fundedOwned - spentOwned (recomputeCoinJoinRecordNet). Direction and fee are kept. A correct row produces an equal record: no payload fetch, no write, no log. A correction needs payload facts and passes the mirror-completeness guard, otherwise it is deferred. It is persisted through the existing compare-and-set on the row's current values. The flag is structural, so a partial recompute made mid-sync is recomputed again until the spent marks are complete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
planMixingGroupUpdates adds a member's net once, when the member is first grouped, and skips it after that. During a restore a round is often grouped while its record still has the income-only net. When the record is corrected later (by the engine via rust-dashcore#979, or by the walker's CoinJoin re-net), the group row keeps the old sum. Measured on pulled stores with #979: Wallet A showed +1.86290304 where its members sum to -0.08511644; Wallet B showed +4.78013929 where they sum to -0.01190863. Each coinjoin_<date> group row is now recomputed from its tx_group_cache members: value = sum of the current nets of the members the SDK store holds, count = member count (planMixingGroupResum). The re-sum runs: - after every complete reconcile walk, once per group, as actions on the pipeline's sequential collector so it never races syncDisplayCache; - when the walker persists corrections (onCorrectionsPersisted -> CutoverUiSource.observeCorrectedRecordTxids), for the groups holding a corrected txid. Members are read in keyset pages of 500 and their nets through the walker's served (reattributed) records, chunked. Only rows whose value or count differ are written, and only those two columns, through a targeted UPDATE, so memos, rates and titles are never touched. Members missing from the SDK store are left out of the value and logged once per group. A group with no member in the store is left as it is. Non-CoinJoin groups are never touched. A dashj-era row for the same date shares the id and is re-summed the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a store with rust-dashcore#979 the engine has already persisted the fully attributed net. During a restore the TXO mirror's spent marks can still be incomplete, so funded - spent reads higher than the truth. The re-net used to overwrite the correct value with that partial one, and if an input's txos row never lands (the rust-dashcore#1006 class) the wrong value would have been permanent. recomputeCoinJoinRecordNet now refuses any recompute higher than the stored net. Without #979 the stored net is born too high and each new spent mark only lowers the recompute, so corrections still move down to the truth. With #979 a partial recompute is higher and is left alone: no payload fetch, no write, no log. Accepted cost: a CoinJoin net stored too low (an output missed at the time) is never raised by the walker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (2)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
✅ Final review complete — no blockers (commit eb6810b) · triage: normal |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Static verification at eb6810b supports both reviewers' clean assessments: CoinJoin corrections only lower the net behind the mirror-completeness guard, preserve direction and fee, and use compare-and-set persistence. Mixing groups are re-summed through paginated member reads and targeted value/count updates, with regression tests covering convergence, incomplete evidence, missing members, and correction signals; no concrete in-scope issue was identified. Builds and tests were not run, and the supplied CI snapshot contains only a successful CodeRabbit check, so the author's reported test results remain independently unverified.
Review provenance
Source: reviewer 1: gemini-3.8-flash-high (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.1-sol(effort low) — The changes involve substantial history reconciliation and paginated group aggregation logic, but do not change funds movement, coin selection, consensus, cryptography, network deserialization, or storage migrations. - Phase 1 reviewers:
gemini-3.8-flash-high— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
gemini-3.8-flash-high— antigravity quota: weekly 85% left, 5h 100% left - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer
#1599 added a second batch read to SdkTxStoreWalker with the same name and parameter type as this one, differing only in return type: fun recordsFor(displayHexes: Collection<String>): List<L1TxUiRecord> // #1599 fun recordsFor(displayHexes: Collection<String>): Map<String, …> // here Kotlin cannot overload on return type. Whichever of the two merges second breaks the branch it lands on — "Conflicting overloads" at both declarations, then "Overload resolution ambiguity" at both call sites. Neither PR conflicts textually, so git merges them clean and only the compiler sees it. Found by trial-merging the two for a QA integration build. Renaming this one keeps the change inside an unmerged PR; #1599 is already merged into chore/sdk-int28. The two reads are not the same operation and should not share a name anyway. #1599's skips the membership probe because its caller already knows the txids are the wallet's (the per-day "Mixing" group re-sum reads its own tx_group_cache members); this one applies the membership rule and keys the result by display hex. The KDoc now says so. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
#1597) * chore(sdk): pin Kotlin SDK 0.1.0-v42int28-SNAPSHOT int28 = int27 without dashpay/platform#4740. The DashPay receive path is upstream #5026 (up to 72b34c0e7b: the stale-debt fix and review rounds 7-8), the fork's one-way contact receival, and #4439 + 56f6c055df, which sends the full account tuple in TXO classification. That last one fixes "malformed outpoint queries: missing field standardTag". The base, engine (d20ecf6a) and Room schema (15) are unchanged. Published as 0.1.0-v42int28-20261002.062748-1 from HashEngineering/platform integration/v42int28-pin @ 4dd8e3d0a2. Device check on topple, int27 -> int28 in place: - the 72-byte record resumed for the 8 known contacts; - the 3 one-way contacts got receiving accounts and one rewind, which found a previously missed contact payment; - the TXO reconcile is consistent; - a relaunch did not rewind. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(sdk): pin the exact int28 SDK build, not the SNAPSHOT name 0.1.0-v42int28-20261002.062748-1 is the build tested on device. A SNAPSHOT name can be republished, which would change what a later build gets with no source change. Resolves from the Sonatype snapshots repo; the AAR is byte-identical to the tested one (sha256 57044712...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore(sdk): pin Kotlin SDK v42int29 (0.1.0-v42int29-20261007.000257-1) The only int29 build on Sonatype. Built from HashEngineering/platform integration/v42int29 @ 762b2ddcdd; the published AAR matches the local build (sha1 f75ebc71). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(history): correct CoinJoin mixing nets and keep the Mixing rows in step (#1599) * fix(walker): re-net CoinJoin rounds stored income-only When a restore processes a mixing round before the transactions that funded its inputs, the SDK stores the round with netAmount = +(our outputs) instead of the true net (0 for a pure denomination round). rust-dashcore#979 fixes this in the engine; stores without it keep the wrong value (236 of 5,070 rounds, +84.41 DASH, on Wallet A; 52 of 1,526, +4.79 DASH, on Wallet B). For every CoinJoin row, funded - spent over the TXO mirror equals the correct net. reattributed() now also flags CoinJoin rows (transactionTypeKind 1, direction COINJOIN) with confirmed spent evidence and corrects only their net to fundedOwned - spentOwned (recomputeCoinJoinRecordNet). Direction and fee are kept. A correct row produces an equal record: no payload fetch, no write, no log. A correction needs payload facts and passes the mirror-completeness guard, otherwise it is deferred. It is persisted through the existing compare-and-set on the row's current values. The flag is structural, so a partial recompute made mid-sync is recomputed again until the spent marks are complete. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(history): re-sum Mixing group rows from their members' current nets planMixingGroupUpdates adds a member's net once, when the member is first grouped, and skips it after that. During a restore a round is often grouped while its record still has the income-only net. When the record is corrected later (by the engine via rust-dashcore#979, or by the walker's CoinJoin re-net), the group row keeps the old sum. Measured on pulled stores with #979: Wallet A showed +1.86290304 where its members sum to -0.08511644; Wallet B showed +4.78013929 where they sum to -0.01190863. Each coinjoin_<date> group row is now recomputed from its tx_group_cache members: value = sum of the current nets of the members the SDK store holds, count = member count (planMixingGroupResum). The re-sum runs: - after every complete reconcile walk, once per group, as actions on the pipeline's sequential collector so it never races syncDisplayCache; - when the walker persists corrections (onCorrectionsPersisted -> CutoverUiSource.observeCorrectedRecordTxids), for the groups holding a corrected txid. Members are read in keyset pages of 500 and their nets through the walker's served (reattributed) records, chunked. Only rows whose value or count differ are written, and only those two columns, through a targeted UPDATE, so memos, rates and titles are never touched. Members missing from the SDK store are left out of the value and logged once per group. A group with no member in the store is left as it is. Non-CoinJoin groups are never touched. A dashj-era row for the same date shares the id and is re-summed the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(walker): only ever lower a CoinJoin round's net On a store with rust-dashcore#979 the engine has already persisted the fully attributed net. During a restore the TXO mirror's spent marks can still be incomplete, so funded - spent reads higher than the truth. The re-net used to overwrite the correct value with that partial one, and if an input's txos row never lands (the rust-dashcore#1006 class) the wrong value would have been permanent. recomputeCoinJoinRecordNet now refuses any recompute higher than the stored net. Without #979 the stored net is born too high and each new spent mark only lowers the recompute, so corrections still move down to the truth. With #979 a partial recompute is higher and is left alone: no payload fetch, no write, no log. Accepted cost: a CoinJoin net stored too low (an output missed at the time) is never raised by the walker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> * chore(sdk): pin Kotlin SDK v42int30 (0.1.0-v42int30-20261009.200225-1) int29 plus #5026's newer backfill-record commits, #5256 (docs) and the SDK fallback that opens DashPay contact requests dashj encrypted with its altered ECDH key. Built from HashEngineering/platform integration/v42int30 @ c4a2b6e83d; the published AAR matches the tested build (sha256 809c0267). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(history): never overwrite a Mixing group total with partial SDK history planMixingGroupResum replaced a group row's value whenever at least one member had an SDK record, summing only the members the store held while keeping the full member count. dashj-era groups share these group ids, so a complete cached total (-300 = -100 + -200) became -100 when the store held only the first member, and stayed truncated until the missing record arrived. A member the store does not hold has an unknown net, not a zero one: the row is now rewritten only when every member has a current SDK net; otherwise it keeps its cached value and count. The partial-member regression tests now protect the complete cached value and check the group converges once the missing record arrives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(history): read Mixing group members off the tx-feed collector A group re-sum read every member of a group (one 500-txid page at a time) inside a single action on txPipeline's sequential collector, so a large group held every live transaction and InstantLock event until the whole group had been read. The reads now run in a child worker coroutine of txPipeline, one group at a time. Each group's tally (member count, present count, net sum, and the row's value/count when the read began) comes back through the collector's lane and is written there. Before writing, the collector re-checks that the row's value and count are unchanged and the group's member count (new TxGroupCacheDao.countGroupMembers) still matches; a group that gained members meanwhile is queued again and re-read rather than overwritten with a sum that misses them. The worker waits for each write before reading the next group. Re-sum requests (reconcile walk, store corrections) go through MixingResumQueue, which coalesces them by group id; a group requested while its re-sum is running is queued once more, never once per request. The result is unchanged. Tests: a transaction event is rendered while a 3-page group re-sum is held between pages; a group that grows mid-read is re-read and written once, complete; queue coalescing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(history): don't re-queue a Mixing group from its own re-sum reads recordNetsFor() read group members through a walker that reports every correction it persists on observeCorrectedRecordTxids. A re-sum reading a group whose members still carried stale nets therefore reported one correction batch per corrected 500-member page, and each batch queued a full re-sum of the same group again: up to ~20 redundant full-group passes for a 10,000-member group, although the running re-sum had already read the corrected nets. recordNetsFor() now reads through a walker with no corrections listener (the correction is still persisted; only the signal is dropped), and the CutoverUiSource contract says so. Corrections reported by other walkers while a re-sum runs are still coalesced by group id (MixingResumQueue): at most one more pass, never one per batch. Tests: a 10,000-member group whose reads each report their page as corrected costs exactly two passes (40 reads), one write, then settles; a walker without the listener still persists the correction once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(history): treat SDK store stubs as absent in the Mixing group re-sum A TXO-parent stub (L1TxUiRecord.isStoreStub: zero timestamp, zero net, no transaction data) was returned by recordNetsFor as a member net, so tallyMixingGroup counted the member as present and the all-members-present guard passed with a placeholder zero: a cached -300 (-100 + -200) became -100 when one member was real and the other still a stub. The member nets now go through a pure mixingMemberNets helper that drops stubs, exactly like a txid the store does not hold. The group keeps its cached total until the stub becomes its real transaction, then re-sums. Regression: one real member + one stub keeps the cached total; replacing the stub with its real record re-sums the group to the full value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
#1603) * fix(metadata): keep metadata for transactions only the SDK store holds WalletTransactionMetadataProvider derived a metadata row only from a dashj wallet Transaction. A transaction the Kotlin SDK found on its own, such as a DashPay one-way-contact receive from the contact backfill, is absent from the held dashj wallet, so opening its details logged "DROPPED — no wallet tx and no fallback row" and its memo, exchange rate and other platform metadata were never shown (topple testnet, tx e5169bfc, 2026-10-02). When the dashj wallet lacks the tx, the provider now asks the SDK store through a new SdkTxMetadataSource, implemented by SdkTxDetailProvider. That lookup reads only the SDK transactions row plus the tx_display_cache correction, with no consensus decode, and never starts the SDK. The row is then filled from the platform metadata documents exactly as for a dashj tx. A caller-supplied fallback row is still used when neither store has the tx. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(metadata): batch SDK store lookups during a platform metadata sync Review follow-up. With a wallet bound, each SDK metadata lookup built a walker and ran recordFor(), whose reattribution reads the wallet-wide pending_inputs aggregate (and may run it again for fee recovery). Platform sync imports one transaction at a time, so a sync of N SDK-only transactions repeated that wallet-wide read N times. - SdkTxStoreWalker.recordsFor(): batch recordFor over the existing chunked relevance probe and record query, so one reattribution pass, and one pending aggregate, covers the whole set. - SdkTxMetadataSource gains a batch defaultMetadataFor(txIds). SdkTxDetailProvider implements it with one walker pass and chunked tx_display_cache reads. correctedRecord() now takes its inputs, so the detail sheet and both metadata paths share it unchanged. - TransactionMetadataProvider.withBatchedImport(txIds, block): the wallet provider prefetches SDK rows for the txids with no metadata row and no dashj tx, and carries them in the coroutine context for that block only. Default implementation just runs the block. - PlatformSyncService wraps the fetched-document loop and the one-shot re-merge loop in it. Those hunks are re-indents apart from the wrapper. Tests: a Robolectric walker test on the real store asserts recordsFor() matches recordFor() per txid, including a pending-reservation send, and runs the pending aggregate at most twice for 22 txids. Provider tests assert one batch lookup per sync and no per-txid lookups. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(sdk-store): name the batch read recordsByHex, not recordsFor #1599 added a second batch read to SdkTxStoreWalker with the same name and parameter type as this one, differing only in return type: fun recordsFor(displayHexes: Collection<String>): List<L1TxUiRecord> // #1599 fun recordsFor(displayHexes: Collection<String>): Map<String, …> // here Kotlin cannot overload on return type. Whichever of the two merges second breaks the branch it lands on — "Conflicting overloads" at both declarations, then "Overload resolution ambiguity" at both call sites. Neither PR conflicts textually, so git merges them clean and only the compiler sees it. Found by trial-merging the two for a QA integration build. Renaming this one keeps the change inside an unmerged PR; #1599 is already merged into chore/sdk-int28. The two reads are not the same operation and should not share a name anyway. #1599's skips the membership probe because its caller already knows the txids are the wallet's (the per-day "Mixing" group re-sum reads its own tx_group_cache members); this one applies the membership rule and keys the result by display hex. The KDoc now says so. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix(metadata): address review on the SDK metadata batch - Keep only payload-free records in the batch. Each SDK store row is turned into its L1TxUiRecord as soon as it is read, so the serialized transaction is not held for the whole batch; a restore's re-merge can batch thousands. correctedRecord() now takes that record; the arithmetic is unchanged. - Prefetch only what the fetch loop will import. importableTxIds() skips documents already held (the fetch window overlaps by 10 minutes) and any item whose txid is not 32 bytes, which Sha256Hash.wrapReversed would throw on and abort the whole fetch before any document is processed. - KDoc for the production functions this PR changes that had none. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(metadata): batch SDK lookups in the past-metadata upload too Review follow-up. publishPastTxMetadata() reads metadata one transaction at a time, so each SDK-only transaction without a row ran its own walker pass and wallet-wide pending_inputs aggregate. Wrap its loop in withBatchedImport over the transactions it will read, like the fetch and re-merge loops. The loop body is only re-indented. Also update two comments that still named the batch read recordsFor; it is recordsByHex since cb90546. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Issue being fixed or feature implemented
Two history problems with CoinJoin mixing rounds on the Kotlin SDK. Neither affects the balance.
processed before the transactions that funded its inputs: the record is saved with
net = +(our CoinJoin outputs)when the true net is 0. On two testnet wallets this was 236 rounds (+84.41 DASH)and 52 rounds (+4.79 DASH).
SdkTxStoreWalkeralready recomputes the net of Standard sends and receives fromthe TXO table, but it never looked at CoinJoin rows.
the member is first grouped. During a restore that often happens before the record is corrected, and the group
row was never added up again. With [NMA-1315] Crowdnode minor fixes #979 the stored records are right, but the visible rows showed +0.35 to
+4.79 DASH on the same wallet across runs, against a true sum of −0.012.
Stacked on #1597 (
chore/sdk-int28).What was done?
SdkTxStoreWalker: re-net CoinJoin rounds (463b17edc,eb6810bb2).transactionTypeKind = 1, direction COINJOIN) that have spent evidence go throughrecomputeCoinJoinRecordNet:net = fundedOwned − spentOwned.additional spent mark only lowers the recompute. With [NMA-1315] Crowdnode minor fixes #979 the stored net is already fully attributed, so a
recompute from incomplete spent marks (mid-restore, or an input row that never lands) is higher and is
refused. The walker never makes an engine-correct net worse.
94ae13f49).planMixingGroupResumandresumMixingGroupsset eachcoinjoin_<date>row's value to the sum of itsmembers' current nets, and its count to its member count.
hold those txids).
they differ. Members missing from the SDK store are left out of the sum, and that can't cause a write loop.
How Has This Been Tested?
Unit tests:
SdkTxStoreWalkerTest: 37 passed, 8 of them new.CutoverUiDataServiceTest: 98 passed, 3 of them new.the sum, a 1,203-member group is summed across pages, and a second walk writes nothing;
--rerun-tasks): 2,301 tests, 2 failures. Both fail identically on the basecommit
d22cce4a5(2,290 tests, the same 2 failures), so this PR adds none:PlatformSyncEngineRestartTest.resume_isRearmableAcrossRepeatedStopRestartCyclesfails on the base too, inthe full suite and on its own;
AssetLockKindResolverNegativeCacheTest.nullTransactionKind_isNotPinned_soLateUnshieldStillResolvesfails inthe full suite on the base too and passes on its own. It depends on test order: an earlier test leaks a
coroutine.
On an Android emulator (Pixel 9 AVD), restoring from seed:
Breaking Changes
None.
Checklist
🤖 Generated with Claude Code