refactor(chain): tidy ChainService and rework its test suite#825
Merged
tcoratger merged 1 commit intoJun 2, 2026
Merged
Conversation
Service: - Reuse the clock's own pre-genesis wait instead of recomputing it by hand. - Drop the redundant no-op store reassignment in the skip-ahead path, and the needless int() cast around INTERVALS_PER_SLOT. - Add a forward-only precondition (target >= store.time) and a note that attestation acceptance for jumped slots defers safely to the final tick. - Rewrite docstrings and comments to the repo documentation rules. Tests: - Replace the mock-heavy suite (MockStore/MockCheckpoint/StoreInterceptingSpec) with a real Store plus a thin recording spec; the clock-timing tests that belonged to SlotClock are dropped (already covered in test_clock.py). - Test the catch-up helpers directly where they return, and drive the run loop only where the loop itself is under test. - Cover the full scenario spread with parametrized cases: no-op, within-slot, slot boundary, just-over, deep skip; plus the backward-target precondition and a store swapped in during the yield (the post-yield re-read). - 22 tests, 100% line and branch coverage of service.py. 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
Cleans up the consensus clock driver (
ChainService) and replaces its mock-heavy test suite with a clearer, real-object suite that covers the full scenario spread.Service (
src/lean_spec/node/chain/service.py)SlotClock's own pre-genesis wait (sleep_until_next_interval) instead of recomputing the wait by hand — one home for that timing, and it no longer truncates the fractional remainder.Storemutates in place), and drop the needlessint()cast aroundINTERVALS_PER_SLOT.assert target_interval >= store.time) documenting the invariant the catch-up loop relies on, plus a note that attestation acceptance for jumped-over slots defers safely to the final slot's tick.Tests (
tests/lean_spec/node/chain/test_service.py)MockStore/MockCheckpoint/StoreInterceptingSpecscaffolding in favor of a realStoreplus a thin recording spec (ProbeSpec) and a 3-fieldSyncServiceStubnaming exactly what the driver touches.SlotClock.sleep_until_next_intervalrather thanChainService— already covered intest_clock.py(test-mirrors-source rule)._tick_to,_initial_tick) directly where they return; only drive the infiniterun()loop in the handful of tests where the loop itself is the subject.Verification
service.py.just checkpasses (lint, format, type check, spell, mdformat).🤖 Generated with Claude Code