Full stack Bitcoin software

01 — Reliability

Source-anchored architecture documentation for libbitcoin-database: heads, bodies, maps, tables, the memory-mapped store and queries.

Companion to 00-overview and 04-storage.

The store is fail-stop and recoverable. Under the assumptions every system must make, it either holds exactly what was written or it is condemned and returned to a known-good state. It never opens a store whose contents it cannot vouch for, and it never repairs one.

Citations are to libbitcoin-database master at 10e63cfe, relative to include/bitcoin/database/, and to libbitcoin-server where marked.


1. Terms#

The common phrase "a reliable store" bundles properties that have to be kept apart.

Term Meaning
Reliability A rate: how often a component fails.
Fail-stop A shape: when a component fails, it stops detectably. It never returns wrong data as good.
Fail-partial The alternative: a failed component may keep running and return wrong or stale data as good.
Crash consistency After a hard shutdown, the store is always in a state its contract allows.
Recoverable A stop is not terminal: the store can be returned to a known-good state.

A component that halts every week is fail-stop and unreliable. One that runs for years and then silently serves stale data is reliable and fail-partial, and it is the second that destroys data, because every layer above it was built on failures being announced.


2. Assumptions#

Two assumptions underlie every claim on this page. Neither is particular to libbitcoin. No software can do without them.

Everything that follows holds under these two assumptions, and only under them.

2.1 Fail-stop hardware is working hardware#

"Working hardware" has a precise meaning here: every fault below the software either does not occur or surfaces as a detectable stop, an error return or a halt, and never as wrong data returned as good. With correct software above it, that leaves no path by which an error can enter the store unannounced. Each failure is either absent (software, by assumption) or announced (hardware, by assumption).

The assumption covers the whole substrate the software touches, not only the drive. A fail-stop drive beneath memory without ECC still admits silent error, because data can change after the drive has delivered it correctly. ECC memory, interface CRCs and drive-internal ECC each buy fail-stop behavior for their own segment.

2.2 What no layer can add#

The fail-stop property cannot be conferred from above.

So software checks are probabilistic mitigation, not a guarantee. A store that assumes fail-stop hardware and does not checksum is not omitting a protection. It declines a permanent cost for a check that cannot deliver the property it suggests.

2.3 Masking#

A component that is always correct and never stops would be stronger than fail-stop. No single device can guarantee it.

Continued correct service through faults requires redundancy across independent failure domains, and its guarantee is conditional on a fault budget.

2.4 RAID#

RAID is that redundancy across drives, and it assumes fail-stop members. A member that stops is an erasure at a known location, so the array reconstructs it from the others and keeps serving. A code that corrects n erasures corrects only n/2 errors at unknown locations, so the announcement is worth twice the redundancy.

Normal reads do not check parity, so a fail-partial member's wrong data passes through. A parity update computed from it writes the error into the parity, and a later rebuild restores it with confidence. RAID masks the stops of fail-stop members and does nothing for silent faults.

2.5 Running bs on the hardware#

bs requires fail-stop hardware and nothing more:


3. The guarantee: fail-stop by construction#

The store does not ask whether its contents after a crash are valid. That question has no reliable answer. It asks whether the store closed cleanly, which is decidable.

The predicate never depends on code that ran during the crash, so it cannot be wrong about the crash. It deliberately over-approximates: some condemned stores were in fact intact. That availability cost is what keeps the guarantee free of exceptions.

The clean-close state itself is sound because the store admits only two kinds of durable change, each consistent at any instant a fault can strike:

  1. Atomic directory renames on one volume: snapshot promotion and rotation, all-old or all-new.
  2. Append-only body writes with logical truncation: content below any recorded count never changes once written, so every body state that can exist on disk is a valid extension of every recorded count.

Mutable state lives in heads, which are replaced only as a whole (04 §6). Every deletion that matters is an atomic rename. Non-atomic deletion touches only directories already defined as garbage.

Invariant (Reliability-1). A store opens only if it closed cleanly, and a store that closed cleanly holds exactly what was written.

Invariant (Reliability-2). No snapshot directory that restore could prefer is ever modified in place.


4. Recovery#

A condemned store is returned to a state whose correctness rests on something other than the damaged store:

Both paths end in a state the store did not have to vouch for. The snapshot was taken while the store was known good. The network is an independent source.

Invariant (Reliability-3). Recovery never trusts content of the condemned store beyond the counts recorded by a snapshot taken at a quiescent point.

4.1 Why not repair#

Repair is not a choice the design declines. It is not possible, because nothing can certify a repaired store as correct.

A repaired store would be trusted on no grounds at all. Rollback to a known-good state, or a rebuild from the source, is the only recovery there is.


5. Runtime faults#

Faults while running are announced, never absorbed.


6. Compared with Bitcoin Core#

Bitcoin Core keeps its chain state in LevelDB. Under the same two assumptions, it can offer no comparable guarantee.

libbitcoin Bitcoin Core
Failure model of the store fail-stop fail-partial
After a hard shutdown clean close or condemned, decided without examining contents examined, repaired, then trusted
After a reported error bad hardware or software, since the store cannot corrupt itself bad hardware, bad software or store corruption, indistinguishable
Recovery snapshot restore or rebuild repair, reindex or resync, each assuming store corruption
Recovered store rests on a snapshot taken while known good, or the network the damaged store's own contents, unless resynchronized

7. The network is the redundancy#

A single component can be at best fail-stop and recoverable. Keeping service through faults requires redundancy across independent failure domains, and redundancy is only sound over members that fail by stopping, since it must know which member failed.

Bitcoin already provides that redundancy: thousands of independent nodes, any one of which can stop while the rest serve. The network is the array and nodes are its members, and like RAID (§2.4) its contract holds only over members that stop rather than lie. For a node, the correct design is therefore exactly fail-stop and recoverable. Masking faults inside the node would duplicate, conditionally and less well, what the network provides as a whole.


Cross-references#

Copyright © 2011-2026 libbitcoin developers