Skip to content

Commit

Permalink
discovery/gossiper: add local updates to graph immediately
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
halseth committed Feb 9, 2021
1 parent 9e81e80 commit cea1b1c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions discovery/gossiper.go
Expand Up @@ -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"
Expand Down Expand Up @@ -1440,7 +1441,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)
Expand All @@ -1460,7 +1463,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
Expand All @@ -1477,6 +1480,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) {
Expand All @@ -1495,7 +1505,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) {

Expand Down Expand Up @@ -1653,7 +1663,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.
Expand Down Expand Up @@ -1921,7 +1931,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)
Expand Down

0 comments on commit cea1b1c

Please sign in to comment.