diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index f0b1219..3b6e736 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -314,9 +314,11 @@ class GossipSub(IPubsubRouter): peers_to_prune: Dict[ID, List[str]], peers_to_gossip: Dict[ID, Dict[str, List[str]]], ) -> None: + graft_msgs: List[rpc_pb2.ControlGraft] = [] + prune_msgs: List[rpc_pb2.ControlPrune] = [] + ihave_msgs: List[rpc_pb2.ControlIHave] = [] # Starting with GRAFT messages for peer, topics in peers_to_graft.items(): - graft_msgs: List[rpc_pb2.ControlGraft] = [] for topic in topics: graft_msg: rpc_pb2.ControlGraft = rpc_pb2.ControlGraft() graft_msg.topicID = topic @@ -324,7 +326,6 @@ class GossipSub(IPubsubRouter): # If there are also PRUNE messages to send to this peer if peer in peers_to_prune: - prune_msgs: List[rpc_pb2.ControlPrune] = [] for topic in peers_to_prune[peer]: prune_msg: rpc_pb2.ControlPrune = rpc_pb2.ControlPrune() prune_msg.topicID = topic @@ -333,7 +334,6 @@ class GossipSub(IPubsubRouter): # If there are also IHAVE messages to send to this peer if peer in peers_to_gossip: - ihave_msgs: List[rpc_pb2.ControlIHave] = [] for topic in peers_to_gossip[peer]: ihave_msg: rpc_pb2.ControlIHave = rpc_pb2.ControlIHave() ihave_msg.messageIDs.extend(peers_to_gossip[peer][topic]) diff --git a/tests/pubsub/test_gossipsub.py b/tests/pubsub/test_gossipsub.py index ca175e5..183ff6b 100644 --- a/tests/pubsub/test_gossipsub.py +++ b/tests/pubsub/test_gossipsub.py @@ -197,7 +197,7 @@ async def test_dense(num_hosts, pubsubs_gsub, hosts): # publish from the randomly chosen host await pubsubs_gsub[origin_idx].publish("foobar", msg_content) - await asyncio.sleep(2) + await asyncio.sleep(0.5) # Assert that all blocking queues receive the message for queue in queues: msg = await queue.get()