From 4b15786f58b6b3bf246f620b33cab22190d93134 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 9 Sep 2026 09:19:21 +0200 Subject: [PATCH 1/3] fix(wallet): reload the runtime when an unconfirmed transaction is removed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing a never-accepted transaction edits the persistence layer and relies on a full runtime reload to make the Rust wallet forget it — there is no removal API at any FFI layer. That reload was requested through `rearmPlatformSync()`, whose `.platformSyncRearm` trigger `shouldSkipRefresh` elides whenever `isRuntimeReady` holds. At removal time the host, Core SPV and BLAST are all running, so the refresh was always elided and no reload ran: the Rust wallet kept the transaction in its in-memory tx set and its inputs stayed marked spent — so the coins the action promises to free stayed unspendable — while dash-spv's mempool tracker kept rebroadcasting, until the next app launch. Give the remover its own `.walletRowsChanged` trigger on the never-elide arm of `shouldSkipRefresh`, next to `.walletMaterialChanged` and `.walletDidChange`, reached through `reloadAfterWalletRowsChanged()`. `rearmPlatformSync` keeps its elision, which is correct for its own caller: `syncNow` reaches it only when BLAST is already down. Deriving the rescan depth moves ahead of the reload. `fullReset` stops SPV, and `resetPublishedState` zeroes the coordinator's `tipHeight`; only a later progress tick re-seeds it. Reading the tip after a reload that now really happens would find 0 and arm no rescan on any removal — and on the bulk path that rescan is the only safety rail, because it never explorer-checks. Anchoring on the pre-reload tip rewinds deeper, never shallower. Co-Authored-By: Claude Opus 5 --- .../SwiftDashSDKWalletRuntime.swift | 39 +++++++++++++--- .../UnconfirmedTransactionRemover.swift | 46 +++++++++++++------ 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift b/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift index 43349fb73e..bb1fd9af8b 100644 --- a/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift +++ b/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift @@ -157,10 +157,23 @@ final class SwiftDashSDKWalletRuntime: NSObject { /// turn "Sync Now" into a real in-session recovery action after Stop or a /// recover-time binding race. func rearmPlatformSync() async { - let task = enqueueAwaitable { [weak self] in - await self?.refresh(trigger: .platformSyncRearm) - } - await task.value + await awaitRefresh(trigger: .platformSyncRearm) + } + + /// Rebuild the shared runtime after the SwiftData rows it loaded from were + /// edited underneath it, and return once that rebuild has settled (started, + /// or failed back to a stopped runtime). + /// + /// Runs the same serialized stop → load → start the lifecycle queue drives + /// for a network or wallet switch: on load the Rust wallet rehydrates its + /// tx set, UTXOs and `spent_outpoints` from the rows as they now are, and + /// dash-spv's mempool tracker restarts without the deleted transactions. + /// + /// `.walletRowsChanged` is never elided by `shouldSkipRefresh`: a runtime + /// that still looks ready is precisely the one holding the pre-edit state + /// this call exists to discard. + func reloadAfterWalletRowsChanged() async { + await awaitRefresh(trigger: .walletRowsChanged) } /// Restart Core SPV to dial a fresh peer set ("sync too slow? change @@ -393,6 +406,16 @@ final class SwiftDashSDKWalletRuntime: NSObject { } } + /// Awaiting sibling of `enqueueRefresh`: appends the same single + /// `refresh(trigger:)` op to the serial chain and returns only once it — + /// and every op queued ahead of it — has finished. Callers that must + /// observe the rebuilt runtime go through here. + private func awaitRefresh(trigger: RefreshTrigger) async { + await enqueueAwaitable { [weak self] in + await self?.refresh(trigger: trigger) + }.value + } + private func enqueueFullReset(lastError: String?, forWipe: Bool) { enqueue { [weak self] in await self?.fullReset(lastError: lastError, forWipe: forWipe) @@ -527,11 +550,14 @@ final class SwiftDashSDKWalletRuntime: NSObject { private func shouldSkipRefresh(for network: Network, trigger: RefreshTrigger) -> Bool { switch trigger { - case .walletMaterialChanged, .walletDidChange: + case .walletMaterialChanged, .walletDidChange, .walletRowsChanged: // A runtime wallet switch always rebuilds — the active-wallet // registry was repointed to a different wallet on the SAME // network, so `currentNetwork == network` would otherwise wrongly - // elide the rebind. + // elide the rebind. A rows-changed rebuild always runs for the + // mirror-image reason: the SwiftData rows were edited behind a + // runtime that never stopped, so a runtime that looks ready is + // exactly the one still holding the pre-edit in-memory wallet. return false case .startIfReady, .networkDidChange, .platformSyncRearm: return isRuntimeReady(for: network) @@ -639,6 +665,7 @@ final class SwiftDashSDKWalletRuntime: NSObject { case networkDidChange case walletMaterialChanged case walletDidChange + case walletRowsChanged case platformSyncRearm } diff --git a/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift b/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift index cfd1781a7a..713e1d6fed 100644 --- a/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift +++ b/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift @@ -266,27 +266,41 @@ struct UnconfirmedTransactionRemover { } } + // How deep the recovery rescan reaches is decided HERE, before the + // reload, because the reload stops SPV and `resetPublishedState` + // zeroes the coordinator's `tipHeight`; the restarted client only + // re-seeds it on a later progress tick, so a post-reload read finds 0 + // and arms nothing. Anchoring on the pre-reload tip is the safe + // direction — the tip only advances, so the older value rewinds + // deeper, never shallower. + // + // The window reaches back past the OLDEST removed transaction's first + // appearance — uncapped in depth, because this is the step that + // restores a removed tx that actually IS mined (the bulk path never + // explorer-checked, and the single path's explorer can be wrong). The + // SDK floors the rescan at the wallet's birth height and the locally + // stored chain data; a row with no usable first-seen time rescans from + // the floor. + let tip = SwiftDashSDKSPVCoordinator.shared.tipHeight + let rescanFromHeight: UInt32? = { + guard tip > 0 else { return nil } + let ageSeconds = max(0, Date().timeIntervalSince1970 - TimeInterval(oldestFirstSeen)) + let ageBlocks = UInt32(clamping: Int(ageSeconds / 150)) + rescanMarginBlocks + let blocksBack = max(minRescanBlocks, ageBlocks) + return tip > blocksBack ? tip - blocksBack : 1 + }() + // Full runtime reload — the same serialized stop → load → start // lifecycle a network switch runs. The reloaded Rust wallet // rebuilds its tx set, UTXOs and spent_outpoints from the rows as // they now are, and dash-spv's mempool tracker (which kept // rebroadcasting) restarts without the removed transactions. - await SwiftDashSDKWalletRuntime.shared.rearmPlatformSync() + await SwiftDashSDKWalletRuntime.shared.reloadAfterWalletRowsChanged() - // Rescan compact filters, reaching back past the OLDEST removed - // transaction's first appearance — uncapped in depth, because - // this is the step that restores a removed tx that actually IS - // mined (the bulk path never explorer-checked, and the single - // path's explorer can be wrong). The SDK floors the rescan at - // the wallet's birth height and the locally stored chain data; - // a row with no usable first-seen time rescans from the floor. + // Rewind the compact-filter checkpoint on the manager the reload just + // built — the previous instance died with the old runtime. var rescanArmed = false - let tip = SwiftDashSDKSPVCoordinator.shared.tipHeight - if tip > 0, let manager = SwiftDashSDKHost.shared.manager { - let ageSeconds = max(0, Date().timeIntervalSince1970 - TimeInterval(oldestFirstSeen)) - let ageBlocks = UInt32(clamping: Int(ageSeconds / 150)) + rescanMarginBlocks - let blocksBack = max(minRescanBlocks, ageBlocks) - let fromHeight = tip > blocksBack ? tip - blocksBack : 1 + if let fromHeight = rescanFromHeight, let manager = SwiftDashSDKHost.shared.manager { do { try manager.spvRescanFilters(walletId: walletId, fromHeight: fromHeight) rescanArmed = true @@ -294,8 +308,10 @@ struct UnconfirmedTransactionRemover { } catch { logger.error("🗑️ TX-REMOVE :: filter rescan arm failed: \(String(describing: error), privacy: .public)") } + } else if rescanFromHeight == nil { + logger.error("🗑️ TX-REMOVE :: filter rescan skipped — no chain tip when the removal started") } else { - logger.error("🗑️ TX-REMOVE :: filter rescan skipped — SPV not running after reload") + logger.error("🗑️ TX-REMOVE :: filter rescan skipped — no manager after the reload") } // App caches that mirror the deleted rows. From 9cb02e42ef25114da6c6d1d560ccd9e939346772 Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Wed, 9 Sep 2026 15:17:52 +0200 Subject: [PATCH 2/3] fix(wallet): report a removal whose runtime reload did not come back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Making the reload real also made a failed reload real. `refresh` starts Core SPV and then BLAST and falls back to `fullReset` if either throws, so a Platform outage — routine on a flaky DAPI path, and unrelated to the Core-side row being repaired — stops the host and Core SPV as well. The removal still reported plain success and sent the user to Rescan Filters, which refuses while SPV is stopped: a stopped wallet, a zero balance, and an instruction that cannot be followed until relaunch. Replace the `rescanArmed` boolean with a `RemovalOutcome` that separates `.runtimeStopped` from `.rescanUnavailable`, decided by `isRuntimeReady(for:)` after the reload. Both callers now name the remedy that actually works in that state — reopen the app, or Sync Now, which rebuilds the runtime in-session — instead of Rescan Filters. Also publish `activeWalletDidChange` for `.walletRowsChanged`. A queued rows-changed refresh can resolve a network key an interactive switch has already flipped and rebuild for the destination; the switch's own refresh then finds that runtime ready and elides, dropping its "network-changed" publish, and consumers that observe only this notification keep their pre-switch snapshot. Co-Authored-By: Claude Opus 5 --- .../SwiftDashSDKWalletRuntime.swift | 11 +++ .../UnconfirmedTransactionRemover.swift | 83 +++++++++++++------ .../SwiftDashSDKSPVStatusScreen.swift | 44 ++++++---- .../Tx/Details/TxDetailViewController.swift | 20 +++-- 4 files changed, 110 insertions(+), 48 deletions(-) diff --git a/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift b/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift index bb1fd9af8b..8465cd7086 100644 --- a/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift +++ b/DashWallet/Sources/Infrastructure/SwiftDashSDK/SwiftDashSDKWalletRuntime.swift @@ -491,6 +491,17 @@ final class SwiftDashSDKWalletRuntime: NSObject { // bound so identity/banner consumers re-read destination // state instead of the cleared transition mirror. publishActiveWalletDidChange(reason: "network-changed") + } else if trigger == .walletRowsChanged { + // A rows-changed rebuild rebinds the wallet just like the + // two above, and it can resolve a network key that an + // interactive switch has ALREADY flipped while its own + // refresh is still queued behind this one. That switch's + // refresh then finds the destination runtime ready and + // elides, taking its "network-changed" publish with it — + // so publish here too, or consumers that listen only for + // this notification (SwiftDashSDKContactsService) keep a + // pre-switch snapshot. + publishActiveWalletDidChange(reason: "wallet-rows-changed") } } catch { Self.logger.error("🧭 RUNTIME :: start failed: \(String(describing: error), privacy: .public)") diff --git a/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift b/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift index 713e1d6fed..0a6dda44ab 100644 --- a/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift +++ b/DashWallet/Sources/Infrastructure/SwiftDashSDK/UnconfirmedTransactionRemover.swift @@ -56,6 +56,22 @@ struct UnconfirmedTransactionRemover { subsystem: "org.dashfoundation.dash", category: "swift-sdk-migration.unconfirmed-tx-remover") + /// What the removal achieved beyond deleting the rows. The rows are gone + /// in every case; the cases differ in how much of the recovery path behind + /// them ran, so a caller never has to claim more than actually happened. + enum RemovalOutcome { + /// Runtime reloaded and the recovery filter rescan is running. + case rescanArmed + /// Runtime reloaded, but the rescan did not arm (no chain tip to + /// anchor on, or the arm threw). Rescan Filters still works. + case rescanUnavailable + /// The reload took the runtime down and it did not come back: a BLAST + /// start failure makes `refresh` fall back to `fullReset`, which stops + /// the host and Core SPV too. Rescan Filters refuses while SPV is + /// stopped, so this case must NOT point the user at it. + case runtimeStopped + } + enum RemovalError: LocalizedError { case notReady case transactionNotFound @@ -89,13 +105,13 @@ struct UnconfirmedTransactionRemover { /// estimate (~1 day), covering clock skew and variable block times. private static let rescanMarginBlocks: UInt32 = 576 - /// - Returns: whether the recovery filter rescan was armed. `false` - /// means the removal itself succeeded but the rescan didn't start - /// (SPV not running / arm threw) — the caller should tell the user - /// to run Rescan Filters manually so the safety net isn't silently - /// skipped. + /// - Returns: how far past the row deletion the removal got. Anything + /// other than `.rescanArmed` means the safety net didn't start, and + /// `.runtimeStopped` additionally means the wallet runtime is down — + /// the caller must say so rather than pointing at Rescan Filters, + /// which refuses while SPV is stopped. @discardableResult - func remove(txidWire: Data) async throws -> Bool { + func remove(txidWire: Data) async throws -> RemovalOutcome { guard let container = SwiftDashSDKHost.shared.modelContainer, let network = WalletEnvironment.network, let walletId = WalletEnvironment.activeWalletId(for: WalletEnvironment.networkKind) else { @@ -161,19 +177,19 @@ struct UnconfirmedTransactionRemover { /// a dropped transaction that IS on the blockchain is re-matched and /// restored by it. Nothing is sent to the network. /// - /// - Returns: how many transactions were dropped (0 = nothing to - /// drop; no reload or rescan runs, so `rescanArmed` is `false`), - /// and whether the recovery rescan was armed — `false` after a - /// non-zero drop means the caller must tell the user to run - /// Rescan Filters manually. - func dropAllUnconfirmedAndRescan() async throws -> (dropped: Int, rescanArmed: Bool) { + /// - Returns: how many transactions were dropped (0 = nothing to drop; + /// no reload or rescan runs, so the outcome is `.rescanUnavailable`), + /// and how far the removal tail got. `.runtimeStopped` after a + /// non-zero drop means the wallet runtime is down, so the caller must + /// not offer Rescan Filters as the remedy. + func dropAllUnconfirmedAndRescan() async throws -> (dropped: Int, outcome: RemovalOutcome) { guard let container = SwiftDashSDKHost.shared.modelContainer, let walletId = WalletEnvironment.activeWalletId(for: WalletEnvironment.networkKind) else { throw RemovalError.notReady } let context = container.mainContext let rows = try Self.unconfirmedRows(in: context, walletId: walletId) - guard !rows.isEmpty else { return (dropped: 0, rescanArmed: false) } + guard !rows.isEmpty else { return (dropped: 0, outcome: .rescanUnavailable) } var oldestFirstSeen = UInt64.max var displayTxids: [String] = [] @@ -188,9 +204,9 @@ struct UnconfirmedTransactionRemover { try context.save() Self.logger.notice("🗑️ TX-REMOVE :: bulk-dropped \(rows.count, privacy: .public) unconfirmed tx(s): \(displayTxids.joined(separator: ","), privacy: .public)") - let rescanArmed = await Self.finishRemoval( + let outcome = await Self.finishRemoval( txidsWire: txidsWire, walletId: walletId, oldestFirstSeen: oldestFirstSeen) - return (dropped: rows.count, rescanArmed: rescanArmed) + return (dropped: rows.count, outcome: outcome) } /// The active wallet's unconfirmed (mempool-context, no block) rows — @@ -250,13 +266,12 @@ struct UnconfirmedTransactionRemover { /// Shared removal tail, after the rows are deleted and saved: /// app-side metadata cleanup, full runtime reload, filter rescan, - /// and cache refresh. Returns whether the rescan was armed — the - /// rescan is the recovery step that restores a wrongly-removed - /// on-chain transaction, so callers surface `false` to the user - /// instead of claiming a complete recovery. + /// and cache refresh. The rescan is the recovery step that restores a + /// wrongly-removed on-chain transaction, so anything short of + /// `.rescanArmed` is surfaced instead of claiming a complete recovery. private static func finishRemoval( txidsWire: [Data], walletId: Data, oldestFirstSeen: UInt64 - ) async -> Bool { + ) async -> RemovalOutcome { // App-side metadata (tax category override) keyed by the same // hash — a fresh install knows nothing about a removed tx, and // neither should this one. @@ -297,26 +312,42 @@ struct UnconfirmedTransactionRemover { // rebroadcasting) restarts without the removed transactions. await SwiftDashSDKWalletRuntime.shared.reloadAfterWalletRowsChanged() - // Rewind the compact-filter checkpoint on the manager the reload just - // built — the previous instance died with the old runtime. - var rescanArmed = false - if let fromHeight = rescanFromHeight, let manager = SwiftDashSDKHost.shared.manager { + // Did the reload actually bring the runtime back? `refresh` starts + // Core SPV and then BLAST, and falls back to `fullReset` if EITHER + // throws — so a Platform outage, which has nothing to do with the + // Core-side row the user just repaired, stops the host and Core SPV + // as well. The rows are already deleted and stay deleted; what this + // decides is which remedy the caller can honestly offer, because + // Rescan Filters refuses while SPV is stopped. + let runtimeReady = WalletEnvironment.network + .map { SwiftDashSDKWalletRuntime.shared.isRuntimeReady(for: $0) } ?? false + + let outcome: RemovalOutcome + if !runtimeReady { + outcome = .runtimeStopped + logger.error("🗑️ TX-REMOVE :: runtime did not come back after the reload — rows deleted, wallet stopped") + } else if let fromHeight = rescanFromHeight, let manager = SwiftDashSDKHost.shared.manager { + // Rewind the compact-filter checkpoint on the manager the reload + // just built — the previous instance died with the old runtime. do { try manager.spvRescanFilters(walletId: walletId, fromHeight: fromHeight) - rescanArmed = true + outcome = .rescanArmed logger.notice("🗑️ TX-REMOVE :: filter rescan armed from height \(fromHeight, privacy: .public) (tip \(tip, privacy: .public))") } catch { + outcome = .rescanUnavailable logger.error("🗑️ TX-REMOVE :: filter rescan arm failed: \(String(describing: error), privacy: .public)") } } else if rescanFromHeight == nil { + outcome = .rescanUnavailable logger.error("🗑️ TX-REMOVE :: filter rescan skipped — no chain tip when the removal started") } else { + outcome = .rescanUnavailable logger.error("🗑️ TX-REMOVE :: filter rescan skipped — no manager after the reload") } // App caches that mirror the deleted rows. await ShieldedTxLookup.shared.refresh(reason: "transaction-removal-completed") - return rescanArmed + return outcome } /// One GET against the network's Insight API. 200 = the explorer diff --git a/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift b/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift index 026dd604bc..69b9b02293 100644 --- a/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift +++ b/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift @@ -952,24 +952,36 @@ extension SwiftDashSDKSPVStatusScreen { dropResultMessage = NSLocalizedString( "No unconfirmed transactions to drop.", comment: "SPV diagnostics") - } else if outcome.rescanArmed { - dropResultIsError = false - dropResultMessage = String( - format: NSLocalizedString( - "Dropped %d unconfirmed transaction(s) — rescanning filters, watch the Filters row.", - comment: "SPV diagnostics"), - outcome.dropped) } else { - // The drop finished but the recovery rescan didn't - // arm — flag it instead of claiming the safety net ran. - dropResultIsError = true - dropResultMessage = String( - format: NSLocalizedString( - "Dropped %d unconfirmed transaction(s), but the filter rescan couldn't start — run Rescan Filters above.", - comment: "SPV diagnostics"), - outcome.dropped) + switch outcome.outcome { + case .rescanArmed: + dropResultIsError = false + dropResultMessage = String( + format: NSLocalizedString( + "Dropped %d unconfirmed transaction(s) — rescanning filters, watch the Filters row.", + comment: "SPV diagnostics"), + outcome.dropped) + case .rescanUnavailable: + // The drop finished but the recovery rescan didn't + // arm — flag it instead of claiming the safety net ran. + dropResultIsError = true + dropResultMessage = String( + format: NSLocalizedString( + "Dropped %d unconfirmed transaction(s), but the filter rescan couldn't start — run Rescan Filters above.", + comment: "SPV diagnostics"), + outcome.dropped) + case .runtimeStopped: + // Rescan Filters above is disabled while SPV is + // stopped, so it is not the remedy to offer here. + dropResultIsError = true + dropResultMessage = String( + format: NSLocalizedString( + "Dropped %d unconfirmed transaction(s), but the wallet stopped — reopen the app, or tap Sync Now in Platform sync to restart it.", + comment: "SPV diagnostics"), + outcome.dropped) + } } - Self.logger.info("🛰️ SPV-STATUS :: bulk unconfirmed drop finished — \(outcome.dropped, privacy: .public) tx(s), rescanArmed=\(outcome.rescanArmed, privacy: .public)") + Self.logger.info("🛰️ SPV-STATUS :: bulk unconfirmed drop finished — \(outcome.dropped, privacy: .public) tx(s), outcome=\(String(describing: outcome.outcome), privacy: .public)") } catch { dropResultIsError = true dropResultMessage = error.localizedDescription diff --git a/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift b/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift index 94922bd7c1..aa01b14a77 100644 --- a/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift +++ b/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift @@ -368,12 +368,20 @@ extension TXDetailViewController { self?.view.dw_hideProgressHUD() } do { - let rescanArmed = try await UnconfirmedTransactionRemover().remove(txidWire: txidWire) - // Never claim the rescan safety net ran when it didn't — - // point at the manual Rescan Filters action instead. - self?.view.dw_showInfoHUD(withText: rescanArmed - ? NSLocalizedString("Transaction removed", comment: "Remove never-accepted transaction: success") - : NSLocalizedString("Transaction removed — rescan couldn't start, run Rescan Filters in Core Sync Status", comment: "Remove never-accepted transaction: removed but the recovery rescan did not arm")) + let outcome = try await UnconfirmedTransactionRemover().remove(txidWire: txidWire) + // Never claim the rescan safety net ran when it didn't, and + // never send the user to Rescan Filters when the runtime is + // down — that control refuses while SPV is stopped. + let message: String + switch outcome { + case .rescanArmed: + message = NSLocalizedString("Transaction removed", comment: "Remove never-accepted transaction: success") + case .rescanUnavailable: + message = NSLocalizedString("Transaction removed — rescan couldn't start, run Rescan Filters in Core Sync Status", comment: "Remove never-accepted transaction: removed but the recovery rescan did not arm") + case .runtimeStopped: + message = NSLocalizedString("Transaction removed, but the wallet stopped — reopen the app, or tap Sync Now in Sync Info to restart it", comment: "Remove never-accepted transaction: removed but the runtime reload left the wallet stopped") + } + self?.view.dw_showInfoHUD(withText: message) // The row this sheet describes no longer exists. self?.closeAction() } catch UnconfirmedTransactionRemover.RemovalError.transactionOnChain { From 5fa73bb52e8bf181236cedb4c5aae73b3ba69b2d Mon Sep 17 00:00:00 2001 From: Bartosz Rozwarski Date: Fri, 11 Sep 2026 08:48:50 +0200 Subject: [PATCH 3/3] fix(wallet): keep the stopped-wallet warning readable and name the rescan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two gaps in the `.runtimeStopped` path. The tx-detail warning was shown with `dw_showInfoHUD`, which adds the HUD to that controller's own view via `showHUDAddedTo:`, and the call was followed immediately by `closeAction()` — so the only explanation of a stopped wallet was torn down with the sheet before it could be read, under a checkmark icon at that. Present an acknowledged alert instead, next to the existing refusal alert, and dismiss the sheet from its OK handler. Neither message said the removal's rescan still has to be run. Restarting the runtime does not replay it: `syncNow` rebuilds the runtime but nothing re-arms this removal's filter rewind, so a bulk-dropped transaction that was actually mined would never be rediscovered. Both messages now name the two steps in order — restart the wallet, then run Rescan Filters. The rescan is not persisted across the restart. `SPVChainResyncMarker` is a store-deleting birth-height resync gated on `armedByThisSession`, so it cannot serve a same-session recovery, and a second pending-rescan marker is lifecycle machinery that belongs with the Core/Platform split in #1118 rather than bolted onto this fix. Co-Authored-By: Claude Opus 5 --- .../SwiftDashSDKSPVStatusScreen.swift | 8 +++- .../Tx/Details/TxDetailViewController.swift | 41 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift b/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift index 69b9b02293..c8c8322ef8 100644 --- a/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift +++ b/DashWallet/Sources/UI/Menu/SyncInfo/SwiftDashSDKSPVStatusScreen.swift @@ -972,11 +972,15 @@ extension SwiftDashSDKSPVStatusScreen { outcome.dropped) case .runtimeStopped: // Rescan Filters above is disabled while SPV is - // stopped, so it is not the remedy to offer here. + // stopped, so restarting comes first — and it has to + // be followed by the rescan, which restarting does + // not replay. This path never explorer-checked, so + // that rescan is the only on-chain safety check the + // dropped transactions ever get. dropResultIsError = true dropResultMessage = String( format: NSLocalizedString( - "Dropped %d unconfirmed transaction(s), but the wallet stopped — reopen the app, or tap Sync Now in Platform sync to restart it.", + "Dropped %d unconfirmed transaction(s), but the wallet stopped and the filter rescan never ran. Restart the wallet (reopen the app, or Sync Now in Platform sync), then run Rescan Filters above.", comment: "SPV diagnostics"), outcome.dropped) } diff --git a/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift b/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift index aa01b14a77..34be507e09 100644 --- a/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift +++ b/DashWallet/Sources/UI/Tx/Details/TxDetailViewController.swift @@ -369,21 +369,24 @@ extension TXDetailViewController { } do { let outcome = try await UnconfirmedTransactionRemover().remove(txidWire: txidWire) - // Never claim the rescan safety net ran when it didn't, and - // never send the user to Rescan Filters when the runtime is - // down — that control refuses while SPV is stopped. - let message: String switch outcome { case .rescanArmed: - message = NSLocalizedString("Transaction removed", comment: "Remove never-accepted transaction: success") + self?.view.dw_showInfoHUD(withText: NSLocalizedString("Transaction removed", comment: "Remove never-accepted transaction: success")) + // The row this sheet describes no longer exists. + self?.closeAction() case .rescanUnavailable: - message = NSLocalizedString("Transaction removed — rescan couldn't start, run Rescan Filters in Core Sync Status", comment: "Remove never-accepted transaction: removed but the recovery rescan did not arm") + // Never claim the rescan safety net ran when it didn't. + self?.view.dw_showInfoHUD(withText: NSLocalizedString("Transaction removed — rescan couldn't start, run Rescan Filters in Core Sync Status", comment: "Remove never-accepted transaction: removed but the recovery rescan did not arm")) + self?.closeAction() case .runtimeStopped: - message = NSLocalizedString("Transaction removed, but the wallet stopped — reopen the app, or tap Sync Now in Sync Info to restart it", comment: "Remove never-accepted transaction: removed but the runtime reload left the wallet stopped") + // A HUD would not survive this: it is added to this + // controller's own view, which `closeAction` tears down. + // The stopped wallet needs an acknowledged alert that + // dismisses the sheet only once the user has read it — + // and it must name BOTH steps, because restarting the + // runtime does not replay this removal's rescan. + self?.presentRemovalLeftWalletStopped() } - self?.view.dw_showInfoHUD(withText: message) - // The row this sheet describes no longer exists. - self?.closeAction() } catch UnconfirmedTransactionRemover.RemovalError.transactionOnChain { self?.presentRemovalRefused() } catch { @@ -397,6 +400,24 @@ extension TXDetailViewController { } } + /// The rows are deleted, but reloading the runtime left the wallet + /// stopped (Core SPV is torn down when the Platform side fails to come + /// back). Both recovery steps are spelled out: restarting the runtime + /// does NOT replay the rescan this removal skipped, so the transaction's + /// on-chain safety check still has to be run by hand afterwards. The + /// sheet is dismissed only after the user acknowledges. + private func presentRemovalLeftWalletStopped() { + let alert = UIAlertController( + title: NSLocalizedString("Transaction removed, but the wallet stopped", comment: "Remove never-accepted transaction: removed but the runtime reload left the wallet stopped"), + message: NSLocalizedString("The transaction was deleted from this device. Reloading the wallet didn't finish, so the wallet is stopped and the rescan that double-checks the blockchain never ran.\n\nRestart the wallet — reopen the app, or tap Sync Now in Sync Info — and then run Rescan Filters in Core Sync Status. Restarting alone does not repeat the rescan.", comment: "Remove never-accepted transaction: both recovery steps after a failed runtime reload"), + preferredStyle: .alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .cancel) { [weak self] _ in + // The row this sheet describes no longer exists. + self?.closeAction() + }) + present(alert, animated: true) + } + /// The explorer knows the transaction, either from the mempool or a /// block. Removal is refused until the local wallet catches up. private func presentRemovalRefused() {