Validate and append count = raw.length/80 headers extending the tip.
All headers validate before anything is committed or persisted.
A prev-hash mismatch on the FIRST header (i.e. at tipHeight+1) throws the typed ReorgLinkError: it is the only failure that is evidence of a chain reorganization rather than a bad batch. Every other failure (PoW, bits, median-time-past, checkpoint, deep linkage break) is a plain Error and must never trigger a rewind.
snapshot the in-memory state (headers, work, file-divergence flag)
write the in-memory chain to the persistence file if it has diverged
restore a snapshot taken by captureState (memory only; file untouched)
Drop headers above height (reorg handling). With persist: false the
rewind stays in memory (the file is rewritten once by the next persisting
append or an explicit flush()).
StaticopenOpen a chain; when file exists its contents are appended through FULL
validation (a tampered file cannot load). The first 80 bytes must be the
configured base header.
cumulative work from base to tip (sum of per-header expected work)