Commit 5cee882
refactor: enforce frozen natively in StrictBaseModel (leanEthereum#845)
Restore the frozen constraint that leanEthereum#789 removed, this time enforced once
in the base model instead of per class. Every spec type is now immutable
by default, with no opt-outs: the State accumulator and the fork-choice
Store are frozen too, and every remaining in-place mutation site is
converted back to the model_copy(update=...) functional style.
Follow-up to leanEthereum#842/leanEthereum#843, as discussed in the leanEthereum#843 review thread.
Changes:
- base.py: add frozen to StrictBaseModel; restore the pre-leanEthereum#789 docstring.
- Delete the 17 per-class model_config | {"frozen": True} overrides
(block, checkpoint, attestation, aggregation, validator, xmss, eth2)
now that the base enforces them.
- state_transition.py: process_slots rebinds through model_copy (the
deepcopy barrier is no longer needed), process_block_header applies
its updates atomically in one final copy, process_attestations
returns a new state.
- fork_choice.py, timeline.py, validator_duties.py, aggregation.py:
every store update flows through model_copy; dicts and inner sets are
shallow-copied before growing so the caller's store is left untouched.
- node/chain/service.py, node/sync/service.py: rebind the store instead
of patching it in place.
- xmss/interface.py: advance_preparation returns a rebuilt secret key.
- enr.py: from_rlp rebuilds the record with the computed node id.
- packages/testing + tests: all fixture-setup mutations converted to
model_copy rebinding; helpers that mutated arguments now return the
new instance.
- Restore test_frozen_rejects_assignment and the immutability wording
in the SSZ patterns rule; add mirrored immutability tests for State
and Store.
Validation:
- just check passes (ruff lint + format, ty, codespell, mdformat, lock)
- Unit suites: lstar spec 257 passed, node 1682 passed,
crypto/ssz/enr/containers/base 1660 passed
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 3738618 commit 5cee882
34 files changed
Lines changed: 505 additions & 322 deletions
File tree
- .claude/rules
- packages/testing/src/consensus_testing
- test_fixtures
- test_types
- src/lean_spec
- node
- chain
- networking/enr
- sync
- spec
- crypto/xmss
- forks/lstar
- containers
- tests/lean_spec
- helpers
- node
- chain
- sync
- validator
- spec/forks/lstar
- containers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | | - | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
250 | 252 | | |
251 | 253 | | |
252 | 254 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
540 | 540 | | |
541 | 541 | | |
542 | 542 | | |
543 | | - | |
544 | | - | |
| 543 | + | |
545 | 544 | | |
546 | 545 | | |
547 | 546 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| 62 | + | |
61 | 63 | | |
62 | 64 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
| 376 | + | |
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
40 | 38 | | |
41 | 39 | | |
42 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
656 | 656 | | |
657 | 657 | | |
658 | 658 | | |
659 | | - | |
| 659 | + | |
660 | 660 | | |
661 | 661 | | |
662 | 662 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
| |||
138 | 136 | | |
139 | 137 | | |
140 | 138 | | |
141 | | - | |
142 | | - | |
143 | 139 | | |
144 | 140 | | |
145 | 141 | | |
| |||
161 | 157 | | |
162 | 158 | | |
163 | 159 | | |
164 | | - | |
165 | | - | |
166 | 160 | | |
167 | 161 | | |
168 | 162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
405 | 408 | | |
406 | 409 | | |
407 | 410 | | |
| |||
0 commit comments