discovery: de-duplicate node announcements with legacy chan graph sync

Fixes #1072.
This commit is contained in:
Olaoluwa Osuntokun
2018-04-19 18:37:27 -07:00
parent 41e1a7b056
commit 55dfc17c05

View File

@@ -269,6 +269,11 @@ func (d *AuthenticatedGossiper) SynchronizeNode(pub *btcec.PublicKey) error {
}, nil }, nil
} }
// We'll use this map to ensure we don't send the same node
// announcement more than one time as one node may have many channel
// anns we'll need to send.
nodePubsSent := make(map[routing.Vertex]struct{})
// As peers are expecting channel announcements before node // As peers are expecting channel announcements before node
// announcements, we first retrieve the initial announcement, as well as // announcements, we first retrieve the initial announcement, as well as
// the latest channel update announcement for both of the directed edges // the latest channel update announcement for both of the directed edges
@@ -298,15 +303,21 @@ func (d *AuthenticatedGossiper) SynchronizeNode(pub *btcec.PublicKey) error {
announceMessages = append(announceMessages, e1Ann) announceMessages = append(announceMessages, e1Ann)
// If this edge has a validated node // If this edge has a validated node
// announcement, then we'll send that as well. // announcement, that we haven't yet sent, then
if e1.Node.HaveNodeAnnouncement { // we'll send that as well.
nodePub := e1.Node.PubKeyBytes
hasNodeAnn := e1.Node.HaveNodeAnnouncement
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
nodeAnn, err := makeNodeAnn(e1.Node) nodeAnn, err := makeNodeAnn(e1.Node)
if err != nil { if err != nil {
return err return err
} }
announceMessages = append( announceMessages = append(
announceMessages, nodeAnn, announceMessages, nodeAnn,
) )
nodePubsSent[nodePub] = struct{}{}
numNodes++ numNodes++
} }
} }
@@ -314,15 +325,21 @@ func (d *AuthenticatedGossiper) SynchronizeNode(pub *btcec.PublicKey) error {
announceMessages = append(announceMessages, e2Ann) announceMessages = append(announceMessages, e2Ann)
// If this edge has a validated node // If this edge has a validated node
// announcement, then we'll send that as well. // announcement, that we haven't yet sent, then
if e2.Node.HaveNodeAnnouncement { // we'll send that as well.
nodePub := e2.Node.PubKeyBytes
hasNodeAnn := e2.Node.HaveNodeAnnouncement
if _, ok := nodePubsSent[nodePub]; !ok && hasNodeAnn {
nodeAnn, err := makeNodeAnn(e2.Node) nodeAnn, err := makeNodeAnn(e2.Node)
if err != nil { if err != nil {
return err return err
} }
announceMessages = append( announceMessages = append(
announceMessages, nodeAnn, announceMessages, nodeAnn,
) )
nodePubsSent[nodePub] = struct{}{}
numNodes++ numNodes++
} }
} }