Skip to content

fix(swift-sdk): detect later added wallet tx to a synced spv client#4062

Merged
ZocoLini merged 1 commit into
v4.1-devfrom
fix/wallet-sync
Jul 10, 2026
Merged

fix(swift-sdk): detect later added wallet tx to a synced spv client#4062
ZocoLini merged 1 commit into
v4.1-devfrom
fix/wallet-sync

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

A wallet added while SPV is already synced (e.g. importing an
existing mnemonic with birth_height = 0) has its historical
funds backfilled by the SPV rescan that insert_wallet above
triggers. That rescan can complete — emitting the
BlockProcessed event that carries the post-backfill balance —
before this wallet lands in self.wallets, so
BalanceUpdateHandler drops those events (the wallet isn't in
the map yet) and the atomic stays at zero even though the inner
ManagedWalletInfo balance is correct. Mirror the inner balance
into the atomic here (as manager::load does for restored
wallets); any later block events are applied normally now that
the wallet is mapped.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • Bug Fixes

    • Updated wallet balance initialization so newly added wallets immediately show correct confirmed, unconfirmed, immature, locked, and total amounts.
    • Prevented a brief zero-balance state when balance updates arrive during wallet setup (including SPV backfill scenarios).
  • Tests

    • Added an integration test for late wallet import into an already synced SPV client, verifying spendable balance after history backfill matches the funded amount.

@thepastaclaw

thepastaclaw commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

✅ Review complete (commit 15dd0eb)

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f2a8a389-9860-4dd0-a36f-8624b18427be

📥 Commits

Reviewing files that changed from the base of the PR and between 6834301 and 15dd0eb.

📒 Files selected for processing (2)
  • packages/rs-platform-wallet/src/manager/wallet_lifecycle.rs
  • packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Core/SpvLateWalletBackfillIntegrationTests.swift

📝 Walkthrough

Walkthrough

register_wallet now re-seeds atomic balances from ManagedWalletInfo after wallet insertion. A Swift integration test covers late wallet import and verifies that SPV backfill produces the expected spendable balance.

Changes

Late wallet balance backfill fix

Layer / File(s) Summary
Atomic balance re-seed on wallet registration
packages/rs-platform-wallet/src/manager/wallet_lifecycle.rs
register_wallet copies confirmed, unconfirmed, immature, and locked balances into the wallet’s atomic balance after insertion.
Late backfill integration test
packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Core/SpvLateWalletBackfillIntegrationTests.swift
The test funds an address, syncs an empty SPV client, imports the wallet with birthHeight: 0, and verifies the backfilled spendable balance.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant IntegrationTest
  participant SPVClient
  participant WalletManager
  participant Blockchain
  IntegrationTest->>Blockchain: Fund and confirm receive address
  IntegrationTest->>SPVClient: Start and sync to chain tip
  IntegrationTest->>WalletManager: Import wallet with birthHeight 0
  SPVClient->>WalletManager: Backfill wallet history and balance
  WalletManager-->>IntegrationTest: Expose updated spendable balance
Loading

Suggested reviewers: shumkov, llbartekll, QuantumExplorer, thepastaclaw

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: handling a wallet added after an SPV client has already synced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/wallet-sync

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added this to the v4.1.0 milestone Jul 9, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Verified PR #4062 at 6834301 against the changed Rust wallet lifecycle code, the Swift integration test, and the FFI balance read path. The reseed copies the same balance fields used by the existing restored-wallet path into the same atomic balance object Swift reads, and the test covers the intended late-import SPV backfill scenario. No in-scope review findings were confirmed.

Source: reviewers claude-general (opus), codex-general (gpt-5.5), claude-ffi-engineer (opus), codex-ffi-engineer (gpt-5.5); verifier codex (gpt-5.5).

@ZocoLini ZocoLini merged commit b42d213 into v4.1-dev Jul 10, 2026
5 checks passed
@ZocoLini ZocoLini deleted the fix/wallet-sync branch July 10, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants