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
17 changes: 0 additions & 17 deletions src/lean_spec/subspecs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
"""Subspecifications for the Lean Ethereum Python specifications."""

from .api import ApiServer, ApiServerConfig
from .genesis import GenesisConfig
from .sync.checkpoint_sync import (
CheckpointSyncError,
fetch_finalized_state,
verify_checkpoint_state,
)

__all__ = [
"ApiServer",
"ApiServerConfig",
"CheckpointSyncError",
"GenesisConfig",
"fetch_finalized_state",
"verify_checkpoint_state",
]
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/containers/state/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ def build_block(

return final_block, post_state, aggregated_attestations, aggregated_signatures

@staticmethod
def _extend_proofs_greedily(
self,
proofs: set[AggregatedSignatureProof] | None,
selected: list[AggregatedSignatureProof],
covered: set[ValidatorIndex],
Expand Down
67 changes: 1 addition & 66 deletions src/lean_spec/subspecs/networking/__init__.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,9 @@
"""Exports the networking subspec components."""

from .config import (
MAX_PAYLOAD_SIZE,
MAX_REQUEST_BLOCKS,
MESSAGE_DOMAIN_INVALID_SNAPPY,
MESSAGE_DOMAIN_VALID_SNAPPY,
RESP_TIMEOUT,
TTFB_TIMEOUT,
)
from .gossipsub.message import GossipsubMessage
from .gossipsub.parameters import GossipsubParameters
from .gossipsub.topic import GossipTopic
from .reqresp import (
BLOCKS_BY_ROOT_PROTOCOL_V1,
STATUS_PROTOCOL_V1,
BlocksByRootRequest,
CodecError,
RequestedBlockRoots,
ResponseCode,
Status,
decode_request,
encode_request,
)
from .service import (
GossipAttestationEvent,
GossipBlockEvent,
NetworkEvent,
NetworkService,
PeerConnectedEvent,
PeerDisconnectedEvent,
PeerStatusEvent,
)
from .service import NetworkService
from .transport import PeerId
from .types import DomainType, ForkDigest, ProtocolId

__all__ = [
# Config
"MAX_REQUEST_BLOCKS",
"MAX_PAYLOAD_SIZE",
"TTFB_TIMEOUT",
"RESP_TIMEOUT",
"MESSAGE_DOMAIN_INVALID_SNAPPY",
"MESSAGE_DOMAIN_VALID_SNAPPY",
# Gossipsub
"GossipsubParameters",
"GossipTopic",
"GossipsubMessage",
# ReqResp - Protocol IDs
"BLOCKS_BY_ROOT_PROTOCOL_V1",
"STATUS_PROTOCOL_V1",
# ReqResp - Message types
"BlocksByRootRequest",
"RequestedBlockRoots",
"Status",
# ReqResp - Codec
"CodecError",
"ResponseCode",
"encode_request",
"decode_request",
# Service
"GossipAttestationEvent",
"GossipBlockEvent",
"NetworkEvent",
"NetworkService",
"PeerConnectedEvent",
"PeerDisconnectedEvent",
"PeerStatusEvent",
# Types
"DomainType",
"ForkDigest",
"PeerId",
"ProtocolId",
]
7 changes: 2 additions & 5 deletions src/lean_spec/subspecs/networking/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Bridges the transport layer to the sync service.

Components
----------

ReqRespClient
Implements NetworkRequester using ConnectionManager.
Handles BlocksByRoot and Status requests.
Expand All @@ -13,11 +13,8 @@
Bridges connection events to NetworkService events.
"""

from .event_source import EventSource, LiveNetworkEventSource
from .reqresp_client import ReqRespClient
from .event_source import LiveNetworkEventSource

__all__ = [
"EventSource",
"LiveNetworkEventSource",
"ReqRespClient",
]
6 changes: 3 additions & 3 deletions src/lean_spec/subspecs/networking/client/reqresp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ async def _do_status_request(

if code == ResponseCode.SUCCESS:
return Status.decode_bytes(ssz_bytes)
else:
logger.debug("Status error response: %s", code)
return None

logger.debug("Status error response: %s", code)
return None

except Exception as e:
# Retry once with a new stream if the first attempt fails.
Expand Down
56 changes: 0 additions & 56 deletions src/lean_spec/subspecs/networking/discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,3 @@
- https://github.com/ethereum/devp2p/blob/master/discv5/discv5-wire.md
- https://github.com/ethereum/devp2p/blob/master/discv5/discv5-theory.md
"""

from .codec import (
DiscoveryMessage,
decode_message,
encode_message,
)
from .config import DiscoveryConfig
from .messages import (
MAX_REQUEST_ID_LENGTH,
PROTOCOL_ID,
PROTOCOL_VERSION,
Distance,
FindNode,
IdNonce,
MessageType,
Nodes,
Nonce,
Ping,
Pong,
RequestId,
TalkReq,
TalkResp,
)
from .routing import NodeEntry, RoutingTable
from .service import DiscoveryService, LookupResult

__all__ = [
# High-level service
"DiscoveryService",
"DiscoveryConfig",
"LookupResult",
# Message types (for protocol interaction)
"DiscoveryMessage",
"encode_message",
"decode_message",
# Routing
"NodeEntry",
"RoutingTable",
# Message types (commonly needed)
"Ping",
"Pong",
"FindNode",
"Nodes",
"TalkReq",
"TalkResp",
# Constants (commonly needed)
"PROTOCOL_ID",
"PROTOCOL_VERSION",
"MAX_REQUEST_ID_LENGTH",
# Types
"Distance",
"IdNonce",
"Nonce",
"RequestId",
"MessageType",
]
41 changes: 3 additions & 38 deletions src/lean_spec/subspecs/networking/gossipsub/__init__.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,40 @@
"""
Gossipsub Protocol Implementation
=================================

Gossipsub is a mesh-based pubsub protocol combining:

1. **Eager push** within topic meshes for low-latency delivery
2. **Lazy pull** via gossip (IHAVE/IWANT) for reliability

Key Concepts
------------

- **Mesh**: Full message exchange with D peers per topic
- **Fanout**: Temporary peers for publish-only topics
- **Gossip**: IHAVE/IWANT for message dissemination to non-mesh peers
- **IDONTWANT**: Bandwidth optimization (v1.2)

References:
----------
- Gossipsub v1.0: https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.0.md
- Gossipsub v1.2: https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.2.md
- Ethereum P2P: https://github.com/ethereum/consensus-specs/blob/master/specs/phase0/p2p-interface.md
"""

from .behavior import (
GossipsubBehavior,
)
from .behavior import GossipsubBehavior
from .message import GossipsubMessage
from .parameters import (
GossipsubParameters,
)
from .rpc import (
ControlGraft,
ControlIDontWant,
ControlIHave,
ControlIWant,
ControlMessage,
ControlPrune,
ProtobufDecodeError,
)
from .parameters import GossipsubParameters
from .topic import (
ForkMismatchError,
GossipTopic,
TopicKind,
parse_topic_string,
)
from .types import (
MessageId,
TopicId,
)

__all__ = [
# Behavior (main entry point)
"GossipsubBehavior",
"GossipsubParameters",
# Message
"GossipsubMessage",
# Topic (commonly needed for Ethereum)
"GossipsubParameters",
"GossipTopic",
"TopicKind",
"parse_topic_string",
"ForkMismatchError",
# Types
"MessageId",
"TopicId",
# Control messages (for custom handlers)
"ControlMessage",
"ControlGraft",
"ControlPrune",
"ControlIHave",
"ControlIWant",
"ControlIDontWant",
# Errors
"ProtobufDecodeError",
]
2 changes: 1 addition & 1 deletion src/lean_spec/subspecs/networking/reqresp/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ async def _dispatch(
# - Correct size (80 bytes for Status)
# - Valid field offsets
try:
request = Status.decode_bytes(ssz_bytes)
_request = Status.decode_bytes(ssz_bytes) # noqa: F841
except Exception as e:
# SSZ decode failure: wrong size, malformed offsets, etc.
#
Expand Down
3 changes: 1 addition & 2 deletions src/lean_spec/subspecs/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
"""

from .database import Database
from .exceptions import StorageCorruptionError, StorageError, StorageReadError, StorageWriteError
from .exceptions import StorageCorruptionError, StorageReadError, StorageWriteError
from .sqlite import SQLiteDatabase

__all__ = [
"Database",
"SQLiteDatabase",
"StorageCorruptionError",
"StorageError",
"StorageReadError",
"StorageWriteError",
]
45 changes: 5 additions & 40 deletions src/lean_spec/subspecs/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,13 @@
from __future__ import annotations

__all__ = [
# Main service
"SyncService",
"SyncProgress",
# States
"SyncState",
# Block cache
"BlockCache",
"PendingBlock",
# Peer management
"PeerManager",
"SyncPeer",
# Backfill sync
"BackfillSync",
"NetworkRequester",
# Head sync
"HeadSync",
"HeadSyncResult",
# Checkpoint sync
"CheckpointSyncError",
"fetch_finalized_state",
"verify_checkpoint_state",
# Configuration constants
"MAX_BLOCKS_PER_REQUEST",
"MAX_CONCURRENT_REQUESTS",
"MAX_CACHED_BLOCKS",
"MAX_BACKFILL_DEPTH",
"PeerManager",
]

from .backfill_sync import BackfillSync, NetworkRequester
from .block_cache import BlockCache, PendingBlock
from .checkpoint_sync import (
CheckpointSyncError,
fetch_finalized_state,
verify_checkpoint_state,
)
from .config import (
MAX_BACKFILL_DEPTH,
MAX_BLOCKS_PER_REQUEST,
MAX_CACHED_BLOCKS,
MAX_CONCURRENT_REQUESTS,
)
from .head_sync import HeadSync, HeadSyncResult
from .peer_manager import PeerManager, SyncPeer
from .service import SyncProgress, SyncService
from .states import SyncState
from .backfill_sync import NetworkRequester
from .block_cache import BlockCache
from .peer_manager import PeerManager
from .service import SyncService
Loading
Loading