Skip to content

Commit d29cd6a

Browse files
authored
Merge pull request #11 from tcoratger/subspec-chain
subspec: add chain model
2 parents af1fe7b + 47434df commit d29cd6a

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Specifications for chain and consensus parameters."""
2+
3+
from .config import DEVNET_CONFIG
4+
5+
__all__ = [
6+
"DEVNET_CONFIG",
7+
]
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
"""
2+
Chain and Consensus Configuration Specification
3+
4+
This file defines the core consensus parameters and chain presets for the
5+
Lean Consensus Experimental Chain.
6+
"""
7+
8+
from pydantic import BaseModel, ConfigDict
9+
from typing_extensions import Final
10+
11+
from lean_spec.subspecs.types import BasisPoint, uint64
12+
13+
# --- Time Parameters ---
14+
15+
# The fixed duration of a single slot in milliseconds.
16+
SLOT_DURATION_MS: Final = 4000
17+
18+
# The deadline within a slot (in basis points) for a proposer to publish a
19+
# block.
20+
#
21+
# Honest validators may re-org blocks published after this cutoff.
22+
#
23+
# (2500 bps = 25% of slot duration).
24+
PROPOSER_REORG_CUTOFF_BPS: Final = 2500
25+
26+
# The deadline within a slot (in basis points) by which validators must
27+
# submit their votes.
28+
#
29+
# (5000 bps = 50% of slot duration).
30+
VOTE_DUE_BPS: Final = 5000
31+
32+
# The deadline within a slot (in basis points) for achieving a fast
33+
# confirmation.
34+
#
35+
# (7500 bps = 75% of slot duration).
36+
FAST_CONFIRM_DUE_BPS: Final = 7500
37+
38+
# The cutoff within a slot (in basis points) after which the current view is
39+
# considered 'frozen', preventing further changes.
40+
#
41+
# (7500 bps = 75% of slot duration).
42+
VIEW_FREEZE_CUTOFF_BPS: Final = 7500
43+
44+
# --- State List Length Presets ---
45+
46+
# The maximum number of historical block roots to store in the state.
47+
#
48+
# With a 4-second slot, this corresponds to a history
49+
# of approximately 12.1 days.
50+
HISTORICAL_ROOTS_LIMIT: Final = 2**18
51+
52+
# The maximum number of validators that can be in the registry.
53+
VALIDATOR_REGISTRY_LIMIT: Final = 2**12
54+
55+
56+
class _ChainConfig(BaseModel):
57+
"""
58+
A model holding the canonical, immutable configuration constants
59+
for the chain.
60+
"""
61+
62+
# Configuration to make the model immutable.
63+
model_config = ConfigDict(frozen=True, extra="forbid")
64+
65+
# Time Parameters
66+
slot_duration_ms: uint64
67+
proposer_reorg_cutoff_bps: BasisPoint
68+
vote_due_bps: BasisPoint
69+
fast_confirm_due_bps: BasisPoint
70+
view_freeze_cutoff_bps: BasisPoint
71+
72+
# State List Length Presets
73+
historical_roots_limit: uint64
74+
validator_registry_limit: uint64
75+
76+
77+
# The Devnet Chain Configuration.
78+
DEVNET_CONFIG: Final = _ChainConfig(
79+
slot_duration_ms=SLOT_DURATION_MS,
80+
proposer_reorg_cutoff_bps=PROPOSER_REORG_CUTOFF_BPS,
81+
vote_due_bps=VOTE_DUE_BPS,
82+
fast_confirm_due_bps=FAST_CONFIRM_DUE_BPS,
83+
view_freeze_cutoff_bps=VIEW_FREEZE_CUTOFF_BPS,
84+
historical_roots_limit=HISTORICAL_ROOTS_LIMIT,
85+
validator_registry_limit=VALIDATOR_REGISTRY_LIMIT,
86+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Reusable type definitions for the Lean Ethereum specification."""
2+
3+
from .basispt import BasisPoint
4+
from .uint64 import uint64
5+
6+
__all__ = [
7+
"uint64",
8+
"BasisPoint",
9+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Basis Point Type Specification."""
2+
3+
from pydantic import Field
4+
from typing_extensions import Annotated
5+
6+
from ..types import uint64
7+
8+
# A type alias for basis points
9+
#
10+
# A basis point (bps) is 1/100th of a percent. 100% = 10,000 bps.
11+
BasisPoint = Annotated[
12+
uint64,
13+
Field(le=10000, description="A value in basis points (1/10000)."),
14+
]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""Unsigned 64-bit Integer Type Specification."""
2+
3+
from pydantic import Field
4+
from typing_extensions import Annotated
5+
6+
# The maximum value for an unsigned 64-bit integer (2**64).
7+
UINT64_MAX = 2**64
8+
9+
# A type alias to represent a uint64.
10+
uint64 = Annotated[int, Field(ge=0, lt=UINT64_MAX)]

0 commit comments

Comments
 (0)