graph/db: let ForEachChannel take a context

This commit is contained in:
Elle Mouton committed 2025-07-08 15:10:30 +02:00
1 parent f8d3a3f3ba
commit 046e106a17
5 files changed
+28 -22

No files matched your search

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