Skip to content

refactor: header class - remove caches and validation struct#148

Draft
fpelliccioni wants to merge 1 commit intomasterfrom
refactor/header-hash-cache
Draft

refactor: header class - remove caches and validation struct#148
fpelliccioni wants to merge 1 commit intomasterfrom
refactor/header-hash-cache

Conversation

@fpelliccioni
Copy link
Copy Markdown
Contributor

Summary

This PR refactors the header class to remove mutable caches and the validation struct.

Changes

  • Created two header implementations for benchmarking (header_raw and header_members)
  • Removed hash_memoizer and caching mechanisms
  • Header is now a simple value type without mutable state
  • Updated insert() signatures to pass median_time_past as parameter
  • Added MTP calculation functions using C++20 concepts

Known Issues (WIP)

block_pool.cpp compilation errors: The class relies on header().validation.height which no longer exists. Possible solutions:

  1. Pass height as parameter to add()
  2. Store height in block_entry
  3. Use block::validation.state->height()

Similar refactoring will be needed for block and transaction classes.

Test plan

  • Fix block_pool compilation errors
  • Run full test suite
  • Benchmark header operations

@fpelliccioni fpelliccioni force-pushed the refactor/header-hash-cache branch 3 times, most recently from f64dbdc to 95de25a Compare December 10, 2025 16:16
…uct (WIP)

This PR refactors the `header` class to remove:
- Mutable caches (hash, serialized size)
- The `validation` struct (containing `height` and `median_time_past`)

- Created two new header implementations for benchmarking:
  - `header_raw`: 80-byte array storage with on-demand field extraction
  - `header_members`: Individual member storage (current approach)
- Removed `hash_memoizer` and caching mechanisms
- Header is now a simple value type without mutable state

- `fast_chain::insert()` and `block_chain::insert()` now take `median_time_past` as parameter
- `reservations::import()` propagates MTP through the call chain

- Added MTP calculation functions using C++20 concepts in `header.hpp`

The `block_pool` class relies on `header().validation.height` which no longer exists.
This affects:
- `block_pool::add()` - needs height to insert blocks
- `block_pool::remove()` - needs height to replant orphaned children as roots
- `block_pool::prune()` - needs height to determine expired blocks

1. Pass height as parameter to `add()`
2. Store height in `block_entry`
3. Use `block::validation.state->height()` (chain_state already has height)
4. Calculate height by traversing parent chain

Similar refactoring will be needed for `block` and `transaction` classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant