Skip to content

bug: spark exit funding is not watched after a restore #1296

Closed

Description

@ovitrif

Twin: synonymdev/bitkit-android#1877
Refs: #1217

Problem

After the wallet is restored from its recovery phrase on a new device, exit funding sent to a funding address at index 1 or above isn't watched. A user who restores after a failed salvage can leave that funding unrecovered, with no automatic way back.

Why

  • The next funding index is a counter in UserDefaults.standard, under sparkExitNextFundingIndex-<network>-<walletIndex> (Bitkit/Managers/SparkExitManager.swift:1174-1179, set at :964, given back at :545-546).
  • The only other input is the exit record stored on the device (SparkExitMath.nextFundingIndex, Bitkit/Services/SparkExit/SparkExitFunding.swift:585-588).
  • Bitkit's settings backup doesn't include the counter (Bitkit/Models/SettingsBackupConfig.swift).
  • The Spark exit backup holds only each leaf with its ancestor chain, with no funding data (unilateral_exit_backup.rs#L29-L34 at Spark SDK 0.28.0).
  • So after a restore from the phrase, the counter reads 0 and no record exists.
  • Unlike Android, an iCloud or Finder device backup restored onto a new iPhone can bring UserDefaults back. A restore from the phrase alone can't.

Raised by @pwltr in review 5850248225 on the Android twin, and checked against the SDK source.

Fix options

  • Scan funding addresses 0..N at start, up to a gap limit.
  • Or back up the counter with the exit backup or the settings backup.

Test

Set the counter to 3, clear UserDefaults and the exit record, restore from the seed, and assert that the next exit finds a UTXO at index 2.

Activity

  1. self-assigned this
    on Nov 11, 2026
  2. added this to the 3.2.0 milestone on Nov 11, 2026
  3. ovitrif commented on Nov 11, 2026

    @ovitrif
    CollaboratorAuthor

    Fixed in synonymdev/bitkit-ios#1217 (7622b77..31be1fe), which now closes this issue. The funding counter and the earlier exit addresses are in the VSS METADATA backup. A restore keeps the higher counter. Without a backed-up counter, the funding addresses are scanned (gap of 20, at most 1,000). Every funding address that still holds coins is watched again after a restore.

  4. ovitrif commented on Nov 12, 2026

    @ovitrif
    CollaboratorAuthor

    Closed: fixed by #1217 on the Spark branch, which reached master through #1128 at 96225a1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions