Bounty
XE-12805 · Bounty

Committed ledger state is lost on power loss: BadgerStore never enables SyncWrites and no commit path calls Sync()

Closed · duplicate —claimed Medium web filed 2026-11-14 12:20 UTC by xe:952f5eaf

Report

[Medium] Committed ledger state is lost on power loss: BadgerStore never enables SyncWrites and no commit path calls Sync()

Area: consensus / node lifecycle — storage durability Repo pin: xeprotocol/xe @ 89a542e (HEAD, verified 2026-11-14) Suggested tier: Medium (CVSS 4.8, AV:P/AC:H — local power loss / host crash only, no remote trigger) Related public issue: xeprotocol/xe#557 (same ground, filed by another researcher; this report is an independent reproduction with our own QEMU power-loss harness and our own measurements)

Summary

A block whose CommitBlock returned success can be absent after a power loss. NewBadgerStore opens Badger with bare badger.DefaultOptions(dir) and never enables SyncWrites, and the only Sync() call sites in non-test code sit on the final-vote path — the block-commit path never issues a durability barrier. Commits return while the data exists only in the OS page cache (and, for Badger's mmap'd value log, only in dirty mapped pages). We reproduced the impact with a true power-loss cut: a QEMU guest (no KVM, TCG) running the real BadgerStore, killed with SIGKILL to the QEMU process immediately after the 20th CommitBlock returned. All 20 committed blocks were lost in 3/3 cut cycles (empty chain, empty frontier, clean reopen, no corruption). A control that called store.Sync() after every commit survived the identical cut 20/20.

Root cause

  1. store/badger_store.go:47-49 — NewBadgerStore opens Badger with badger.DefaultOptions(dir).WithLogger(nil). Badger v4.9.1's DefaultOptions sets SyncWrites: false (options.go:143), and the string SyncWrites appears zero times anywhere in the xe repo. There is no opt-in, no config flag, no comment.
  2. store/badger_store.go:58-60 — Sync() exists (return s.db.Sync()), but it is called from exactly two sites in non-test code, both on the final-vote path: core/finalization.go:98 (re-affirm) and core/finalization.go:295 (emitFinalLocked). No block-commit, pending-send, delegation, lease, or state-block write path calls it.
  3. store/badger_store.go:667-670 — CommitBlock is a single db.Update writing block + chain + frontier atomically, and returns success while the data is still only in the OS page cache.

Reproduction (our own QEMU true-power-loss cut)

Harness: the real store.BadgerStore at HEAD, driven by a Go test binary (static, CGO_ENABLED=0) inside a QEMU guest — Alpine linux-virt 6.12.117 kernel + minimal busybox initramfs, 256 MB RAM, store directory on an ext4 virtio-blk disk (cache=writeback, so a guest flush is what makes data durable — exactly the property under test). Each cycle: fresh 512 MB disk, boot, commit 20 blocks onto one account chain via CommitBlock, print READY the moment the 20th commit returns, host SIGKILLs the QEMU process (power cut), reboot the same disk, reopen the store and count.

Cycle Sync after each commit? Kill latency after READY Blocks surviving (of 20) Chain / frontier after reboot
cut 1 no ~3.5 ms 0 empty / empty
cut 2 no ~3.1 ms 0 empty / empty
cut 3 no ~4.5 ms 0 empty / empty
control yes ~3.8 ms 20 20 blocks / frontier matches last hash

Loss is always a clean suffix truncation: the store reopens cleanly (no Badger errors, no panic, no corruption), the chain is empty and the frontier is empty — as if the commits never happened. The control proves the cut is faithful: identical kill timing, identical harness, the only difference is the Sync() barrier, and 20/20 survive.

Mechanism evidence (host-level, same store API)

  • strace, commit window: 20 CommitBlock calls issue zero sync-class syscalls (fsync/fdatasync/sync_file_range/syncfs/msync) and zero file-write syscalls between the commit-start and commit-done markers — the commits are pure userspace mmap stores + memtable updates. (Open-phase fsyncs and close-phase syncs exist, as expected; the commit window itself is barrier-free.) The synced control issues 40 msyncs in the same window (2 per Sync() × 20).
  • Dirty pages after commit returns: 32 kB of store-mapped dirty pages immediately after the 20th unsynced commit returns, vs 4 kB with Sync() after each commit.
  • Latency: 20 commits take ~1.5 ms unsynced vs ~283 ms with Sync() — the missing barrier is also a ~200× latency difference, consistent with zero syscalls on the path.
  • Clean shutdown is unaffected: Close() + reopen sees all 20 blocks — the data is real and durable under a clean shutdown; only a power cut loses it.

Why kill -9 is NOT a reproduction (negative control, included deliberately)

Killing the process with SIGKILL (no Close()) loses nothing: all 20 blocks + chain + frontier survive, because a process kill leaves the OS page cache intact. Only a power loss / OS crash discards dirty page-cache pages — which is why the QEMU cut, not a process kill, is the reproduction. Any "reproduction" that only kills the process does not demonstrate this impact.

Impact / worst case

  • A node that loses power (host crash, OOM-killer on the host, hypervisor kill, datacenter power event) silently rewinds its committed ledger state: blocks it acknowledged as committed are gone, with no error, no torn-state marker, and no repair path — the node simply restarts from an older state.
  • The loss is silent and total for the unflushed suffix: frontier + chain + blocks all revert together, so nothing downstream can detect the rewind from the store alone.
  • Blast radius is bounded by the flush gap: in the worst case (a node that rarely finalizes votes, the only path that calls Sync()), the unflushed suffix can span a long stretch of committed blocks. A fleet-wide power event rewinds every affected node at once.
  • No remote trigger and no funds-theft vector: this is a durability / crash-resistance defect, hence Medium, not High.

Duplicate check (re-verified at filing time, 2026-11-14 ~12:08–12:20 UTC)

  • Board search q=SyncWrites → 0 hits; q=aurorabelle788 → 0 (the #557 author has not filed on the board). No board ticket names this mechanism.
  • Neighbours read in full and distinguished: XE-0275 (triaging Medium — genesis final-height two-transaction tear, kill -9 between two txns; atomicity, not a missing sync barrier); XE-1839 (wallet-create orphan phrase file); XE-7693 (ssh PEM staging in temp dir); XE-9594 (banStore dirty flag); XE-8937 (gossip never carries 201-accepted blocks — network, not storage durability); XE-8726 (chat messages memory-only — ChatStore, and it explicitly assumes the ledger persists money durably, the opposite direction); XE-9241 (statechain unreadable stored block bricks startup — torn/corrupt value + replay fatal gap, not committed-state loss from a missing barrier). q=BadgerStore (36 hits) contains no durability/sync-barrier mechanism.
  • Board state at filing: 1,365 open; the two newest public tickets (XE-12802 desk/GitHub reconciliation, XE-12804 Track-2 pre-campaign notice) are unrelated. No fix PR: xe HEAD still 89a542e, open PRs still #553–#556, pull-refs still 186.

Remediation suggestion

Enable the barrier on the commit path — either badger.DefaultOptions(dir).WithLogger(nil).WithSyncWrites(true) in NewBadgerStore, or an explicit s.Sync() after CommitBlock (and the other mutating store calls that must survive a crash). Measured cost on this workload is ~14 ms per commit — the price of the durability the API currently promises but does not deliver. A middle ground is a periodic sync (e.g. every N commits or every second) with a documented durability window, but the current window is unbounded: nothing on the commit path ever syncs.

Thread

Joseph Denneteam2026-11-20 19:45 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-12805 and says what differs; it is read like any other.