Skip to content

Commit 0fb8a71

Browse files
committed
PR Feedback
1 parent 8178de5 commit 0fb8a71

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

p2p/peer.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ def subscription_msg_types(self) -> Set[Type[protocol.Command]]:
567567
568568
The base command class `p2p.protocol.Command` can be used to enable
569569
**all** command types.
570+
571+
.. note: This API only applies to sub-protocol commands. Base protocol
572+
commands are handled exclusively at the peer level and cannot be
573+
consumed with this API.
570574
"""
571575
pass
572576

@@ -610,25 +614,22 @@ def add_msg(self, msg: 'PEER_MSG_TYPE') -> bool:
610614
peer, cmd, _ = msg
611615

612616
if not self.is_subscription_command(type(cmd)):
613-
if hasattr(self, 'logger'):
614-
self.logger.trace( # type: ignore
615-
"Discarding %s msg from %s; not subscribed to msg type; "
616-
"subscriptions: %s",
617-
cmd, peer, self.subscription_msg_types,
618-
)
617+
self.logger.trace( # type: ignore
618+
"Discarding %s msg from %s; not subscribed to msg type; "
619+
"subscriptions: %s",
620+
cmd, peer, self.subscription_msg_types,
621+
)
619622
return False
620623

621624
try:
622-
if hasattr(self, 'logger'):
623-
self.logger.trace( # type: ignore
624-
"Adding %s msg from %s to queue; queue_size=%d", cmd, peer, self.queue_size)
625+
self.logger.trace( # type: ignore
626+
"Adding %s msg from %s to queue; queue_size=%d", cmd, peer, self.queue_size)
625627
self.msg_queue.put_nowait(msg)
626628
return True
627629
except asyncio.queues.QueueFull:
628-
if hasattr(self, 'logger'):
629-
self.logger.warn( # type: ignore
630-
"%s msg queue is full; discarding %s msg from %s",
631-
self.__class__.__name__, cmd, peer)
630+
self.logger.warn( # type: ignore
631+
"%s msg queue is full; discarding %s msg from %s",
632+
self.__class__.__name__, cmd, peer)
632633
return False
633634

634635
@contextlib.contextmanager

tests/p2p/test_peer_subscriber.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import logging
23

34
import pytest
45

@@ -13,12 +14,17 @@
1314
)
1415

1516

17+
logger = logging.getLogger('testing.p2p.PeerSubscriber')
18+
19+
1620
class HeadersSubscriber(PeerSubscriber):
21+
logger = logger
1722
msg_queue_maxsize = 10
1823
subscription_msg_types = {GetBlockHeaders}
1924

2025

2126
class AllSubscriber(PeerSubscriber):
27+
logger = logger
2228
msg_queue_maxsize = 10
2329
subscription_msg_types = {Command}
2430

0 commit comments

Comments
 (0)