diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 6d88f87..7fbcfdf 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -43,6 +43,7 @@ class GossipSub(IPubsubRouter): mcache: MessageCache + heartbeat_initial_delay: float heartbeat_interval: int def __init__( @@ -54,6 +55,7 @@ class GossipSub(IPubsubRouter): time_to_live: int, gossip_window: int = 3, gossip_history: int = 5, + heartbeat_initial_delay: int = 0.1, heartbeat_interval: int = 120, ) -> None: self.protocols = list(protocols) @@ -84,6 +86,7 @@ class GossipSub(IPubsubRouter): self.mcache = MessageCache(gossip_window, gossip_history) # Create heartbeat timer + self.heartbeat_initial_delay = heartbeat_initial_delay self.heartbeat_interval = heartbeat_interval # Interface functions @@ -294,7 +297,7 @@ class GossipSub(IPubsubRouter): state changes in the preceding heartbeat """ # Start after a delay. Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L410 # Noqa: E501 - await asyncio.sleep(0.1) + await asyncio.sleep(self.heartbeat_initial_delay) while True: await self.mesh_heartbeat() diff --git a/libp2p/tools/constants.py b/libp2p/tools/constants.py index 34dade4..2f132bb 100644 --- a/libp2p/tools/constants.py +++ b/libp2p/tools/constants.py @@ -24,6 +24,7 @@ class GossipsubParams(NamedTuple): time_to_live: int = 30 gossip_window: int = 3 gossip_history: int = 5 + heartbeat_initial_delay: int = 0.1 heartbeat_interval: float = 0.5 diff --git a/libp2p/tools/factories.py b/libp2p/tools/factories.py index b189cfa..1b98eaa 100644 --- a/libp2p/tools/factories.py +++ b/libp2p/tools/factories.py @@ -142,6 +142,7 @@ class GossipsubFactory(factory.Factory): time_to_live = GOSSIPSUB_PARAMS.time_to_live gossip_window = GOSSIPSUB_PARAMS.gossip_window gossip_history = GOSSIPSUB_PARAMS.gossip_history + heartbeat_initial_delay = GOSSIPSUB_PARAMS.heartbeat_initial_delay heartbeat_interval = GOSSIPSUB_PARAMS.heartbeat_interval