Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/testing/src/consensus_testing/cli/apitest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def apitest(
SERVER_URL is the base URL of the API server (e.g., http://localhost:5052).

For testing the local leanSpec implementation, use the local pytest suite under
tests/api, which automatically starts a local server.
tests/node/api/endpoints, which automatically starts a local server.
"""
config_path = Path(__file__).parent / "pytest_ini_files" / "pytest-apitest.ini"

Expand All @@ -59,7 +59,7 @@ def apitest(
str(config_path),
f"--rootdir={project_root}",
f"--server-url={server_url}",
"tests/api",
"tests/node/api/endpoints",
]

args.extend(pytest_args)
Expand Down
2 changes: 0 additions & 2 deletions src/lean_spec/node/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""API server module for various API endpoints."""

from lean_spec.node.api.aggregator_controller import AggregatorController
from lean_spec.node.api.server import ApiServer, ApiServerConfig

__all__ = [
"AggregatorController",
"ApiServer",
"ApiServerConfig",
]
71 changes: 0 additions & 71 deletions src/lean_spec/node/api/aggregator_controller.py

This file was deleted.

48 changes: 48 additions & 0 deletions src/lean_spec/node/api/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Typed dependencies the HTTP API handlers receive."""

from __future__ import annotations

from collections.abc import Callable
from dataclasses import dataclass
from typing import Protocol

from aiohttp import web

from lean_spec.spec.forks import LstarSpec, Store


class AggregatorRoleControl(Protocol):
"""The slice of the sync service the admin endpoints read and write."""

is_aggregator: bool


@dataclass(frozen=True, slots=True)
class ApiContext:
"""Dependencies shared across handlers, resolved once at startup."""

spec: LstarSpec
"""Fork spec driving consensus computations such as fork-choice weights."""

store_getter: Callable[[], Store | None] | None
"""Callable returning the live store, or None before the store exists."""

aggregator_role_control: AggregatorRoleControl | None
"""Holder of the aggregator flag, or None when aggregator control is unwired."""

def require_store(self) -> Store:
"""
Return the live store, or raise 503 when the node has no store yet.

The store is a frozen snapshot, so all reads in one handler stay consistent.
"""
store = self.store_getter() if self.store_getter else None
if store is None:
raise web.HTTPServiceUnavailable(reason="Store not initialized")
return store

def require_aggregator_role_control(self) -> AggregatorRoleControl:
"""Return the aggregator role control, or raise 503 when it is unwired."""
if self.aggregator_role_control is None:
raise web.HTTPServiceUnavailable(reason="Aggregator role control not available")
return self.aggregator_role_control
1 change: 0 additions & 1 deletion src/lean_spec/node/api/endpoints/__init__.py

This file was deleted.

78 changes: 0 additions & 78 deletions src/lean_spec/node/api/endpoints/aggregator.py

This file was deleted.

40 changes: 0 additions & 40 deletions src/lean_spec/node/api/endpoints/checkpoints.py

This file was deleted.

74 changes: 0 additions & 74 deletions src/lean_spec/node/api/endpoints/fork_choice.py

This file was deleted.

33 changes: 0 additions & 33 deletions src/lean_spec/node/api/endpoints/health.py

This file was deleted.

Loading
Loading