Skip to content

Compact-filter committed_height freezes one block below tip after client restart, leaving SyncProgress::is_synced() permanently false #824

Closed

Description

@lklimek

Crate: dash-spv
Rev observed: 981e97f1015960ae5d277afdabcba1cbbc0b3a63
Network: Testnet (core chain ~1,502,6xx)
Severity: High — a single mistimed block permanently wedges sync with no client-side recovery.

Summary

After a DashSpvClient restart in which compact-filter headers are already persisted up to the chain tip, a core block that arrives during the client's reinit window falls into a one-block gap between the from-genesis filter-body rescan and the live tip tracker. That block's compact-filter body is never requested or committed, so the Filters phase committed_height freezes one block below the chain tip — permanently. Because SyncProgress::is_synced() requires the Filters phase to be Synced, it stays false forever, and every downstream consumer reads the client as "syncing" indefinitely even though the chain, filter headers, masternodes, and chainlocks are all fully synced.

This was observed in a host application (Dash Evo Tool) where a Disconnect→Reconnect recreates the DashSpvClient; the reinit window during that recreation is when the offending block arrived. The host UI then displayed "Syncing…" forever with no recovery path.

Symptom

After the restart, every sync phase reaches Synced except Filters, which is wedged:

Headers:        Synced 1502629/1502629
Filter Headers: Synced 1502629/1502629
Filters:        Syncing 1502615/1502629 (100.0%) stored:1502615, downloaded: 0, processed: 0
Blocks:         Synced ...
Masternodes:    Synced 1502629/1502629
ChainLocks:     Synced ; InstantSend: Synced ; Mempool: Synced

FiltersProgress::current_height() returns committed_height (1502615), which never crosses 1502616, so the phase state stays Syncing (committed_height < target_height) and SyncProgress::is_synced() (all phases must be Synced) returns false for the life of the client.

Root cause (analysis)

The offending block (1502616) arrived inside the reinit window — its header was stored ~2s after the fresh client initialized filter headers to the prior tip (1502615), straddling the boundary between:

  1. the from-genesis historical filter-body rescan (whose tail batch nominally covered up to 1502616 but never committed it — batch-complete download ≠ commit), and
  2. the live tip tracker, which began requesting filter bodies at 1502617.

The contiguous commit pointer (committed_height) therefore cannot cross the 1502616 hole. All later tip filters (1502617…1502632) download and "complete" fine but are wasted — the pointer is stuck behind the gap.

Relevant code paths (rev 981e97f):

  • dash-spv/src/sync/filters/sync_manager.rs ~L89 — pipeline.init(stored_filters_tip + 1, stored_filters_tip) on restart; the boundary block that lands between init and the first live FilterHeadersStored is the one that slips through.
  • dash-spv/src/sync/filters/pipeline.rs / manager.rs — batch download vs. commit/contiguity accounting; a downloaded-but-not-committed batch does not advance committed_height.
  • dash-spv/src/sync/filters/progress.rs — current_height() returns committed_height.
  • dash-spv/src/sync/progress.rs — SyncProgress::is_synced() requires all phases (incl. Filters) Synced.

