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

@@ -50,20 +50,17 @@ func NewSimpleGraph(ctx context.Context, g ChannelGraph) (*SimpleGraph, error) {
// Iterate over each node and each channel and update the adj and the
// node index.
err := g.ForEachNode(ctx, func(ctx context.Context, node Node) error {
err := g.ForEachNodesChannels(ctx, func(_ context.Context,
node Node, channels []*ChannelEdge) error {
u := getNodeIndex(node.PubKey())
return node.ForEachChannel(
ctx, func(_ context.Context,
edge ChannelEdge) error {
for _, edge := range channels {
v := getNodeIndex(edge.Peer)
adj[u] = append(adj[u], v)
}
v := getNodeIndex(edge.Peer)
adj[u] = append(adj[u], v)
return nil
},
)
return nil
}, func() {
clear(adj)
clear(nodes)