Skip to content

Commit 63da9b3

Browse files
committed
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.
1 parent f8b5cb0 commit 63da9b3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

server.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,6 +3378,18 @@ func (s *server) genNodeAnnouncement(features *lnwire.RawFeatureVector,
33783378
modifier(&newNodeAnn)
33793379
}
33803380

3381+
// The modifiers may have added duplicate addresses, so we need to
3382+
// de-duplicate them here.
3383+
uniqueAddrs := map[string]struct{}{}
3384+
dedupedAddrs := make([]net.Addr, 0)
3385+
for _, addr := range newNodeAnn.Addresses {
3386+
if _, ok := uniqueAddrs[addr.String()]; !ok {
3387+
uniqueAddrs[addr.String()] = struct{}{}
3388+
dedupedAddrs = append(dedupedAddrs, addr)
3389+
}
3390+
}
3391+
newNodeAnn.Addresses = dedupedAddrs
3392+
33813393
// Sign a new update after applying all of the passed modifiers.
33823394
err := netann.SignNodeAnnouncement(
33833395
s.nodeSigner, s.identityKeyLoc, &newNodeAnn,

0 commit comments

Comments
 (0)