diff --git a/autopilot/graph.go b/autopilot/graph.go index ad9ffb39ee..40c1a3f954 100644 --- a/autopilot/graph.go +++ b/autopilot/graph.go @@ -104,10 +104,7 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error { return nil } - node, err := d.db.FetchLightningNode( - context.TODO(), graphdb.NewKVDBRTx(tx), - ep.ToNode, - ) + node, err := d.db.FetchLightningNodeWithTx(tx, ep.ToNode) if err != nil { return err } diff --git a/cmd/multinode/graph_mux.go b/cmd/multinode/graph_mux.go index 012ae71277..9df2c8c327 100644 --- a/cmd/multinode/graph_mux.go +++ b/cmd/multinode/graph_mux.go @@ -193,7 +193,7 @@ func (g *GraphSourceMux) ForEachNode(ctx context.Context, // a new one will be created. // // NOTE: this is part of the GraphSource interface. -func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, tx graphdb.RTx, +func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, nodePub route.Vertex) (*models.LightningNode, error) { srcPub, err := g.selfNodePub() @@ -201,16 +201,11 @@ func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, tx graphdb.RTx, return nil, err } - lTx, rTx, err := extractRTxSet(tx) - if err != nil { - return nil, err - } - if bytes.Equal(srcPub[:], nodePub[:]) { - return g.local.FetchLightningNode(ctx, lTx, nodePub) + return g.local.FetchLightningNode(ctx, nodePub) } - return g.remote.FetchLightningNode(ctx, rTx, nodePub) + return g.remote.FetchLightningNode(ctx, nodePub) } // ForEachNodeChannel iterates through all channels of the given node, diff --git a/cmd/multinode2/graph_mux.go b/cmd/multinode2/graph_mux.go index 8efa524065..e3fab531f2 100644 --- a/cmd/multinode2/graph_mux.go +++ b/cmd/multinode2/graph_mux.go @@ -193,7 +193,7 @@ func (g *GraphSourceMux) ForEachNode(ctx context.Context, // a new one will be created. // // NOTE: this is part of the GraphSource interface. -func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, tx graphdb.RTx, +func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, nodePub route.Vertex) (*models.LightningNode, error) { srcPub, err := g.selfNodePub() @@ -201,16 +201,11 @@ func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, tx graphdb.RTx, return nil, err } - lTx, rTx, err := extractRTxSet(tx) - if err != nil { - return nil, err - } - if bytes.Equal(srcPub[:], nodePub[:]) { - return g.local.FetchLightningNode(ctx, lTx, nodePub) + return g.local.FetchLightningNode(ctx, nodePub) } - return g.remote.FetchLightningNode(ctx, rTx, nodePub) + return g.remote.FetchLightningNode(ctx, nodePub) } // ForEachNodeChannel iterates through all channels of the given node, diff --git a/cmd/multinode2/wrapper.go b/cmd/multinode2/wrapper.go index f0a5486ded..78cfc3e695 100644 --- a/cmd/multinode2/wrapper.go +++ b/cmd/multinode2/wrapper.go @@ -350,7 +350,7 @@ func (r *remoteWrapper) FetchNodeFeatures(ctx context.Context, tx graphdb.RTx, n return unmarshalFeatures(resp.Node.Features), nil } -func (r *remoteWrapper) FetchLightningNode(ctx context.Context, tx graphdb.RTx, +func (r *remoteWrapper) FetchLightningNode(ctx context.Context, nodePub route.Vertex) (*models.LightningNode, error) { resp, err := r.lnConn.GetNodeInfo(ctx, &lnrpc.NodeInfoRequest{ diff --git a/cmd/multinode3/graph_mux.go b/cmd/multinode3/graph_mux.go index 8efa524065..e3fab531f2 100644 --- a/cmd/multinode3/graph_mux.go +++ b/cmd/multinode3/graph_mux.go @@ -193,7 +193,7 @@ func (g *GraphSourceMux) ForEachNode(ctx context.Context, // a new one will be created. // // NOTE: this is part of the GraphSource interface. -func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, tx graphdb.RTx, +func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, nodePub route.Vertex) (*models.LightningNode, error) { srcPub, err := g.selfNodePub() @@ -201,16 +201,11 @@ func (g *GraphSourceMux) FetchLightningNode(ctx context.Context, tx graphdb.RTx, return nil, err } - lTx, rTx, err := extractRTxSet(tx) - if err != nil { - return nil, err - } - if bytes.Equal(srcPub[:], nodePub[:]) { - return g.local.FetchLightningNode(ctx, lTx, nodePub) + return g.local.FetchLightningNode(ctx, nodePub) } - return g.remote.FetchLightningNode(ctx, rTx, nodePub) + return g.remote.FetchLightningNode(ctx, nodePub) } // ForEachNodeChannel iterates through all channels of the given node, diff --git a/cmd/multinode3/wrapper.go b/cmd/multinode3/wrapper.go index f0a5486ded..78cfc3e695 100644 --- a/cmd/multinode3/wrapper.go +++ b/cmd/multinode3/wrapper.go @@ -350,7 +350,7 @@ func (r *remoteWrapper) FetchNodeFeatures(ctx context.Context, tx graphdb.RTx, n return unmarshalFeatures(resp.Node.Features), nil } -func (r *remoteWrapper) FetchLightningNode(ctx context.Context, tx graphdb.RTx, +func (r *remoteWrapper) FetchLightningNode(ctx context.Context, nodePub route.Vertex) (*models.LightningNode, error) { resp, err := r.lnConn.GetNodeInfo(ctx, &lnrpc.NodeInfoRequest{ diff --git a/graph/builder.go b/graph/builder.go index 95b5a7377a..bff559144b 100644 --- a/graph/builder.go +++ b/graph/builder.go @@ -1626,7 +1626,7 @@ func (b *Builder) GetChannelByID(chanID lnwire.ShortChannelID) ( func (b *Builder) FetchLightningNode( node route.Vertex) (*models.LightningNode, error) { - return b.cfg.Graph.FetchLightningNode(context.TODO(), nil, node) + return b.cfg.Graph.FetchLightningNode(context.TODO(), node) } // ForAllOutgoingChannels is used to iterate over all outgoing channels owned by diff --git a/graph/db/graph.go b/graph/db/graph.go index 6eb39e45be..11b3a7af6a 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -436,7 +436,7 @@ func (c *ChannelGraph) AddrsForNode(ctx context.Context, nodePub *btcec.PublicKe return false, nil, err } - node, err := c.FetchLightningNode(ctx, nil, pubKey) + node, err := c.FetchLightningNodeWithTx(nil, pubKey) // We don't consider it an error if the graph is unaware of the node. switch { case err != nil && !errors.Is(err, ErrGraphNodeNotFound): @@ -586,8 +586,13 @@ func (c *ChannelGraph) FetchNodeFeatures(ctx context.Context, tx RTx, return c.graphCache.GetFeatures(node), nil } + kvdbRTx, err := extractKVDBRTx(tx) + if err != nil { + return nil, err + } + // Fallback that uses the database. - targetNode, err := c.FetchLightningNode(ctx, tx, node) + targetNode, err := c.FetchLightningNodeWithTx(kvdbRTx, node) switch err { // If the node exists and has features, return them directly. case nil: @@ -2980,19 +2985,18 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex, // FetchLightningNode attempts to look up a target node by its identity public // key. If the node isn't found in the database, then ErrGraphNodeNotFound is -// returned. An optional transaction may be provided. If none is provided, then -// a new one will be created. -func (c *ChannelGraph) FetchLightningNode(_ context.Context, tx RTx, +// returned. +func (c *ChannelGraph) FetchLightningNode(_ context.Context, nodePub route.Vertex) (*models.LightningNode, error) { - return c.fetchLightningNode(tx, nodePub) + return c.FetchLightningNodeWithTx(nil, nodePub) } -// fetchLightningNode attempts to look up a target node by its identity public +// FetchLightningNodeWithTx attempts to look up a target node by its identity public // key. If the node isn't found in the database, then ErrGraphNodeNotFound is // returned. An optional transaction may be provided. If none is provided, then // a new one will be created. -func (c *ChannelGraph) fetchLightningNode(tx RTx, +func (c *ChannelGraph) FetchLightningNodeWithTx(tx kvdb.RTx, nodePub route.Vertex) (*models.LightningNode, error) { var node *models.LightningNode @@ -3024,12 +3028,7 @@ func (c *ChannelGraph) fetchLightningNode(tx RTx, return nil } - kvdbRTx, err := extractKVDBRTx(tx) - if err != nil { - return nil, err - } - - if kvdbRTx == nil { + if tx == nil { err := kvdb.View( c.db, fetch, func() { node = nil @@ -3042,7 +3041,7 @@ func (c *ChannelGraph) fetchLightningNode(tx RTx, return node, nil } - err = fetch(kvdbRTx) + err := fetch(tx) if err != nil { return nil, err } diff --git a/graph/interfaces.go b/graph/interfaces.go index 19fd6a4317..382546592e 100644 --- a/graph/interfaces.go +++ b/graph/interfaces.go @@ -236,8 +236,8 @@ type DB interface { // FetchLightningNode attempts to look up a target node by its identity // public key. If the node isn't found in the database, then // ErrGraphNodeNotFound is returned. - FetchLightningNode(ctx context.Context, tx graphdb.RTx, - nodePub route.Vertex) (*models.LightningNode, error) + FetchLightningNode(ctx context.Context, nodePub route.Vertex) ( + *models.LightningNode, error) // ForEachNode iterates through all the stored vertices/nodes in the // graph, executing the passed callback with each node encountered. If diff --git a/interfaces.go b/interfaces.go index f95fc9a158..9173201eab 100644 --- a/interfaces.go +++ b/interfaces.go @@ -6,7 +6,6 @@ import ( "github.com/btcsuite/btcd/btcec/v2" "github.com/lightningnetwork/lnd/channeldb" - graphdb "github.com/lightningnetwork/lnd/graph/db" "github.com/lightningnetwork/lnd/graph/db/models" "github.com/lightningnetwork/lnd/graph/graphsession" "github.com/lightningnetwork/lnd/graph/stats" @@ -70,8 +69,8 @@ type GraphSource interface { // public key. If the node isn't found in the database, then // graphdb.ErrGraphNodeNotFound is returned. An optional transaction may // be provided. If none is provided, then a new one will be created. - FetchLightningNode(ctx context.Context, tx graphdb.RTx, - nodePub route.Vertex) (*models.LightningNode, error) + FetchLightningNode(ctx context.Context, nodePub route.Vertex) ( + *models.LightningNode, error) } // Providers is an interface that LND itself can satisfy. diff --git a/rpcserver.go b/rpcserver.go index 3f1d35a458..a7b95a9f78 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -6778,7 +6778,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context, // With the public key decoded, attempt to fetch the node corresponding // to this public key. If the node cannot be found, then an error will // be returned. - node, err := graph.FetchLightningNode(ctx, nil, pubKey) + node, err := graph.FetchLightningNode(ctx, pubKey) switch { case errors.Is(err, graphdb.ErrGraphNodeNotFound): return nil, status.Error(codes.NotFound, err.Error()) @@ -7775,7 +7775,7 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context, return "", err } - peer, err := r.server.graphSource.FetchLightningNode(ctx, nil, vertex) + peer, err := r.server.graphSource.FetchLightningNode(ctx, vertex) if err != nil { return "", err } diff --git a/server.go b/server.go index 42da0fc29e..091da13f6a 100644 --- a/server.go +++ b/server.go @@ -4908,7 +4908,7 @@ func (s *server) fetchNodeAdvertisedAddrs(pub *btcec.PublicKey) ([]net.Addr, err return nil, err } - node, err := s.graphSource.FetchLightningNode(context.TODO(), nil, vertex) + node, err := s.graphSource.FetchLightningNode(context.TODO(), vertex) if err != nil { return nil, err }