diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go index b1206281d..b63651188 100644 --- a/graph/db/graph_test.go +++ b/graph/db/graph_test.go @@ -922,15 +922,20 @@ func TestEdgePolicyCRUD(t *testing.T) { // Use the ForEachChannel method to fetch the policies and // assert that the deserialized policies match the original // ones. - err := graph.ForEachChannel(func(info *models.ChannelEdgeInfo, - policy1 *models.ChannelEdgePolicy, - policy2 *models.ChannelEdgePolicy) error { + err := graph.ForEachChannel( + ctx, func(info *models.ChannelEdgeInfo, + policy1 *models.ChannelEdgePolicy, + policy2 *models.ChannelEdgePolicy) error { - require.NoError(t, compareEdgePolicies(edge1, policy1)) - require.NoError(t, compareEdgePolicies(edge2, policy2)) + require.NoError( + t, compareEdgePolicies(edge1, policy1), + ) + require.NoError( + t, compareEdgePolicies(edge2, policy2), + ) - return nil - }) + return nil + }) require.NoError(t, err) } @@ -1374,7 +1379,7 @@ func TestGraphTraversal(t *testing.T) { // Iterate through all the known channels within the graph DB, once // again if the map is empty that indicates that all edges have // properly been reached. - err = graph.ForEachChannel(func(ei *models.ChannelEdgeInfo, + err = graph.ForEachChannel(ctx, func(ei *models.ChannelEdgeInfo, _ *models.ChannelEdgePolicy, _ *models.ChannelEdgePolicy) error { @@ -1663,13 +1668,14 @@ func assertPruneTip(t *testing.T, graph *ChannelGraph, func assertNumChans(t *testing.T, graph *ChannelGraph, n int) { numChans := 0 - if err := graph.ForEachChannel(func(*models.ChannelEdgeInfo, - *models.ChannelEdgePolicy, - *models.ChannelEdgePolicy) error { + if err := graph.ForEachChannel(context.Background(), + func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, + *models.ChannelEdgePolicy) error { - numChans++ - return nil - }); err != nil { + numChans++ + return nil + }, + ); err != nil { _, _, line, _ := runtime.Caller(1) t.Fatalf("line %v: unable to scan channels: %v", line, err) } diff --git a/graph/db/interfaces.go b/graph/db/interfaces.go index b43e3b004..e46e578a9 100644 --- a/graph/db/interfaces.go +++ b/graph/db/interfaces.go @@ -158,7 +158,7 @@ type V1Store interface { //nolint:interfacebloat // NOTE: If an edge can't be found, or wasn't advertised, then a nil // pointer for that particular channel edge routing policy will be // passed into the callback. - ForEachChannel(cb func(*models.ChannelEdgeInfo, + ForEachChannel(ctx context.Context, cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error diff --git a/graph/db/kv_store.go b/graph/db/kv_store.go index 8fb330e81..02e6a4ab6 100644 --- a/graph/db/kv_store.go +++ b/graph/db/kv_store.go @@ -404,8 +404,9 @@ func (c *KVStore) AddrsForNode(ctx context.Context, // NOTE: If an edge can't be found, or wasn't advertised, then a nil pointer // for that particular channel edge routing policy will be passed into the // callback. -func (c *KVStore) ForEachChannel(cb func(*models.ChannelEdgeInfo, - *models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error { +func (c *KVStore) ForEachChannel(_ context.Context, + cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, + *models.ChannelEdgePolicy) error) error { return forEachChannel(c.db, cb) } diff --git a/graph/db/sql_store.go b/graph/db/sql_store.go index bc9064252..c8f80c9f8 100644 --- a/graph/db/sql_store.go +++ b/graph/db/sql_store.go @@ -1333,10 +1333,9 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo, // callback. // // NOTE: part of the V1Store interface. -func (s *SQLStore) ForEachChannel(cb func(*models.ChannelEdgeInfo, - *models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error { - - ctx := context.TODO() +func (s *SQLStore) ForEachChannel(ctx context.Context, + cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, + *models.ChannelEdgePolicy) error) error { handleChannel := func(db SQLQueries, row sqlc.ListChannelsWithPoliciesPaginatedRow) error { diff --git a/rpcserver.go b/rpcserver.go index 5b39c47ca..a092dda8d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -6730,7 +6730,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context, // Next, for each active channel we know of within the graph, create a // similar response which details both the edge information as well as // the routing policies of th nodes connecting the two edges. - err = graph.ForEachChannel(func(edgeInfo *models.ChannelEdgeInfo, + err = graph.ForEachChannel(ctx, func(edgeInfo *models.ChannelEdgeInfo, c1, c2 *models.ChannelEdgePolicy) error { // Do not include unannounced channels unless specifically