WO-19 — node storage redesign

Status: DONE WO-19 — builder acceptance complete, ready for independent review. Date: 17 October 2026. Handoff: private main at 92c8ded, decision #33. Code: public ~/Documents/E46Tessera, branch wo-19-storage. Base: 2a70ba8. Final commit: fae421cf80d5f525949533bad3a84123518d3ea9.

Commits, in order: 8db681b (storage/checkpoint), 718e17f (bounded four-worker fixture tool), fae421c (startup deferred-branch regression and fix). No push, merge, rebase, or amend. Public working tree is clean; local identity remains 3xc@users.noreply.github.com. This report and evidence are in the private repo, left for the owner/reviewer to commit.

Implementation

  • IndexEntry holds header, raw record, identity/ancestry, height/work, pool totals, size and validation flags. It contains no State or coin set. State is noncopyable; the node owns one active tip state.

  • Active blocks have undo containing original spent/overwritten coins, created outpoints, added commitments, previous pools and at most 11 prior timestamps. Disconnect restores those changes. Detached branches retain their raw records, not their undo.

  • Side admission performs checks independent of spent coins. Full witness/spend validation waits until cumulative work strictly exceeds the active tip. A failed switch reconnects the original branch, marks the failure and descendants invalid and logs the reason. Stored rejected records have byte-bound local rejection metadata so restart does not retry them.

  • Startup first indexes all branch headers, then validates the strongest eligible chain. A regression demonstrated that the earlier implementation could transiently activate a losing branch in filename order. It failed before this fix and passes afterward on both builds.

  • mine_on explicitly requires the active tip. Historical active-block reads reconstruct from raw records and the transaction index. Deferred side bodies are not exposed by getblock as fully validated blocks; this limitation is documented.

  • Removed the P2P total 4,096-block ceiling. Kept the 512 side-branch budget, held-checkpoint policy, 1 GiB disk floor and the existing transport bounds. Transport remains v1.

Acceptance evidence

All final evidence is preserved in artifacts/WO-19, including per-command differential outputs, daemon logs, rollback outputs, mined fixtures, compiler flags, and a SHA-256 manifest.

Criterion

Evidence and result

1. Builds

Both presets configured with -DE46_BUILD_STORAGE_TESTS=ON. Dev and sanitizer rebuilt successfully after the final source change, zero warnings, under -Wall -Wextra -Werror. Sanitizer uses AddressSanitizer + UndefinedBehaviorSanitizer. See build-*-replay.log, configure-*-final.log, compiler-flags-*.txt.

2. Differential

Old binary built from detached 2a70ba8; new binary from final branch. 282 byte-identical outputs: 274 getblock calls for heights 0–273, snapshot 64, mempool, and balance/utxos for all three addresses discovered from every output in the fixture. All 274 input and copied block records retained their hashes. See differential/result.json and 564 individual output files.

3. Existing suites

22/22 P2P milestones on dev and 22/22 on sanitize; both end ALL REQUESTED EXERCISE CHECKS PASSED. Both default-directory suites end ALL DATADIR CHECKS PASSED. All sanitizer runs use ASAN_OPTIONS=detect_leaks=0; scan of 9 final sanitizer suite/daemon logs found zero diagnostics. See p2p-*-final.log, defaults-*-final.log, sanitizer-scan.json.

4. Real-PoW reorgs

Both builds end ALL STORAGE REORG CHECKS PASSED. One-block switch, two-block disconnect/three-block connect, equal-work stability, retained abandoned records, restart and rebuild pass. Invalid second branch block fails, restores exact state, marks two invalid entries and does not increment validation attempts on retry. Six rollback CLI outputs are byte-identical. Additional losing-side replay regression passes. See reorg-*-final.log and rollback-*.

5. Linear storage

Structural: IndexEntry has no coin set; State copies are deleted. Counter on 274 records: 274 tip coins + 1 saved undo coin = 275 coin entries, 275 created-outpoint undo entries, 273 active undo records, 274 index entries. Startup daemon RSS: 11,456 KiB old → 5,824 KiB new, about 49% lower in this run. See stats-*-final.log, differential/result.json.

6. Unchanged boundaries

