Merge pull request #4964 from halseth/gossip-local-no-batch
channeldb+routing+gossiper: add local updates to graph immediately
This commit is contained in:
6 files changed
+108
-30
No files matched your search
+15
-5
@@ -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"
|
||||
@@ -1468,7 +1469,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)
|
||||
@@ -1488,7 +1491,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
|
||||
@@ -1505,6 +1508,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) {
|
||||
@@ -1523,7 +1533,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) {
|
||||
|
||||
@@ -1681,7 +1691,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.
|
||||
@@ -2031,7 +2041,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)
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/batch"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
@@ -115,7 +116,9 @@ func newMockRouter(height uint32) *mockGraphSource {
|
||||
|
||||
var _ routing.ChannelGraphSource = (*mockGraphSource)(nil)
|
||||
|
||||
func (r *mockGraphSource) AddNode(node *channeldb.LightningNode) error {
|
||||
func (r *mockGraphSource) AddNode(node *channeldb.LightningNode,
|
||||
_ ...batch.SchedulerOption) error {
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
@@ -123,7 +126,9 @@ func (r *mockGraphSource) AddNode(node *channeldb.LightningNode) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *mockGraphSource) AddEdge(info *channeldb.ChannelEdgeInfo) error {
|
||||
func (r *mockGraphSource) AddEdge(info *channeldb.ChannelEdgeInfo,
|
||||
_ ...batch.SchedulerOption) error {
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
@@ -135,7 +140,9 @@ func (r *mockGraphSource) AddEdge(info *channeldb.ChannelEdgeInfo) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *mockGraphSource) UpdateEdge(edge *channeldb.ChannelEdgePolicy) error {
|
||||
func (r *mockGraphSource) UpdateEdge(edge *channeldb.ChannelEdgePolicy,
|
||||
_ ...batch.SchedulerOption) error {
|
||||
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
|
||||
Reference in new issue
Block a user