From a06208321e13be8d557058a82bc916e58ff266ea Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Tue, 18 Jun 2024 08:06:16 +0530 Subject: [PATCH] fix: add peer addresses on expiry if peer is discovered again (#1128) --- waku/v2/peermanager/peer_manager.go | 9 +++++++-- waku/v2/protocol/relay/waku_relay.go | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/waku/v2/peermanager/peer_manager.go b/waku/v2/peermanager/peer_manager.go index d9f60b0f..554688da 100644 --- a/waku/v2/peermanager/peer_manager.go +++ b/waku/v2/peermanager/peer_manager.go @@ -433,6 +433,11 @@ func (pm *PeerManager) AddDiscoveredPeer(p service.PeerData, connectNow bool) { //Check if the peer is already present, if so skip adding _, err := pm.host.Peerstore().(wps.WakuPeerstore).Origin(p.AddrInfo.ID) if err == nil { + //Add addresses if existing addresses have expired + existingAddrs := pm.host.Peerstore().Addrs(p.AddrInfo.ID) + if len(existingAddrs) == 0 { + pm.host.Peerstore().AddAddrs(p.AddrInfo.ID, p.AddrInfo.Addrs, peerstore.AddressTTL) + } enr, err := pm.host.Peerstore().(wps.WakuPeerstore).ENR(p.AddrInfo.ID) // Verifying if the enr record is more recent (DiscV5 and peer exchange can return peers already seen) if err == nil { @@ -474,8 +479,8 @@ func (pm *PeerManager) AddDiscoveredPeer(p service.PeerData, connectNow bool) { } } -// addPeer adds peer to only the peerStore. -// It also sets additional metadata such as origin, ENR and supported protocols +// addPeer adds peer to the peerStore. +// It also sets additional metadata such as origin and supported protocols func (pm *PeerManager) addPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubSubTopics []string, protocols ...protocol.ID) error { if pm.maxPeers <= pm.host.Peerstore().Peers().Len() { pm.logger.Error("could not add peer as peer store capacity is reached", logging.HostID("peer", ID), zap.Int("capacity", pm.maxPeers)) diff --git a/waku/v2/protocol/relay/waku_relay.go b/waku/v2/protocol/relay/waku_relay.go index d2ec331b..f2fd823b 100644 --- a/waku/v2/protocol/relay/waku_relay.go +++ b/waku/v2/protocol/relay/waku_relay.go @@ -513,7 +513,7 @@ func (w *WakuRelay) unsubscribeFromPubsubTopic(topicData *pubsubTopicSubscriptio err := topicData.topic.Close() if err != nil { - w.log.Error("failed to close the pubsubTopic", zap.String("topic", pubSubTopic)) + w.log.Error("failed to close the pubsubTopic", zap.String("topic", pubSubTopic), zap.Error(err)) return err } @@ -521,7 +521,7 @@ func (w *WakuRelay) unsubscribeFromPubsubTopic(topicData *pubsubTopicSubscriptio err = w.pubsub.UnregisterTopicValidator(pubSubTopic) if err != nil { - w.log.Error("failed to unregister topic validator", zap.String("topic", pubSubTopic)) + w.log.Error("failed to unregister topic validator", zap.String("topic", pubSubTopic), zap.Error(err)) return err }