Skip to content

dash-spv: a rescan below the wallet birth height restarts the filter scan forever #1542

Done

Description

@romchornyi

What happens

After a filter rescan that rewinds a wallet below its birth height (the "full rescan from 0" a wallet app offers), the filter scan never finishes. tick restarts it every couple of seconds:

Wallet synced_height 0 fell below filter committed_height 204999, restarting scan at 200000
Starting filter download (scan_start=200000, ...)
Committed batch 200000-204999, committed_height now 204999
Wallet synced_height 0 fell below filter committed_height 204999, restarting scan at 200000

On a mainnet device this ran 3,817 times in 1 h 40 min until the app was closed. The wallet's synced_height stayed at 0, no SyncHeightAdvanced was emitted, and the SPV log grew by about 200 MB. A brand-new mainnet wallet reproduces it in seconds: 73 restarts in the first 13 s after the rescan.

Seen with dash-spv 0.47.0 (f0ddfd45f78e). dash-spv 0.46.0 (aca020263990) does not loop.

Why

Two places compute the lowest height a scan covers, and they disagree:

  • tick (and start_download) floor the scan at earliest_required_height().max(header start).
  • try_commit_batches floors the contiguity guard at the header start only.

Since #1161 a checkpoint stores CHECKPOINT_HEADERS (25) headers ending at its height, so the stored chain starts 24 blocks under a wallet born at that checkpoint (mainnet imports default to birth 200000; new wallets are born at the latest checkpoint). With synced_height = 0 the first batch starts at the birth height, the guard sees heights start - 24 .. birth - 1 as an uncovered gap, and refuses to certify. The wallet stays behind, so tick resets the scan again.

A normal sync does not hit it, because the wallet's synced_height already sits at or above its birth height. Relaunching the client stops the loop, but the rescan that was asked for never happens.

Steps to reproduce

  1. Mainnet wallet with birth height equal to a checkpoint height (e.g. 200000 or 2550000), fully synced.
  2. Rewind its synced_height to 0 while SPV runs.
  3. Watch the filter manager restart at the birth height forever.

Fix direction

Use the same floor in both places.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions