refactor: order Checkpoint by slot to drop max() lambda noise#684
Merged
tcoratger merged 1 commit intoleanEthereum:mainfrom Apr 26, 2026
Merged
Conversation
Add Checkpoint.__lt__ ordered by slot so the four max(...) calls in the forkchoice store can drop their `key=lambda c: c.slot` argument. Tie-break behavior is preserved: equal-slot checkpoints are incomparable, so max() keeps its first argument — same semantics each call site already relied on. Adds unit tests covering strict/reverse/equal ordering, anti-reflexivity, the NotImplemented sentinel for foreign types, the resulting TypeError on the < operator, and the two max() integration cases (different slots, equal slots). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tcoratger
added a commit
to tcoratger/leanSpec
that referenced
this pull request
Apr 27, 2026
Absorbs 14 commits from main and resolves two textual conflicts in genesis/config.py and the matching test (PR leanEthereum#683 deleted the dead GenesisConfig.create_state helper that this branch had refactored to take a fork argument; production code goes through fork.generate_genesis directly, so the wrapper is genuinely dead). Reroutes two stale subspecs.containers imports left behind by the auto-merge: a new test file from PR leanEthereum#684 (Checkpoint __lt__) and a sync test fixture from PR leanEthereum#672. Both now resolve through forks.devnet4.containers. Tightens the docstring and inline comment introduced for update_safe_target by PR leanEthereum#680 to follow the project's documentation rules (short sentences, bullets over paragraphs). Co-Authored-By: Claude Opus 4.7 (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
Adds
Checkpoint.__lt__ordered by slot so the fourmax(...)calls inforkchoice/store.pycan drop theirkey=lambda c: c.slotargument.Tie-break semantics preserved
Equal-slot checkpoints are intentionally incomparable (
a < bandb < aboth returnFalse). Python'smax()keeps its first argument when neither is strictly less, which matches what each call site already relied on:on_block:max(self.X, post_state.X)— store wins ties (the documented "anchor-pinned, authoritative on ties" invariant).produce_block_with_signatures:max(final_post_state.X, store.X)— post-state wins ties (existing behavior; not changed in this PR).No behavioral change at any call site. Just the lambda noise removed.
Tests
tests/lean_spec/subspecs/containers/test_checkpoint.py— 8 tests, no duplicate scenarios:Truefor lower slotFalsefor higher slotNotImplementedsentinel for foreign types<operator raisesTypeErrorafter Python's reflected fallback failsmax()picks the higher-slot checkpoint regardless of argument ordermax()keeps the first argument on slot ties (the property the forkchoice store relies on)Test plan
uvx tox -e all-checkspasses (ruff, format, ty, codespell, mdformat).uv run pytest tests/lean_spec/subspecs/containers/test_checkpoint.py— 8 passed.🤖 Generated with Claude Code