diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 43602a29..9f26865c 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -354,10 +354,11 @@ class GossipSub(IPubsubRouter, Service): topic_in_fanout: bool = topic in self.fanout fanout_peers: set[ID] = set() - for peer in self.fanout[topic]: - if self._check_back_off(peer, topic): - continue - fanout_peers.add(peer) + if topic_in_fanout: + for peer in self.fanout[topic]: + if self._check_back_off(peer, topic): + continue + fanout_peers.add(peer) fanout_size = len(fanout_peers) if not topic_in_fanout or (topic_in_fanout and fanout_size < self.degree): diff --git a/libp2p/tools/constants.py b/libp2p/tools/constants.py index a9ba4b76..f7d367e7 100644 --- a/libp2p/tools/constants.py +++ b/libp2p/tools/constants.py @@ -26,6 +26,7 @@ LISTEN_MADDR = multiaddr.Multiaddr("/ip4/127.0.0.1/tcp/0") FLOODSUB_PROTOCOL_ID = floodsub.PROTOCOL_ID GOSSIPSUB_PROTOCOL_ID = gossipsub.PROTOCOL_ID +GOSSIPSUB_PROTOCOL_ID_V1 = gossipsub.PROTOCOL_ID_V11 class GossipsubParams(NamedTuple): @@ -40,6 +41,10 @@ class GossipsubParams(NamedTuple): heartbeat_interval: float = 0.5 direct_connect_initial_delay: float = 0.1 direct_connect_interval: int = 300 + do_px: bool = False + px_peers_count: int = 16 + prune_back_off: int = 60 + unsubscribe_back_off: int = 10 GOSSIPSUB_PARAMS = GossipsubParams() diff --git a/tests/utils/factories.py b/tests/utils/factories.py index 4df82033..1beac861 100644 --- a/tests/utils/factories.py +++ b/tests/utils/factories.py @@ -443,6 +443,10 @@ class GossipsubFactory(factory.Factory): heartbeat_interval = GOSSIPSUB_PARAMS.heartbeat_interval direct_connect_initial_delay = GOSSIPSUB_PARAMS.direct_connect_initial_delay direct_connect_interval = GOSSIPSUB_PARAMS.direct_connect_interval + do_px = GOSSIPSUB_PARAMS.do_px + px_peers_count = GOSSIPSUB_PARAMS.px_peers_count + prune_back_off = GOSSIPSUB_PARAMS.prune_back_off + unsubscribe_back_off = GOSSIPSUB_PARAMS.unsubscribe_back_off class PubsubFactory(factory.Factory): @@ -568,6 +572,10 @@ class PubsubFactory(factory.Factory): heartbeat_initial_delay: float = GOSSIPSUB_PARAMS.heartbeat_initial_delay, direct_connect_initial_delay: float = GOSSIPSUB_PARAMS.direct_connect_initial_delay, # noqa: E501 direct_connect_interval: int = GOSSIPSUB_PARAMS.direct_connect_interval, + do_px: bool = GOSSIPSUB_PARAMS.do_px, + px_peers_count: int = GOSSIPSUB_PARAMS.px_peers_count, + prune_back_off: int = GOSSIPSUB_PARAMS.prune_back_off, + unsubscribe_back_off: int = GOSSIPSUB_PARAMS.unsubscribe_back_off, security_protocol: TProtocol | None = None, muxer_opt: TMuxerOptions | None = None, msg_id_constructor: None @@ -588,6 +596,10 @@ class PubsubFactory(factory.Factory): heartbeat_interval=heartbeat_interval, direct_connect_initial_delay=direct_connect_initial_delay, direct_connect_interval=direct_connect_interval, + do_px=do_px, + px_peers_count=px_peers_count, + prune_back_off=prune_back_off, + unsubscribe_back_off=unsubscribe_back_off, ) else: gossipsubs = GossipsubFactory.create_batch( @@ -602,6 +614,10 @@ class PubsubFactory(factory.Factory): heartbeat_initial_delay=heartbeat_initial_delay, direct_connect_initial_delay=direct_connect_initial_delay, direct_connect_interval=direct_connect_interval, + do_px=do_px, + px_peers_count=px_peers_count, + prune_back_off=prune_back_off, + unsubscribe_back_off=unsubscribe_back_off, ) async with cls._create_batch_with_router(