Repository navigation
fix(swift-sdk): admit shielded spend wrappers as native operations - #6179
Conversation
The shielded spend wrappers on PlatformWalletManager ran their FFI call from a detached task without admitNativeOp / finishNativeOp, so deleteWallet passed its in-flight check and shutdown() destroyed the native manager while a payment was still proving or broadcasting. Admit the thirteen that were not: transfer, shield, shield to recipient, shield from identity, unshield, withdraw, identity top-up and identity create from the pool, token purchase from the pool, fund from asset lock, fund from CoinJoin drain, pool seeding and identity debit abandonment. Their native calls go through an injectable table so tests pause each wrapper in flight without reaching Rust. Refs #6060, #5868 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Warning Review limit reachedYou'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 11 minutes. View limit details
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. |
|
⛔ Final review complete — 1 blocking finding(s) (commit 6adcc91) · triage: normal |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (queue backlog)
Changes requested: 1 blocker
- Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock —
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift:153-159(new)
Impact: An iOS host that stops SPV and replaces the wallet manager while a broadcast asset lock still needs finality can be left with an unusable old manager and no active replacement.
This PR holds Swift native-operation admission through the result of thirteen shielded wallet calls and adds XCTest coverage using injected native exports. The Swift frozen-schema check passed; the Swift build-and-test and Kotlin SDK checks were still pending.
🔴 1 blocking | 🟡 3 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 8: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The change applies native-operation tracking across thirteen Swift wrappers, requiring review of cancellation and shutdown behavior without changing how funds are moved. - Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
- Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift:153-159: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock
Impact: An iOS host that stops SPV and replaces the wallet manager while a broadcast asset lock still needs finality can be left with an unusable old manager and no active replacement.
A same-network SDK rebuild can now strand the active wallet manager, not just the payment. The Send screen calls this wrapper directly (`SendViewModel.swift:1051`), so the funding check in `OptionsView.swift:692–696` misses it and the rebuild stops SPV before awaiting the old manager's shutdown (`WalletManagerStore.swift:317`). The fresh funding and CoinJoin drain exports pass no ChainLock deadline (`shielded_send.rs:2325–2327, 2483–2485`); without a locally usable proof, the Rust loop only retries and never checks for shutdown (`asset_lock/sync/proof.rs:769–774`). The new admission makes shutdown wait for that call after revoking the handle needed to restart SPV (`PlatformWalletManager.swift:1021–1025, 1058–1062`). Keep the handle fence, but signal the Rust funding flow before draining so it can return a pending result with the tracked outpoint intact. Have seeding stop at a safe batch boundary as well. Cover shutdown after SPV stops without delivering a covering ChainLock; releasing a mocked export does not exercise this path.
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift:248-254: Asset-lock funding remains outside the PR's stated Clear protection
Impact: A host that clears shielded state during asset-lock funding, a CoinJoin drain, or a seed batch can see Clear succeed and then receive an activity write from that same call.
The PR description says Clear will refuse these payments once the companion changes land, but that guarantee does not cover the asset-lock paths. Swift `clearShielded()` does not read the new admission count, and #6178 does not add coordinator admission to these paths. Native funding takes `shield_guard`, which coordinator Clear does not take, then records the landed shield through the wallet's persister (`fund_from_asset_lock.rs:211, 615–616, 798–807`). Changing Clear to a retryable refusal in #6182 therefore does not fence that write. Narrow the description to Swift deletion and shutdown, and keep the asset-lock Clear gap tracked on v5.1. The Clear epoch check proposed in #5934 shows how to reject the stale write without making Clear wait for finality.
In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ShieldedSpendAdmissionTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ShieldedSpendAdmissionTests.swift:326-331: The shutdown test hangs if a wrapper leaks its admission
Impact: A regression that leaves the admission count above zero can make Swift CI hit its job timeout instead of identifying the wrapper that prevented shutdown.
After the fake native call is released, `call.value` can return even if the wrapper forgot to release admission. The next `await shutdown.value` then waits indefinitely on the manager's drain continuation; the recorder's semaphore timeout no longer applies. Have the shutdown task fulfill a wrapper-specific XCTest expectation, and exit the case on timeout rather than awaiting an unfinished task. The rejection and cancellation tests have the same unbounded final await.
In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1063-1067: The new spend wrappers duplicate the existing admission sequence
Impact: A future change to the admission helper can update token spends and asset-lock resume while leaving the thirteen newly guarded wrappers with different teardown behavior.
`withAdmittedNativeOperation` already covers the same lifetime: it admits on the main actor, captures the handle, awaits a detached native call and its result conversion, and releases admission even when the call throws. Use it for wrappers that have no separate main-actor work after the native result. Capture the injected call table before entering the helper, and keep the signer or resolver alive while reading its raw pointer inside the closure, as `shieldedTokenTransfer` already does.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Clear can still erase recovery state during a token purchase — Token purchase holds the wallet-generation guard but not the coordinator's operation guard. Clear can still remove saved recovery state while the purchase proceeds; the new Swift handle admission does not change that ordering.
- Follow-up: Resolve #6176 in the Rust wallet and test that Clear refuses while a token purchase is paused with recovery state saved.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
Review follow-up on the shielded spend admission: - shieldedFundFromAssetLock, shieldedFundFromCoinJoinDrain and seedShieldedPoolNotes are not admitted after all. The fundings wait for a ChainLock with no deadline and a seeding run lasts tens of minutes; shutdown() cannot cancel a native call, so admitting them let shutdown hang once the host had stopped SPV (#6003). Ten bounded wrappers stay admitted; - those ten go through withAdmittedNativeOperation instead of repeating its admit / detach / finish sequence; - every wait in ShieldedSpendAdmissionTests is bounded, so a wrapper that leaks its admission fails the test by name instead of hanging. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Changes requested: 1 blocker
- Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock —
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1236-1237(carried)
Impact: An iOS host that stops SPV to reconfigure a manager while a Platform-credit shield is queued behind Core funding on the same wallet can be left with a revoked manager and no active replacement.
New on this head: This revision routes ten shielded-payment and recovery wrappers through the shared native-operation admission helper, leaves fresh asset-lock funding and pool seeding unadmitted, and bounds the tests’ completion waits. The Tests workflow was pending and the Kotlin build and tests were queued; no code check had failed, and there was no Swift build or test result against this head’s native library.
🔴 1 blocking
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The ten wrappers change when Swift admits native calls and releases the wallet manager, so cancellation and shutdown ordering warrant review, but the diff does not change how funds are selected or moved. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(lane failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1236-1237: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock
Impact: An iOS host that stops SPV to reconfigure a manager while a Platform-credit shield is queued behind Core funding on the same wallet can be left with a revoked manager and no active replacement.
Removing admission from fresh funding fixes the funding-only case, but a second call can still make manager replacement wait indefinitely. A host can call `shieldedFundFromAssetLock` with spendable Core funds, then call `shieldedShield` using existing Platform credits on the same wallet while the asset lock is pending. Neither public wrapper refuses the overlap. Both native exports resolve the same wallet, and funding holds its `shield_guard` across the ChainLock fallback (`fund_from_asset_lock.rs:211–236, 417–420`). The new Swift admission counts the Platform-credit shield before its synchronous export blocks on that same mutex, before input selection (`shielded_send.rs:1221–1237`; `platform_wallet.rs:3094–3115`). An identity top-up from existing shielded notes can queue on the same guard (`platform_wallet.rs:2024–2035`). If the host stops SPV before the wallet applies a covering ChainLock, the funding fallback has neither a deadline nor a teardown signal (`shielded_send.rs:2325–2327`; `asset_lock/sync/proof.rs:751–775`). `shutdown()` has already revoked the public handle and waits for the counted caller before destroying the manager (`PlatformWalletManager.swift:1022–1026, 1059–1063`). The example app demonstrates this teardown order: rebuild stops SPV first, its funding check misses the direct Send funding path, and the replacement is not activated until the old manager shuts down. Neither call in the Platform-credit shield sequence entered the Swift drain on `v5.1-dev`; the new admission makes shutdown inherit the existing finality wait. Keep the handle fence, but make the Rust funding wait respond to teardown while preserving the pending outpoint, or return a retryable busy result before a queued shield builds or broadcasts. Add a regression test that exercises the shared native guard without delivering a covering ChainLock; releasing a mocked export only tests the Swift fence.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- Fresh asset-lock funding and pool seeding still lack teardown protection — The excluded wrappers retain their base behavior: wallet removal can overlap asset-lock funding, and Clear can finish before an in-flight funding call records its activity. That is separate from shutdown now waiting on an admitted caller queued behind funding.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
Five admitted wrappers share a Rust lock with Core asset-lock funding, so one started while a funding is pending on the same wallet queues behind it, and shutdown() then waits as long. A funding can wait for a ChainLock with no deadline. Say so on the five wrappers, on shutdown() and on the two funding calls, whose notes read as if leaving them unadmitted avoided the wait altogether (#6003). Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Changes requested: 1 blocker
- Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock —
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1241(thread, carried)
Impact: An iOS host that stops SPV to replace its wallet manager can be left with a revoked manager and no active replacement when a Platform-credit shield is queued behind Core funding on the same wallet.
New on this head: This revision updates the Swift SDK documentation for shielded-operation admission and shutdown; runtime and test code are unchanged from the previous review. The Swift SDK build and tests and the Kotlin SDK emulator job are pending, with no failed code checks reported.
🔴 1 blocking
Still open from earlier rounds (1)
- 🔴 Blocking: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock —
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1241(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The diff changes admission, cancellation, and shutdown behavior across ten Swift wrappers without changing how shielded payments are constructed, proved, or executed. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(lane failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift:1241: Wallet shutdown can hang if SPV stops before shielded funding gets its ChainLock
(carried; thread: https://github.com/dashpay/platform/pull/6179#discussion_r4673828940)
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix. |
Basic explanation
What this does. When the iOS SDK starts a shielded payment, it now counts that payment as "in progress" on the wallet manager until the payment's result is back. Ten calls that did not do this now do: transfer, shield (three variants), unshield, withdraw, identity top-up and identity create from the pool, token purchase from the pool, and abandoning an identity debit.
Value. A shielded payment takes tens of seconds to prove. Before this, the app could delete the wallet or shut the manager down in that window:
deleteWalletpassed its "nothing is running" check, andshutdown()destroyed the native manager under the payment. NowdeleteWalletis refused while a payment runs, andshutdown()waits for it.Risks.
shutdown()now waits for one of these payments in flight. For five of them (transfer, unshield, withdraw, identity create, token purchase) that is a proof, a broadcast and its result wait.shieldedShield,shieldedShieldToRecipient,shieldedShieldFromIdentity,shieldedIdentityTopUpFromPool,abandonShieldedIdentityDebit) share a Rust lock with Core asset-lock funding, so one started while a funding is pending on the same wallet queues behind it. That funding can wait for a ChainLock with no deadline. If the host has stopped SPV by then, the ChainLock never comes, andshutdown()does not return anddeleteWalletstays refused until the app restarts. No funds are lost and the asset lock stays resumable. It takes a stuck funding, a second shield-class payment on the same wallet and a host that stops SPV before shutting down; in SwiftExampleApp that needs two windows. The base already has the direct form of this throughshieldedResumeFundFromAssetLockand the wallet-drain funding. Let shutdown cancel long-running shielded wallet operations #6003 tracks the fix (shutdown cancels the funding wait); the five wrappers andshutdown()now document it.deleteWallet, the synchronouscreateWallet/createWalletFromSeed/loadFromPersistor) now throwinvalidHandlewhile one of these payments runs.Issue being fixed or feature implemented
Closes #6060 for the payments; its funding calls are tracked in #6003 and its recovery read in #6177. The Swift half of #5868; the Rust half (the wallet's lifecycle gate and Clear's admission held across the credit pool payments) is #6178.
Confirmed on
v5.1-dev: each wrapper below called its FFI export fromTask.detachedwith noadmitNativeOp/finishNativeOp. Already admitted, and unchanged:shieldedTokenTransfer,shieldedTokenUnshield,shieldedTokenSpendPreview,shieldedResumeFundFromAssetLock, the wallet-drain calls,createPrivateDocumentEntry,privateDocumentCreateFee,privateDocumentRecipientKeysand the three private contact request writes.Prior work: #5863 on
v5.2-dev(commitaba2e7bb4a) admits one wrapper,shieldedShieldFromIdentityToRecipient, which does not exist onv5.1-dev. This follows the same shape (admit on the main actor before the detached task, an injectable native call for tests) and stays out of the lines that commit touches, so the forward merge should be clean. No open pull request covered the rest.What was done?
Each wrapper now runs its native call through the existing
withAdmittedNativeOperationhelper, after its parameter checks, the wayshieldedTokenTransferdoes. The helper admits on the main actor, runs the call on a detached task and releases the admission once the result is back. Cancelling the awaiting task does not release it: the detached call is not cancelled, and the helper keeps waiting for it.PlatformWalletManagerShieldedSync.swiftshieldedTransfer,shieldedShield,shieldedShieldFromIdentity,shieldedShieldToRecipient,shieldedUnshield,shieldedIdentityTopUpFromPool,shieldedTokenPurchaseFromPool,shieldedWithdraw,shieldedIdentityCreateFromPoolPlatformWalletManagerShieldedRecovery.swiftabandonShieldedIdentityDebitThe native exports behind them are called through a new function table,
PlatformWalletNativeShieldedSpendCalls(.livein production), so a test can pause a real wrapper inside its native call without a fake handle ever reaching Rust.clearShielded()is deliberately not changed and not gated in Swift. Whether a Clear may run during a payment is decided in Rust: #6182 makes the native Clear return a typed, retryable refusal while a shielded operation runs, and #6178 makes the credit pool payments hold the admission that refusal reads. With all three merged, tapping Clear during one of those payments gives that refusal. Nothing here can deadlock with it: none of the wrappers runs main-actor work between admission and the return of the native call,deleteWalletis refused before any native call, and the callbacks a spend makes (mnemonic resolver, Keychain signer, persister) do not hop synchronously to the main thread. The persister callback bodies were not audited line by line.Before / after
deleteWalletran beside the payment, andshutdown()returned after destroying the native manager while the payment was still in its native call.deleteWalletthrowsPlatformWalletError.invalidHandle("an async native operation is in flight; synchronous deleteWallet rejected"), andshutdown()returns only after the payment has returned its result.Public interface changes
No public signature, type or error case changes. Behaviour changes on
PlatformWalletManager:deleteWallet(walletId:)and the synchronouscreateWallet,createWalletFromSeedandloadFromPersistorthrowinvalidHandle, as they already did beside a token pool transfer or a wallet create.shutdown()waits for them before it destroys the native handle.invalidHandlebefore any native work. It already did, through itsisConfiguredcheck; the admission is now a second check behind it.shieldedFundFromAssetLock,shieldedFundFromCoinJoinDrainandseedShieldedPoolNotesgained a doc note saying they are deliberately not admitted, and are otherwise unchanged.Internal additions (not visible to SDK users):
struct PlatformWalletNativeShieldedSpendCalls, in the newPlatformWalletNativeShieldedSpendCalls.swift: one field per native export, typed as the export is imported into Swift.PlatformWalletManager.nativeShieldedSpendCalls, the test seam, next to the existingnativeTeardownCalls/nativeCreateCalls/nativeLoadCalls.Not covered here
shieldedFundFromAssetLock,shieldedFundFromCoinJoinDrain,seedShieldedPoolNotesstay unadmitted, on purpose. Onv5.1-devthe two fundings wait for a ChainLock with no deadline and a seeding run lasts tens of minutes, andshutdown()cannot cancel a native call. Admitting them let shutdown hang directly once the host had stopped SPV, which SwiftExampleApp's SDK rebuild does (SwiftExampleApp: hold one funding reservation from dispatch to return so an SDK rebuild never stops SPV under a Core funding #6083). Leaving them out does not remove the hang altogether: a shield-class payment queued behind one still holds shutdown, as the Risks say. Let shutdown cancel long-running shielded wallet operations #6003 tracks the cancellation that has to come first; it also coversshieldedResumeFundFromAssetLockand the wallet-drain funding, which were already admitted on the base and already wait this way. On the Rust side these paths hold neither the lifecycle gate nor Clear's admission (platform-wallet: token purchase, private contact request and private document payments do not hold the shielded coordinator's operation admission #6176, platform-wallet: an asset-lock build is not excluded from wallet removal, so a lock can be broadcast for a wallet that is gone #5516), so neither Swift deletion and shutdown nor the Clear refusal protects them yet.shieldedIdentityDebitRecoveryRecords(a read whose native lock wait has no deadline; admitting it without a bound would make shutdown wait behind a scan) andshieldedTokenPoolWatch/shieldedTokenPoolUnwatch: swift-sdk: shieldedIdentityDebitRecoveryRecords parks a thread with no deadline, and token pool watch/unwatch are not admitted #6177.syncShieldedNow/syncShieldedWalletNow: Decide whether manual shielded sync passes are admitted against wallet deletion #6004 owns that decision.ManagedPlatformWallet: swift-sdk: ManagedPlatformWallet identity writes run without native-operation admission, so a manager replacement can overlap their store writes #6082.PlatformWalletManageralready opens withteardownGate.op, andGateCoverageLintTestenforces it; its exposure was the Rust gap that fix(platform-wallet): hold the lifecycle gate and Clear admission across credit pool spends #6178 closes.How Has This Been Tested?
New
ShieldedSpendAdmissionTests, every case through the real public wrappers with only the native exports replaced, and every wait bounded so a leaked admission fails by wrapper name instead of hanging:testShouldRefuseDeleteWalletWhileShieldedTransferIsInFlighttestShouldHoldShutdownUntilEveryPausedSpendReturns(all ten wrappers:deleteWalletrefused, the injecteddestroynot run andshutdown()not finished while paused; result returned anddestroyrun once after release; each wrapper reaches its own export with the right handle and wallet id)testShouldRejectSpendsStartedAfterShutdownBeganWithoutNativeWork(all ten)testShouldHoldAdmissionAfterTheAwaitingTaskIsCancelledWhat ran:
xcodebuild test -scheme SwiftDashSDK -only-testing:SwiftDashSDKTests/ShieldedSpendAdmissionTests -only-testing:SwiftDashSDKTests/PlatformWalletShutdownTests -parallel-testing-enabled NOon an iPhone 17e simulator, in a scratch copy of the package: 19 tests, 0 failures (the 4 new ones and the 15 existing shutdown tests). Swift compiled with no warnings in the touched files.A deliberate leak (an unbalanced admission in
shieldedWithdraw) madetestShouldHoldShutdownUntilEveryPausedSpendReturnsfail in 7.7 s with "shieldedWithdraw: shutdown did not finish within 5.0 s"; the run went on through the other wrappers and the other three tests passed. The leak was then removed and the clean run repeated.The scratch copy linked a simulator xcframework built from a sibling checkout, with headers regenerated from this branch's base. That library predates six exports older code calls (none of them among the ten here), so the link needed scratch-only stubs for those six; no test calls them. The spend exports are replaced by the test table in every case, so the only native code these tests ran was
MnemonicResolverandKeychainSignersetup.Not yet verified
swift testneeds a macOS slice ofDashSDKFFI.xcframework, which no prebuilt copy on this machine has, and I did not start a native build. The "Swift SDK build + tests (warnings as errors)" job on this pull request runspackages/swift-sdk/run_tests.sh(build_ios.sh --target tests, thenswift test), which does.build_ios.sh, no SwiftExampleApp build, no simulator run of a real payment with a delete or shutdown in flight.Breaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull request🤖 Generated with Claude Code
PR Hygiene ·
6adcc91/self-reviewedswift-sdk(packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift,packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift,packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedRecovery.swiftand 3 more) — llbartekll or romchornyiWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.