multi: add reset to ForEachNode

This commit is contained in:
Elle Mouton committed 2025-07-15 11:25:09 +02:00
1 parent c32bf642d2
commit 21ac7ef6f4
9 files changed
+17 -13

No files matched your search

+2 -2
View File
@@ -121,7 +121,7 @@ func (d *dbNode) ForEachChannel(ctx context.Context,
//
// NOTE: Part of the autopilot.ChannelGraph interface.
func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
cb func(context.Context, Node) error, _ func()) error {
cb func(context.Context, Node) error, reset func()) error {
return d.db.ForEachNode(ctx, func(nodeTx graphdb.NodeRTx) error {
// We'll skip over any node that doesn't have any advertised
@@ -136,7 +136,7 @@ func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
}
return cb(ctx, node)
})
}, reset)
}
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
+1 -1
View File
@@ -229,7 +229,7 @@ type GraphSource interface {
// the callback returns an error, then the transaction is aborted and
// the iteration stops early. Any operations performed on the NodeTx
// passed to the call-back are executed under the same read transaction.
ForEachNode(context.Context, func(graphdb.NodeRTx) error) error
ForEachNode(context.Context, func(graphdb.NodeRTx) error, func()) error
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
// channel graph cache if one is available. It is less consistent than
+3 -3
View File
@@ -1454,7 +1454,7 @@ func TestGraphTraversalCacheable(t *testing.T) {
nodeMap[tx.Node().PubKeyBytes] = struct{}{}
return nil
})
}, func() {})
require.NoError(t, err)
require.Len(t, nodeMap, numNodes)
@@ -1583,7 +1583,7 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
err := graph.ForEachNode(ctx, func(tx NodeRTx) error {
delete(nodeIndex, tx.Node().Alias)
return nil
})
}, func() {})
require.NoError(t, err)
require.Len(t, nodeIndex, 0)
@@ -1693,7 +1693,7 @@ func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
numNodes++
return nil
})
}, func() {})
if err != nil {
_, _, line, _ := runtime.Caller(1)
t.Fatalf("line %v: unable to scan nodes: %v", line, err)
+2 -1
View File
@@ -102,7 +102,8 @@ type V1Store interface { //nolint:interfacebloat
// passed to the call-back are executed under the same read transaction
// and so, methods on the NodeTx object _MUST_ only be called from
// within the call-back.
ForEachNode(ctx context.Context, cb func(tx NodeRTx) error) error
ForEachNode(ctx context.Context, cb func(tx NodeRTx) error,
reset func()) error
// ForEachNodeCacheable iterates through all the stored vertices/nodes
// in the graph, executing the passed callback with each node
+1 -3
View File
@@ -802,9 +802,7 @@ func (c *KVStore) DisabledChannelIDs() ([]uint64, error) {
// executed under the same read transaction and so, methods on the NodeTx object
// _MUST_ only be called from within the call-back.
func (c *KVStore) ForEachNode(_ context.Context,
cb func(tx NodeRTx) error) error {
reset := func() {}
cb func(tx NodeRTx) error, reset func()) error {
return forEachNode(c.db, func(tx kvdb.RTx,
node *models.LightningNode) error {
+2
View File
@@ -401,6 +401,8 @@ func fetchAllNodes(t *testing.T, store V1Store) []*models.LightningNode {
nodes = append(nodes, node)
return nil
}, func() {
nodes = nil
})
require.NoError(t, err)
+1 -3
View File
@@ -785,9 +785,7 @@ func (s *SQLStore) ForEachSourceNodeChannel(ctx context.Context,
//
// NOTE: part of the V1Store interface.
func (s *SQLStore) ForEachNode(ctx context.Context,
cb func(tx NodeRTx) error) error {
reset := func() {}
cb func(tx NodeRTx) error, reset func()) error {
var lastID int64 = 0
handleNode := func(db SQLQueries, dbNode sqlc.Node) error {
+3
View File
@@ -82,6 +82,9 @@ func testGraphMigration(ht *lntest.HarnessTest) {
return nil
},
)
}, func() {
clear(edges)
numNodes = 0
})
require.NoError(ht, err)
require.Equal(ht, expNumNodes, numNodes)
+2
View File
@@ -6745,6 +6745,8 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
resp.Nodes = append(resp.Nodes, lnNode)
return nil
}, func() {
resp.Nodes = nil
})
if err != nil {
return nil, err