refactor(world-state): always index block 0 regardless of initial tree size#22724
Merged
PhilWindle merged 1 commit intomerge-train/spartanfrom Apr 22, 2026
Merged
Conversation
…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
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Follow-up to #22711 addressing a review flag from PhilWindle:
commit_genesis_stateonly wrote a block-index entry for block 0 wheninitialSize > 0. This created a minor asymmetry with the regular commit path, which writeswrite_block_index_dataunconditionally 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) usesget_value_or_greater(index + 1), so asizeAtBlock=0entry 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
initialSize > 0guard around the block-0write_block_index_datacall so the genesis commit matches the regular commit path.