From a7e0c5d7378a9bfd28ac3f1431ab3cb851b31b6d Mon Sep 17 00:00:00 2001 From: NIC619 Date: Mon, 2 Dec 2019 22:41:49 +0800 Subject: [PATCH] Add missing cleanup in gossipsub `remove_peer` --- libp2p/pubsub/gossipsub.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 78e55040..39397003 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -145,6 +145,21 @@ class GossipSub(IPubsubRouter): elif peer_id in self.peers_floodsub: self.peers_floodsub.remove(peer_id) + for topic in self.mesh: + if peer_id in self.mesh[topic]: + # Delete the entry if no other peers left + if len(self.mesh[topic]) == 1: + del self.mesh[topic] + else: + self.mesh[topic].remove(peer_id) + for topic in self.fanout: + if peer_id in self.fanout[topic]: + # Delete the entry if no other peers left + if len(self.fanout[topic]) == 1: + del self.fanout[topic] + else: + self.fanout[topic].remove(peer_id) + self.peers_to_protocol.pop(peer_id, None) async def handle_rpc(self, rpc: rpc_pb2.RPC, sender_peer_id: ID) -> None: