|
5 | 5 | Lean Consensus Experimental Chain. |
6 | 6 | """ |
7 | 7 |
|
8 | | -from pydantic import BaseModel, ConfigDict, Field |
9 | | -from typing_extensions import Annotated |
| 8 | +from pydantic import BaseModel, ConfigDict |
| 9 | +from typing_extensions import Final |
10 | 10 |
|
11 | | -# The maximum value for an unsigned 64-bit integer (2**64). |
12 | | -UINT64_MAX = 2**64 |
| 11 | +from lean_spec.subspecs.types import BasisPoint, uint64 |
13 | 12 |
|
14 | | -# A type alias to represent a uint64. |
15 | | -uint64 = Annotated[int, Field(ge=0, lt=UINT64_MAX)] |
| 13 | +# --- Time Parameters --- |
16 | 14 |
|
17 | | -# A type alias for basis points, now based on the uint64 type. |
| 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. |
18 | 47 | # |
19 | | -# A basis point (bps) is 1/100th of a percent. 100% = 10,000 bps. |
20 | | -BasisPoint = Annotated[ |
21 | | - uint64, |
22 | | - Field(le=10000, description="A value in basis points (1/10000)."), |
23 | | -] |
| 48 | +# With a 4-second slot, this corresponds to a history |
| 49 | +# of approximately 12.1 days. |
| 50 | +HISTORICAL_ROOTS_LIMIT: Final = 2**18 |
24 | 51 |
|
| 52 | +# The maximum number of validators that can be in the registry. |
| 53 | +VALIDATOR_REGISTRY_LIMIT: Final = 2**12 |
25 | 54 |
|
26 | | -class ChainConfig(BaseModel): |
| 55 | + |
| 56 | +class _ChainConfig(BaseModel): |
27 | 57 | """ |
28 | 58 | A model holding the canonical, immutable configuration constants |
29 | 59 | for the chain. |
30 | | -
|
31 | | - These parameters are considered "presets" and define the fundamental rules |
32 | | - of the consensus protocol. |
33 | 60 | """ |
34 | 61 |
|
35 | 62 | # Configuration to make the model immutable. |
36 | 63 | model_config = ConfigDict(frozen=True, extra="forbid") |
37 | 64 |
|
38 | | - # ========================================================================= |
39 | 65 | # Time Parameters |
40 | | - # |
41 | | - # These constants define the timing and deadlines within a single slot. |
42 | | - # ========================================================================= |
43 | | - |
44 | | - SLOT_DURATION_MS: uint64 = Field( |
45 | | - default=4000, |
46 | | - description="The fixed duration of a single slot in milliseconds.", |
47 | | - ) |
48 | | - |
49 | | - PROPOSER_REORG_CUTOFF_BPS: BasisPoint = Field( |
50 | | - default=2500, |
51 | | - description=( |
52 | | - "The deadline within a slot (in basis points) for a proposer to " |
53 | | - "publish a block. Honest validators may re-org blocks published " |
54 | | - "after this cutoff. (2500 bps = 25% of slot duration)." |
55 | | - ), |
56 | | - ) |
57 | | - |
58 | | - VOTE_DUE_BPS: BasisPoint = Field( |
59 | | - default=5000, |
60 | | - description=( |
61 | | - "The deadline within a slot (in basis points) by which validators " |
62 | | - "must submit their votes. (5000 bps = 50% of slot duration)." |
63 | | - ), |
64 | | - ) |
65 | | - |
66 | | - FAST_CONFIRM_DUE_BPS: BasisPoint = Field( |
67 | | - default=7500, |
68 | | - description=( |
69 | | - "The deadline within a slot (in basis points) for achieving a " |
70 | | - "fast confirmation. (7500 bps = 75% of slot duration)." |
71 | | - ), |
72 | | - ) |
73 | | - |
74 | | - VIEW_FREEZE_CUTOFF_BPS: BasisPoint = Field( |
75 | | - default=7500, |
76 | | - description=( |
77 | | - "The cutoff within a slot (in basis points) after which the " |
78 | | - "current view is considered 'frozen', preventing further changes. " |
79 | | - "(7500 bps = 75% of slot duration)." |
80 | | - ), |
81 | | - ) |
82 | | - |
83 | | - # ========================================================================= |
| 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 | + |
84 | 72 | # State List Length Presets |
85 | | - # |
86 | | - # These constants define the maximum capacity of certain data structures |
87 | | - # within the consensus state, preventing unbounded growth. |
88 | | - # ========================================================================= |
89 | | - |
90 | | - HISTORICAL_ROOTS_LIMIT: uint64 = Field( |
91 | | - default=2**18, |
92 | | - description=( |
93 | | - "The maximum number of historical block roots to store in the " |
94 | | - "state. With a 4-second slot, this corresponds to a history of " |
95 | | - "approximately 12.1 days." |
96 | | - ), |
97 | | - ) |
98 | | - |
99 | | - VALIDATOR_REGISTRY_LIMIT: uint64 = Field( |
100 | | - default=2**12, |
101 | | - description=( |
102 | | - "The maximum number of validators that can be in the registry." |
103 | | - ), |
104 | | - ) |
105 | | - |
106 | | - |
107 | | -# Global constant for the devnet chain configuration. |
108 | | -DEVNET_CONFIG = ChainConfig() |
| 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 | +) |
0 commit comments