Shared Archive and Finality-Bounded Storage
One writer keeps the history, many nodes keep only what is not yet final and read the rest from a shared archive they never write to. What that requires of the reader, the writer, and the boundary between them.
Abstract
A node on a Lux network keeps the whole chain because it might be asked about any of it. On a host running many nodes this is the dominant cost, and almost all of it is the same bytes written many times: the history each node holds is identical, and identical because finality made it so.
This LP specifies a second arrangement. One node writes — it participates in consensus, it keeps the full history, and it is the only process that may modify the store. Other nodes on the same host keep only the blocks that are not yet final, a working set bounded by the finality window rather than by the age of the chain, and answer anything older by reading the writer's store without ever writing to it.
The arrangement rests on a property Quasar already provides and nothing currently consumes for storage. A block is final when α distinct validators have signed ACCEPT over the same position and their cumulative stake exceeds two thirds; the certificate is identical whichever node assembles it, and any node can recompute it (LP-0110 §3, LP-4655). A reader therefore does not have to trust the writer about what is final. It can check.
What this LP does not do is pretend the remaining problem is small. A reader opening a store an active writer is compacting can observe a state that never existed. Sections The boundary a reader may read to and Where this can still be got wrong say what that costs and what has to be true before it is safe.
Motivation
Three facts, and the arrangement follows from them.
Storage on a many-node host is dominated by history. The C-Chain on Lux mainnet is past 1.1 million blocks. A host running a hundred nodes writes that history a hundred times, and every copy after the first is redundant in the precise sense that its contents are determined: two honest nodes that have both finalised block n hold the same bytes for it, or one of them is wrong.
Finality on this network is not probabilistic. Under Nakamoto-style consensus a node cannot discard old blocks, because a longer fork may arrive and require them. Under Quasar a finalised block cannot be reverted — Flare's cascade is "deliberate, irreversible" (LP-0112) — so a block older than the finality window is not a thing a node needs in order to participate. It is only a thing a node needs in order to answer questions about the past.
Those are different needs and they currently share one mechanism. A node that
answers eth_getBalance at a block from last year needs that history. A node
voting on the current round does not. Today both keep everything, because there
is no way to say "keep the second, borrow the first."
What the arrangement is
Two roles, on one host, over one store.
The writer is an ordinary full node with one added responsibility: its data directory is readable by the readers, and it publishes a finality boundary they can act on. It votes, it stores everything, it is the only process that mutates the store.
A reader is a node that keeps blocks from the finality boundary forward in its own small store, and for anything below the boundary reads the writer's store directly. It never writes there. It votes if it is a validator; nothing about this arrangement changes its consensus behaviour, because consensus only ever concerns unfinalised state, which a reader holds locally in full.
The names matter less than the asymmetry: exactly one process may write, and the readers' correctness must not depend on the writer being well-behaved beyond what a certificate proves.
Why the obvious implementation is wrong
zapdb supports opening a store read-only, and a reader that does so takes a
shared lock:
opts := unix.LOCK_EX | unix.LOCK_NB
if readOnly {
opts = unix.LOCK_SH | unix.LOCK_NB
}
zapdb/dir_unix.go:47. The writer holds LOCK_EX. Those are mutually exclusive,
so a reader cannot open a directory a live writer holds. The arrangement in
this LP is not possible today, and that is the first thing an implementer will
discover.
There is an option that removes the check — BypassLockGuard, whose own
documentation says it "can cause data corruption if multiple badger instances
are using the same directory" (zapdb/options.go:88). Setting it and declaring
the problem solved would be a mistake, and it is worth naming precisely why: the
warning is about multiple writers. Bypassing the guard removes the protection
against a second writer as well as the obstacle to a reader, and nothing at the
storage layer then distinguishes the safe case from the unsafe one.
So the storage layer needs a mode it does not have. A reader MUST NOT reach it by bypassing the lock guard.
The mode zapdb needs
An implementation MUST add an open mode that is explicit about the asymmetry rather than achieved by removing a check. Call it what it is: the store is being opened by a process that will not write to it, while another process might.
Requirements on that mode:
- It MUST take a shared lock and MUST fail if it cannot, so two writers remain impossible. What it must not do is fail because a writer holds the directory — which is the whole point, and is why this cannot be the existing read-only mode with the lock weakened.
- It MUST NOT write to the directory. Today read-only open still creates
directories and files where they are absent (
db.gocreateDirsruns before the lock is taken). A reader on a shared archive MUST NOT do that: the store is not its to initialise, and a reader that creates a file has already made the writer's directory something the writer did not write. - It MUST NOT run compaction, garbage collection, or any background task that mutates state.
- It MUST observe a stable view of the store for the life of a read, per the boundary below.
The boundary a reader may read to
This is the hard part and the reason the design needs specifying rather than just building.
An LSM store is a set of immutable sorted tables plus a manifest naming which tables are live. Immutability is what makes this tractable: a table, once written, does not change. What changes is the manifest, when compaction replaces a set of tables with a new one and deletes the originals.
A reader that follows the manifest while the writer compacts can therefore observe a set of tables that never simultaneously existed, or hold a file the writer has unlinked. Neither is a hypothetical.
The rule this LP sets:
A reader MUST pin a manifest generation, and MUST serve every read for the life of that pin from the tables that generation names. A reader MUST NOT follow the writer's manifest as it advances.
And the corresponding obligation, which is the price:
A writer MUST NOT delete a table that any live pin names. It MUST retain superseded tables until every pin naming them is released.
That is a real cost and it belongs in the open. A pin held for a long query, or leaked by a crashed reader, holds disk the writer would otherwise have reclaimed. An implementation MUST therefore make pins expire, and a reader whose pin has expired MUST re-pin and MUST NOT silently serve from tables it can no longer prove are live.
The pin is what makes a reader's view a snapshot rather than a race. Everything else here is bookkeeping.
What a reader keeps, and where the boundary sits
A reader keeps, in its own store:
- every block from the finality boundary forward, in full;
- the state needed to validate and vote on those blocks;
- nothing below the boundary.
The boundary is a block height B such that every block at or below B carries a finality certificate. A reader MUST verify that certificate itself. It MUST NOT take the writer's word for the boundary, and an implementation that has the writer simply assert a height has moved the trust and not removed it.
This is the part Quasar makes cheap. The certificate is a set of validator signatures over a position with cumulative stake above two thirds; it is "identical regardless of who assembles it" (LP-0110 §3), so verification is arithmetic on a signature set the reader already knows how to check. A reader that cannot verify a certificate for height B MUST treat B as not final and MUST keep those blocks locally.
The window between the boundary and the head is bounded by finality latency, which on this network is sub-second, plus whatever margin an operator chooses. An operator MUST be able to set that margin. Setting it to the whole chain degrades a reader to an ordinary full node, which is the correct behaviour for that setting rather than an error.
What a reader answers, and what it refuses
A reader answers a query about a block below the boundary from the archive. A query about a block above the boundary it answers from its own store. Both are ordinary reads and neither needs to say which it was.
Three cases MUST be distinguished in what a reader returns, and this LP is explicit because collapsing them is the failure that turns a storage optimisation into a lie:
| Case | What it means | What the reader returns |
|---|---|---|
| Present | The archive holds it | The value |
| Absent | The archive is complete and does not hold it | Not found |
| Unavailable | The archive could not be read, or the pin expired | An error naming the cause |
A reader MUST NOT return not found when the truth is unavailable. A caller cannot tell those apart from an empty result, and a client that treats an unreachable archive as an empty chain will report a balance of zero for an account that has one. This is the same failure the exchange interfaces guard against when an indexer refuses a query, and it has the same shape here.
What this does not do
It does not make a reader trustless with respect to the archive's contents below the boundary. A reader verifies that block B is final; it does not re-verify the state of block B − 100,000 that it reads from the archive. A writer that serves corrupted history to a reader that does not check will be believed.
Mitigating that is possible and out of scope here: the state root at the boundary commits to everything below it, so a reader could verify an archive read against that root. Doing so on every read costs the arrangement most of its benefit. LP-0550 (vector commitment state tree) is the machinery an implementation would reach for, and the trade — verify always, verify on sample, or trust the host — SHOULD be an operator's choice rather than a constant in the code.
An implementation MUST document which of those it does. An arrangement that verifies nothing and says nothing is the one to refuse.
It also does not address readers on a different host. Everything here assumes a shared filesystem. A network archive is a different design with a different failure model, and calling this one "shared" should not be read as implying it.
Conformance
An implementation conforms if:
- A reader opened against a live writer's directory succeeds, and a second writer against the same directory still fails.
- A reader creates no file and modifies no file in the writer's directory, verified by comparing the directory before and after a reader's full lifecycle.
- A reader's answers do not change while its pin is held, across writer compactions — the test is to compact aggressively under a held pin and assert a stable view.
- A reader independently verifies the finality certificate at its boundary, and refuses to prune below a height whose certificate does not verify.
- A reader distinguishes absent from unavailable, verified by making the archive unreadable mid-query and asserting an error rather than an empty result.
- A writer retains tables named by a live pin, verified by holding a pin, compacting, and reading a superseded table through it.
- Disk for a reader is bounded by the finality window rather than by chain length, verified by running a reader against a chain that grows and asserting its store does not.
Open questions
Pin expiry has no obvious right value. Too short and long queries fail; too long and a crashed reader pins disk indefinitely. An implementation should measure rather than guess, and the number belongs in configuration.
Whether a reader may itself be a validator on a chain whose archive it reads is not settled here. Nothing in consensus forbids it — a validator only ever votes on unfinalised blocks, which it holds locally — but the failure mode where an archive stall stops a validator voting deserves an answer before anyone relies on it.
The arrangement assumes readers and writer are the same software version. A reader against a store written by a newer node may meet a table format it does not know. A version check at open is the obvious answer and this LP does not specify one.