Skip to content

Commit 9930041

Browse files
authored
refactor: gossipsub and reqresp domains (#87)
* refactor: gossipsub and reqresp dirs * fix: linting * fix: linting
1 parent 9c57bcc commit 9930041

File tree

7 files changed

+95
-64
lines changed

7 files changed

+95
-64
lines changed

src/lean_spec/subspecs/networking/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,30 @@
55
MESSAGE_DOMAIN_INVALID_SNAPPY,
66
MESSAGE_DOMAIN_VALID_SNAPPY,
77
)
8-
from .gossipsub import GossipsubParameters
9-
from .messages import (
8+
from .gossipsub.message import GossipsubMessage
9+
from .gossipsub.parameters import GossipsubParameters
10+
from .gossipsub.topic import GossipsubTopic
11+
from .reqresp import (
1012
BLOCKS_BY_ROOT_PROTOCOL_V1,
1113
STATUS_PROTOCOL_V1,
1214
BlocksByRootRequest,
1315
BlocksByRootResponse,
1416
Status,
1517
)
16-
from .topics import GossipTopic
1718
from .types import DomainType, ProtocolId
1819

1920
__all__ = [
2021
"MAX_REQUEST_BLOCKS",
2122
"MESSAGE_DOMAIN_INVALID_SNAPPY",
2223
"MESSAGE_DOMAIN_VALID_SNAPPY",
2324
"GossipsubParameters",
25+
"GossipsubTopic",
26+
"GossipsubMessage",
2427
"BLOCKS_BY_ROOT_PROTOCOL_V1",
2528
"STATUS_PROTOCOL_V1",
2629
"BlocksByRootRequest",
2730
"BlocksByRootResponse",
2831
"Status",
29-
"GossipTopic",
3032
"DomainType",
3133
"ProtocolId",
3234
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Gossipsub specs for the Lean Ethereum consensus specification."""
2+
3+
from .message import GossipsubMessage, MessageId
4+
from .parameters import GossipsubParameters
5+
from .topic import GossipsubTopic
6+
7+
__all__ = [
8+
"GossipsubMessage",
9+
"GossipsubParameters",
10+
"GossipsubTopic",
11+
"MessageId",
12+
]

src/lean_spec/subspecs/networking/gossipsub.py renamed to src/lean_spec/subspecs/networking/gossipsub/message.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Gossipsub protocol
33
4-
- Parameters for gossipsub operation.
54
- Message ID computation based on topic and message data, with snappy decompression handling.
65
"""
76

@@ -10,66 +9,10 @@
109

1110
from pydantic import Field
1211

13-
from lean_spec.subspecs.chain.config import DEVNET_CONFIG
1412
from lean_spec.subspecs.networking.config import (
1513
MESSAGE_DOMAIN_INVALID_SNAPPY,
1614
MESSAGE_DOMAIN_VALID_SNAPPY,
1715
)
18-
from lean_spec.types import StrictBaseModel
19-
20-
21-
class GossipsubParameters(StrictBaseModel):
22-
"""A model holding the canonical gossipsub parameters."""
23-
24-
protocol_id: str = "/meshsub/1.0.0"
25-
"""The protocol ID for gossip messages."""
26-
27-
d: int = 8
28-
"""The target number of peers for a stable gossip mesh topic."""
29-
30-
d_low: int = 6
31-
"""
32-
The low watermark for the number of peers in a stable gossip mesh topic.
33-
"""
34-
35-
d_high: int = 12
36-
"""
37-
The high watermark for the number of peers in a stable gossip mesh topic.
38-
"""
39-
40-
d_lazy: int = 6
41-
"""The target number of peers for gossip-only connections."""
42-
43-
heartbeat_interval_secs: float = 0.7
44-
"""The frequency of the gossipsub heartbeat in seconds."""
45-
46-
fanout_ttl_secs: int = 60
47-
"""The time-to-live for fanout maps in seconds."""
48-
49-
mcache_len: int = 6
50-
"""The number of history windows to retain full messages in the cache."""
51-
52-
mcache_gossip: int = 3
53-
"""The number of history windows to gossip about."""
54-
55-
seen_ttl_secs: int = (
56-
DEVNET_CONFIG.second_per_slot.as_int()
57-
* DEVNET_CONFIG.justification_lookback_slots.as_int()
58-
* 2
59-
)
60-
"""
61-
The expiry time in seconds for the cache of seen message IDs.
62-
63-
This is calculated as SECONDS_PER_SLOT * JUSTIFICATION_LOOKBACK_SLOTS * 2.
64-
"""
65-
66-
validation_mode: str = "strict_no_sign"
67-
"""The message validation mode. `strict_no_sign` requires the author,
68-
sequence number and signature fields of a message to be empty. Any message
69-
that contains these fields is considered invalid. In some libp2p
70-
implementations, this mode is also known as Anonymous mode.
71-
"""
72-
7316

7417
MessageId = Annotated[bytes, Field(min_length=20, max_length=20)]
7518
"""A 20-byte ID for gossipsub messages."""
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
"""Gossipsub parameters for the Lean Ethereum consensus specification."""
2+
3+
from lean_spec.subspecs.chain.config import DEVNET_CONFIG
4+
from lean_spec.types import StrictBaseModel
5+
6+
7+
class GossipsubParameters(StrictBaseModel):
8+
"""A model holding the canonical gossipsub parameters."""
9+
10+
protocol_id: str = "/meshsub/1.0.0"
11+
"""The protocol ID for gossip messages."""
12+
13+
d: int = 8
14+
"""The target number of peers for a stable gossip mesh topic."""
15+
16+
d_low: int = 6
17+
"""
18+
The low watermark for the number of peers in a stable gossip mesh topic.
19+
"""
20+
21+
d_high: int = 12
22+
"""
23+
The high watermark for the number of peers in a stable gossip mesh topic.
24+
"""
25+
26+
d_lazy: int = 6
27+
"""The target number of peers for gossip-only connections."""
28+
29+
heartbeat_interval_secs: float = 0.7
30+
"""The frequency of the gossipsub heartbeat in seconds."""
31+
32+
fanout_ttl_secs: int = 60
33+
"""The time-to-live for fanout maps in seconds."""
34+
35+
mcache_len: int = 6
36+
"""The number of history windows to retain full messages in the cache."""
37+
38+
mcache_gossip: int = 3
39+
"""The number of history windows to gossip about."""
40+
41+
seen_ttl_secs: int = (
42+
DEVNET_CONFIG.second_per_slot.as_int()
43+
* DEVNET_CONFIG.justification_lookback_slots.as_int()
44+
* 2
45+
)
46+
"""
47+
The expiry time in seconds for the cache of seen message IDs.
48+
49+
This is calculated as SECONDS_PER_SLOT * JUSTIFICATION_LOOKBACK_SLOTS * 2.
50+
"""
51+
52+
validation_mode: str = "strict_no_sign"
53+
"""The message validation mode. `strict_no_sign` requires the author,
54+
sequence number and signature fields of a message to be empty. Any message
55+
that contains these fields is considered invalid. In some libp2p
56+
implementations, this mode is also known as Anonymous mode.
57+
"""

src/lean_spec/subspecs/networking/topics.py renamed to src/lean_spec/subspecs/networking/gossipsub/topic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from lean_spec.subspecs.containers.block.block import SignedBlockWithAttestation
88

99

10-
class GossipTopic(Enum):
10+
class GossipsubTopic(Enum):
1111
"""
1212
Enumerates gossip topics, bundling a topic's name with its payload type.
1313
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""ReqResp specs for the Lean Ethereum consensus specification."""
2+
3+
from .message import (
4+
BLOCKS_BY_ROOT_PROTOCOL_V1,
5+
STATUS_PROTOCOL_V1,
6+
BlocksByRootRequest,
7+
BlocksByRootResponse,
8+
Status,
9+
)
10+
11+
__all__ = [
12+
"BLOCKS_BY_ROOT_PROTOCOL_V1",
13+
"STATUS_PROTOCOL_V1",
14+
"BlocksByRootRequest",
15+
"BlocksByRootResponse",
16+
"Status",
17+
]

src/lean_spec/subspecs/networking/messages.py renamed to src/lean_spec/subspecs/networking/reqresp/message.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from lean_spec.subspecs.containers import Checkpoint, SignedBlockWithAttestation
1212
from lean_spec.types import Bytes32, StrictBaseModel
1313

14-
from .config import MAX_REQUEST_BLOCKS
15-
from .types import ProtocolId
14+
from ..config import MAX_REQUEST_BLOCKS
15+
from ..types import ProtocolId
1616

1717
# --- Status v1 ---
1818

0 commit comments

Comments
 (0)