Data directory, restarts and disk usage #
This page describes the data directory of specborn run (--datadir DIR). The checkpoint-sync command's directory is described at the end.
What is in it #
DIR is created if it does not exist. It holds one store of specborn's own storage engine (Specborn/Storage.lean, piece persist):
| File | Role |
|---|---|
LOG | the append-only log of committed batches, each CRC-32C-checksummed |
CKPT | a checkpoint of the index, so that opening does not scan the whole log |
IDX.* | auxiliary index files, rebuilt when missing; IDX.lock is the lock file |
LOG.tmp, CKPT.tmp | present only while a compaction or checkpoint is being written |
Do not edit, copy into, or partly restore these files. The data directory is trusted input: the store detects damage it can see (checksums, shape checks on CKPT), but a crafted file written by someone with access to the directory is outside what is proved (TRUST.md; open item SA-persist-5 in STATUS.md). Give the directory the same protection as the binary.
What the node stores:
- every block and execution payload envelope it accepted, one atomic record each, in acceptance order;
- the data-column sidecars from which an accepted envelope's (or a Fulu block's) data availability was established, stored before it;
- a snapshot of the finalized block: its beacon state and the execution state at its payload, written each time finality advances;
- the chain's identity: a hash of the genesis state root and the execution genesis hash;
- the JSON-RPC server's history (its blocks and receipts, at most the newest 8,192 blocks), committed with the rest and checked record by record when it is restored at a restart (JSON-RPC).
Not stored: the node's network key (fresh at every start, never written to disk), peer addresses, logs.
Validator files #
The validator files live in subdirectories of the same DIR (Validators):
| Path | Written by | Contents |
|---|---|---|
validators/keystores/0x<pubkey>.json | specborn validator keys import | the imported EIP-2335 keystore, byte for byte (encrypted) |
validators/secrets/0x<pubkey> | the same, unless --no-store-password | the keystore's password, in clear |
validator/slashing-protection/ | specborn validator slashing-protection import, register, and specborn run --validator-keys (every attestation and block it signs) | the EIP-3076 database: a store of the same engine (LOG, IDX.*, its own IDX.lock) |
Files are created with mode 0600 and directories with mode 0700. Note the two spellings: validators/ for keys, validator/ for slashing protection. specborn run --validator-keys reads validators/ at start (and decrypts the keys into memory only), then opens the slashing-protection database and keeps it open, and locked, while it runs: stop the node before an import, export or register.
Back up validators/ as you would your keystores (it holds passwords). Move slashing-protection history with export and import, while nothing uses the database, rather than by copying its files. Never restore an old copy of validator/slashing-protection/: it would forget what was signed since, and that is exactly what slashing protection must not forget.
One chain, one process #
- A data directory belongs to one chain. Starting with another network's files fails with
store: DIR holds another chain. - A data directory is used by one process at a time: the store takes an exclusive lock on
IDX.lockbefore touching anything, and a second process fails to open it (store: open failed (…locked)). The exclusion is TESTED; that the operating system's lock behaves as assumed is TRUSTED (docs/pieces/persist.md, R-8).
Crash safety and durability #
A commit is acknowledged only after it is on disk: the store calls the coreutils program /usr/bin/sync (sync -d FILE = fdatasync, sync -f DIR = syncfs) at each commit and directory change, because Lean's standard library has no fsync. /usr/bin/sync must therefore exist (GNU coreutils and uutils coreutils both work); if it is missing, opening the store fails.
- PROVED (piece
persist, theoremsendToEnd_crashandendToEnd_failure, seePROOF_LEDGER.md): in the store's model of the file system, a crash at any point, or an I/O failure, leaves a store that opens to a prefix of the acknowledged commits, and a failed write poisons the store (it stops instead of continuing on a state it cannot trust). - TESTED: crash sweeps at every byte of the log and checkpoint files (
docs/pieces/persist.md), and SIGKILL restarts of the running node on devnets (docs/pieces/node.md§13.5). - TRUSTED: that the runtime, the kernel,
fdatasync/syncfsand the disk behave as the model says (a device that ignores cache flushes breaks any database); no power-cut experiment has been run.
You can therefore stop the node at any time, with any signal; there is no shutdown procedure.
What happens at a restart #
Start the node again with the same flags. It then (Specborn/Node/Sync/Run.lean, resume):
- loads the newest snapshot and checks it: the beacon state's root is the recorded root, the state is the recorded block's post-state, it is this chain's state, and the execution state is that of the recorded execution block (header chain, hash, state root) and of the chain id in
genesis.json; - replays every item stored after the snapshot through the full import pipeline — every check, every signature, the execution of every payload, every KZG check of the stored columns — exactly as if it came from the network;
- syncs the rest from its peers and follows the head.
On the devnets, restarts after SIGKILL took between about 8 and 41 seconds, depending on how many stored items were replayed (docs/pieces/node.md §0.5, R4.5 and R6.6).
If the snapshot's execution state is of another chain id than genesis.json gives, the node does not start and deletes nothing (store: the snapshot's execution state is of chain id X, but genesis.json gives chain id Y: not starting, nothing deleted …; exit 1): one of the two directories belongs to another network (Troubleshooting). If the snapshot fails another check, it is not used: the node starts from genesis and replays the stored items if they are all still there; if older items were already deleted (the default, below), it deletes the snapshot and the stored items and syncs the chain again from its peers. State that failed a check is never used. The node exits only when a stored item inside the range it replays is missing or cannot be decoded, which means the storage itself is damaged.
Pruning and disk usage #
Default: when a snapshot of the finalized block has been written, the items before its replay point are deleted, except the newest 8,192, which are kept so that the node can serve recent history by range and by root after a restart. The directory then holds those items, the items of the unfinalized part of the chain and one snapshot, and a restart replays only the items after the snapshot.
--keep-history keeps every stored item. The directory then grows with the chain (one record per block, envelope and stored column), and a restart still starts from the newest snapshot.
Measured: snapshots on the 4-client devnets were about 3.3 MB and took 40 to 67 ms to write (docs/pieces/node.md R6.6). Each snapshot costs time and space proportional to the beacon state plus the execution world state; that cost on a public network is not measured (open item OPEN-node-snapshot-cost). In memory, the fork-choice store and the execution engine's state are pruned on finality.
Backups and moving a node #
Stop the node, then copy the whole directory. Copying a directory while a node is writing to it gives an inconsistent copy. Restoring an old copy works the same way as a restart: the node resumes from that copy's snapshot and syncs forward, as long as its peers still serve the blocks since then.
There is no export or import format for the node's chain data and no migration between specborn versions yet; when in doubt, start with an empty directory. (Slashing-protection history has one: the EIP-3076 interchange format, see Validator files.)
Checkpoint-sync data directories #
specborn checkpoint-sync (Checkpoint sync) uses the same storage engine. With --datadir it stores every imported and backfilled block, envelope and column, keyed by slot or root. The directory is bound to its anchor (another anchor is refused), and the command does not replay these items after a restart: it syncs them again from its peers. With a Fulu anchor, while an execution catch-up runs (not stopped), it also keeps the state of its finalized execution block, in the store and as the file el-state.rlp (written as el-state.rlp.tmp, then renamed), each time that block changes. A restart with the same anchor and directory resumes the catch-up from that state, after checking it (header chain, state root, chain id; a state that fails is refused and the node does not start), and the file can be given to another node with --el-state (Checkpoint sync). Without --datadir nothing is written. Do not point it at the data directory of specborn run.