diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index d16b69dd..4eddd090 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -208,8 +208,16 @@ func (pm *PeerManager) ensureMinRelayConnsPerTopic() { pm.topicMutex.RLock() defer pm.topicMutex.RUnlock() for topicStr, topicInst := range pm.subRelayTopics { - curPeers := topicInst.topic.ListPeers() - curPeerLen := len(curPeers) + + // @cammellos reported that ListPeers returned an invalid number of + // peers. This will ensure that the peers returned by this function + // match those peers that are currently connected + curPeerLen := 0 + for _, p := range topicInst.topic.ListPeers() { + if pm.host.Network().Connectedness(p) == network.Connected { + curPeerLen++ + } + } if curPeerLen < waku_proto.GossipSubOptimalFullMeshSize { pm.logger.Debug("subscribed topic is unhealthy, initiating more connections to maintain health", zap.String("pubSubTopic", topicStr), zap.Int("connectedPeerCount", curPeerLen),