refactor(forks): make Store generic over StateT, BlockT (Stage 5 of #686)#705
Merged
tcoratger merged 1 commit intoleanEthereum:mainfrom May 3, 2026
Merged
Conversation
…eanEthereum#686) Per the multi-fork roadmap, Store now declares its State and Block types as type parameters so future forks can specialize them with a typedef instead of copy-pasting the whole class. Design (per the py-architect agent): - `Store(StrictBaseModel, Generic[StateT, BlockT])` in forks/lstar/store.py. StateT and BlockT are bound to Container so Pydantic can build a real schema at parameterization time; structural protocols would not. - `LstarStore = Store[State, Block]` in forks/lstar/spec.py is the concrete binding owned by the lstar fork. `LstarSpec.store_class` and `create_store` are typed against it. - `BlockLookup` is dropped — it was a single-line alias used in two helper signatures that read just as clearly as `dict[Bytes32, Block]`. - Public `from lean_spec.forks import Store` resolves to `LstarStore`, so every existing call site keeps working without change. `LstarStore` is also exported under its canonical name for callers that prefer to be explicit. - Mutable Store defaults move from bare `= {}` to `Field(default_factory= dict)` to silence the Pydantic generic-default warning ty raised intermittently and to keep the schema honest. The third Stage 5 item (a `Devnet5Store` typedef demonstrating the pattern) is dropped because devnet5 was unified back into lstar. 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
Per the multi-fork roadmap, Stage 5 makes
Storegeneric so future forks can specialize theirState/Blockwith a typedef instead of copying the class.Store(StrictBaseModel, Generic[StateT, BlockT])lives inforks/lstar/store.py. TypeVars bind toContainerso Pydantic can resolve real schemas at parameterization time.LstarStore = Store[State, Block]is the concrete binding for the lstar fork (defined inforks/lstar/spec.py).LstarSpec.store_classandcreate_storeare typed against it.BlockLookupis dropped — single-line alias used in two helpers, not worth the indirection.from lean_spec.forks import Storeresolves toLstarStore, so every existing call site keeps working unchanged.LstarStoreis also exported under its canonical name.= {}toField(default_factory=dict)to silence Pydantic's generic-default warning.The third Stage 5 item (a
Devnet5Storetypedef showing the pattern) is dropped because devnet5 was unified back into lstar.Design provenance
Design reviewed with the
py-architectanddoc-writeragents:Container-bounded TypeVars over the structuralSpecStateType/SpecBlockTypeprotocols — Pydantic v2 generic models need a concrete class at specialization time.Storeclass docstring; theGeneric[...]clause documents itself. Only the new TypeVars get one-line role docstrings.Test plan
uvx tox -e all-checks— ruff, format, ty, codespell, mdformat all passpytest tests -n auto— 3291 passedStore is LstarStoreisTrue; instantiation producesStore[State, Block]with(State, Block)resolved in__pydantic_generic_metadata__🤖 Generated with Claude Code