<!-- XE-0275 · core/ledger: genesis final-height tear can leave an isolated sole-representative node unable to self-finalize after kill -9 · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0275>. The page is the record; this is the same page for reading.*

XE-0275 · Bounty

# core/ledger: genesis final-height tear can leave an isolated sole-representative node unable to self-finalize after kill -9

Triaging
claimed Medium
[xe#246](https://github.com/xeprotocol/xe/issues/246)
filed 2026-11-03 01:25 UTC
by Sektorial12

Verdict
:   published when the fix ships

Tier
:   published when the fix ships

Claimed
:   Medium

Area
:   —

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-05 04:17 UTC

### Patches

- [xe#249](https://github.com/xeprotocol/xe/pull/249) open by Khanhtnq
  fix(core,store,net): atomic genesis final-height commit/repair and sync request/dependency convergence (fixes #244, #245, #246)

### History

- [5055](https://bounty.xe.network/log/5055) 2026-11-05 04:17 UTC github.labels
- [5034](https://bounty.xe.network/log/5034) 2026-11-05 04:17 UTC ticket.status accepted → triaging
- [5033](https://bounty.xe.network/log/5033) 2026-11-05 04:17 UTC ticket.status fixing → accepted
- [2434](https://bounty.xe.network/log/2434) 2026-11-03 14:29 UTC github.labels
- [2431](https://bounty.xe.network/log/2431) 2026-11-03 14:28 UTC ticket.status accepted → fixing
- [2430](https://bounty.xe.network/log/2430) 2026-11-03 14:28 UTC ticket.status triaging → accepted
- [2429](https://bounty.xe.network/log/2429) 2026-11-03 14:28 UTC ticket.status new → triaging
- [2428](https://bounty.xe.network/log/2428) 2026-11-03 14:28 UTC patch.linked
- [2170](https://bounty.xe.network/log/2170) 2026-11-03 01:26 UTC note.added
- [2169](https://bounty.xe.network/log/2169) 2026-11-03 01:26 UTC ticket.created

[Full history](https://bounty.xe.network/log?ref=XE-0275) · [JSON](https://bounty.xe.network/v1/tickets/XE-0275) · [markdown](https://bounty.xe.network/XE-0275.md)

### 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)
- `crashlab` SHA-256:
  `999f65207a8a464567a5cfb3bcaf925151ad06ba9a3007ebf88d687febfde48c`,
  built from `lab/scenarios/t-105` with the target `replace`; target tree clean
  at `9787859`.
- 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/4f19518` was 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: {}`;
- `/ready` 503 (`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 is `quorum_reachable:false` together with
  `final_height:0` and empty `spendable`).

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`: genesis `commitBlockWrite` and the separate
  `SetFinalHeight` at `:339` have no enclosing transaction or recovery marker.
- `core/ledger.go:348-375`: non-empty restart rebuilds caches but never calls
  `SetFinalHeight` for the persisted genesis.
- `core/finalization.go:44-57`: `depsFinalized` requires the dependency to be
  final; `sweepFrontiersOnce` skips `BlockGenesis`.
- `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 at `node/node.go:586-589` to
  `net/votesync.go:40-70`; the provider returns final votes via
  `core/finalization.go:519-540`; the pulled vote is tallied at
  `core/quorum.go:151-181`; `confirmConflict` sets the
  final height at `core/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, `SwapBlock` credential/cache
  issues, renewed-lease reputation, `CommitCascade` lease 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 -9` between 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.
