Commit 1589f87
refactor(types): centralize proposer selection on ValidatorIndex (leanEthereum#732)
The round-robin arithmetic `int(slot) % int(num_validators)` was
duplicated between `ValidatorIndex.is_proposer_for` and the debug
log line in `validator/service.py`. Both sites now derive from one
classmethod, so the rule cannot drift.
Adds `ValidatorIndex.proposer_for_slot(slot, num_validators)` as a
classmethod factory. Returns a `ValidatorIndex`, type lives on the
type it returns. `is_proposer_for` becomes a one-line predicate that
delegates to the classmethod.
Picked over a free function or a method on `Slot`/`Validators`:
- Free function felt procedural in an OO codebase where every other
selection helper in `types/` is a method.
- Method on `Slot` would have needed a forward reference to
`ValidatorIndex` and a circular-import workaround.
- Method on `Validators` lives in fork-specific code, but the
arithmetic is fork-stable.
The classmethod sits next to `is_proposer_for` in `types/validator.py`,
no new file, no cycle, no fork dependency.
A parametric consistency test verifies the classmethod and the
predicate agree at every slot for any registry size.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 08868e7 commit 1589f87
3 files changed
Lines changed: 55 additions & 12 deletions
File tree
- src/lean_spec
- subspecs/validator
- types
- tests/lean_spec/types
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
280 | | - | |
| 280 | + | |
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
| 1 | + | |
7 | 2 | | |
8 | 3 | | |
9 | 4 | | |
| |||
16 | 11 | | |
17 | 12 | | |
18 | 13 | | |
19 | | - | |
20 | | - | |
21 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
22 | 17 | | |
23 | | - | |
| 18 | + | |
24 | 19 | | |
25 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
8 | 52 | | |
9 | 53 | | |
10 | 54 | | |
| |||
0 commit comments