perf(spv): incremental discovery, parallel chains, persistent header cache

Speed up wallet synchronization, especially re-syncs of large wallets:

- Incremental address discovery: known indices from the previous sync
  (NextReceiveIndex/NextChangeIndex) are fetched in a single parallel
  burst instead of sequential gap-limit rounds, cutting round-trips from
  O(used/gapLimit) to ~O(1). Receive and change chains scan in parallel.
- Merge tx download and Merkle verification into one parallel phase
  (no barrier between them); the per-call semaphore is dropped in favor
  of the transport-level in-flight gate.
- Persist verified block headers (SyncCache.BlockHeaders, height -> hex):
  immutable once stored, so blockchain.block.header round-trips for
  already-verified proofs are eliminated on later syncs.
- RetryOnBusyAsync with exponential backoff around server calls, treating
  -101/-102 and "server busy"/"excessive resource usage" as transient.

Wire the new PreloadCaches/ExportCaches signatures through the desktop
view model and the CLI sync command.
This commit is contained in:
2026-06-16 09:27:40 +02:00
parent 38e0f0a52e
commit 5ff2075a45
4 changed files with 227 additions and 148 deletions
+7
View File
@@ -113,6 +113,13 @@ public sealed class SyncCache
/// riverificare le stesse prove ad ogni avvio: le conferme sono immutabili.
/// </summary>
public Dictionary<string, int>? VerifiedAt { get; set; }
/// <summary>
/// Header grezzi per altezza (altezza → hex). Immutabili: non vengono mai
/// rifetchati una volta salvati. Elimina i GetBlockHeader sulle prove Merkle
/// già verificate nei sync successivi.
/// </summary>
public Dictionary<int, string>? BlockHeaders { get; set; }
}
/// <summary>Indirizzo scansionato con saldo proprio e numero di transazioni (vista indirizzi).</summary>