refactor(clock): relocate Interval to the spec layer and tidy SlotClock#819
Merged
tcoratger merged 2 commits intoJun 1, 2026
Merged
Conversation
The chain and consensus configuration constants lived under node/chain/config.py, but they are protocol parameters that client teams must match, not node implementation details. Several spec/ modules already imported them from node/, an inverted dependency where the protocol-spec layer reached down into a specific node implementation. SSZ container bounds (HISTORICAL_ROOTS_LIMIT, MAX_ATTESTATIONS_DATA) and forkchoice/timing parameters belong with the fork they define. Move the file to spec/forks/lstar/config.py, scoping the constants to the lstar fork in line with the per-fork registry pattern, and update all import sites across src, tests, and packages/testing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Interval is the type of the store's time field, yet it lived in the node-layer clock module. That forced the consensus spec to import from the node layer, an inverted dependency papered over with F821 and ty-ignore suppressions on the Slot annotations. Move Interval into src/lean_spec/spec/forks/lstar/interval.py next to the config and slot primitives it depends on. clock.py can now import Slot and Interval normally at module top, and all suppression comments are gone. Further cleanups: - Delete the test-only Interval.from_unix_time. Its two callers (the fork-choice fixture tick path and the slot-clock conformance fixture) now go through SlotClock.total_intervals, the node-layer owner of wall-clock to interval conversion. Generated vectors are unchanged. - Derive current_slot from the millisecond base and drop the redundant seconds helper, removing a latent precision asymmetry between the slot and interval paths. - Add a before-genesis guard equivalent so pre-genesis input clamps to zero instead of underflowing. - Mirror the test layout to the source layout: Interval tests move to tests/lean_spec/spec/forks/lstar/test_interval.py. Add a CLAUDE.md rule requiring the test tree to mirror the source tree. - Rewrite the Interval and SlotClock tests as parametrized suites with cross-method consistency invariants, reaching full line and branch coverage. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Intervalis the type of the store'stimefield, yet it lived in the node-layer clock module. That forced the consensus spec (spec.py,containers.py) to importIntervalfrom the node layer — an inverted dependency that was papered over with# noqa: F821 # ty: ignore[unresolved-reference]suppressions on theSlotannotations inclock.py.This PR relocates
Intervalto where it belongs and cleans upSlotClock, removing the suppressions entirely.Changes
Intervaltosrc/lean_spec/spec/forks/lstar/interval.py, next to theconfigandslotprimitives it depends on.clock.pynow importsSlotandIntervalnormally at module top — nonoqa, noty: ignore.Interval.from_unix_time. Its only callers were the fork-choice fixture tick path and the slot-clock conformance fixture; both now go throughSlotClock.total_intervals, the node-layer owner of wall-clock→interval conversion. Generated test vectors are unchanged (verified bit-identical).current_slotfrom the millisecond base and drop the redundant seconds helper, removing a latent precision asymmetry between the slot and interval paths.Intervaltests move totests/lean_spec/spec/forks/lstar/test_interval.py;test_clock.pykeeps onlySlotClock. Adds aCLAUDE.mdrule requiring the test tree to mirror the source tree.current_slot == total_intervals // INTERVALS_PER_SLOT, etc.), reaching 100% line and branch coverage for both modules.Testing
just checkpasses (ruff, format, ty, codespell, mdformat).interval.pyandclock.pyat 100% coverage.🤖 Generated with Claude Code