diff --git a/graph/db/graph.go b/graph/db/graph.go index a192ae3f1..85e87852d 100644 --- a/graph/db/graph.go +++ b/graph/db/graph.go @@ -729,12 +729,13 @@ func (c *ChannelGraph) FetchChanInfos(v lnwire.GossipVersion, // FetchChannelEdgesByOutpoint attempts to lookup directed edges by funding // outpoint. -func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) ( +func (c *ChannelGraph) FetchChannelEdgesByOutpoint(ctx context.Context, + op *wire.OutPoint) ( *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { return c.db.FetchChannelEdgesByOutpoint( - lnwire.GossipVersion1, op, + ctx, lnwire.GossipVersion1, op, ) } @@ -823,11 +824,12 @@ func (c *VersionedGraph) FetchChannelEdgesByID(ctx context.Context, // FetchChannelEdgesByOutpoint attempts to lookup directed edges by funding // outpoint. -func (c *VersionedGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint) ( +func (c *VersionedGraph) FetchChannelEdgesByOutpoint(ctx context.Context, + op *wire.OutPoint) ( *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { - return c.db.FetchChannelEdgesByOutpoint(c.v, op) + return c.db.FetchChannelEdgesByOutpoint(ctx, c.v, op) } // IsZombieEdge returns whether the edge is considered zombie for this version. diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index b201e969a..088b3dcf2 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -693,7 +693,9 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) { } // Also verify fetching by outpoint returns the same data. - dbEdge2, _, _, err := graph.FetchChannelEdgesByOutpoint(&outpoint) + dbEdge2, _, _, err := graph.FetchChannelEdgesByOutpoint( + ctx, &outpoint, + ) require.NoError(t, err) require.Equal(t, dbEdge.ChannelID, dbEdge2.ChannelID) @@ -706,7 +708,7 @@ func testEdgeInsertionDeletion(t *testing.T, v lnwire.GossipVersion) { // Ensure that any query attempts to lookup the delete channel edge are // properly deleted. - _, _, _, err = graph.FetchChannelEdgesByOutpoint(&outpoint) + _, _, _, err = graph.FetchChannelEdgesByOutpoint(ctx, &outpoint) require.ErrorIs(t, err, ErrEdgeNotFound) // Assert that if the edge is a zombie, then FetchChannelEdgesByID @@ -1206,7 +1208,7 @@ func testEdgeInfoUpdates(t *testing.T, v lnwire.GossipVersion) { // Next, attempt to query the channel edges according to the outpoint // of the channel. dbEdgeInfo, dbEdge1, dbEdge2, err = graph.FetchChannelEdgesByOutpoint( - &outpoint, + ctx, &outpoint, ) require.NoError(t, err, "unable to fetch channel by ID") compareEdgePolicies(t, dbEdge1, edge1) diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index 550c78ae9..8db7e0ebe 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -296,7 +296,8 @@ type Store interface { //nolint:interfacebloat // houses the general information for the channel itself is returned as // well as two structs that contain the routing policies for the channel // in either direction. - FetchChannelEdgesByOutpoint(v lnwire.GossipVersion, op *wire.OutPoint) ( + FetchChannelEdgesByOutpoint(ctx context.Context, + v lnwire.GossipVersion, op *wire.OutPoint) ( *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index f77484a7c..6fbd7df5a 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -3899,8 +3899,9 @@ func computeEdgePolicyKeys(info *models.ChannelEdgeInfo) ([]byte, []byte) { // found, then ErrEdgeNotFound is returned. A struct which houses the general // information for the channel itself is returned as well as two structs that // contain the routing policies for the channel in either direction. -func (c *KVStore) FetchChannelEdgesByOutpoint(v lnwire.GossipVersion, - op *wire.OutPoint) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, +func (c *KVStore) FetchChannelEdgesByOutpoint(_ context.Context, + v lnwire.GossipVersion, op *wire.OutPoint) ( + *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { var ( diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index 9085e06e5..71f9d083a 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -2167,12 +2167,12 @@ func (s *SQLStore) FetchChannelEdgesByID(ctx context.Context, // contain the routing policies for the channel in either direction. // // NOTE: part of the Store interface. -func (s *SQLStore) FetchChannelEdgesByOutpoint(v lnwire.GossipVersion, - op *wire.OutPoint) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, +func (s *SQLStore) FetchChannelEdgesByOutpoint(ctx context.Context, + v lnwire.GossipVersion, op *wire.OutPoint) ( + *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { var ( - ctx = context.TODO() edge *models.ChannelEdgeInfo policy1, policy2 *models.ChannelEdgePolicy ) diff --git a/netann/chan_status_manager.go b/netann/chan_status_manager.go index feb3a5dd1..b21aeb18a 100644 --- a/netann/chan_status_manager.go +++ b/netann/chan_status_manager.go @@ -1,6 +1,7 @@ package netann import ( + "context" "errors" "sync" "time" @@ -654,7 +655,9 @@ func (m *ChanStatusManager) fetchLastChanUpdateByOutPoint(op wire.OutPoint) ( *lnwire.ChannelUpdate1, bool, error) { // Get the edge info and policies for this channel from the graph. - info, edge1, edge2, err := m.cfg.Graph.FetchChannelEdgesByOutpoint(&op) + info, edge1, edge2, err := m.cfg.Graph.FetchChannelEdgesByOutpoint( + context.TODO(), &op, + ) if err != nil { return nil, false, err } diff --git a/netann/chan_status_manager_test.go b/netann/chan_status_manager_test.go index 59ce324c6..02669ce4a 100644 --- a/netann/chan_status_manager_test.go +++ b/netann/chan_status_manager_test.go @@ -2,6 +2,7 @@ package netann_test import ( "bytes" + "context" "crypto/rand" "encoding/binary" "fmt" @@ -173,7 +174,8 @@ func (g *mockGraph) FetchAllOpenChannels() ([]*channeldb.OpenChannel, error) { } func (g *mockGraph) FetchChannelEdgesByOutpoint( - op *wire.OutPoint) (*models.ChannelEdgeInfo, + _ context.Context, op *wire.OutPoint) ( + *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) { g.mu.Lock() diff --git a/netann/interface.go b/netann/interface.go index aa559435d..78acc24cd 100644 --- a/netann/interface.go +++ b/netann/interface.go @@ -1,6 +1,8 @@ package netann import ( + "context" + "github.com/btcsuite/btcd/wire" "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/graph/db/models" @@ -19,6 +21,7 @@ type DB interface { type ChannelGraph interface { // FetchChannelEdgesByOutpoint returns the channel edge info and most // recent channel edge policies for a given outpoint. - FetchChannelEdgesByOutpoint(*wire.OutPoint) (*models.ChannelEdgeInfo, - *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) + FetchChannelEdgesByOutpoint(context.Context, *wire.OutPoint) ( + *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, + *models.ChannelEdgePolicy, error) } diff --git a/peer/brontide.go b/peer/brontide.go index d92f9c459..0f4d6e349 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -1217,7 +1217,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) ( // the database. graph := p.cfg.ChannelGraph info, p1, p2, err := graph.FetchChannelEdgesByOutpoint( - &chanPoint, + context.TODO(), &chanPoint, ) if err != nil && !errors.Is(err, graphdb.ErrEdgeNotFound) { return nil, err diff --git a/rpcserver.go b/rpcserver.go index 4a9c8e76a..bf01fc82f 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -7132,7 +7132,7 @@ func (r *rpcServer) GetChanInfo(ctx context.Context, return nil, err } edgeInfo, edge1, edge2, err = graph.FetchChannelEdgesByOutpoint( - chanPoint, + ctx, chanPoint, ) default: