diff --git a/autopilot/graph.go b/autopilot/graph.go index 74b04c503..83447af9b 100644 --- a/autopilot/graph.go +++ b/autopilot/graph.go @@ -105,7 +105,9 @@ func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error { return nil } - node, err := d.db.FetchLightningNode(tx, ep.ToNode) + node, err := d.db.FetchLightningNodeTx( + tx, ep.ToNode, + ) if err != nil { return err } @@ -164,7 +166,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey, return nil, err } - dbNode, err := d.db.FetchLightningNode(nil, vertex) + dbNode, err := d.db.FetchLightningNode(vertex) switch { case err == channeldb.ErrGraphNodeNotFound: fallthrough diff --git a/channeldb/db.go b/channeldb/db.go index 93bb239bb..1e210d032 100644 --- a/channeldb/db.go +++ b/channeldb/db.go @@ -1351,7 +1351,7 @@ func (d *DB) AddrsForNode(nodePub *btcec.PublicKey) ([]net.Addr, if err != nil { return nil, err } - graphNode, err := d.graph.FetchLightningNode(nil, pubKey) + graphNode, err := d.graph.FetchLightningNode(pubKey) if err != nil && err != ErrGraphNodeNotFound { return nil, err } else if err == ErrGraphNodeNotFound { diff --git a/channeldb/graph.go b/channeldb/graph.go index 0ac0ec2f7..a37ea9682 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -529,7 +529,7 @@ func (c *ChannelGraph) FetchNodeFeatures( } // Fallback that uses the database. - targetNode, err := c.FetchLightningNode(nil, node) + targetNode, err := c.FetchLightningNode(node) switch err { // If the node exists and has features, return them directly. case nil: @@ -2963,11 +2963,30 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex, return nodeIsPublic, nil } +// FetchLightningNodeTx 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) FetchLightningNodeTx(tx kvdb.RTx, nodePub route.Vertex) ( + *LightningNode, error) { + + return c.fetchLightningNode(tx, nodePub) +} + // 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. +func (c *ChannelGraph) FetchLightningNode(nodePub route.Vertex) (*LightningNode, + error) { + + return c.fetchLightningNode(nil, nodePub) +} + +// 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(tx kvdb.RTx, +func (c *ChannelGraph) fetchLightningNode(tx kvdb.RTx, nodePub route.Vertex) (*LightningNode, error) { var node *LightningNode diff --git a/channeldb/graph_test.go b/channeldb/graph_test.go index 9e430296b..46bc0d3fd 100644 --- a/channeldb/graph_test.go +++ b/channeldb/graph_test.go @@ -141,7 +141,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) { // Next, fetch the node from the database to ensure everything was // serialized properly. - dbNode, err := graph.FetchLightningNode(nil, testPub) + dbNode, err := graph.FetchLightningNode(testPub) require.NoError(t, err, "unable to locate node") if _, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes); err != nil { @@ -164,7 +164,7 @@ func TestNodeInsertionAndDeletion(t *testing.T) { // Finally, attempt to fetch the node again. This should fail as the // node should have been deleted from the database. - _, err = graph.FetchLightningNode(nil, testPub) + _, err = graph.FetchLightningNode(testPub) if err != ErrGraphNodeNotFound { t.Fatalf("fetch after delete should fail!") } @@ -192,7 +192,7 @@ func TestPartialNode(t *testing.T) { // Next, fetch the node from the database to ensure everything was // serialized properly. - dbNode, err := graph.FetchLightningNode(nil, testPub) + dbNode, err := graph.FetchLightningNode(testPub) require.NoError(t, err, "unable to locate node") if _, exists, err := graph.HasLightningNode(dbNode.PubKeyBytes); err != nil { @@ -222,7 +222,7 @@ func TestPartialNode(t *testing.T) { // Finally, attempt to fetch the node again. This should fail as the // node should have been deleted from the database. - _, err = graph.FetchLightningNode(nil, testPub) + _, err = graph.FetchLightningNode(testPub) if err != ErrGraphNodeNotFound { t.Fatalf("fetch after delete should fail!") } @@ -3014,7 +3014,7 @@ func TestPruneGraphNodes(t *testing.T) { // Finally, we'll ensure that node3, the only fully unconnected node as // properly deleted from the graph and not another node in its place. - _, err = graph.FetchLightningNode(nil, node3.PubKeyBytes) + _, err = graph.FetchLightningNode(node3.PubKeyBytes) if err == nil { t.Fatalf("node 3 should have been deleted!") } @@ -3048,13 +3048,13 @@ func TestAddChannelEdgeShellNodes(t *testing.T) { // Ensure that node1 was inserted as a full node, while node2 only has // a shell node present. - node1, err = graph.FetchLightningNode(nil, node1.PubKeyBytes) + node1, err = graph.FetchLightningNode(node1.PubKeyBytes) require.NoError(t, err, "unable to fetch node1") if !node1.HaveNodeAnnouncement { t.Fatalf("have shell announcement for node1, shouldn't") } - node2, err = graph.FetchLightningNode(nil, node2.PubKeyBytes) + node2, err = graph.FetchLightningNode(node2.PubKeyBytes) require.NoError(t, err, "unable to fetch node2") if node2.HaveNodeAnnouncement { t.Fatalf("should have shell announcement for node2, but is full") diff --git a/routing/router.go b/routing/router.go index c968f8d32..c91e0b187 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2915,7 +2915,7 @@ func (r *ChannelRouter) GetChannelByID(chanID lnwire.ShortChannelID) ( func (r *ChannelRouter) FetchLightningNode( node route.Vertex) (*channeldb.LightningNode, error) { - return r.cfg.Graph.FetchLightningNode(nil, node) + return r.cfg.Graph.FetchLightningNode(node) } // ForEachNode is used to iterate over every node in router topology. diff --git a/routing/router_test.go b/routing/router_test.go index 6f11894dc..49ca6a266 100644 --- a/routing/router_test.go +++ b/routing/router_test.go @@ -1596,14 +1596,14 @@ func TestAddEdgeUnknownVertexes(t *testing.T) { _, _, err = ctx.router.FindRoute(req) require.NoError(t, err, "unable to find any routes") - copy1, err := ctx.graph.FetchLightningNode(nil, pub1) + copy1, err := ctx.graph.FetchLightningNode(pub1) require.NoError(t, err, "unable to fetch node") if copy1.Alias != n1.Alias { t.Fatalf("fetched node not equal to original") } - copy2, err := ctx.graph.FetchLightningNode(nil, pub2) + copy2, err := ctx.graph.FetchLightningNode(pub2) require.NoError(t, err, "unable to fetch node") if copy2.Alias != n2.Alias { diff --git a/rpcserver.go b/rpcserver.go index c2ab4eb54..2012e75d9 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -6345,7 +6345,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(nil, pubKey) + node, err := graph.FetchLightningNode(pubKey) switch { case err == channeldb.ErrGraphNodeNotFound: return nil, status.Error(codes.NotFound, err.Error()) @@ -7393,7 +7393,7 @@ func (r *rpcServer) ForwardingHistory(ctx context.Context, return "", err } - peer, err := r.server.graphDB.FetchLightningNode(nil, vertex) + peer, err := r.server.graphDB.FetchLightningNode(vertex) if err != nil { return "", err } diff --git a/server.go b/server.go index b3852dbcc..555513406 100644 --- a/server.go +++ b/server.go @@ -4634,7 +4634,7 @@ func (s *server) fetchNodeAdvertisedAddrs(pub *btcec.PublicKey) ([]net.Addr, err return nil, err } - node, err := s.graphDB.FetchLightningNode(nil, vertex) + node, err := s.graphDB.FetchLightningNode(vertex) if err != nil { return nil, err }