nmc(P1f): HeaderChain LevelDB persistence (h/tip/height) + 6 KATs (52->58) - #201
Merged
Conversation
…->64) Rebased onto master (771f586) post-#200/get_locator. Persists every accepted entry under "h"+block_hash (IndexEntryDiskV1), plus tip/height pointers, in one synced WriteBatch; init() restores m_index/m_tip/m_tip_height/m_best_work via load_from_db(). NMC has no height-index (full-residency m_index), so no "i" key. Auxpow blob deferred (presence flag only). Coexists with get_locator: 6 persist KATs + 6 locator KATs = 58->64 green.
frstrtr
force-pushed
the
nmc/p1f-leveldb-persist
branch
from
June 19, 2026 11:03
197d91d to
19c00f8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
P1f LevelDB persistence leg (NMC embedded merge-mined chain)
Stacks on the P1f get_locator slice conceptually but is independent — touches
disjoint regions of
header_chain.hpp, so it bases cleanly on master (does notrequire #200/get_locator to land first).
What it does
connect_lockedsuccess path under
"h"+block_hash(32)→ serializedIndexEntryDiskV1, plus"tip"(32B) and"height"(4B BE) pointers, in onecommit_sync()batch.Rejected (idempotent / orphan / activation-gate) headers write nothing.
init()opens the store (whendb_pathgiven) andload_from_db()rebuildsm_indexfrom the"h"prefix, then restoresm_tip/m_tip_height/m_best_workfrom the tip entry.db_pathor open failure → pure in-memory, no crash.Mirror-of-btc with a documented divergence
Adapted from
btc::coin::HeaderChainpersistence. No"i"height-index key:NMC keeps a full-residency
m_index(not btc's bounded LRU + separate heightindex), so the
"i"schema has no consumer here. The"height"key collisionwith the
"h"prefix scan is handled by asize()==33guard (covered by a KAT).P1f-DEFER
AuxPow blobs are not serialized yet — only a
has_auxpowpresence flag. Areloaded merge-mined header keeps its
HEADER_VALID_CHAINstatus; itsauxpowcomes back
nullopt. The blob lands behind this same flag in the next sub-leg(
nmc::coin::AuxPowhas no serialization yet; not hand-rolled here per the fence).Tests / fence
+6 KATs (
NmcP1fPersist): disk-format round-trips (incl. status + aux-flag) andreal LevelDBStore reopen round-trips under a temp dir. Suite 52 → 58 green,
nmc_auxpow_merkle_testEXIT=0 locally. NMC-tree only (two files:coin/header_chain.hpp,test/auxpow_merkle_test.cpp); rides the allowlistedtest target — no
build.yml/ CI change. GPG-signed, attribution-clean.