graph/db: expose reset in ForEachChannel
Add a `reset` call-back param to the V1Store ForEachChannel method.
This commit is contained in:
6 files changed
+18
-22
No files matched your search
+11
-13
@@ -935,7 +935,8 @@ func TestEdgePolicyCRUD(t *testing.T) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}, func() {},
|
||||||
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1385,7 +1386,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
|
|
||||||
delete(chanIndex, ei.ChannelID)
|
delete(chanIndex, ei.ChannelID)
|
||||||
return nil
|
return nil
|
||||||
})
|
}, func() {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Len(t, chanIndex, 0)
|
require.Len(t, chanIndex, 0)
|
||||||
|
|
||||||
@@ -1669,22 +1670,19 @@ 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(context.Background(),
|
err := graph.ForEachChannel(
|
||||||
func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
context.Background(), func(*models.ChannelEdgeInfo,
|
||||||
|
*models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error {
|
*models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
numChans++
|
numChans++
|
||||||
return nil
|
return nil
|
||||||
|
}, func() {
|
||||||
|
numChans = 0
|
||||||
},
|
},
|
||||||
); err != nil {
|
)
|
||||||
_, _, line, _ := runtime.Caller(1)
|
require.NoError(t, err)
|
||||||
t.Fatalf("line %v: unable to scan channels: %v", line, err)
|
require.Equal(t, n, numChans)
|
||||||
}
|
|
||||||
if numChans != n {
|
|
||||||
_, _, line, _ := runtime.Caller(1)
|
|
||||||
t.Fatalf("line %v: expected %v chans instead have %v", line,
|
|
||||||
n, numChans)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
||||||
|
|||||||
@@ -159,8 +159,8 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// 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(ctx context.Context, cb func(*models.ChannelEdgeInfo,
|
ForEachChannel(ctx context.Context, cb func(*models.ChannelEdgeInfo,
|
||||||
*models.ChannelEdgePolicy,
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error,
|
||||||
*models.ChannelEdgePolicy) error) error
|
reset func()) error
|
||||||
|
|
||||||
// ForEachChannelCacheable iterates through all the channel edges stored
|
// ForEachChannelCacheable iterates through all the channel edges stored
|
||||||
// within the graph and invokes the passed callback for each edge. The
|
// within the graph and invokes the passed callback for each edge. The
|
||||||
|
|||||||
@@ -406,9 +406,7 @@ func (c *KVStore) AddrsForNode(ctx context.Context,
|
|||||||
// callback.
|
// callback.
|
||||||
func (c *KVStore) ForEachChannel(_ context.Context,
|
func (c *KVStore) ForEachChannel(_ context.Context,
|
||||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||||
|
|
||||||
reset := func() {}
|
|
||||||
|
|
||||||
return forEachChannel(c.db, cb, reset)
|
return forEachChannel(c.db, cb, reset)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ func fetchAllChannelsAndPolicies(t *testing.T, store V1Store) chanSet {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}, func() {})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Sort the channels by their channel ID to ensure a consistent order.
|
// Sort the channels by their channel ID to ensure a consistent order.
|
||||||
|
|||||||
@@ -1343,9 +1343,7 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
|
|||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachChannel(ctx context.Context,
|
func (s *SQLStore) ForEachChannel(ctx context.Context,
|
||||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error, reset func()) error {
|
||||||
|
|
||||||
reset := func() {}
|
|
||||||
|
|
||||||
handleChannel := func(db SQLQueries,
|
handleChannel := func(db SQLQueries,
|
||||||
row sqlc.ListChannelsWithPoliciesPaginatedRow) error {
|
row sqlc.ListChannelsWithPoliciesPaginatedRow) error {
|
||||||
|
|||||||
@@ -6768,6 +6768,8 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
resp.Edges = append(resp.Edges, edge)
|
resp.Edges = append(resp.Edges, edge)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
}, func() {
|
||||||
|
resp.Edges = nil
|
||||||
})
|
})
|
||||||
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
if err != nil && !errors.Is(err, graphdb.ErrGraphNoEdgesFound) {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in new issue
Block a user