mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-12 06:44:25 +00:00
fix: crash noticed while adding existing peer that doesn't have an ENR (#1113)
This commit is contained in:
parent
8115ec7013
commit
269417c5e9
@ -331,7 +331,7 @@ func Execute(options NodeOptions) error {
|
||||
}
|
||||
|
||||
for _, d := range discoveredNodes {
|
||||
wakuNode.AddDiscoveredPeer(d.PeerID, d.PeerInfo.Addrs, wakupeerstore.DNSDiscovery, nil, true)
|
||||
wakuNode.AddDiscoveredPeer(d.PeerID, d.PeerInfo.Addrs, wakupeerstore.DNSDiscovery, nil, d.ENR, true)
|
||||
}
|
||||
|
||||
//For now assuming that static peers added support/listen on all topics specified via commandLine.
|
||||
|
@ -74,7 +74,7 @@ func TestConnectionStatusChanges(t *testing.T) {
|
||||
|
||||
goCheckConnectedness(t, &wg, topicHealthStatusChan, peermanager.MinimallyHealthy)
|
||||
|
||||
node1.AddDiscoveredPeer(node2.host.ID(), node2.ListenAddresses(), peerstore.Static, []string{pubsubTopic}, true)
|
||||
node1.AddDiscoveredPeer(node2.host.ID(), node2.ListenAddresses(), peerstore.Static, []string{pubsubTopic}, nil, true)
|
||||
|
||||
wg.Wait()
|
||||
|
||||
|
@ -698,7 +698,7 @@ func (w *WakuNode) AddPeer(address ma.Multiaddr, origin wps.Origin, pubSubTopics
|
||||
}
|
||||
|
||||
// AddDiscoveredPeer to add a discovered peer to the node peerStore
|
||||
func (w *WakuNode) AddDiscoveredPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubsubTopics []string, connectNow bool) {
|
||||
func (w *WakuNode) AddDiscoveredPeer(ID peer.ID, addrs []ma.Multiaddr, origin wps.Origin, pubsubTopics []string, enr *enode.Node, connectNow bool) {
|
||||
p := service.PeerData{
|
||||
Origin: origin,
|
||||
AddrInfo: peer.AddrInfo{
|
||||
@ -706,6 +706,7 @@ func (w *WakuNode) AddDiscoveredPeer(ID peer.ID, addrs []ma.Multiaddr, origin wp
|
||||
Addrs: addrs,
|
||||
},
|
||||
PubsubTopics: pubsubTopics,
|
||||
ENR: enr,
|
||||
}
|
||||
w.peermanager.AddDiscoveredPeer(p, connectNow)
|
||||
}
|
||||
|
@ -431,17 +431,21 @@ func (pm *PeerManager) AddDiscoveredPeer(p service.PeerData, connectNow bool) {
|
||||
if err == nil {
|
||||
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 && enr.Record().Seq() >= p.ENR.Seq() {
|
||||
if err == nil {
|
||||
if p.ENR != nil {
|
||||
if enr.Record().Seq() >= p.ENR.Seq() {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
//Peer is already in peer-store but it doesn't have an enr, but discovered peer has ENR
|
||||
pm.logger.Info("peer already found in peerstore, but doesn't have an ENR record, re-adding",
|
||||
logging.HostID("peer", p.AddrInfo.ID), zap.Uint64("newENRSeq", p.ENR.Seq()))
|
||||
} else {
|
||||
//Peer is already in peer-store but stored ENR is older than discovered one.
|
||||
pm.logger.Info("peer already found in peerstore, but re-adding it as ENR sequence is higher than locally stored",
|
||||
logging.HostID("peer", p.AddrInfo.ID), zap.Uint64("newENRSeq", p.ENR.Seq()), zap.Uint64("storedENRSeq", enr.Record().Seq()))
|
||||
} else {
|
||||
pm.logger.Info("peer already found in peerstore, but no new ENR", logging.HostID("peer", p.AddrInfo.ID))
|
||||
}
|
||||
} else {
|
||||
//Peer is in peer-store but it doesn't have an enr
|
||||
pm.logger.Info("peer already found in peerstore, but doesn't have an ENR record, re-adding",
|
||||
logging.HostID("peer", p.AddrInfo.ID))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,6 @@ func (pm *PeerManager) SelectRandom(criteria PeerSelectionCriteria) (peer.IDSlic
|
||||
peerIDs = make(PeerSet)
|
||||
}
|
||||
// if not found in serviceSlots or proto == WakuRelayIDv200
|
||||
pm.logger.Debug("looking for peers in peerStore", zap.String("proto", string(criteria.Proto)))
|
||||
filteredPeers, err := pm.FilterPeersByProto(criteria.SpecificPeers, criteria.ExcludePeers, criteria.Proto)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -253,6 +252,5 @@ func (pm *PeerManager) FilterPeersByProto(specificPeers peer.IDSlice, excludePee
|
||||
peers = append(peers, peer)
|
||||
}
|
||||
}
|
||||
pm.logger.Debug("peers selected", zap.Int("peerCnt", len(peers)))
|
||||
return peers, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user