discovery/gossiper: add local updates to graph immediately

Since the batch interval can potentially be long, adding local updates
to the graph could be slow. This would slow down operations like adding
our own channel update and announcements during the funding process, and
updating edge policies for local channels.

Now we instead check whether the update is remote or not, and only for
remote updates use the SchedulerOption to lazily add them to the graph.
This commit is contained in:
Johan T. Halseth 2021-01-27 13:38:23 +01:00
parent 7e34132c53
commit c9afc93151
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -12,6 +12,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/btcutil"
"github.com/davecgh/go-spew/spew"
"github.com/lightningnetwork/lnd/batch"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/lnpeer"
@ -1449,7 +1450,9 @@ func (d *AuthenticatedGossiper) processRejectedEdge(
// addNode processes the given node announcement, and adds it to our channel
// graph.
func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement) error {
func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement,
op ...batch.SchedulerOption) error {
if err := routing.ValidateNodeAnn(msg); err != nil {
return fmt.Errorf("unable to validate node announcement: %v",
err)
@ -1469,7 +1472,7 @@ func (d *AuthenticatedGossiper) addNode(msg *lnwire.NodeAnnouncement) error {
ExtraOpaqueData: msg.ExtraOpaqueData,
}
return d.cfg.Router.AddNode(node)
return d.cfg.Router.AddNode(node, op...)
}
// processNetworkAnnouncement processes a new network relate authenticated
@ -1486,6 +1489,13 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
return chanID.BlockHeight+delta > d.bestHeight
}
// If this is a remote update, we set the scheduler option to lazily
// add it to the graph.
var schedulerOp []batch.SchedulerOption
if nMsg.isRemote {
schedulerOp = append(schedulerOp, batch.LazyAdd())
}
var announcements []networkMsg
switch msg := nMsg.msg.(type) {
@ -1504,7 +1514,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
return nil
}
if err := d.addNode(msg); err != nil {
if err := d.addNode(msg, schedulerOp...); err != nil {
if routing.IsError(err, routing.ErrOutdated,
routing.ErrIgnored) {
@ -1662,7 +1672,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
// writes to the DB.
d.channelMtx.Lock(msg.ShortChannelID.ToUint64())
defer d.channelMtx.Unlock(msg.ShortChannelID.ToUint64())
if err := d.cfg.Router.AddEdge(edge); err != nil {
if err := d.cfg.Router.AddEdge(edge, schedulerOp...); err != nil {
// If the edge was rejected due to already being known,
// then it may be that case that this new message has a
// fresh channel proof, so we'll check.
@ -2002,7 +2012,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
ExtraOpaqueData: msg.ExtraOpaqueData,
}
if err := d.cfg.Router.UpdateEdge(update); err != nil {
if err := d.cfg.Router.UpdateEdge(update, schedulerOp...); err != nil {
if routing.IsError(err, routing.ErrOutdated,
routing.ErrIgnored) {
log.Debug(err)