@@ -3,11 +3,8 @@ import DashSDKFFI
33import Foundation
44import SwiftData
55
6- /// Named checkpoints make two exports from the same device directly
7- /// comparable without putting any user-controlled text in the log.
6+ /// Deep Core diagnostics are emitted only on explicit log export.
87enum CoreWalletDiagnosticCheckpoint : String , Sendable {
9- case startupPreRestore = " startup_pre_restore "
10- case startupPostRestore = " startup_post_restore "
118 case preExport = " pre_export "
129}
1310
@@ -154,26 +151,6 @@ func diagnosticTxoFingerprint(
154151 return data
155152}
156153
157- /// Canonical material for one exact `UtxoRestoreEntryFFI` row. The general
158- /// DB↔memory UTXO query cannot observe these three flags, so they live only in
159- /// this restore-specific fingerprint instead of creating false memory diffs.
160- func diagnosticRestoreTxoFingerprint(
161- _ candidate: CoreWalletDiagnosticAnalyzer . RestoreCandidate
162- ) -> Data {
163- var data = diagnosticTxoFingerprint (
164- outpoint: candidate. txo. outpoint,
165- amount: candidate. txo. amount,
166- height: candidate. txo. height,
167- scriptPubKey: candidate. txo. scriptPubKey,
168- isLocked: candidate. txo. isLocked,
169- account: candidate. txo. account
170- )
171- data. append ( candidate. isCoinbase ? 1 : 0 )
172- data. append ( candidate. isConfirmed ? 1 : 0 )
173- data. append ( candidate. isInstantLocked ? 1 : 0 )
174- return data
175- }
176-
177154extension PlatformWalletPersistenceHandler {
178155 /// Main-actor-friendly entry point used by manual log export. The handler's
179156 /// serial queue owns the ModelContext; only a Sendable value snapshot is
@@ -185,18 +162,6 @@ extension PlatformWalletPersistenceHandler {
185162 await withCheckedContinuation { continuation in
186163 serialQueue. async { [ self ] in
187164 let snapshot = autoreleasepool { ( ) -> CoreWalletDatabaseDiagnosticSnapshot ? in
188- if checkpoint == . startupPostRestore,
189- let cached = startupCoreDiagnosticSnapshots. removeValue ( forKey: walletId) {
190- SDKLogger . event (
191- " core_db_startup_snapshot_reused " ,
192- category: . persistence,
193- fields: [
194- " checkpoint " : . publicText( checkpoint. rawValue) ,
195- " wallet_reference " : . reference( walletId) ,
196- ]
197- )
198- return cached
199- }
200165 return emitCoreWalletDatabaseDiagnosticsOnQueue (
201166 walletId: walletId,
202167 checkpoint: checkpoint
@@ -207,44 +172,25 @@ extension PlatformWalletPersistenceHandler {
207172 }
208173 }
209174
210- /// Synchronous companion for the legacy synchronous restore overload .
175+ /// Synchronous companion used by focused persistence tests .
211176 func emitCoreWalletDatabaseDiagnostics(
212177 walletId: Data ,
213178 checkpoint: CoreWalletDiagnosticCheckpoint
214179 ) -> CoreWalletDatabaseDiagnosticSnapshot ? {
215180 onQueue {
216- if checkpoint == . startupPostRestore,
217- let cached = startupCoreDiagnosticSnapshots. removeValue ( forKey: walletId) {
218- SDKLogger . event (
219- " core_db_startup_snapshot_reused " ,
220- category: . persistence,
221- fields: [
222- " checkpoint " : . publicText( checkpoint. rawValue) ,
223- " wallet_reference " : . reference( walletId) ,
224- ]
225- )
226- return cached
227- }
228181 return emitCoreWalletDatabaseDiagnosticsOnQueue (
229182 walletId: walletId,
230183 checkpoint: checkpoint
231184 )
232185 }
233186 }
234187
235- /// Must be called while `serialQueue` is held. `loadWalletList` uses this
236- /// directly, avoiding a recursive `serialQueue.sync` deadlock.
188+ /// Must be called while `serialQueue` is held.
237189 @discardableResult
238190 func emitCoreWalletDatabaseDiagnosticsOnQueue(
239191 walletId: Data ,
240192 checkpoint: CoreWalletDiagnosticCheckpoint
241193 ) -> CoreWalletDatabaseDiagnosticSnapshot ? {
242- // A previous restore can fail after the pre-snapshot was cached but
243- // before post-restore consumes it. Never let a later attempt compare
244- // Rust against that stale value.
245- if checkpoint == . startupPreRestore {
246- startupCoreDiagnosticSnapshots. removeValue ( forKey: walletId)
247- }
248194 do {
249195 let walletDescriptor = FetchDescriptor < PersistentWallet > (
250196 predicate: PersistentWallet . predicate ( walletId: walletId)
@@ -530,9 +476,6 @@ extension PlatformWalletPersistenceHandler {
530476 assetLocks: assetLocks,
531477 assetLocksAvailable: assetLocksAvailable
532478 )
533- if checkpoint == . startupPreRestore {
534- startupCoreDiagnosticSnapshots [ walletId] = snapshot
535- }
536479 return snapshot
537480 } catch {
538481 SDKLogger . event (
@@ -571,20 +514,10 @@ extension PlatformWalletPersistenceHandler {
571514 rejection = nil
572515 }
573516 return CoreWalletDiagnosticAnalyzer . RestoreCandidate (
574- txo: CoreWalletDatabaseDiagnosticSnapshot . Txo (
575- outpoint: PersistentTxo . makeOutpoint ( txid: row. txid, vout: row. vout) ,
576- amount: row. amount,
577- height: row. height,
578- scriptPubKey: row. scriptPubKey,
579- isLocked: row. isLocked,
580- account: Self . diagnosticAccountKey ( row. account)
581- ) ,
517+ amount: row. amount,
582518 accountType: row. account? . accountType,
583519 standardTag: row. account? . standardTag,
584- rejectionReason: rejection,
585- isCoinbase: row. isCoinbase,
586- isConfirmed: row. isConfirmed,
587- isInstantLocked: row. isInstantLocked
520+ rejectionReason: rejection
588521 )
589522 }
590523 // A validation error deallocates the compact buffer and aborts the
@@ -595,7 +528,6 @@ extension PlatformWalletPersistenceHandler {
595528 emittedCount: emittedCount,
596529 errored: errored
597530 )
598- let emittedMaterials = summary. emittedCandidates. map ( diagnosticRestoreTxoFingerprint)
599531 let hasRejectedRows = summary. missingAccountCount > 0
600532 || summary. invalidTxidCount > 0
601533 || summary. invalidAccountTypeCount > 0
@@ -616,7 +548,7 @@ extension PlatformWalletPersistenceHandler {
616548 ) ,
617549 " candidate_value_duffs " : . unsignedInteger( summary. candidateValueDuffs) ,
618550 " built_count " : . integer( Int64 ( summary. builtCount) ) ,
619- " checkpoint " : . publicText( CoreWalletDiagnosticCheckpoint . startupPreRestore . rawValue ) ,
551+ " checkpoint " : . publicText( " restore_buffer " ) ,
620552 " emitted_count " : . integer( Int64 ( summary. emittedCandidates. count) ) ,
621553 " emitted_bip44_count " : . integer( Int64 ( summary. emittedBip44Count) ) ,
622554 " emitted_bip44_value_duffs " : . unsignedInteger(
@@ -626,7 +558,6 @@ extension PlatformWalletPersistenceHandler {
626558 " emitted_coinjoin_value_duffs " : . unsignedInteger(
627559 summary. emittedCoinJoinValueDuffs
628560 ) ,
629- " emitted_fingerprint " : . reference( diagnosticFingerprint ( emittedMaterials) ) ,
630561 " emitted_value_duffs " : . unsignedInteger( summary. emittedValueDuffs) ,
631562 " errored " : . boolean( errored) ,
632563 " skipped_invalid_account_type_count " : . integer(
@@ -1026,7 +957,7 @@ extension PlatformWalletManager {
1026957 await emitCoreWalletDiagnostics ( for: walletId, checkpoint: . preExport)
1027958 }
1028959
1029- func emitCoreWalletDiagnostics(
960+ private func emitCoreWalletDiagnostics(
1030961 for walletId: Data ,
1031962 checkpoint: CoreWalletDiagnosticCheckpoint
1032963 ) async {
@@ -1096,29 +1027,6 @@ extension PlatformWalletManager {
10961027 }
10971028 }
10981029
1099- /// Blocking variant used only by the already-blocking synchronous restore
1100- /// API. New application code should use the async public entry point.
1101- func emitCoreWalletDiagnosticsSynchronously(
1102- for walletId: Data ,
1103- checkpoint: CoreWalletDiagnosticCheckpoint
1104- ) {
1105- guard walletId. count == 32 ,
1106- let handler = persistence,
1107- let database = handler. emitCoreWalletDatabaseDiagnostics (
1108- walletId: walletId,
1109- checkpoint: checkpoint
1110- ) ,
1111- isConfigured,
1112- handle != NULL_HANDLE
1113- else { return }
1114- Self . emitCoreMemoryDiagnostics (
1115- managerHandle: handle,
1116- managedWallet: wallets [ walletId] ,
1117- database: database,
1118- checkpoint: checkpoint
1119- )
1120- }
1121-
11221030 private nonisolated static func emitCoreMemoryDiagnostics(
11231031 managerHandle: Handle ,
11241032 managedWallet: ManagedPlatformWallet ? ,
0 commit comments