You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor(domain): turn header into an immutable value type
The old header inherited from header_basis, mixed in hash_memoizer to
cache the block hash, and carried a mutable `validation` struct holding
height and median_time_past stamped from outside. The cache was a thread
hazard, the inheritance leaked basis internals, and the validation
struct was a side-channel for height/MTP that the value type should
never own.
Replace it with two interchangeable value types selected at compile
time via `KTH_USE_HEADER_MEMBERS`:
- header_raw (default): 80-byte contiguous storage, fields decoded on
access. Wins on the IBD hot path — faster deserialization, zero-copy
raw access for wire-handling code.
- header_members: traditional struct, field-per-member. Wins on
repeated full-record access (wallets, explorers).
Both expose the same surface plus a free function `chain::hash(header)`
in lieu of the cached `header.hash()` member.
The validation side-channel is gone: block_pool and branch now read
height and MTP off the block's chain_state, which the validator
already populates. block_organizer no longer stamps the header.
C-API regenerated via kth-tools (no hand edits). The generator picks
up `chain::hash(header const&)` automatically thanks to a new
`extra_namespaces=['kth::domain::chain']` on the header config, so
`kth_chain_header_hash` is exposed as a normal accessor.
Caught while wiring up the tests, fixed in passing:
- block_entry::parent() returned `hash_digest const&` but the new
header decodes previous_block_hash from raw bytes into a temporary
— every caller was holding a dangling reference.
- Same dangle in header_organizer.cpp and internal_database test.
Old files (header.cpp, header_basis.cpp, hash_memoizer.hpp, original
message/header.{hpp,cpp}) are renamed to `.disabled` so any stragglers
trip the compiler instead of silently linking against legacy code.
0 commit comments