autopilot: remove the ForEachChannel method from Node interface

And instead make use of the new ForEachNodesChannels method which
uses a much more efficient method for iterating through nodes&channels.
This commit is contained in:
Elle Mouton
2025-08-03 17:22:56 +02:00
parent ce7fe84da7
commit 699e335954
5 changed files with 82 additions and 168 deletions

View File

@@ -242,25 +242,23 @@ func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
numNodes := 0
twoChans := false
nodes := make(map[NodeID]struct{})
err = graph.ForEachNode(
ctx, func(ctx context.Context, n Node) error {
err = graph.ForEachNodesChannels(
ctx, func(_ context.Context, node Node,
edges []*ChannelEdge) error {
numNodes++
nodes[n.PubKey()] = struct{}{}
nodes[node.PubKey()] = struct{}{}
numChans := 0
err := n.ForEachChannel(ctx,
func(_ context.Context, c ChannelEdge) error { //nolint:ll
numChans++
return nil
},
)
if err != nil {
return err
for range edges {
numChans++
}
twoChans = twoChans || (numChans == 2)
return nil
}, func() {
},
func() {
numNodes = 0
twoChans = false
clear(nodes)