Evidence (falsifiable, from a ~1.9M-line client log)

  1. The body for the gap block was never requested. GetCFilters: 1502616 to 1502616 — 0 occurrences in the entire post-restart log. Tip body requests are contiguous except 1502616: … 1502614, 1502615, [1502616 ABSENT], 1502617, 1502618 ….
  2. committed_height is frozen at 1502615 across the entire post-restart log. Every Filters progress line reads 1502615/…; not one line has a first value ≥ 1502616.
  3. Download ≠ commit. Immediately after the rescan's final batch logged Filter batch 1502001-1502616 complete, the very next progress still read Filters: Syncing 1502615/1502617 stored:1502615.
  4. Not environmental / not a peer-capability issue. Peers served ~1.5M cfilter responses with zero unknown block hash / validation rejections post-restart. The wedge is purely client-side commit accounting. (This distinguishes it from dash-spv: compact-filter sync stalls silently when the only connected peer lacks NODE_COMPACT_FILTERS #815, which is the same symptom — Filters phase never reaching Synced — via a different cause, a peer lacking NODE_COMPACT_FILTERS.)

Timeline (UTC)

Time Event
08:25:41 Old client shutdown complete; storage persisted (Disconnect)
08:25:44 Fresh client starts (SpvRuntime::run() recreates DashSpvClient)
08:25:46 BlockHeadersManager initialized at height 1502615; sync-manager tasks spawned; best_height=1502615
08:25:54 New header arrives: Segment 0: 1 headers ready to store from height 1502616
08:25:56 FilterHeadersStored(1502616-1502616, tip=1502616); from-genesis filter-body rescan begins
08:26–08:28 ~1.5M cfilter messages downloaded; rescan tail Filter batch 1502001-1502616 complete — yet committed_height stays 1502615
08:28→tail Tip requests 1502615 → [1502616 skipped] → 1502617, 1502618, …; every later filter "completes" but cannot advance the frozen pointer
later Every phase Synced except Filters: Syncing 1502615/1502629

Reproduction

  1. Sync a DashSpvClient to tip (filter headers + bodies committed to height H).
  2. Restart the client (recreate DashSpvClient) while a new block H+1 lands during the reinit window — i.e. after filter headers init to H but before the live tip tracker starts requesting bodies.
  3. Observe: committed_height stays at H; the Filters phase reports Syncing H/(H+k) indefinitely; SyncProgress::is_synced() never returns true, despite all other phases Synced and peers healthy.

Suggested fix

On restart, guarantee no gap at the rescan/tip boundary: re-request and commit any filter body in (committed_height, filter_header_tip] that is not yet committed before (or as part of) starting live tip tracking. In practice, resume tip tracking from committed_height + 1 rather than filter_header_tip + 1, and ensure the historical-rescan tail batch actually advances committed_height to its upper bound on completion (investigate why batch 1502001-1502616 completed download without committing 1502616 — the commit/contiguity logic in filters/pipeline.rs + manager.rs).

A committed_height-stall guard (Filters committed_height not advancing while filter_header_tip/Headers advance for N seconds → re-drive the gap) would also make this self-healing rather than terminal.

Related

🤖 Co-authored by Claudius the Magnificent AI Agent

Activity

  1. lklimek commented on Jul 1, 2026

    @lklimek
    ContributorAuthor

    Independent reproduction at a second rev (5c0113e, dash-evo-tool's pin) plus a mechanism-level root cause that answers the open question in the report — "why did the tail batch complete download but never commit?"

    TL;DR: on an already-synced boot, FiltersManager::start_download takes its "Filters already synced" early return before it initializes the download pipeline or the store cursor. The pipeline is left uninitialized (target_height = 0) and next_batch_to_store = 0. When the next block's filter header arrives, handle_new_filter_headers calls extend_target on that uninitialized pipeline, which re-enqueues from height 1 (a full from-genesis re-download), and the in-order store loop then wedges forever because the lowest completed batch starts at height 1 while next_batch_to_store == 0. Nothing commits → stored_height/committed_height frozen at the persisted height, exactly as reported. (The gap isn't strictly one block — it's tip − persisted_height, and it grows with every new block: I observed stored:1506436 while the tip climbed 1506438 → 1506444.)

    Mechanism (code refs @ 5c0113e, dash-spv/src/sync/filters/):

    1. Early return skips init. manager.rs:195-204 — when the wallet boots already synced (scan_start > filter_header_tip), start_download logs Filters already synced to … and returns at :201-203, before self.next_batch_to_store = download_start (:220), self.processing_height = scan_start (:221), and self.filter_pipeline.init(download_start, tip) (:235). So next_batch_to_store stays 0 (default :113) and the pipeline stays uninitialized (FiltersPipeline::new() → target_height = 0).

    2. extend_target re-downloads from genesis (off-by-one). The next filter header drives handle_new_filter_headers (manager.rs:870), which calls self.filter_pipeline.extend_target(tip) (:888). In pipeline.rs:113-128, old_target = 0, so it enqueues batches from current = old_target + 1 = 1 up to tip — a full-chain re-download even though filters are already stored. send_pending (:891) then issues GetCFilters from height 1.

    3. In-order store loop wedges. Completed batches flow to store_and_match_batches (manager.rs:286). The store loop (:306-315) requires batch.start_height() == self.next_batch_to_store; the lowest completed batch starts at 1, but next_batch_to_store == 0, so it breaks on the first iteration, every time. Nothing is ever stored (stored_height never advances via :397), so the tip batch never becomes scannable/commitable and committed_height is frozen — the "download ≠ commit" this issue observed.

    Control A/B (proof it's the resume path):

    Clean boot (filters wiped) Resume boot (persisted state) — the stall
    init log Starting filter download (scan_start=0, download_start=0, stored_filters_tip=0, …) (full init) 0× "Starting filter download"; 1× Filters already synced (early return)
    first request GetCFilters: 0 to 999 (init from download_start=0, matches next_batch_to_store=0) GetCFilters: 1 to 1000 (extend_target old_target+1, ≠ next_batch_to_store=0)
    result Filters: Synced … processed:1506465, matched:365; wallet tx detected at its block Filters: Syncing … stored:<frozen>, processed:0, matched:0 (permanent)

    Same binary, same wallet, same peers — the only difference is persisted filter state, and the divergence is exactly init() (from height 0) vs extend_target (from height 1).

    Note on PR #816: #816 sets processing_height = scan_start before the early return, which fixes the height-0 lookahead panic under checkpoint sync. But it does not set next_batch_to_store or init() the pipeline on the early-return path, and pipeline.rs::extend_target is unchanged — so by code reading the genesis re-download (step 2) and the store-loop wedge (step 3) persist past #816. Bumping to ≥ #816 alone likely does not resolve this.

    Suggested fix (in addition to the boundary guard already proposed): on the already-synced early-return path, either initialize the pipeline (init(download_start, tip)) and set next_batch_to_store = download_start, or have handle_new_filter_headers call start_download when filter_pipeline.is_idle() instead of extend_target on an uninitialized pipeline. That both removes the pointless from-genesis re-download and lets the store cursor advance from the correct frontier. A committed_height-stall watchdog (as suggested) is still worthwhile as a self-healing backstop.

    🤖 Co-authored by Claudius the Magnificent AI Agent

  2. added 6 commits that reference this issue on Jul 2, 2026
    f1ba38b
    03a5d70
    74d1805
    dfe0520
    a45445f
    f2b4c18
  3. lklimek commented on Jul 2, 2026

    @lklimek
    ContributorAuthor

    Claudius says it's fixed:

    rust-dashcore#835 (filter tip-boundary stall on restart) — confirmed fixed: spv_reconnect::spv_reconnect_succeeds_without_already_open now passes

  4. added a commit that references this issue on Jul 5, 2026
    c88264e
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