diff --git a/discovery/gossiper.go b/discovery/gossiper.go index e669f61a..8993e34a 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -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)