Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 14c0303

Browse files
committed
Make register_peer of PeerPoolSubscriber non-abstract
1 parent 9de6a6a commit 14c0303

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

p2p/peer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,16 @@ async def process_sub_proto_handshake(
538538
class PeerPoolSubscriber(ABC):
539539
_msg_queue: 'asyncio.Queue[PEER_MSG_TYPE]' = None
540540

541-
@abstractmethod
542541
def register_peer(self, peer: BasePeer) -> None:
543-
raise NotImplementedError("Must be implemented by subclasses")
542+
"""
543+
Notify about each registered peer in the :class:`~p2p.peer.PeerPool`. Is called upon
544+
subscription for each :class:`~p2p.peer.BasePeer` that exists in the pool at that time and
545+
then for each :class:`~p2p.peer.BasePeer` that joins the pool later on.
546+
547+
A :class:`~p2p.peer.PeerPoolSubscriber` that wants to act upon peer registration needs to
548+
overwrite this method to provide an implementation.
549+
"""
550+
pass
544551

545552
@property
546553
def msg_queue(self) -> 'asyncio.Queue[PEER_MSG_TYPE]':

p2p/shard_syncer.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
)
4343
from p2p.service import BaseService
4444
from p2p.peer import (
45-
BasePeer,
4645
PeerPool,
4746
PeerPoolSubscriber,
4847
)
@@ -109,9 +108,6 @@ def propose(self) -> Collation:
109108
#
110109
# Peer handling
111110
#
112-
def register_peer(self, peer: BasePeer) -> None:
113-
pass
114-
115111
async def _run(self) -> None:
116112
with self.subscribe(self.peer_pool):
117113
while True:

p2p/state.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from p2p import protocol
3434
from p2p.cancel_token import CancelToken
3535
from p2p.exceptions import OperationCancelled
36-
from p2p.peer import BasePeer, ETHPeer, PeerPool, PeerPoolSubscriber
36+
from p2p.peer import ETHPeer, PeerPool, PeerPoolSubscriber
3737
from p2p.service import BaseService
3838
from p2p.utils import get_process_pool_executor
3939

@@ -59,9 +59,6 @@ def __init__(self,
5959
self._peers_with_pending_requests: Dict[ETHPeer, float] = {}
6060
self._executor = get_process_pool_executor()
6161

62-
def register_peer(self, peer: BasePeer) -> None:
63-
pass
64-
6562
@property
6663
def idle_peers(self) -> List[ETHPeer]:
6764
# FIXME: Should probably use get_peers() and pass the TD of our head? It's not really

0 commit comments

Comments
 (0)