Skip to content

Commit e653aba

Browse files
refactor(spec): move observability seam into the spec layer (leanEthereum#830)
The spec layer's last upward dependency on node was the observability import in fork_choice.py and state_transition.py. A prior refactor moved the Interval type and protocol constants into the spec layer but left this edge, so spec still reached up into node. Relocate node/observability/ to spec/observability/. The package is purely the vendor-neutral observer seam: a SpecObserver Protocol, a no-op default, the observe_* context-manager timers, and set_observer. Spec emits through it with a no-op default, so spec imports stay side-effect-free. The concrete Prometheus backend stays in node/metrics and the startup set_observer wiring stays in the CLI; only the seam moves. Pure relocation, no behavior change. The test moves to the mirrored spec path per the test-structure convention. After this, grep -rn "lean_spec.node" src/lean_spec/spec/ is empty: the spec layer no longer depends on node in either direction. Alternative considered: leave the seam in node and inject an observer into every spec entry point. Rejected as strictly worse churn that fights the existing module-level singleton design; the seam is itself a spec-level concern (the spec defines what it observes), so it belongs in spec with the no-op default. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 30ffb6c commit e653aba

6 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/lean_spec/cli/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
from lean_spec.node.networking.client import LiveNetworkEventSource
2323
from lean_spec.node.networking.gossipsub import GossipTopic
2424
from lean_spec.node.node import Node, NodeConfig
25-
from lean_spec.node.observability import set_observer
2625
from lean_spec.spec.forks import SubnetId
2726
from lean_spec.spec.forks.lstar.config import ATTESTATION_COMMITTEE_COUNT
27+
from lean_spec.spec.observability import set_observer
2828

2929
logger = logging.getLogger(__name__)
3030

src/lean_spec/spec/forks/lstar/fork_choice.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
import math
44
from collections import defaultdict
55

6-
from lean_spec.node.observability import (
7-
observe_on_attestation,
8-
observe_on_block,
9-
)
106
from lean_spec.spec.crypto.merkleization import hash_tree_root
117
from lean_spec.spec.crypto.xmss.interface import TARGET_SIGNATURE_SCHEME
128
from lean_spec.spec.forks.lstar._base import LstarSpecBase, LstarStore
@@ -30,6 +26,10 @@
3026
ValidatorIndex,
3127
)
3228
from lean_spec.spec.forks.protocol import SpecBlockType, SpecStateType
29+
from lean_spec.spec.observability import (
30+
observe_on_attestation,
31+
observe_on_block,
32+
)
3333
from lean_spec.spec.ssz import Bytes32, Uint64
3434

3535

src/lean_spec/spec/forks/lstar/state_transition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
from collections.abc import Iterable, Sequence
55
from typing import Any
66

7-
from lean_spec.node.observability import (
8-
observe_state_transition,
9-
)
107
from lean_spec.spec.crypto.merkleization import hash_tree_root
118
from lean_spec.spec.forks.lstar._base import LstarSpecBase
129
from lean_spec.spec.forks.lstar.containers import (
@@ -24,6 +21,9 @@
2421
Validators,
2522
)
2623
from lean_spec.spec.forks.protocol import SpecStateType
24+
from lean_spec.spec.observability import (
25+
observe_state_transition,
26+
)
2727
from lean_spec.spec.ssz import ZERO_HASH, Boolean, Bytes32, SSZList, Uint64
2828

2929

src/lean_spec/node/observability/__init__.py renamed to src/lean_spec/spec/observability/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
their own.
1212
"""
1313

14-
from lean_spec.node.observability.observer import (
14+
from lean_spec.spec.observability.observer import (
1515
SpecObserver,
1616
observe_on_attestation,
1717
observe_on_block,
File renamed without changes.

tests/lean_spec/node/observability/test_observer.py renamed to tests/lean_spec/spec/observability/test_observer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from prometheus_client import CollectorRegistry, Histogram
1111

1212
from lean_spec.node.metrics import PrometheusObserver, registry as metrics
13-
from lean_spec.node.observability import (
13+
from lean_spec.spec.observability import (
1414
observe_on_attestation,
1515
observe_on_block,
1616
observe_state_transition,
1717
observer as observer_module,
1818
set_observer,
1919
)
20-
from lean_spec.node.observability.observer import _NullObserver
20+
from lean_spec.spec.observability.observer import _NullObserver
2121

2222

2323
@pytest.fixture

0 commit comments

Comments
 (0)