feat: eager init Spark wallet and add stream recovery#3358
Merged
TaprootFreak merged 3 commits intodevelopfrom Mar 5, 2026
Merged
feat: eager init Spark wallet and add stream recovery#3358TaprootFreak merged 3 commits intodevelopfrom
TaprootFreak merged 3 commits intodevelopfrom
Conversation
Initialize SparkWallet eagerly at boot so the background stream starts immediately, enabling automatic claiming of incoming transfers without waiting for the first API call. Register a stream:disconnected handler that re-initializes the wallet with a fresh background stream after the SDK exhausts its 10 reconnect attempts.
- Add DfxLogger for observability on disconnect/reconnect events - Use exponential backoff (1s, 2s, 4s, ... up to 60s) between reconnect attempts to avoid hammering the Spark API - Retry initialization on failure instead of leaving the wallet in a permanently broken state
Consider TRANSFER_STATUS_SENDER_KEY_TWEAKED as confirmed for outgoing transfers since funds have already left the wallet at that point. Waiting for COMPLETED would block until the receiver claims.
davidleomay
approved these changes
Mar 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The SparkWallet is initialized lazily (only on first access). This means:
setupBackgroundStream()) doesn't start until the wallet is first usedSolution
AsyncFieldeager mode, so the SDK background stream starts right away and incoming transfers are automatically claimedstream:disconnectedevent handler that re-initializes the wallet with a fresh background stream after the SDK exhausts its 10 internal reconnect attemptsDfxLoggerfor production observabilityTRANSFER_STATUS_SENDER_KEY_TWEAKEDas confirmed for outgoing transfers, since funds have already left the wallet at that point — no need to wait for the receiver to claimTest plan
isTxCompletereturnstrueafterSENDER_KEY_TWEAKED(without waiting for receiver claim)getIncomingTransfers()returns incoming transfers asCOMPLETED