Skip to content

Generalise reconstruct_historic_states for ranged replay#9222

Merged
mergify[bot] merged 1 commit intosigp:unstablefrom
dapplion:era-reconstruct-on-range
May 6, 2026
Merged

Generalise reconstruct_historic_states for ranged replay#9222
mergify[bot] merged 1 commit intosigp:unstablefrom
dapplion:era-reconstruct-on-range

Conversation

@dapplion
Copy link
Copy Markdown
Collaborator

Upcoming work to support ERA files uses reconstruct_historic_states but needs slight tweaks to reconstruct arbitrary ranges of slots.

This PR changes no functionality in practice but makes the scary production code changes upfront so the later bigger ERA files PR is less risky.

reconstruct_historic_states keeps its signature and behaviour, now a thin shell that derives the slot range from the anchor/split, then delegates to the ranged helper with an on_commit closure that performs the existing per-commit anchor advance and the final flip to as_archive_anchor().

@dapplion dapplion requested a review from michaelsproul as a code owner April 29, 2026 10:51
@dapplion dapplion added ready-for-review The code is ready for review database labels Apr 29, 2026
Splits the inner replay loop out of `reconstruct_historic_states` into a new
public `reconstruct_historic_states_on_range(with_state_at_slot, from_slot,
to_slot, write_block_roots, on_commit)` so it can be reused by an upcoming
ERA file importer (separate PR).

`reconstruct_historic_states` keeps its signature and behaviour, now a thin
shell that derives the slot range from the anchor/split, then delegates to
the ranged helper with `write_block_roots = false` and an `on_commit`
closure that performs the existing per-commit anchor advance and the
final flip to `as_archive_anchor()`.

The ranged helper:
- iterates `BeaconBlockRoots` directly via `FrozenForwardsIterator`,
- detects skipped slots via `block.slot() != iterator slot` instead of
  tuple-window comparison,
- supports a starting state at any slot `<= from_slot` (catches up via
  `per_slot_processing` in a `while`),
- optionally writes the `BeaconBlockRoots` index inline (for callers
  populating the cold DB rather than reading an already-populated one),
- runs a tree-hash equality check against the last stored state root at
  the final slot of the batch.

Verified with `make lint`, `cargo fmt --check`, `cargo nextest run -p store`,
and `cargo nextest run --release -p beacon_chain --test beacon_chain_tests
store_tests::weak_subjectivity_sync` (7/7 pass — covers the existing
reconstruction code path).
@dapplion dapplion force-pushed the era-reconstruct-on-range branch from 0f6e43b to 044c442 Compare April 29, 2026 11:00
@mergify
Copy link
Copy Markdown

mergify Bot commented Apr 29, 2026

Some required checks have failed. Could you please take a look @dapplion? 🙏

@mergify mergify Bot added waiting-on-author The reviewer has suggested changes and awaits thier implementation. ready-for-review The code is ready for review and removed ready-for-review The code is ready for review waiting-on-author The reviewer has suggested changes and awaits thier implementation. labels Apr 29, 2026
Copy link
Copy Markdown
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. We have quite good tests for reconstruction in the beacon chain tests, so I'm confident this change doesn't cause any regressions.

Comment on lines +101 to +103
/// `on_commit(slot)` is invoked after each atomic commit (whenever the hierarchy says to
/// commit, plus once at the final slot) so callers can update anchor metadata or log
/// progress.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need a different definition of on_commit for the Era use case?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to not update the anchor at all during reconstruction as it would be jumping around. Would be fine if reconstruct_historic_states just updates the anchor once after completing num_blocks?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would that help? Isn't there fundamentally something a bit wonky with a linear anchor and parallel updates?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you start the node from ERA files the DB is empty. Then it does funky things (parallel reconstruction) and ends up in a valid fully synced state. The node is not meant to be used during parallel reconstruction

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok we can cross that bridge when we come to it

Comment thread beacon_node/store/src/reconstruct.rs
@michaelsproul michaelsproul added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels May 6, 2026
@mergify mergify Bot added the queued label May 6, 2026
@mergify
Copy link
Copy Markdown

mergify Bot commented May 6, 2026

Merge Queue Status

This pull request spent 31 minutes 9 seconds in the queue, including 28 minutes 45 seconds running CI.

Required conditions to merge

mergify Bot added a commit that referenced this pull request May 6, 2026
@mergify mergify Bot merged commit 31e5f30 into sigp:unstable May 6, 2026
61 of 62 checks passed
@mergify mergify Bot removed the queued label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

database ready-for-merge This PR is ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants