Repository navigation
Description
Problem
An identity-funded shield (ShieldFromIdentity, Type 21) writes a durable retry record to shielded_pending_spends before it broadcasts. Every later identity shield calls has_unresolved_identity_shield (wallet/shielded/operations.rs) first and refuses with ShieldedIdentityDebitPending (55) while that record is unresolved. This guard is what makes "do not retry after ShieldedSpendUnconfirmed" safe across restarts: the next identity nonce cannot be used for a second debit until the first is reconciled or explicitly abandoned.
Two destructive paths delete the guard without checking it:
NetworkShieldedCoordinator::clear→FileBackedShieldedStore::purge_all_subwalletsrunsDELETE FROM shielded_pending_spendsfor every wallet.- Wallet removal → coordinator unregister →
purge_wallet(wallet_id)deletes that wallet's rows.
clear() already orders the tree reset first so that a failed clear keeps the guards (comment in coordinator.rs), but a successful clear, and every removal, deletes them.
Two timings
- While the shield is running. Clear and removal take the coordinator
lifecyclelock; the shield holds onlyshield_guard. A reset during proof construction or the broadcast/result wait deletes the record while the transition can still execute. (Live exclusion is swift-sdk/platform-wallet: hold native-op admission and the generation guard across shielded spends #5868.) - After an ambiguous return. The call returns
ShieldedSpendUnconfirmed; no operation is in flight. The host clears shielded storage, or removes and re-imports the wallet. The guard is gone, so a new call signs a fresh transition with the next nonce. If the first one executed, the identity is debited twice. swift-sdk/platform-wallet: hold native-op admission and the generation guard across shielded spends #5868 does not cover this.
With shieldedShieldFromIdentityToRecipient (Swift since #5863, Kotlin in #5896), the second debit pays a third party, so it is a loss rather than a move between the user's own balances.
Fix direction
The decision belongs in rs-platform-wallet, so every host (Swift, Kotlin, direct C callers) gets it:
- Before mutating anything,
clear()and wallet removal check for unresolved identity-debit records and refuse with a typed error while any exist, unless the caller has resolved them or explicitly abandoned them through the existing acknowledged-abandon path (identity_user_abandoned). Refusal fits removal better than keeping rows for a deleted wallet. - Alternatively for clear:
purge_all_subwalletskeeps unresolved identity-debit rows (empty-nullifier redrives that are not abandoned) and rebind restores them. - Together with swift-sdk/platform-wallet: hold native-op admission and the generation guard across shielded spends #5868, exclude destructive operations from a running identity shield.
- Map any new error code in Swift (
PlatformWalletResult.swift) and Kotlin (DashSdkError.kt), and update theclearShielded/clearShieldedStorageanddeleteWallet/removeWalletdocs to distinguish call completion from reconciliation.
Tests
Wallet-level tests for both timings:
- a reset and a removal while an identity shield is suspended mid-broadcast;
- a reset and a removal after the shield returned
ShieldedSpendUnconfirmed, followed by rebind or re-import and a second identity shield, which must be refused.
Context
Raised by the automated review on #5896 (Kotlin shieldedShieldFromIdentityToRecipient). It applies equally to the existing self-shield and to Swift's binding from #5863. A binding-level counter was tried in #5896 and reverted, because it covered one wrapper and only the live call.
Related: #5868 (live exclusion of shielded spends from destructive operations; this issue covers the case after the call returns), #5918 (the opposite failure: an identity shield's retry record kept armed), #5988 (the same clear() / purge_all_subwallets path), #5989 (the Kotlin clear flow that calls clearShieldedStorage), #5675 and #3706 (other work not fenced against clear or removal), #6010 (telling hosts a request is blocked by an earlier payment, which a new refusal would join).
Activity
QuantumExplorer commentedon Nov 23, 2026
One more ordering for the fix here, from the review of #6178 (the live exclusion from #5868).
With #6178, a removal or a Clear issued while an identity-funded shield is still building its proof no longer runs under the shield: it waits for the shield to return (and once #6182 lands, Clear is refused instead of waiting). If that shield returns
ShieldedSpendUnconfirmedwith its retry record armed, the removal that was waiting then proceeds and purges the record. That is timing 2 of this issue, reached without a second user action: the request was made before the record existed and is carried out after.So the check this issue asks for ("refuse while unresolved identity-debit records exist") has to run after the destructive call holds its exclusion (the wallet generation's teardown gate for removal, the coordinator's operation admission for Clear), not before it starts waiting. A check made up front would pass, and the purge would still happen once the shield returns. The test list should include: a removal requested while an identity shield is held before its record is written, where the shield then returns unconfirmed; the removal must be refused and the record kept.
Claudius-Maginificent commentedon Nov 27, 2026
Clear can delete pending-spend guards before a later purge error, while the wallet stays bound
A related failure order, found while reviewing dashpay/dash-evo-tool#1255 at pin
d6556f98:purge_all_subwallets(file_store.rs, around lines 1944-1956) commitsDELETE FROM shielded_pending_spendsand then runstoken_pool::purge_all, with no shared transaction. If the token-pool purge fails, the clear reports an error, but the pending-spend guards are already gone while the coordinator stays bound to the wallet. A later spend can then reuse a note whose earlier spend is still unresolved.The fix proposed here, keeping unresolved identity-debit rows during the purge, would also cover this case. Running both deletes in one transaction would close it independently.
🤖 Generated with Claude Code