<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "BitcoinKernel",
  "identifier" : "/documentation/BitcoinKernel/BlockchainSync",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "BitcoinKernel"
    ],
    "preciseIdentifier" : "s:13BitcoinKernel14BlockchainSyncV"
  },
  "title" : "BlockchainSync"
}
-->

# BlockchainSync

Drives a [`ChainstateManager`](/documentation/BitcoinKernel/ChainstateManager) from a [`BlockSource`](/documentation/BitcoinKernel/BlockSource) toward the source’s
tip, emitting typed progress updates as blocks are validated.

```
struct BlockchainSync
```

## 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()`](/documentation/BitcoinKernel/Context/interrupt()).

```swift
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`](/documentation/BitcoinKernel/BlockchainSync/progress) (a
`Foundation.Progress` bound to the same state for `SwiftUI.ProgressView`
and `BGContinuedProcessingTask.progress` integration).