|
| 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 | +) |
0 commit comments