fix(litebe-sync): bound the reorg recovery window to the max depth

When sync hit a reorg it stepped the scan back to just before the
invalidated block, then set the top of the re-scan range to that
point plus the full forward batch size. That window is far larger
than any reorg can be: the batch size is tuned for forward streaming
(tens of thousands of blocks), while a reorg is capped at the maximum
reorg depth and the pass aborts once it is exceeded. So the recovery
pass re-fetched and re-scanned a large span of already-good blocks
before it could resume moving forward.

- The recovery range now reaches only the maximum reorg depth (plus
  one) above the rewind point, which is the most a reorg can ever
  disturb. Forward syncing still uses the full batch size; only the
  pass immediately after a reorg is bounded this way.
- The set of blocks that ultimately get scanned is unchanged - the
  next pass picks up from where recovery stops - so the resulting
  wallet is identical, just reached with far less redundant fetching
  and scanning.

The wallet file format is unchanged.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 08:50:12 -05:00
co-authored by Claude Opus 4.8
parent d9dae45c39
commit be69c9bafe
@@ -1805,7 +1805,7 @@ pub fn start_mempool_monitor(lc: Arc<LightClient>) -> Result<(), String> {
self.taddr_note_unscanned(start_height, &block_times);
// Reset the scanning heights
last_scanned_height = (invalid_height - 1) as u64;
end_height = std::cmp::min(last_scanned_height + scan_batch_size, latest_block);
end_height = std::cmp::min(last_scanned_height + crate::lightwallet::MAX_REORG as u64 + 1, latest_block);
warn!("Reorg: reset scanning from {} to {}", last_scanned_height, end_height);