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
## 🗒️ Description / Motivation
- Adds a canonical slot-to-block-root index to storage.
- BlocksByRange currently has to walk backward from the head and collect
roots by slot.
- This PR makes range lookups efficient by reading canonical block roots
directly by slot.
## What Changed
- Added a new `BlockRoots` storage table:
- key: slot / block number
- value: canonical block root
- Registers the new table for in-memory and RocksDB backends.
- Initializes the index for anchor/checkpoint stores.
- Maintains the index when fork-choice head changes.
- Handles reorgs by deleting old canonical slot entries and inserting
the new canonical branch.
- Rebuilds the index on DB restore if the persisted index is missing.
- Cleans index entries when old block data is pruned.
- Updates BlocksByRange handling to use `Store::get_block_root_by_slot`
instead of walking parent headers.
## Correctness / Behavior Guarantees
- The index points only to canonical block roots.
- Side-fork blocks do not appear in BlocksByRange responses.
- Skipped slots remain absent from the index and are skipped in
responses.
- Reorgs update the index to match the new canonical chain.
- Existing persisted DBs can rebuild the index from the current head
chain.
- Pruned blocks have their canonical index entries removed when
applicable.
## Tests Added / Run
- Added storage tests for:
- canonical slot index updates
- skipped slots
- side forks
- reorgs
- DB restore index rebuild
- pruning cleanup
- Existing BlocksByRange test now exercises indexed lookup.
## Related Issues / PRs
- Closes#355
- Related to #348
- Related to #351
## ✅ Verification Checklist
- [x] Ran `make fmt` — clean
- [x] Ran `make lint` (clippy with `-D warnings`) — clean
- [x] Ran `cargo test --workspace --release` — all passing
---------
Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
0 commit comments