|
| 1 | +"""State Container.""" |
| 2 | + |
| 3 | +from pydantic import Field |
| 4 | +from typing_extensions import Annotated |
| 5 | + |
| 6 | +from lean_spec.subspecs.chain import DEVNET_CONFIG |
| 7 | +from lean_spec.types import Bytes32, StrictBaseModel, Uint64 |
| 8 | + |
| 9 | +from .block import BlockHeader |
| 10 | +from .checkpoint import Checkpoint |
| 11 | +from .config import Config |
| 12 | + |
| 13 | + |
| 14 | +class State(StrictBaseModel): |
| 15 | + """The main consensus state object.""" |
| 16 | + |
| 17 | + # Configuration |
| 18 | + config: Config |
| 19 | + """The chain's configuration parameters.""" |
| 20 | + |
| 21 | + # Slot and block tracking |
| 22 | + slot: Uint64 |
| 23 | + """The current slot number.""" |
| 24 | + |
| 25 | + latest_block_header: BlockHeader |
| 26 | + """The header of the most recent block.""" |
| 27 | + |
| 28 | + # Fork choice |
| 29 | + latest_justified: Checkpoint |
| 30 | + """The latest justified checkpoint.""" |
| 31 | + |
| 32 | + latest_finalized: Checkpoint |
| 33 | + """The latest finalized checkpoint.""" |
| 34 | + |
| 35 | + # Historical data |
| 36 | + historical_block_hashes: Annotated[ |
| 37 | + list[Bytes32], |
| 38 | + Field(max_length=DEVNET_CONFIG.historical_roots_limit), |
| 39 | + ] |
| 40 | + """A list of historical block root hashes.""" |
| 41 | + |
| 42 | + justified_slots: Annotated[ |
| 43 | + list[bool], |
| 44 | + Field(max_length=DEVNET_CONFIG.historical_roots_limit), |
| 45 | + ] |
| 46 | + """A bitfield indicating which historical slots were justified.""" |
| 47 | + |
| 48 | + # Justification tracking (flattened for SSZ compatibility) |
| 49 | + justifications_roots: Annotated[ |
| 50 | + list[Bytes32], |
| 51 | + Field(max_length=DEVNET_CONFIG.historical_roots_limit), |
| 52 | + ] |
| 53 | + """Roots of justified blocks.""" |
| 54 | + |
| 55 | + justifications_validators: Annotated[ |
| 56 | + list[bool], |
| 57 | + Field( |
| 58 | + max_length=( |
| 59 | + DEVNET_CONFIG.historical_roots_limit |
| 60 | + * DEVNET_CONFIG.historical_roots_limit |
| 61 | + ) |
| 62 | + ), |
| 63 | + ] |
| 64 | + """A bitlist of validators who participated in justifications.""" |
0 commit comments