diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index bd8b62293..daec52526 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -348,7 +348,7 @@ func TestAliasLookup(t *testing.T) { // the one which the test node was assigned. nodePub, err := testNode.PubKey() require.NoError(t, err, "unable to generate pubkey") - dbAlias, err := graph.LookupAlias(nodePub) + dbAlias, err := graph.LookupAlias(ctx, nodePub) require.NoError(t, err, "unable to find alias") require.Equal(t, testNode.Alias, dbAlias) @@ -356,7 +356,7 @@ func TestAliasLookup(t *testing.T) { node := createTestVertex(t) nodePub, err = node.PubKey() require.NoError(t, err, "unable to generate pubkey") - _, err = graph.LookupAlias(nodePub) + _, err = graph.LookupAlias(ctx, nodePub) require.ErrorIs(t, err, ErrNodeAliasNotFound) } diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index 238688569..df629383e 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -111,7 +111,7 @@ type V1Store interface { //nolint:interfacebloat // LookupAlias attempts to return the alias as advertised by the target // node. - LookupAlias(pub *btcec.PublicKey) (string, error) + LookupAlias(ctx context.Context, pub *btcec.PublicKey) (string, error) // DeleteLightningNode starts a new database transaction to remove a // vertex/node from the database according to the node's public key. diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index b47e4fb32..4bd635737 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -997,7 +997,9 @@ func addLightningNode(tx kvdb.RwTx, node *models.LightningNode) error { // LookupAlias attempts to return the alias as advertised by the target node. // TODO(roasbeef): currently assumes that aliases are unique... -func (c *KVStore) LookupAlias(pub *btcec.PublicKey) (string, error) { +func (c *KVStore) LookupAlias(_ context.Context, + pub *btcec.PublicKey) (string, error) { + var alias string err := kvdb.View(c.db, func(tx kvdb.RTx) error { diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index 6cf64b1ed..ce44b2f78 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -355,11 +355,10 @@ func (s *SQLStore) FetchNodeFeatures(nodePub route.Vertex) ( // LookupAlias attempts to return the alias as advertised by the target node. // // NOTE: part of the V1Store interface. -func (s *SQLStore) LookupAlias(pub *btcec.PublicKey) (string, error) { - var ( - ctx = context.TODO() - alias string - ) +func (s *SQLStore) LookupAlias(ctx context.Context, + pub *btcec.PublicKey) (string, error) { + + var alias string err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error { dbNode, err := db.GetNodeByPubKey( ctx, sqlc.GetNodeByPubKeyParams{ diff --git a/rpcserver.go b/rpcserver.go index a82187ddc..48b5b3bc4 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -4645,7 +4645,7 @@ func (r *rpcServer) ListChannels(ctx context.Context, // our list depending on the type of channels requested to us. isActive := peerOnline && linkActive channel, err := createRPCOpenChannel( - r, dbChannel, isActive, in.PeerAliasLookup, + ctx, r, dbChannel, isActive, in.PeerAliasLookup, ) if err != nil { return nil, err @@ -4761,7 +4761,10 @@ func encodeCustomChanData(lnChan *channeldb.OpenChannel) ([]byte, error) { } // createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel. -func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel, +// +//nolint:funlen +func createRPCOpenChannel(ctx context.Context, r *rpcServer, + dbChannel *channeldb.OpenChannel, isActive, peerAliasLookup bool) (*lnrpc.Channel, error) { nodePub := dbChannel.IdentityPub @@ -4863,7 +4866,7 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel, // Look up our channel peer's node alias if the caller requests it. if peerAliasLookup { - peerAlias, err := r.server.graphDB.LookupAlias(nodePub) + peerAlias, err := r.server.graphDB.LookupAlias(ctx, nodePub) if err != nil { peerAlias = fmt.Sprintf("unable to lookup "+ "peer alias: %v", err) @@ -5307,7 +5310,8 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription, } case channelnotifier.OpenChannelEvent: channel, err := createRPCOpenChannel( - r, event.Channel, true, false, + updateStream.Context(), r, + event.Channel, true, false, ) if err != nil { return err