Overview
Diagnostic Mode provides a set of APIs for troubleshooting wallet issues, scanning for UTXOs, and performing sweep transactions. Each diagnostic operation is scoped to a session identified by a unique session ID.Diagnostic Session Flow
A typical diagnostic session follows this workflow:- Start Session - Create a new diagnostic session and receive a session descriptor
- Scan for UTXOs - Perform a blockchain scan to discover unspent outputs
- Submit Logs - Upload diagnostic logs for analysis (optional)
- Prepare Sweep - Create a sweep transaction to consolidate funds
- Sign & Broadcast - Sign and broadcast the sweep transaction
Session Management
StartDiagnosticSession
Initiate a new diagnostic session. This creates a session with a unique ID, logger, and buffer for collecting diagnostic data. Request:google.protobuf.Empty
Response: DiagnosticSessionDescriptor
Unique identifier for the diagnostic session. Use this ID in all subsequent diagnostic operations.
- ID: Unique session identifier
- LogBuffer: In-memory buffer for diagnostic logs
- Logger: Structured logger for the session
- LastScanReport: Results from the most recent UTXO scan
- SweepTx: Prepared sweep transaction (if created)
UTXO Scanning
PerformDiagnosticScanForUtxos
Perform a blockchain scan to discover unspent transaction outputs (UTXOs) associated with the wallet. Returns a streaming response with real-time progress updates. Request:DiagnosticSessionDescriptor
The session ID returned by StartDiagnosticSession
stream ScanProgressUpdate
The stream returns one of two update types:
Indicates that the scan has finished
Status message describing the scan completion
Log Submission
SubmitDiagnosticLog
Submit the diagnostic logs collected during the session to the server for analysis. Request:DiagnosticSessionDescriptor
The session ID for which to submit logs
DiagnosticSubmitStatus
HTTP-style status code indicating submission result (e.g., 200 for success)
Human-readable status message
Sweep Transaction Operations
PrepareSweepTx
Prepare a sweep transaction that consolidates all discovered UTXOs to a destination address. This creates the transaction but does not sign or broadcast it. Request:PrepareSweepTxRequest
The diagnostic session descriptor
Bitcoin address where funds will be swept
Fee rate in satoshis per virtual byte (vByte)
PrepareSweepTxResponse
The session descriptor (echoed back)
The destination address (echoed back)
Size of the prepared transaction in bytes
Total transaction fee in satoshis
SignAndBroadcastSweepTx
Sign and broadcast the previously prepared sweep transaction to the Bitcoin network. Request:SignAndBroadcastSweepTxRequest
The diagnostic session descriptor
Recovery code required to sign the transaction
SignAndBroadcastSweepTxResponse
The session descriptor (echoed back)
Transaction ID of the broadcast transaction
Session Lifecycle
Diagnostic sessions are stored in an in-memory map and persist for the lifetime of the application or until explicitly deleted. Session Operations:AddDiagnosticSession(data)- Add a new sessionGetDiagnosticSession(id)- Retrieve session by IDDeleteDiagnosticSession(id)- Remove session from memory
Error Handling
Diagnostic operations may fail with standard WalletService errors. Common error scenarios:- Invalid Session ID: Session not found or expired
- Scan Failed: Unable to complete blockchain scan
- Transaction Preparation Failed: Insufficient funds or invalid destination address
- Signing Failed: Invalid recovery code or signing error
- Broadcast Failed: Network error or transaction rejected by network
Source References
- Protobuf definition:
libwallet/presentation/api/wallet_service.proto:18-22 - Session management:
libwallet/domain/diagnostic_mode/diagnostic_session_data.go