Skip to content

refactor(testing): consolidate consensus_testing genesis builders - #1153

Merged
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:refactor/consensus-testing-genesis
Jun 18, 2026
Merged

refactor(testing): consolidate consensus_testing genesis builders#1153
tcoratger merged 2 commits into
leanEthereum:mainfrom
tcoratger:refactor/consensus-testing-genesis

Conversation

@tcoratger

Copy link
Copy Markdown
Collaborator

Summary

Tidies up packages/testing/src/consensus_testing/genesis.py, which had grown a tangle of overlapping, inconsistently named builders. Collapses them into a small, consistent surface and removes duplication, updating all call sites.

The public surface goes from 7 symbols to 3 functions:

build_genesis_state(num_validators=4, *, genesis_time=Uint64(0), keyed=True, fork=LstarSpec())
build_anchor(num_validators, anchor_slot, *, fork=LstarSpec(), genesis_time=Uint64(0), keyed=True, synced=False)
build_genesis_store(num_validators=4, *, genesis_time=0, validator_index=ValidatorIndex(0), observer=False, keyed=True, time=None)

What changed

  • Merged the keyed/zeroed builders. _build_validators (real XMSS keys) and make_validators (zeroed keys) were the same loop with a different key source; both now live inside build_genesis_state behind a keyed flag. generate_pre_state and make_genesis_state collapse into that one function too.
  • Unified the verb. make_genesis_storebuild_genesis_store; everything is now build_*.
  • Removed reconstruct_block_from_header — a trivial helper; the genesis-block construction is inlined at its call sites.
  • Single source for the genesis block. build_anchor now accepts anchor_slot=0 as the genesis case (its advance loop is simply empty there), so build_genesis_store delegates to it. The genesis-block construction now exists in exactly one place, and the if anchor_slot == 0 dodge branches in the sync/api_endpoint fixtures collapse away.
  • Inlined the former module-level defaults (_DEFAULT_GENESIS_TIME, _DEFAULT_VALIDATOR_INDEX) and defaulted fork directly in the signatures. The immutable Uint64/ValidatorIndex/LstarSpec calls are whitelisted in ruff's flake8-bugbear.extend-immutable-calls so the in-signature defaults pass B008.
  • Updated all call sites across tests/ and packages/.

No backward-compatibility shims — old names are removed, not aliased.

Testing

  • just check passes (ruff lint + format, ty, codespell, mdformat, lock).
  • Unit tests across the affected node modules pass (test_anchor, test_node, chain/test_service, api/endpoints, validator/test_service).

🤖 Generated with Claude Code

tcoratger and others added 2 commits June 18, 2026 00:28
Collapse the genesis/anchor construction helpers into a small, consistent
surface and remove duplication.

- Merge the keyed and zeroed validator/state builders into one
  build_genesis_state(..., keyed=...); drop generate_pre_state,
  make_genesis_state, make_validators, _build_validators.
- Rename make_genesis_store to build_genesis_store and unify the build_ verb.
- Inline the trivial genesis-block reconstruction at its call sites and
  remove reconstruct_block_from_header.
- Let build_anchor handle slot 0 as the genesis case so build_genesis_store
  delegates to it; the genesis-block construction now lives in one place.
- Inline the former module-level defaults and default fork directly in
  signatures; whitelist the immutable Uint64/ValidatorIndex/LstarSpec calls
  in ruff's flake8-bugbear config.
- Update all call sites across tests/ and packages/.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The inlined genesis-block construction hurt readability across the
fixtures and tests. Bring the helper back, export it, and call it
again everywhere the block is rebuilt from a state's latest header,
including inside build_anchor.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tcoratger
tcoratger merged commit ebaf6bc into leanEthereum:main Jun 18, 2026
14 checks passed
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