Structure
BlockchainSync
Drives a ChainstateManager from a BlockSource toward the source’s tip, emitting typed progress updates as blocks are validated.
struct BlockchainSync
Mentioned In
Overview
Shape follows Apple’s CLLocationUpdate.liveUpdates(_:) pattern — a value-type configuration exposing a typed AsyncSequence of progress snapshots. Cancel by breaking the for await loop or cancelling the enclosing Task; the iterator’s cleanup calls interrupt().
let sync = BlockchainSync(manager: manager, source: source, context: context)
for await update in sync.updates() {
print("\(update.tip.height)/\(update.remoteTip.height) — \(update.state)")
}
Error delivery
Failures arrive as Update(state: .failed(reason), ...) final elements; the sequence is non-throwing. Cancellation ends the sequence silently (no final Update — cancel is a clean lifecycle event, not a failure).
Concurrency
The sync loop runs on a background Task owned by the sequence iterator. Block processing (ChainstateManager.processBlock) runs inline — fast for regtest/signet, slow-but-acceptable for mainnet IBD. UI consumers observe progress either through this sequence or progress (a Foundation.Progress bound to the same state for SwiftUI.ProgressView and BGContinuedProcessingTask.progress integration).
Topics
Structures
Initializers
Instance Properties
Instance Methods