Original 274 chain records still match pre-task hashes, with no additions/removals. Record serialization remains E46NDB01. Transport document, checkpoint sources, header/PoW, transaction, QTL, emission, Merkle and RL sources, and CLI dispatcher are byte-identical to base. All 41 private GOLD files match private 92c8ded; none were copied into public. See unchanged-final.log. Consensus validation was moved into connect/admission without intentionally changing its rules.

Exact reorg evidence

PASS one-block switch, equal-work stability, abandoned record and restart
BALANCE deep before_A=7019042970 after_A=0 after_B=10528564455
PASS two-block disconnect, three-block connect, balances and restart
PASS restart indexes losing side branch without decoding or connecting it
Rejected branch 4361de35637a2dc818ed36f5c6c4341ecc23e05ffad38d97e5fd86390d94298d: Stored transaction spends an unknown output
PASS invalid second block rolls back exact state, descendants rejected without retry, restart preserved
PASS rollback: 6 byte-identical snapshot/mempool/balance/utxos outputs after restart
PASS all branch stores reproduce identical snapshots after explicit rebuild
ALL STORAGE REORG CHECKS PASSED

The owner generated the real-PoW fixtures locally. The final resumed invocation used one worker, not four, and completed b3, bad2, bad3 in 832.855 s, 167.919 s, 219.719 s respectively. Every generated block used unchanged testnet bits 494927871 (0x1d7fffff); no target reduction or validation bypass. Earlier completed b1/b2 were reused and all records validated by the exercise. The test tool also supports an optional 1–4 worker argument and a shared wall-clock deadline.

Reproduction

Working evidence root: /tmp/e46s-ij5l4kil. Original chain ~/E46-testnet/chain-wo17 was only read to copy/hash it; every node run used disposable copies. Old detached worktree: /tmp/e46s-ij5l4kil/old. The preserved private evidence includes the seven branch records, so repeating reorg checks does not require mining again.

From the public repo (use fresh output directory names on each repetition):

cmake --preset dev -DE46_BUILD_STORAGE_TESTS=ON
cmake --build --preset dev
cmake --preset sanitize -DE46_BUILD_STORAGE_TESTS=ON
cmake --build --preset sanitize

python3 tests/storage_replay.py \
  --old /tmp/e46s-ij5l4kil/old/build/dev/e46-node \
  --new build/dev/e46-node --chain /tmp/e46s-ij5l4kil/fixture \
  --output /tmp/e46-review-diff

python3 tests/p2p_integration.py --node build/dev/e46-node \
  --chain /tmp/e46s-ij5l4kil/fixture --payment /tmp/e46s-ij5l4kil/payment.tx.hex
ASAN_OPTIONS=detect_leaks=0 python3 tests/p2p_integration.py \
  --node build/sanitize/e46-node --chain /tmp/e46s-ij5l4kil/fixture \
  --payment /tmp/e46s-ij5l4kil/payment.tx.hex
python3 tests/datadir_defaults.py --node build/dev/e46-node
ASAN_OPTIONS=detect_leaks=0 python3 tests/datadir_defaults.py --node build/sanitize/e46-node

python3 tests/storage_reorg.py --tool build/dev/e46-storage-checks \
  --node build/dev/e46-node --fixtures /tmp/e46s-ij5l4kil/branches \
  --output /tmp/e46-review-reorg
ASAN_OPTIONS=detect_leaks=0 python3 tests/storage_reorg.py \
  --tool build/sanitize/e46-storage-checks --node build/sanitize/e46-node \
  --fixtures /tmp/e46s-ij5l4kil/branches --output /tmp/e46-review-reorg-san
./build/dev/e46-storage-checks stats /tmp/e46s-ij5l4kil/fixture

Limits and remaining scope

RSS is a single 274-record measurement, not a 10,000-block benchmark; linear storage is supported by structure and the counter. Reorg fixtures cover ordinary coinbase balances and an invalid ordinary spend, not a new QTL relay or dependent-mempool resurrection exercise. The existing newest-first disconnected-transaction reconsideration behavior is preserved. Post-quantum transport (#32), public binding/deployment and other queued work were not started. No open consensus decision was needed for this storage change. Independent reviewer acceptance is still to follow.