Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/lean_spec/forks/lstar/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
The Store tracks all information required for the LMD GHOST forkchoice algorithm.
"""

__all__ = ["AttestationSignatureEntry", "BlockT", "StateT", "Store"]
__all__ = ["AttestationSignatureEntry", "Store"]

from typing import Generic, NamedTuple, TypeVar
from typing import NamedTuple

from pydantic import Field

Expand All @@ -21,12 +21,6 @@
from lean_spec.types.base import StrictBaseModel
from lean_spec.types.container import Container

StateT = TypeVar("StateT", bound=Container)
"""Per-fork post-state type tracked alongside each known block."""

BlockT = TypeVar("BlockT", bound=Container)
"""Per-fork block type stored in the forkchoice view."""


class AttestationSignatureEntry(NamedTuple):
"""
Expand All @@ -40,7 +34,7 @@ class AttestationSignatureEntry(NamedTuple):
signature: Signature


class Store(StrictBaseModel, Generic[StateT, BlockT]):
class Store[StateT: Container, BlockT: Container](StrictBaseModel):
"""
Forkchoice store tracking chain state and validator attestations.

Expand Down
14 changes: 2 additions & 12 deletions src/lean_spec/types/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
IO,
Any,
ClassVar,
Generic,
Protocol,
Self,
TypeVar,
cast,
overload,
override,
Expand All @@ -38,14 +36,6 @@ class IntFieldElement(Protocol):
value: int


T = TypeVar("T", bound=SSZType)
"""Generic type parameter for SSZ collection elements.

Bound to SSZType to ensure elements are valid SSZ types.
Enables type checkers to infer correct return types for indexed access.
"""


def _extract_element_type_from_generic(cls: type, origin_class: type) -> type[SSZType] | None:
"""Extract ELEMENT_TYPE from Pydantic's generic metadata."""
for base in cls.__bases__:
Expand Down Expand Up @@ -94,7 +84,7 @@ def _validate_offsets(offsets: list[int], scope: int, type_name: str) -> None:
)


class SSZVector(SSZModel, Generic[T]):
class SSZVector[T: SSZType](SSZModel):
"""Fixed-length, immutable SSZ sequence.

Contains exactly LENGTH elements of type ELEMENT_TYPE.
Expand Down Expand Up @@ -260,7 +250,7 @@ def elements(self) -> list[T]:
return list(self.data)


class SSZList(SSZModel, Generic[T]):
class SSZList[T: SSZType](SSZModel):
"""Variable-length SSZ sequence with a maximum capacity.

Contains between 0 and LIMIT elements of type ELEMENT_TYPE.
Expand Down
Loading