mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-11 00:12:40 +02:00
discovery: skip sending channel_announcement
with no channel_update
s
Base on BOLT07: > If a channel_announcement has no corresponding channel_updates: > - MUST NOT send the channel_announcement.
This commit is contained in:
@@ -136,7 +136,21 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
updates = append(updates, chanAnn)
|
// Create a slice to hold the `channel_announcement` and
|
||||||
|
// potentially two `channel_update` msgs.
|
||||||
|
//
|
||||||
|
// NOTE: Based on BOLT7, if a channel_announcement has no
|
||||||
|
// corresponding channel_updates, we must not send the
|
||||||
|
// channel_announcement. Thus we use this slice to decide we
|
||||||
|
// want to send this `channel_announcement` or not. By the end
|
||||||
|
// of the operation, if the len of the slice is 1, we will not
|
||||||
|
// send the `channel_announcement`. Otherwise, when sending the
|
||||||
|
// msgs, the `channel_announcement` must be sent prior to any
|
||||||
|
// corresponding `channel_update` or `node_annoucement`, that's
|
||||||
|
// why we create a slice here to maintain the order.
|
||||||
|
chanUpdates := make([]lnwire.Message, 0, 3)
|
||||||
|
chanUpdates = append(chanUpdates, chanAnn)
|
||||||
|
|
||||||
if edge1 != nil {
|
if edge1 != nil {
|
||||||
// We don't want to send channel updates that don't
|
// We don't want to send channel updates that don't
|
||||||
// conform to the spec (anymore).
|
// conform to the spec (anymore).
|
||||||
@@ -145,18 +159,28 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
|
|||||||
log.Errorf("not sending invalid channel "+
|
log.Errorf("not sending invalid channel "+
|
||||||
"update %v: %v", edge1, err)
|
"update %v: %v", edge1, err)
|
||||||
} else {
|
} else {
|
||||||
updates = append(updates, edge1)
|
chanUpdates = append(chanUpdates, edge1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if edge2 != nil {
|
if edge2 != nil {
|
||||||
err := netann.ValidateChannelUpdateFields(0, edge2)
|
err := netann.ValidateChannelUpdateFields(0, edge2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("not sending invalid channel "+
|
log.Errorf("not sending invalid channel "+
|
||||||
"update %v: %v", edge2, err)
|
"update %v: %v", edge2, err)
|
||||||
} else {
|
} else {
|
||||||
updates = append(updates, edge2)
|
chanUpdates = append(chanUpdates, edge2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there's no corresponding `channel_update` to send, skip
|
||||||
|
// sending this `channel_announcement`.
|
||||||
|
if len(chanUpdates) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append the all the msgs to the slice.
|
||||||
|
updates = append(updates, chanUpdates...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next, we'll send out all the node announcements that have an update
|
// Next, we'll send out all the node announcements that have an update
|
||||||
|
Reference in New Issue
Block a user