fix: number of connected peers per topic (#948)

This commit is contained in:
richΛrd 2023-12-06 09:38:56 -04:00 committed by GitHub
parent 6ab2cfb53b
commit 48ab9e6ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -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),