Commit 45ba21e
refactor(forks): move verify_signatures body into the spec (Stage 4C, part 1 of leanEthereum#686) (leanEthereum#704)
* refactor(forks): move verify_signatures body into the spec class
Moves the full XMSS signature verification logic from
SignedBlock.verify_signatures into LstarSpec.verify_signatures.
SignedBlock becomes a pure SSZ data container.
Internal callers that still hold a Store (notably Store.on_block,
which itself moves to the spec class in a follow-up) reach the
verification path via a deferred import of LstarSpec to sidestep
the spec ↔ store module-load cycle.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(forks): move State and Store bodies into the spec class
Migrates every State and Store method body into LstarSpec. Containers
(State, Store, SignedBlock) become thin Pydantic data classes whose
methods are one-line forwarders to the active fork spec, reached via a
deferred import that breaks the spec ↔ container module-load cycle.
Inside the moved bodies, every literal Block(...), BlockBody(...),
BlockHeader(...), Config(...), AggregatedAttestations(...), and other
container constructor is now self.<name>_class(...). An inheriting fork
that swaps a single container type therefore receives the parent fork's
logic for free.
Observability hooks (observe_state_transition, observe_on_block,
observe_on_attestation) ride along with the bodies, preserving the
metrics surface.
The obsolete delegator-forwarding test file is removed; behavioural
coverage now lives in the existing state-transition, fork-choice, and
block-production test suites.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(forks): delete the trivial container forwarders (Stage 4D of leanEthereum#686)
State, Store, and SignedBlock become pure Pydantic data containers.
All forwarder methods that delegated through the lazy spec singleton
are removed; the lazy singleton helpers are removed alongside them.
Every remaining call site that used to go through a container method
now goes through the active fork spec:
- Tests use the session-scoped `spec` fixture from `tests/lean_spec/conftest.py`.
- Subspec services (`sync`, `validator`, `chain`, plus the fork-choice
API endpoint) carry a module-level `_SPEC = LstarSpec()` constant.
- Library helpers (`tests/lean_spec/helpers/builders.py`,
`packages/testing/...`) follow the same `_SPEC` pattern.
`ForkProtocol.generate_genesis` and `ForkProtocol.create_store` become
abstract; the previous default implementations referenced container
methods that no longer exist.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(forks): resolve Block forward reference in BlockLookup
The Store.blocks field is annotated as `BlockLookup`, which was defined
as `dict[Bytes32, "Block"]` — a string forward reference. After the
container methods moved off Store, Pydantic's model rebuild could no
longer resolve `Block` because it was never imported into store.py
alongside the alias.
Drop the forward-reference quoting: `BlockLookup` lives in the same
module as `Block`, so the type can refer to the class directly. Pydantic
then resolves `Store.blocks` correctly through the alias re-export.
Without this, every consensus filler that constructed a Store via
`spec.create_store(...)` raised
`PydanticUserError: 'Store' is not fully defined`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(forks): route mock-store tests through autouse spec patches
The forwarders that used to live on `Store` (and were patched in
`tests/lean_spec/subspecs/{sync,chain,networking,validator}/`) are gone
after Stage 4D. The mocks (`MockStore`, `MockForkchoiceStore`) still
implement the same method surface, but the service code now calls the
real spec, which expects a Pydantic Store.
Add an autouse fixture per affected subspec that patches the active
spec's methods to delegate back to `store.method(...)`. The mocks
intercept calls in-place, preserving every test's recording semantics
without touching service code.
The validator service tests that previously patched
`Store.produce_block_with_signatures` and `Store.on_gossip_attestation`
now patch the matching methods on the validator service's `_SPEC` —
same intent, current attribute path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(forks): drop cast(Store, ...) at call sites
Casts were a workaround for Liskov violations on LstarSpec.create_store
when it returned the SpecStoreType protocol while concretely producing
Store. cast had no runtime effect and pushed type-checker noise into
fixtures and tests.
Move the imprecision into the fork itself: create_store now declares
its concrete Store return and suppresses the override warning at the
single definition site. Callers receive Store directly and need no cast.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(forks): replace 17-site _SPEC duplication with DI
Each module declared its own _SPEC = LstarSpec(), creating value-equal
but identity-distinct instances. The pattern also baked LstarSpec into
17 import sites; a future fork would have to grep-and-replace them all.
Production services (chain, sync, validator, api) now take spec as a
dataclass field with default_factory=LstarSpec — explicit at the
composition root in node.py, optional in tests. node.py narrows
config.fork (ForkProtocol) to LstarSpec once with isinstance, which
also lets the cast(State, ...) and cast(Store, ...) at the genesis
construction sites drop.
Test conftests that intercept spec calls now monkey-patch LstarSpec
at the class level (not the deleted module-level _SPEC instance).
Test types and fixtures instantiate LstarSpec at call time — no
module-level cache, no shared mutable state to alias.
ForkProtocol still declares only the three abstract construction
methods (generate_genesis, create_store, upgrade_state). Services and
tests that drive consensus methods (process_slots, build_block,
tick_interval, ...) keep the concrete LstarSpec type until the
protocol surface is widened in a follow-up.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* refactor(tests): replace conftest monkey-patches with injected spec
Three autouse fixtures in chain/sync/networking conftests patched
LstarSpec class methods so MockStore / MockForkchoiceStore could
intercept consensus calls in place. Class-level patching mutates
shared state and runs against every test in the directory whether
needed or not.
Now that services accept a spec field, tests inject a small
StoreInterceptingSpec subclass that forwards each spec call back to
the store argument. make_store() (used by sync/networking tests)
hands the intercepting spec to the real SyncService transparently.
Chain test_service.py threads it through ChainService directly.
Two conftests delete entirely; the sync conftest keeps only its
sample_checkpoint / sample_status fixtures.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(tests): patch validator spec on the instance, not the dropped module
Two validator tests still resolved `lean_spec.subspecs.validator.service._SPEC`,
which was removed when the spec moved onto the service as a field. Patching now
targets `service.spec` directly via `patch.object`, which also exercises the
single instance the test actually calls into.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 22afd98 commit 45ba21e
38 files changed
Lines changed: 2183 additions & 2582 deletions
File tree
- packages/testing/src/consensus_testing
- test_fixtures
- test_types
- src/lean_spec
- forks
- lstar
- containers
- block
- state
- subspecs
- api
- endpoints
- chain
- node
- sync
- validator
- tests
- consensus/devnet/state_transition
- lean_spec
- forks
- helpers
- subspecs
- chain
- containers
- forkchoice
- genesis
- validator
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 13 | | |
20 | 14 | | |
21 | 15 | | |
| |||
44 | 38 | | |
45 | 39 | | |
46 | 40 | | |
47 | | - | |
| 41 | + | |
48 | 42 | | |
49 | 43 | | |
50 | 44 | | |
51 | 45 | | |
52 | 46 | | |
53 | 47 | | |
54 | | - | |
| 48 | + | |
| 49 | + | |
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
58 | 53 | | |
59 | 54 | | |
60 | 55 | | |
| 56 | + | |
61 | 57 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 58 | + | |
65 | 59 | | |
66 | 60 | | |
67 | 61 | | |
68 | 62 | | |
69 | 63 | | |
70 | | - | |
| 64 | + | |
71 | 65 | | |
72 | 66 | | |
73 | 67 | | |
| |||
101 | 95 | | |
102 | 96 | | |
103 | 97 | | |
| 98 | + | |
104 | 99 | | |
105 | 100 | | |
106 | 101 | | |
| |||
124 | 119 | | |
125 | 120 | | |
126 | 121 | | |
127 | | - | |
| 122 | + | |
128 | 123 | | |
129 | 124 | | |
130 | 125 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
Lines changed: 9 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
38 | 37 | | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | 40 | | |
45 | 41 | | |
46 | 42 | | |
| |||
190 | 186 | | |
191 | 187 | | |
192 | 188 | | |
| 189 | + | |
| 190 | + | |
193 | 191 | | |
194 | 192 | | |
195 | 193 | | |
| |||
202 | 200 | | |
203 | 201 | | |
204 | 202 | | |
205 | | - | |
| 203 | + | |
206 | 204 | | |
207 | 205 | | |
208 | 206 | | |
| |||
257 | 255 | | |
258 | 256 | | |
259 | 257 | | |
260 | | - | |
| 258 | + | |
261 | 259 | | |
262 | 260 | | |
263 | 261 | | |
| |||
293 | 291 | | |
294 | 292 | | |
295 | 293 | | |
296 | | - | |
| 294 | + | |
297 | 295 | | |
298 | 296 | | |
299 | 297 | | |
| |||
326 | 324 | | |
327 | 325 | | |
328 | 326 | | |
329 | | - | |
| 327 | + | |
330 | 328 | | |
331 | 329 | | |
332 | 330 | | |
333 | 331 | | |
334 | 332 | | |
335 | | - | |
| 333 | + | |
336 | 334 | | |
337 | 335 | | |
338 | 336 | | |
| |||
350 | 348 | | |
351 | 349 | | |
352 | 350 | | |
353 | | - | |
| 351 | + | |
354 | 352 | | |
355 | 353 | | |
356 | 354 | | |
| |||
364 | 362 | | |
365 | 363 | | |
366 | 364 | | |
367 | | - | |
| 365 | + | |
368 | 366 | | |
369 | 367 | | |
370 | 368 | | |
| |||
Lines changed: 7 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 20 | | |
24 | 21 | | |
25 | 22 | | |
| |||
113 | 110 | | |
114 | 111 | | |
115 | 112 | | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
| |||
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
143 | | - | |
| 141 | + | |
144 | 142 | | |
145 | | - | |
| 143 | + | |
146 | 144 | | |
147 | 145 | | |
148 | 146 | | |
| |||
217 | 215 | | |
218 | 216 | | |
219 | 217 | | |
220 | | - | |
| 218 | + | |
221 | 219 | | |
222 | 220 | | |
223 | 221 | | |
| |||
260 | 258 | | |
261 | 259 | | |
262 | 260 | | |
263 | | - | |
| 261 | + | |
264 | 262 | | |
265 | 263 | | |
266 | 264 | | |
| |||
295 | 293 | | |
296 | 294 | | |
297 | 295 | | |
298 | | - | |
299 | | - | |
| 296 | + | |
| 297 | + | |
300 | 298 | | |
301 | 299 | | |
302 | 300 | | |
| |||
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
| |||
115 | 112 | | |
116 | 113 | | |
117 | 114 | | |
118 | | - | |
| 115 | + | |
119 | 116 | | |
120 | 117 | | |
121 | 118 | | |
| |||
Lines changed: 15 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | 35 | | |
39 | 36 | | |
40 | 37 | | |
| |||
294 | 291 | | |
295 | 292 | | |
296 | 293 | | |
| 294 | + | |
297 | 295 | | |
298 | 296 | | |
299 | 297 | | |
| |||
308 | 306 | | |
309 | 307 | | |
310 | 308 | | |
311 | | - | |
| 309 | + | |
312 | 310 | | |
313 | 311 | | |
314 | 312 | | |
| |||
364 | 362 | | |
365 | 363 | | |
366 | 364 | | |
367 | | - | |
| 365 | + | |
368 | 366 | | |
369 | 367 | | |
370 | 368 | | |
| |||
405 | 403 | | |
406 | 404 | | |
407 | 405 | | |
| 406 | + | |
408 | 407 | | |
409 | 408 | | |
410 | 409 | | |
| |||
429 | 428 | | |
430 | 429 | | |
431 | 430 | | |
432 | | - | |
| 431 | + | |
433 | 432 | | |
434 | 433 | | |
435 | 434 | | |
| |||
442 | 441 | | |
443 | 442 | | |
444 | 443 | | |
445 | | - | |
| 444 | + | |
446 | 445 | | |
447 | 446 | | |
448 | 447 | | |
| |||
454 | 453 | | |
455 | 454 | | |
456 | 455 | | |
457 | | - | |
458 | | - | |
| 456 | + | |
| 457 | + | |
459 | 458 | | |
460 | 459 | | |
461 | | - | |
| 460 | + | |
462 | 461 | | |
463 | 462 | | |
464 | 463 | | |
| |||
470 | 469 | | |
471 | 470 | | |
472 | 471 | | |
473 | | - | |
474 | | - | |
475 | | - | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
476 | 475 | | |
477 | 476 | | |
478 | 477 | | |
| |||
483 | 482 | | |
484 | 483 | | |
485 | 484 | | |
486 | | - | |
| 485 | + | |
487 | 486 | | |
488 | 487 | | |
489 | 488 | | |
| |||
495 | 494 | | |
496 | 495 | | |
497 | 496 | | |
498 | | - | |
499 | | - | |
| 497 | + | |
| 498 | + | |
500 | 499 | | |
501 | 500 | | |
502 | 501 | | |
Lines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
| |||
204 | 201 | | |
205 | 202 | | |
206 | 203 | | |
207 | | - | |
| 204 | + | |
208 | 205 | | |
209 | 206 | | |
210 | 207 | | |
| |||
0 commit comments