Skip to content

refactor(world-state): always index block 0 regardless of initial tree size#22724

Merged
PhilWindle merged 1 commit intomerge-train/spartanfrom
spl/genesis-block-index-unconditional
Apr 22, 2026
Merged

refactor(world-state): always index block 0 regardless of initial tree size#22724
PhilWindle merged 1 commit intomerge-train/spartanfrom
spl/genesis-block-index-unconditional

Conversation

@spalladino
Copy link
Copy Markdown
Contributor

Motivation

Follow-up to #22711 addressing a review flag from PhilWindle: commit_genesis_state only wrote a block-index entry for block 0 when initialSize > 0. This created a minor asymmetry with the regular commit path, which writes write_block_index_data unconditionally for every block (including zero-size blocks).

Approach

Drop the if (meta.initialSize > 0) guard so genesis state is indexed the same way as any other block. The read API (find_block_for_index) uses get_value_or_greater(index + 1), so a sizeAtBlock=0 entry is unreachable and the extra write is harmless — it just restores the invariant that every committed block appears in the index-to-block database.

Changes

  • barretenberg (cached_content_addressed_tree_store): remove the initialSize > 0 guard around the block-0 write_block_index_data call so the genesis commit matches the regular commit path.

…e size

Drop the `initialSize > 0` guard around `write_block_index_data(0, ...)` in
`commit_genesis_state`. The regular commit path writes the block-index entry
unconditionally for every block (including zero-size blocks), so this aligns
genesis with that invariant. The read API (`find_block_for_index`) uses
`get_value_or_greater(index + 1)` and thus never returns the `sizeAtBlock=0`
slot, so the extra write is harmless when `initialSize == 0`.
@PhilWindle PhilWindle merged commit 1749ac3 into merge-train/spartan Apr 22, 2026
12 checks passed
@PhilWindle PhilWindle deleted the spl/genesis-block-index-unconditional branch April 22, 2026 18:10
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.

2 participants