Skip to content

fix(cutover): migrate CoinJoin funds through bounded consolidation - #1607

Merged
HashEngineering merged 40 commits into
feat/kotlin-sdk-phase-1from
codex/d-068-coinjoin-spendable
Oct 24, 2026
Merged

HashEngineering merged 40 commits into
feat/kotlin-sdk-phase-1from
codex/d-068-coinjoin-spendable

Conversation

@HashEngineering

@HashEngineering HashEngineering commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Addresses D-069: CoinJoin funds are included in the wallet header after SDK cutover but excluded from ordinary sends. Restore the migration prompt and provide a working route to either the shielded balance or the wallet's BIP44 balance.

For shielding, accounts with more than 100 outputs first consolidate within CoinJoin account 0. Select an unused external address from the SDK's persisted CoinJoin address pool. Build ordinary transactions with at most 500 inputs, keeping both the payment and any change on that address, until the account has at most 100 outputs. Smaller accounts proceed directly to the dedicated CoinJoin asset-lock API. No BIP44 funds participate in shielding.

The regular-balance option also uses 500-input consolidation batches. Accounts above 500 outputs consolidate within CoinJoin first, then the remaining outputs drain to the wallet's saved BIP44 destination. The final transfer is checkpointed before broadcast and must settle before the migration completes. Both options support retrying the persisted migration without replacing an uncertain transaction.

Migration requires completed blockchain sync and agreement between the persisted CoinJoin UTXOs and the engine's confirmed balance. Each consolidation must become InstantSend-locked or confirmed and its resulting outputs must reach persistence before the next step. Inspect the signed consolidation's input count, input ownership, and output destinations before broadcast.

Persist the destination, stage, wallet identity, and transaction ID before broadcasting consolidation. Resume observation after app locking or restart; uncertain submissions are not rebuilt. Existing pending asset locks block new funding and are resumed through the SDK recovery API. The activity-scoped migration presentation survives auto-lock, with Later, a Tools entry, retry, and explicit completion states.

A shield migration completes only when the SDK records its own asset lock as Consumed. Platform's AssetLockAlreadyConsumed answer is not authenticated, so it never completes, clears, or releases a migration's own record. It only stops retrying a lock whose inputs are already final on L1 (InstantSend-locked, ChainLocked, or recovered). Such a lock no longer blocks a new drain or another migration's proof. Adopted records and invalid stages held only by such locks return to the choice without recording success. When a shield record can no longer be proven, either because its own lock is in that state or because it is a legacy record with no saved inputs over an empty, synced CoinJoin account, the "could not confirm" sheet offers a confirmed "Close this migration". Closing drops the record without recording success.

Consolidation publicly links the inputs it combines.

Validation

  • 20 affected testnet3 unit tests passed: 12 consolidation tests, two recovery tests, and six migration ViewModel tests. Migration detection and dedicated shield funding tests passed in the preceding validation.
  • Tests cover address selection, acceptance of 500 inputs and rejection of 501, sync/persistence gates, finality before shielding or regular-transfer completion, restart without duplicate consolidation, direct shielding for small accounts, and synthetic 2,000-output wallets exercising both migration options. Regular-transfer tests also cover a single-input drain and retrying saved progress without starting another migration.
  • The latest targeted run (*CoinJoin*, *MixedFundsMigration*, *ShieldedBalanceService*, *SdkL1Send*, *SeamOutputLock*, *MainViewModel*) passed 423 tests with one skipped. Mutation checks cover the Consumed-only proof, retry suppression, the release paths, and each "Close this migration" condition.
  • Testnet3 debug APK builds successfully.
  • No live migration transaction was submitted as part of these automated tests; emulator testing of the new flow remains necessary.

Remaining Recovery Limitation

This change does not discard previously persisted rejected asset locks. A process death between saving a consolidation transaction ID and submitting it can leave an uncertain checkpoint: recovery observes that transaction and will not silently construct a replacement. The pinned SDK does not expose a durable raw-transaction rebroadcast API through this path.

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

2 participants