core/ledger: genesis final-height tear can leave an isolated sole-representative node unable to self-finalize after kill -9
Report
core/ledger: genesis final-height tear can leave an isolated sole-representative node unable to self-finalize after kill -9
Suggested tier: Medium. Availability only; no fund loss, mint, double spend, or network-wide finality effect.
Summary
core/ledger.go:325-342 commits the genesis block in one Badger transaction and
then sets SetFinalHeight(genesis.Account, 1) in a second transaction at :339.
A kill -9 between them persists the genesis block, account chain, frontier,
balance, delegation, and account key, but leaves the final-height key absent.
On restart the non-empty path (core/ledger.go:348-375) rebuilds caches but
never sets or reconstructs the genesis final height. Because depsFinalized
requires the genesis to be final and VoteManager.sweepFrontiersOnce skips
BlockGenesis, an isolated node that holds all delegated weight cannot
self-finalize blocks on the genesis account or blocks whose dependency includes
the torn genesis position. Unrelated account chains are not shown affected.
The affected case is an isolated sole-representative node. A torn non-representative node connected to a healthy representative recovered via votesync in the two-node test below.
Target
- Pinned commit:
978785929bc17a2f4ab30c383e5fc9cf4d634512 - Unmodified binary SHA-256:
c3bbf2612ab282fd31ea9b78eec109e9554a260b4ca6e6aa6e01d9fb04ff1f34 - Instrumented pause build SHA-256:
b7cfe3552be4501b4ec98e13914a9a741f76dfe0f4cfd601891fefab86f1e77f(env-controlled pauses only; every restart and the two-node run use the unmodified binary) crashlabSHA-256:999f65207a8a464567a5cfb3bcaf925151ad06ba9a3007ebf88d687febfde48c, built fromlab/scenarios/t-105with the targetreplace; target tree clean at9787859.- Network:
t102-lab(custom local genesis) - Ledger genesis:
85694777dcff96bd9bb4dbc0aa826561c64e24ebaa73e6ef4970f62f88ca03f1 - Statechain genesis:
bdf1594c9a5fb323bb059f87eb11b02430195200b95eb710a558a263893708fe - Activation state: no activations exercised
- Store/topology: Badger; local nodes;
--disable-mdns --no-discovery; default PoW; loopback API/metrics. No public testnet. - Scope: pinned target only; the live build
xe/4f19518was not tested.
Preconditions
A kill -9 (or equivalent power loss) between the genesis CommitBlock and the
separate SetFinalHeight transaction during the first start on an empty data
directory. No attacker, malformed block, forged signature, or special account is
needed. The tested affected node is isolated and is the sole representative with
all delegated weight; no other representative or healthy quorum is reachable.
The instrumented pause patch widens the real two-transaction window to 30 s so
the kill is deterministic. The crash was not observed in a real first bootstrap
without the pause patch. The manual store-level case (crashlab -mode init-gap)
proves the resulting state through the unmodified store API, and the pause case
proves the kill window; all restarts and controls are the unmodified target.
Torn state (isolated case)
After the kill, raw Badger state is one account with
blocks=[genesis], frontier=genesis, final_height=0, pending empty.
On restart the unmodified node stays up (/health 200), accepts the send
(block_count 2, pending 1,000 XE), but keeps:
- treasury (the genesis account)
final_height: 0; finality_advances: 0,last_finality_ns: 0;spendable: {};/ready503 (quorum_reachable:false, no representative vote; note the readiness checks also include a no-peer check in this isolated setup, so the finality-specific evidence isquorum_reachable:falsetogether withfinal_height:0and emptyspendable).
A clean control on the same genesis and representative key, given the same send,
reaches final_height: 2, finality_advances: 1, and
spendable {XE:41999999999000}. Supply is conserved on both nodes
(balances + in-flight = created, discrepancy 0). The send is
b19c69111efefc6558d5456352aa5bda2fe9ce8e89c9594305e4fe7b681b1bda
at height 2.
The tear survives local restarts; no local startup path repairs it. The isolated sole representative cannot self-heal locally.
Two-node peer recovery
H was the healthy sole representative (representative key, all delegated
weight). T was the torn chain with a non-representative node key, same genesis
and same send, explicitly dialed T to H. T started at final_height 0,
finality_advances 0, spendable {}, /ready 503; by the 20 s sample it had
final_height 2, finality_advances 1, spendable {XE:41999999999000}, and
/ready 200. H was at final_height 2, finality_advances 1.
T/node.log records:
votesync: ingested 1 vote(s) for 32020cbc47cf...|85694777dcff... from peers
Thus a torn non-representative node can recover from a 67% final-vote quorum. The remaining affected case is the isolated/sole-representative node, which has no other representative to supply that quorum. This report does not claim a network-wide finality stall.
Evidence labels
- [U] unmodified target: restarts, clean control, two-node H/T run.
- [I] instrumented pause build: only the 30 s crash-window widening.
- [M] manual store-level gap: unmodified store API writes the genesis commit
and omits
SetFinalHeight; the unmodified target restarts on it. - [C] code reading from the pinned tree.
Impact
In the isolated sole-representative case, the affected node remains alive and
API-reachable but cannot finalize blocks on the genesis account or blocks whose
dependency includes the torn genesis position; the tested treasury (genesis
account) has an empty spendable balance and /ready is 503.
No fund loss, no mint, no double spend, and no network-wide finality effect was observed. Supply is conserved and the crash state is conservative: spendable is empty, not above balance. The affected node's impact is availability only. Recovery options: connect a healthy representative quorum (the r-037 non-representative case), wipe and resync/rejoin, or repair the missing final height. The isolated sole representative does not self-heal locally.
Root cause
core/ledger.go:325-342: genesiscommitBlockWriteand the separateSetFinalHeightat:339have no enclosing transaction or recovery marker.core/ledger.go:348-375: non-empty restart rebuilds caches but never callsSetFinalHeightfor the persisted genesis.core/finalization.go:44-57:depsFinalizedrequires the dependency to be final;sweepFrontiersOnceskipsBlockGenesis.core/spendable.go:15-49: spendability starts from the account final height.- Peer recovery: non-representative nodes take the pull-only path
(
core/finalization.go:413-490), wired atnode/node.go:586-589tonet/votesync.go:40-70; the provider returns final votes viacore/finalization.go:519-540; the pulled vote is tallied atcore/quorum.go:151-181;confirmConflictsets the final height atcore/quorum.go:353-362. The two-node run observed this path. [C]/[U]
Reproduction
Use a fresh run ID; the scripts refuse to overwrite existing artifact
directories. r-035b/r-037 are the existing artifact labels.
# Isolated kill -9 at the genesis commit -> final-height boundary, then an
# unmodified-target restart and clean control.
lab/scenarios/t-105/genesis-crash.sh r-035c-repro 25501 25502 25601 25602
# Two-node peer recovery: H healthy sole representative, T torn
# non-representative; T dials H. Uses the r-035b torn chain as T.
lab/scenarios/t-105/peer-recovery.sh r-037-peer-recovery 25701 25702 25801 25802
# Deterministic store-level state without the pause patch, then the unmodified
# target restart. The exact commands are in the finding draft and
# lab/scenarios/t-105/scenario.md.
lab/scenarios/t-105/crashlab -mode init-gap -data <dir>/data \
-genesis-dir <setup>/genesis -keys <setup>/keys.json
# Commit-boundary control: before/after CommitBlock for pending add/delete.
lab/scenarios/t-105/commit-crash.sh r-036-commit-boundary-kill
Duplicate distinction
- #226 (open): cascade/lease stale reads,
SwapBlockcredential/cache issues, renewed-lease reputation,CommitCascadelease CAS and pending-dst duplicate append. This report is the genesis bootstrap/final-height split; no cascade, lease, or pending-dst index is involved. - #200 (open): account-chain Θ(N²) writes and full lease scans. This report is a two-transaction durability gap, not write amplification.
- #60 (open): SIGTERM during sync does not cancel; shutdown holds the Badger
lock. This report is a
kill -9between bootstrap transactions and does not depend on SIGTERM handling or lock drain. - #196 (open): statechain sync byte cap. This report is ledger-store bootstrap, not statechain sync.
- #96 (open) and #106 (open PR): descendant finalization implicitly finalizing ancestors / gating descendant finalization on ancestor resolution. They are related to the peer-recovery and ancestor-finalization surface but do not describe the genesis commit/final-height split. #106 is an open PR, not a merged fix.
Suggested fix
Make the genesis block commit and its final-height watermark one transaction
(for example, carry the final height in BlockCommit and write it inside the
same Badger db.Update). Independently, repair on non-empty startup: if the
persisted genesis chain exists and the genesis final height is less than 1, set
it to 1 before serving. Add a regression test that opens a store with the
genesis chain committed and no final-height key, constructs the ledger, and
asserts the genesis is final and a child block can finalize; add a two-node test
for the non-representative votesync recovery path.
Payout
XE address: b50f71f5ad1743456550ad7bd7720e18ce3a271f1c73eb90c56a79915404521b
Thread
Nothing public yet.