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
// 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)
}
+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
// 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
+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
// 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)
}
+3 -4
View File
@@ -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 {