graph/db: thread context through ForEachNodeDirectedChannel

This commit is contained in:
Elle Mouton committed 2026-02-25 15:33:34 +02:00
1 parent 2f0d2962dd
commit 6ccf93c2c9
10 files changed
+36 -31

No files matched your search

+3 -1
View File
@@ -1,6 +1,7 @@
package routing
import (
"context"
"fmt"
"github.com/lightningnetwork/lnd/fn/v2"
@@ -64,7 +65,8 @@ func newBandwidthManager(graph Graph, sourceNode route.Vertex,
// First, we'll collect the set of outbound edges from the target
// source node and add them to our bandwidth manager's map of channels.
err := graph.ForEachNodeDirectedChannel(
sourceNode, func(channel *graphdb.DirectedChannel) error {
context.TODO(), sourceNode,
func(channel *graphdb.DirectedChannel) error {
shortID := lnwire.NewShortChanIDFromInt(
channel.ChannelID,
)
+1 -1
View File
@@ -15,7 +15,7 @@ import (
type Graph interface {
// ForEachNodeDirectedChannel calls the callback for every channel of
// the given node.
ForEachNodeDirectedChannel(nodePub route.Vertex,
ForEachNodeDirectedChannel(ctx context.Context, nodePub route.Vertex,
cb func(channel *graphdb.DirectedChannel) error,
reset func()) error
+3 -2
View File
@@ -166,8 +166,9 @@ func (m *mockGraph) addChannel(id uint64, node1id, node2id byte,
// forEachNodeChannel calls the callback for every channel of the given node.
//
// NOTE: Part of the Graph interface.
func (m *mockGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
cb func(channel *graphdb.DirectedChannel) error, _ func()) error {
func (m *mockGraph) ForEachNodeDirectedChannel(_ context.Context,
nodePub route.Vertex, cb func(channel *graphdb.DirectedChannel) error,
_ func()) error {
// Look up the mock node.
node, ok := m.nodes[nodePub]
+4 -3
View File
@@ -578,7 +578,7 @@ func getOutgoingBalance(node route.Vertex, outgoingChans map[uint64]struct{},
// Iterate over all channels of the to node.
err := g.ForEachNodeDirectedChannel(
node, cb, func() {
context.TODO(), node, cb, func() {
max = 0
total = 0
},
@@ -1291,7 +1291,7 @@ func findBlindedPaths(g Graph, target route.Vertex,
nextTargetReset = nextTarget
)
err := g.ForEachNodeDirectedChannel(
nextTarget,
context.TODO(), nextTarget,
func(channel *graphdb.DirectedChannel) error {
// This is not the right channel, continue to
// the node's other channels.
@@ -1466,7 +1466,8 @@ func processNodeForBlindedPath(g Graph, node route.Vertex,
// Now, iterate over the node's channels in search for paths to this
// node that can be used for blinded paths
err = g.ForEachNodeDirectedChannel(
node, func(channel *graphdb.DirectedChannel) error {
context.TODO(), node,
func(channel *graphdb.DirectedChannel) error {
// Keep track of how many incoming channels this node
// has. We only use a node as an introduction node if it
// has channels other than the one that lead us to it.
+2 -1
View File
@@ -1,6 +1,7 @@
package routing
import (
"context"
"math"
"github.com/btcsuite/btcd/btcutil"
@@ -116,7 +117,7 @@ func (u *nodeEdgeUnifier) addGraphPolicies(g Graph) error {
// Iterate over all channels of the to node.
err := g.ForEachNodeDirectedChannel(
u.toNode, cb, func() {
context.TODO(), u.toNode, cb, func() {
channels = nil
},
)