Repository navigation
Description
Expected Behavior
When the app is killed during the 5-second background save, the block-header store either reopens at a height it holds contiguously, or detects the gap and refills it. Filter-header sync then carries on to the tip.
Current Behavior
A kill partway through the save can leave an interior run of Segment::sentinel() records in block_headers, with a later segment already on disk. On reopen, the tip comes from the highest segment, so the store reports itself synced to the tip and the hole is never refilled. Filter-header sync then asks peers for a CFHeaders batch whose stop hash is the sentinel's hash. Every peer drops the connection about 0.3–1 s after the request, and sync never moves.
Seen on a devnet wallet (reproduction, sakura, protocol 14), after one app kill in the first session:
segment_000015.dat(heights 150000–159999): records 0–2000 are real, and records 2001–9999 are all sentinel (version0x7fffffff, prev-hash allff, time0xffffffff).segment_000016.datholds real headers from 160000.- Session 1's last storage line:
BlockHeadersStored(tip=160000), then the process is gone (no shutdown lines, noFailed to persist segment). - Next launch:
BlockHeadersManager initialized at height 160000. Header sync continues above the hole up to the tip. - From then on, in every session (three relaunches, about 35 min in the last one):
Filter Headers: Syncing 152000/<tip> (85.2%) processed: 0 Starting filter header sync from 152001 to <tip> Built CFHeaders request queue: 14 batches Peer <ip>:20001 closed connection (EOF) ×~3,600 Reconnecting to exclusive peer <ip>:20001 ×~46,000 handshakes - The stop hash for batch 152001–154000 is the sentinel record's hash (
516fdbb8…d21b53); the real header at 154000 is0ddab145…526f08. - A second wallet, killed the same way in the same minute, lost the newest segment instead. It reopened consistently at 129999, re-downloaded, and synced. So the outcome depends on which segment the kill caught.
Possible Solution
Three pieces combine here, at 626c91d (the commit dashpay/platform 41b6acb39e pins):
- The save is not atomic across segments, and its order is arbitrary. The worker persists every 5 s (storage/mod.rs#L200-L214). Each segment is written separately while iterating a
HashMap(segments.rs#L484-L492), so a later segment can reach disk before an earlier one. - The tip on reopen comes from the highest segment's last valid slot (segments.rs#L124-L129). Nothing checks that the segments below it are filled.
- The CFHeaders stop hash is read from that store unchecked (sync/filter_headers/pipeline.rs#L87-L92). A sentinel record yields a hash no peer knows.
Fix direction, any of these:
- Persist segments in ascending order and record the contiguous tip only after the lower segments are written (or write a tip marker last).
- On reopen, take the tip as the end of the first contiguous run from the lowest segment, so the hole is re-downloaded.
- Treat a sentinel as missing in
get_header, which turns the stop-hash lookup intoMissing header at height …rather than a request peers reject. Today that check runs only underdebug_assertions, see dash-spv: SegmentedStorage::get_items() panics on segments with non-zero first_valid_offset (checkpoint-based / sparse segments) #792.
Steps to Reproduce
There is no deterministic repro yet; it depends on when the kill lands relative to the 5-s save.
- Create a new wallet on a devnet or testnet and let header sync run.
- Kill the app (
simctl terminate/ swipe away) while headers are being stored, a few segments into the chain. - Relaunch. If the newest segment reached disk but an older one did not,
initialized at heightreports the higher tip, and filter-header sync stalls at the start of the hole with peers dropping every connection.
The segment files and logs of the affected store are kept and can be shared on request.
Context
This came up while running QA scenarios for dashpay/dashwallet-ios#1199: one of the case's wallets showed "Syncing 90.2%" indefinitely. Same family as #792 (sentinel reads from sparse segments are not caught in release builds), with a different trigger: a kill during the save, on block headers. #1183 (merged 2026-10-19) changes the storage worker's lifetime but not the save order, atomicity, or the tip read on reopen, so it does not cover this.
Workaround in the app: Core Sync Status → Edit birth height → Clear & resync, or delete Documents/SPV/<network> while the app is not running. Either route re-downloads only chain data.
Your Environment
- dashwallet-ios
feat/contested-username-fees@2397b36fd(Debug, iOS 26.5 simulator) - dashpay/platform
41b6acb39e→ rust-dashcore626c91d - Network: devnet sakura (protocol 14)
Activity