Skip to content

Commit 94109e4

Browse files
authored
feat: add python specs for Gossip Topics (leanEthereum#80)
* feat: add python specs for Gossip Topics * fix: CI checks * fix: apply refactor suggestion
1 parent b83e6c0 commit 94109e4

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/lean_spec/subspecs/networking/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
BlocksByRootResponse,
1414
Status,
1515
)
16+
from .topics import GossipTopic
1617
from .types import DomainType, ProtocolId
1718

1819
__all__ = [
@@ -25,6 +26,7 @@
2526
"BlocksByRootRequest",
2627
"BlocksByRootResponse",
2728
"Status",
29+
"GossipTopic",
2830
"DomainType",
2931
"ProtocolId",
3032
]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Gossipsub topics"""
2+
3+
from enum import Enum
4+
from typing import Any, Type
5+
6+
from lean_spec.subspecs.containers.block.block import SignedBlock
7+
from lean_spec.subspecs.containers.vote import SignedVote
8+
9+
10+
class GossipTopic(Enum):
11+
"""
12+
Enumerates gossip topics, bundling a topic's name with its payload type.
13+
14+
Attributes:
15+
value (str): The network name of the topic (e.g., "block").
16+
payload_type (Type): The class representing the data structure
17+
of the topic's message (e.g., `SignedBlock`).
18+
"""
19+
20+
def __init__(self, value: str, payload_type: Type[Any]):
21+
"""
22+
Initializes the GossipTopic.
23+
24+
Args:
25+
value: The topic in string.
26+
payload_type: The associated gossip.
27+
"""
28+
self._value_ = value
29+
self.payload_type = payload_type
30+
31+
BLOCK = ("block", SignedBlock)
32+
"""
33+
Topic for gossiping new blocks.
34+
35+
- `value`: "block"
36+
- `payload_type`: `SignedBlock`
37+
"""
38+
39+
VOTE = ("vote", SignedVote)
40+
"""
41+
Topic for gossiping new votes (attestations).
42+
43+
- `value`: "vote"
44+
- `payload_type`: `SignedVote`
45+
"""

0 commit comments

Comments
 (0)