Skip to content

Commit 004440a

Browse files
committed
graph/db: thread context through to LookupAlias
1 parent 81c063e commit 004440a

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

graph/db/graph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ func TestAliasLookup(t *testing.T) {
348348
// the one which the test node was assigned.
349349
nodePub, err := testNode.PubKey()
350350
require.NoError(t, err, "unable to generate pubkey")
351-
dbAlias, err := graph.LookupAlias(nodePub)
351+
dbAlias, err := graph.LookupAlias(ctx, nodePub)
352352
require.NoError(t, err, "unable to find alias")
353353
require.Equal(t, testNode.Alias, dbAlias)
354354

355355
// Ensure that looking up a non-existent alias results in an error.
356356
node := createTestVertex(t)
357357
nodePub, err = node.PubKey()
358358
require.NoError(t, err, "unable to generate pubkey")
359-
_, err = graph.LookupAlias(nodePub)
359+
_, err = graph.LookupAlias(ctx, nodePub)
360360
require.ErrorIs(t, err, ErrNodeAliasNotFound)
361361
}
362362

graph/db/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ type V1Store interface { //nolint:interfacebloat
111111

112112
// LookupAlias attempts to return the alias as advertised by the target
113113
// node.
114-
LookupAlias(pub *btcec.PublicKey) (string, error)
114+
LookupAlias(ctx context.Context, pub *btcec.PublicKey) (string, error)
115115

116116
// DeleteLightningNode starts a new database transaction to remove a
117117
// vertex/node from the database according to the node's public key.

graph/db/kv_store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,9 @@ func addLightningNode(tx kvdb.RwTx, node *models.LightningNode) error {
997997

998998
// LookupAlias attempts to return the alias as advertised by the target node.
999999
// TODO(roasbeef): currently assumes that aliases are unique...
1000-
func (c *KVStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
1000+
func (c *KVStore) LookupAlias(_ context.Context,
1001+
pub *btcec.PublicKey) (string, error) {
1002+
10011003
var alias string
10021004

10031005
err := kvdb.View(c.db, func(tx kvdb.RTx) error {

graph/db/sql_store.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,10 @@ func (s *SQLStore) FetchNodeFeatures(nodePub route.Vertex) (
355355
// LookupAlias attempts to return the alias as advertised by the target node.
356356
//
357357
// NOTE: part of the V1Store interface.
358-
func (s *SQLStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
359-
var (
360-
ctx = context.TODO()
361-
alias string
362-
)
358+
func (s *SQLStore) LookupAlias(ctx context.Context,
359+
pub *btcec.PublicKey) (string, error) {
360+
361+
var alias string
363362
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
364363
dbNode, err := db.GetNodeByPubKey(
365364
ctx, sqlc.GetNodeByPubKeyParams{

rpcserver.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4645,7 +4645,7 @@ func (r *rpcServer) ListChannels(ctx context.Context,
46454645
// our list depending on the type of channels requested to us.
46464646
isActive := peerOnline && linkActive
46474647
channel, err := createRPCOpenChannel(
4648-
r, dbChannel, isActive, in.PeerAliasLookup,
4648+
ctx, r, dbChannel, isActive, in.PeerAliasLookup,
46494649
)
46504650
if err != nil {
46514651
return nil, err
@@ -4761,7 +4761,10 @@ func encodeCustomChanData(lnChan *channeldb.OpenChannel) ([]byte, error) {
47614761
}
47624762

47634763
// createRPCOpenChannel creates an *lnrpc.Channel from the *channeldb.Channel.
4764-
func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
4764+
//
4765+
//nolint:funlen
4766+
func createRPCOpenChannel(ctx context.Context, r *rpcServer,
4767+
dbChannel *channeldb.OpenChannel,
47654768
isActive, peerAliasLookup bool) (*lnrpc.Channel, error) {
47664769

47674770
nodePub := dbChannel.IdentityPub
@@ -4863,7 +4866,7 @@ func createRPCOpenChannel(r *rpcServer, dbChannel *channeldb.OpenChannel,
48634866

48644867
// Look up our channel peer's node alias if the caller requests it.
48654868
if peerAliasLookup {
4866-
peerAlias, err := r.server.graphDB.LookupAlias(nodePub)
4869+
peerAlias, err := r.server.graphDB.LookupAlias(ctx, nodePub)
48674870
if err != nil {
48684871
peerAlias = fmt.Sprintf("unable to lookup "+
48694872
"peer alias: %v", err)
@@ -5307,7 +5310,8 @@ func (r *rpcServer) SubscribeChannelEvents(req *lnrpc.ChannelEventSubscription,
53075310
}
53085311
case channelnotifier.OpenChannelEvent:
53095312
channel, err := createRPCOpenChannel(
5310-
r, event.Channel, true, false,
5313+
updateStream.Context(), r,
5314+
event.Channel, true, false,
53115315
)
53125316
if err != nil {
53135317
return err

0 commit comments

Comments
 (0)