server: ensure unique addresses for node ann

Modifiers of the node announcement may add duplicate addresses, which we
remove here after the modifications were applied. This also ensures that
any previously added duplicate addresses are removed as well.
This commit is contained in:
bitromortac committed 2025-11-26 16:56:07 +01:00
1 parent c746aeed31
commit 031903f275
1 file changed
+12
+12
View File
@@ -3399,6 +3399,18 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
modifier(&newNodeAnn)
}
// The modifiers may have added duplicate addresses, so we need to
// de-duplicate them here.
uniqueAddrs := map[string]struct{}{}
dedupedAddrs := make([]net.Addr, 0)
for _, addr := range newNodeAnn.Addresses {
if _, ok := uniqueAddrs[addr.String()]; !ok {
uniqueAddrs[addr.String()] = struct{}{}
dedupedAddrs = append(dedupedAddrs, addr)
}
}
newNodeAnn.Addresses = dedupedAddrs
// Sign a new update after applying all of the passed modifiers.
err := netann.SignNodeAnnouncement(
s.nodeSigner, s.identityKeyLoc, &newNodeAnn,