Skip to content

fix(wallet): imported wallets scan from genesis, not from the newest checkpoint - #804

Merged
QuantumExplorer merged 3 commits into
swift-sdk-integrationfrom
fix/import-birth-height
Jul 15, 2026
Merged

QuantumExplorer merged 3 commits into
swift-sdk-integrationfrom
fix/import-birth-height

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

The bug

Import a wallet and its creation/birth height gets stamped as 2,500,000 — dash-spv's newest hardcoded mainnet checkpoint (testnet's would be 1,500,000). Consequence: the imported wallet's SPV compact-filter scan starts at ~now, so funds and history received before the import never appear, and Tools → Rescan Filters can't recover them either — it rescans from PersistentWallet.birthHeight, i.e. from the same wrong height.

Root cause

The SDK's createWallet(birthHeight:) contract is explicit:

  • nil → freshly generated mnemonic: anchor the scan at the current tip (with unsynced headers at first launch, the SDK falls back to the network's newest hardcoded checkpoint — hence the exact 2,500,000)
  • 0 → importing/restoring: scan from genesis

dashwallet called createWallet without the parameter on every path, so imports were silently treated as freshly generated. The isImported provenance flag already existed at every call site (onboarding creator, Wallets add sheet, DashSync key migrator) — it just was never threaded into the host's createWallet calls. This is an app bug, not an SDK bug.

Fix

  • createOrImportWallet and addWallet (now addWallet(mnemonic:isImported:)) pass the network's import floor for imports (importedWalletBirthHeight: mainnet 200,000 — pre-2015 blocks predate any importable wallet, skipping a year of filter work — testnet 0/genesis) and keep nil (tip) for freshly generated mnemonics; WalletsViewModel threads the flag it already had. The DashSync upgrade migrator passes isImported: true already, so migrated wallets get genesis scans with no further change.
  • recoverPersistedWallet (reinstall recovery / first registration after a network switch) passes 0 unconditionally: provenance is unknown there — the SwiftData rows are gone or never existed on this network — and the mnemonic may hold years of history. A needless full scan is recoverable; a tip-anchored miss of old funds is not.
  • The one untouched manager.addWallet (in derivationWallet()) is the throwaway key-derivation stack — no SPV scan, birth height not applicable.

Escape hatch for already-stamped wallets

Wallets imported before this fix keep their wrong stamp (there's no way to distinguish them from legitimately-new wallets after the fact), so the second commit adds the recovery affordance: Tools → SwiftDashSDK SPV Status now shows the wallet's birth height with an edit control. Saving writes PersistentWallet.birthHeight (durable — the SDK's loadWallets restore feeds the row back to Rust at every launch) and then offers an immediate filter rescan from the new height. Set it to 0 on a mis-stamped import and rescan to recover pre-import history without wiping.

Verification

  • dashpay Debug arm64-sim build green.
  • QA smoke (no PIN needed for the observation): import a funded testnet wallet → Storage Explorer / SPV Status should show birth height 0, and the wallet's pre-existing transactions should appear as the filter scan progresses from genesis.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e3af67b9-8319-4ddd-be53-6dc308e7dd81

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/import-birth-height

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.

QuantumExplorer and others added 2 commits July 15, 2026 19:15
…checkpoint

Every wallet-creation path called the SDK's createWallet without a
birthHeight, so the SDK applied its freshly-generated-mnemonic default:
anchor the SPV scan at the current tip — which, at first launch before
any headers have synced, falls back to the network's newest hardcoded
checkpoint (mainnet: block 2,500,000). An IMPORTED wallet stamped that
way never scans its history: pre-existing funds and transactions don't
appear, and Rescan Filters can't recover them either because it uses
PersistentWallet.birthHeight as its floor.

The provenance was already known at every call site (isImported flags
in the onboarding creator, the Wallets add sheet, and the key
migrator) — it just wasn't threaded through the host. Now:

- createOrImportWallet / addWallet pass birthHeight 0 (genesis) for
  imports and keep nil (tip) for freshly generated mnemonics, per the
  SDK's documented contract. The DashSync upgrade migrator already
  flags isImported: true, so migrated wallets get genesis scans too.
- recoverPersistedWallet (reinstall recovery / first registration on a
  switched network) passes 0 unconditionally: provenance is unknown
  there and the wallet may hold history from long before — a needless
  full scan is recoverable, a tip-anchored miss of old funds is not.

Wallets imported BEFORE this fix keep their wrong stamp; wipe and
re-import (or re-add via the Wallets sheet) to correct them.

Co-Authored-By: Claude Fable 5 <[email protected]>
…creen

The escape hatch for wallets stamped with a wrong creation height
(e.g. imports made before the import-birth-height fix in this PR):
the heights card now shows the bound wallet's persisted birth height
with an edit affordance. Saving writes PersistentWallet.birthHeight —
the SDK's loadWallets restore feeds that row back to Rust at every
launch, so the edit is the wallet's scan floor from the next start —
and then offers an immediate filter rescan from the new height (which
reads the row, so it honors the edit right away).

Co-Authored-By: Claude Fable 5 <[email protected]>
@QuantumExplorer
QuantumExplorer force-pushed the fix/import-birth-height branch from 0319438 to 4fce88e Compare July 15, 2026 12:17
Per-network import floor (importedWalletBirthHeight): mainnet 200,000
— early-2015 and older blocks predate any wallet this app could
import, so starting there skips a year of filter work without risking
missed funds — testnet stays 0. Applied to all three unknown-provenance
paths (import, additive add, keychain recovery); the birth-height
editor's guidance copy states the defaults.

Co-Authored-By: Claude Fable 5 <[email protected]>
@QuantumExplorer
QuantumExplorer merged commit 89dd24d into swift-sdk-integration Jul 15, 2026
2 checks passed
QuantumExplorer added a commit that referenced this pull request Jul 15, 2026
…qual height

The QA mainnet wallet exposed a state the first commit couldn't repair
from the UI: the row's birth height is already correct (200,000, stamped
by the post-#804 recovery registration) but the chain store predates the
fix and is anchored at the newest checkpoint (2,500,000), so every
rescan still clamps to the anchor. The editor's equal-height guard made
"rebuild the store from my existing floor" inexpressible.

Saving a height at or below the current one now presents an explicit
"Clear chain data and resync?" confirmation; nothing is written until
the user confirms, and confirming saves the row, rewinds its synced
checkpoint, and arms the next-launch resync marker. Raising stays
persist-only. This replaces the previous save-then-inform alert, which
armed the wipe before the user saw the consequence.

Co-Authored-By: Claude Fable 5 <[email protected]>
QuantumExplorer added a commit that referenced this pull request Jul 16, 2026
… merge-dropped l10n (#808)

* fix(l10n): restore en source strings dropped by the release-8.7.0 merge

The merge commit 1ca07eb resolved DashWallet/en.lproj/Localizable.strings
mostly to master's side, silently dropping 203 integration-branch entries.
English UI kept rendering via the NSLocalizedString key fallback, but the
Transifex source lost the strings.

This restores the 34 dropped entries that are still referenced by an exact
NSLocalizedString key in the current tree (shielded-DashPay Usernames
strings from #801, Log export strings from #802, and DashPay registration
strings), inserted in the file's case-insensitive key order with their
original comment blocks. The file stays UTF-8.

Deliberately not restored:
- 160 dropped keys with no remaining NSLocalizedString reference (their
  call sites no longer exist on this branch)
- the SPV-diagnostics entries from #804: fix/birth-height-chain-resync
  restores/rewords that screen's strings, and re-adding the old wordings
  here would only orphan them when that PR lands

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(l10n): restore DashPay contacts/invitations source strings

Restores the 37 contacts- and invitations-flow entries that the
release-8.7.0 merge (1ca07eb) dropped from the en source file. Their
call sites were deleted when the contacts subsystem was rebuilt on
SwiftDashSDK (#787), but the flows are about to be redone now that
invitations live in the Dash SDK — keeping the entries preserves the
Transifex source (and existing translations) for that rework.

Selection rule: dropped keys whose last call site lived under
DashWallet/Sources/UI/DashPay/{Contacts,Notifications,Items,Profile}
or in a DWDP* contact view, as of the tree before the #787 rebuild.
Inserted in the file's case-insensitive key order with their original
comment blocks; file stays UTF-8.

Co-Authored-By: Claude Fable 5 <[email protected]>

* feat(invitations): rebuild the DashPay invitation claim on SwiftDashSDK

Resolves teardown item T1's accept arm as PORT (INVITATIONS_REBUILD_PLAN.md
is the full plan; the create/history/reclaim side follows). Invitations are
DIP-13 vouchers, cross-platform-compatible with Android's shipping
implementation (dashpay://invite?du/assetlocktx/pk/islock).

Distribution is paste/scan-first with no third-party services: the invitee
installs the app, then redeems by QR scan or paste ("Have an invitation?"
in the Join DashPay dialog), or via a dashpay:// / applink deep link when
the app is already installed. No AppsFlyer, no hosted link infrastructure.

New:
- DWInvitationLinkNormalizer — canonicalizes dashpay://invite, legacy
  invitations.dashpay.io/applink, and Android OneLink long-URLs (af_dp
  unwrap; keys tried in Android's order) down to the URI the SDK parser
  accepts. Obj-C-visible for the AppDelegate routing gate.
- DWInvitationService — protocol-seamed facade: normalize, parse/preview,
  local-identity gate, post-claim contact request to the du inviter (DPNS
  resolve + SwiftDashSDKContactsService, which owns the PIN gate and the
  lazy DashPay-key upgrade).
- ClaimInvitationScreen (+ ClaimInvitationFlow push glue) — paste field,
  QR scan sheet (GenericQRScannerView), inviter preview, inline invalid /
  already-registered states.
- DWIdentityRegistrationCoordinator.startClaimInvitation — fourth funding
  path (.invitation): same PIN gate, key pre-persist, DPNS register, phase
  reporting and identity-resume semantics; the claim consumes the INVITER's
  asset lock via wallet.claimInvitation (no local PersistentAssetLock).
- CreateUsernameView(Model) invitation mode: voucher funds the registration,
  so the balance cost rule and funding-source picker don't apply; success
  offers the inviter contact request; failures surface the SDK's typed
  claim errors.

Rewired / deleted:
- AppDelegate: dead FIRDynamicLinks handling removed (service shut down in
  2025 — it silently swallowed universal links); invitation URLs route
  directly. dashpay:// added to CFBundleURLSchemes.
- DashSync accept arm deleted: DWDashPayModel verifyDeeplink /
  createUsername:invitation: invitation branch / inviter friend-request via
  DSIdentitiesManager / invitationSteps; DWHomeModel deeplink passthrough;
  protocol surface narrowed to createUsername:.
- DashUIKit package retargeted import/final → master @ 046f0875 (matches
  release-8.7.0; the stale pin's tip no longer resolves).

Verified: clean dashpay arm64-sim builds under Xcode 26.3/Swift 6.2.4 and
Xcode 26.6/Swift 6.3.3; fresh-wallet simulator smoke of the full invitee
flow — menu entry → paste → parse/preview ("Invitation from …") → username
form (zero balance, live DPNS availability) → PIN gate → SDK claim against
testnet DAPI → typed funding-tx-not-found failure surfaced. Companion
platform change (invitation cap 0.05 → 0.25 DASH for Android's contested
tier) rides separately in dashpay/platform.

Co-Authored-By: Claude Fable 5 <[email protected]>

* docs(dashpay): record the translation-reuse audit in the invitations plan

All 42 lproj files carry translations for the legacy claim-flow strings
(already-claimed / invalid-invitation / invited-by-share copy) — the
claim error mapping and the create-side share sheet must reuse those keys
instead of minting new copy. The 37 restored contacts/invitations keys
turn out to be English source only (no repo translations survive).

Co-Authored-By: Claude Fable 5 <[email protected]>

---------

Co-authored-by: Claude Fable 5 <[email protected]>
@QuantumExplorer
QuantumExplorer deleted the fix/import-birth-height branch August 7, 2026 08:23
aliblik pushed a commit to aliblik/dashwallet-ios that referenced this pull request Nov 28, 2026
Brings the 4 new swift-sdk-integration commits (dashpay#799, dashpay#801, dashpay#802, dashpay#804:
shielded-spend resolver adaptation, Join DashPay from Shielded, in-app
diagnostic log export, imported-wallet genesis scan) onto the branch.

- 2 conflicts (project.pbxproj, en.lproj/Localizable.strings); the rest
  auto-merged. en.strings kept ours (release-8.7.0 strings); the 4 features'
  new keys are re-extracted by bartycrouch on build.
- Added the 3 new source files to targets: DiagnosticLogExporter (both),
  JoinDashPayReadinessScreen + ShieldedIdentityFundingReadiness (dashpay).
- Requires platform pinned at v4.1-dev tip dc1d645df4 (#4131 adds
  LoggingPreferences.logsRootDirectory); local ../platform bumped and the
  DashSDKFFI sim xcframework rebuilt.

Builds clean via the dashwallet-dashpay scheme (ARCHS=arm64).
aliblik pushed a commit to aliblik/dashwallet-ios that referenced this pull request Nov 28, 2026
…launch so the rescan can actually reach it

The birth-height editor shipped in dashpay#804 claimed "Rescan now" honored the
edit immediately. It never could, for two engine-level reasons:

- The live Rust wallet's birth height is fed once from PersistentWallet
  at load and has no update FFI; the rescan FFI only rewinds
  synced_height, and dash-spv's filter scan clamps its start to
  max(birth height, header store start). Same-session rescans below the
  live birth height are silent no-ops.
- dash-spv never re-anchors an existing header store
  (initialize_genesis_block returns early when any headers exist), so a
  store anchored at the newest checkpoint by the original mis-stamped
  import permanently caps how far back ANY rescan can reach — even
  after a relaunch with the corrected birth height.

The repair that works is: rebuild the chain store on a launch that
restores the lowered birth height. Lowering the height in the editor now
also rewinds the row's syncedHeight (so the restored wallet's filter
scan starts at the new height) and arms SPVChainResyncMarker, a
UserDefaults marker the SPV coordinator applies on the next launch —
deleting the network's SPV store before startSpv so the client
re-anchors at the restored birth height, and re-arming the filter
rescan in case the arming session re-raised the persisted checkpoint.
A session guard keeps the marker from firing in the process that armed
it (the store would just re-anchor at the stale in-memory floor).
Raising the height keeps the plain persist-only path and disarms any
pending marker it supersedes.

UI copy now states the real contract: lowering requires a relaunch and
triggers a full chain resync; rescans are floored at the wallet's
creation height and locally stored chain data. The false "Rescan now"
prompt is gone; wallet wipes drop pending markers.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

1 participant