Skip to content

Commit 24e7320

Browse files
fixed failing demo
Co-authored-by: Khwahish Patel <[email protected]>
1 parent 303bf30 commit 24e7320

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

libp2p/pubsub/gossipsub.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,11 @@ async def join(self, topic: str) -> None:
354354
topic_in_fanout: bool = topic in self.fanout
355355
fanout_peers: set[ID] = set()
356356

357-
for peer in self.fanout[topic]:
358-
if self._check_back_off(peer, topic):
359-
continue
360-
fanout_peers.add(peer)
357+
if topic_in_fanout:
358+
for peer in self.fanout[topic]:
359+
if self._check_back_off(peer, topic):
360+
continue
361+
fanout_peers.add(peer)
361362

362363
fanout_size = len(fanout_peers)
363364
if not topic_in_fanout or (topic_in_fanout and fanout_size < self.degree):

libp2p/tools/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
FLOODSUB_PROTOCOL_ID = floodsub.PROTOCOL_ID
2828
GOSSIPSUB_PROTOCOL_ID = gossipsub.PROTOCOL_ID
29+
GOSSIPSUB_PROTOCOL_ID_V1 = gossipsub.PROTOCOL_ID_V11
2930

3031

3132
class GossipsubParams(NamedTuple):
@@ -40,6 +41,10 @@ class GossipsubParams(NamedTuple):
4041
heartbeat_interval: float = 0.5
4142
direct_connect_initial_delay: float = 0.1
4243
direct_connect_interval: int = 300
44+
do_px: bool = False
45+
px_peers_count: int = 16
46+
prune_back_off: int = 60
47+
unsubscribe_back_off: int = 10
4348

4449

4550
GOSSIPSUB_PARAMS = GossipsubParams()

tests/utils/factories.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,10 @@ class Meta:
443443
heartbeat_interval = GOSSIPSUB_PARAMS.heartbeat_interval
444444
direct_connect_initial_delay = GOSSIPSUB_PARAMS.direct_connect_initial_delay
445445
direct_connect_interval = GOSSIPSUB_PARAMS.direct_connect_interval
446+
do_px = GOSSIPSUB_PARAMS.do_px
447+
px_peers_count = GOSSIPSUB_PARAMS.px_peers_count
448+
prune_back_off = GOSSIPSUB_PARAMS.prune_back_off
449+
unsubscribe_back_off = GOSSIPSUB_PARAMS.unsubscribe_back_off
446450

447451

448452
class PubsubFactory(factory.Factory):
@@ -568,6 +572,10 @@ async def create_batch_with_gossipsub(
568572
heartbeat_initial_delay: float = GOSSIPSUB_PARAMS.heartbeat_initial_delay,
569573
direct_connect_initial_delay: float = GOSSIPSUB_PARAMS.direct_connect_initial_delay, # noqa: E501
570574
direct_connect_interval: int = GOSSIPSUB_PARAMS.direct_connect_interval,
575+
do_px: bool = GOSSIPSUB_PARAMS.do_px,
576+
px_peers_count: int = GOSSIPSUB_PARAMS.px_peers_count,
577+
prune_back_off: int = GOSSIPSUB_PARAMS.prune_back_off,
578+
unsubscribe_back_off: int = GOSSIPSUB_PARAMS.unsubscribe_back_off,
571579
security_protocol: TProtocol | None = None,
572580
muxer_opt: TMuxerOptions | None = None,
573581
msg_id_constructor: None
@@ -588,6 +596,10 @@ async def create_batch_with_gossipsub(
588596
heartbeat_interval=heartbeat_interval,
589597
direct_connect_initial_delay=direct_connect_initial_delay,
590598
direct_connect_interval=direct_connect_interval,
599+
do_px=do_px,
600+
px_peers_count=px_peers_count,
601+
prune_back_off=prune_back_off,
602+
unsubscribe_back_off=unsubscribe_back_off,
591603
)
592604
else:
593605
gossipsubs = GossipsubFactory.create_batch(
@@ -602,6 +614,10 @@ async def create_batch_with_gossipsub(
602614
heartbeat_initial_delay=heartbeat_initial_delay,
603615
direct_connect_initial_delay=direct_connect_initial_delay,
604616
direct_connect_interval=direct_connect_interval,
617+
do_px=do_px,
618+
px_peers_count=px_peers_count,
619+
prune_back_off=prune_back_off,
620+
unsubscribe_back_off=unsubscribe_back_off,
605621
)
606622

607623
async with cls._create_batch_with_router(

0 commit comments

Comments
 (0)