Merge pull request #10043 from ellemouton/ctx3
multi: add context.Context param to more graphdb.V1Store methods
This commit is contained in:
17 files changed
+124
-109
No files matched your search
+2
-2
@@ -123,7 +123,7 @@ func (d *dbNode) ForEachChannel(ctx context.Context,
|
|||||||
func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
|
func (d *databaseChannelGraph) ForEachNode(ctx context.Context,
|
||||||
cb func(context.Context, Node) error) error {
|
cb func(context.Context, Node) error) error {
|
||||||
|
|
||||||
return d.db.ForEachNode(func(nodeTx graphdb.NodeRTx) error {
|
return d.db.ForEachNode(ctx, func(nodeTx graphdb.NodeRTx) error {
|
||||||
// We'll skip over any node that doesn't have any advertised
|
// We'll skip over any node that doesn't have any advertised
|
||||||
// addresses. As we won't be able to reach them to actually
|
// addresses. As we won't be able to reach them to actually
|
||||||
// open any channels.
|
// open any channels.
|
||||||
@@ -219,7 +219,7 @@ func (nc dbNodeCached) ForEachChannel(ctx context.Context,
|
|||||||
func (dc *databaseChannelGraphCached) ForEachNode(ctx context.Context,
|
func (dc *databaseChannelGraphCached) ForEachNode(ctx context.Context,
|
||||||
cb func(context.Context, Node) error) error {
|
cb func(context.Context, Node) error) error {
|
||||||
|
|
||||||
return dc.db.ForEachNodeCached(func(n route.Vertex,
|
return dc.db.ForEachNodeCached(ctx, func(n route.Vertex,
|
||||||
channels map[uint64]*graphdb.DirectedChannel) error {
|
channels map[uint64]*graphdb.DirectedChannel) error {
|
||||||
|
|
||||||
if len(channels) > 0 {
|
if len(channels) > 0 {
|
||||||
|
|||||||
@@ -228,12 +228,12 @@ type GraphSource interface {
|
|||||||
// the callback returns an error, then the transaction is aborted and
|
// the callback returns an error, then the transaction is aborted and
|
||||||
// the iteration stops early. Any operations performed on the NodeTx
|
// the iteration stops early. Any operations performed on the NodeTx
|
||||||
// passed to the call-back are executed under the same read transaction.
|
// passed to the call-back are executed under the same read transaction.
|
||||||
ForEachNode(func(graphdb.NodeRTx) error) error
|
ForEachNode(context.Context, func(graphdb.NodeRTx) error) error
|
||||||
|
|
||||||
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
|
// ForEachNodeCached is similar to ForEachNode, but it utilizes the
|
||||||
// channel graph cache if one is available. It is less consistent than
|
// channel graph cache if one is available. It is less consistent than
|
||||||
// ForEachNode since any further calls are made across multiple
|
// ForEachNode since any further calls are made across multiple
|
||||||
// transactions.
|
// transactions.
|
||||||
ForEachNodeCached(cb func(node route.Vertex,
|
ForEachNodeCached(ctx context.Context, cb func(node route.Vertex,
|
||||||
chans map[uint64]*graphdb.DirectedChannel) error) error
|
chans map[uint64]*graphdb.DirectedChannel) error) error
|
||||||
}
|
}
|
||||||
@@ -731,12 +731,12 @@ func (t *testNodeTx) Node() *models.LightningNode {
|
|||||||
func (t *testNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
|
func (t *testNodeTx) ForEachChannel(f func(*models.ChannelEdgeInfo,
|
||||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return t.db.db.ForEachNodeChannel(t.node.PubKeyBytes, func(
|
return t.db.db.ForEachNodeChannel(context.Background(),
|
||||||
edge *models.ChannelEdgeInfo, policy1,
|
t.node.PubKeyBytes, func(edge *models.ChannelEdgeInfo, policy1,
|
||||||
policy2 *models.ChannelEdgePolicy) error {
|
policy2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
return f(edge, policy1, policy2)
|
return f(edge, policy1, policy2)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testNodeTx) FetchNode(pub route.Vertex) (graphdb.NodeRTx, error) {
|
func (t *testNodeTx) FetchNode(pub route.Vertex) (graphdb.NodeRTx, error) {
|
||||||
|
|||||||
@@ -1709,7 +1709,7 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(ctx context.Context,
|
|||||||
havePublicChannels bool
|
havePublicChannels bool
|
||||||
edgesToUpdate []updateTuple
|
edgesToUpdate []updateTuple
|
||||||
)
|
)
|
||||||
err := d.cfg.Graph.ForAllOutgoingChannels(func(
|
err := d.cfg.Graph.ForAllOutgoingChannels(ctx, func(
|
||||||
info *models.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
edge *models.ChannelEdgePolicy) error {
|
edge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
@@ -211,8 +211,9 @@ func (r *mockGraphSource) ForEachNode(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) ForAllOutgoingChannels(cb func(
|
func (r *mockGraphSource) ForAllOutgoingChannels(_ context.Context,
|
||||||
i *models.ChannelEdgeInfo, c *models.ChannelEdgePolicy) error) error {
|
cb func(i *models.ChannelEdgeInfo,
|
||||||
|
c *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
@@ -3716,7 +3717,7 @@ out:
|
|||||||
// policy of all of them.
|
// policy of all of them.
|
||||||
const newTimeLockDelta = 100
|
const newTimeLockDelta = 100
|
||||||
var edgesToUpdate []EdgeWithInfo
|
var edgesToUpdate []EdgeWithInfo
|
||||||
err = ctx.router.ForAllOutgoingChannels(func(
|
err = ctx.router.ForAllOutgoingChannels(context.Background(), func(
|
||||||
info *models.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
edge *models.ChannelEdgePolicy) error {
|
edge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -1275,10 +1275,11 @@ func (b *Builder) FetchLightningNode(ctx context.Context,
|
|||||||
// the router.
|
// the router.
|
||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (b *Builder) ForAllOutgoingChannels(cb func(*models.ChannelEdgeInfo,
|
func (b *Builder) ForAllOutgoingChannels(ctx context.Context,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
cb func(*models.ChannelEdgeInfo,
|
||||||
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return b.cfg.Graph.ForEachNodeChannel(b.cfg.SelfNode,
|
return b.cfg.Graph.ForEachNodeChannel(ctx, b.cfg.SelfNode,
|
||||||
func(c *models.ChannelEdgeInfo, e *models.ChannelEdgePolicy,
|
func(c *models.ChannelEdgeInfo, e *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
+7
-6
@@ -75,7 +75,7 @@ func (c *ChannelGraph) Start() error {
|
|||||||
defer log.Debug("ChannelGraph started")
|
defer log.Debug("ChannelGraph started")
|
||||||
|
|
||||||
if c.graphCache != nil {
|
if c.graphCache != nil {
|
||||||
if err := c.populateCache(); err != nil {
|
if err := c.populateCache(context.TODO()); err != nil {
|
||||||
return fmt.Errorf("could not populate the graph "+
|
return fmt.Errorf("could not populate the graph "+
|
||||||
"cache: %w", err)
|
"cache: %w", err)
|
||||||
}
|
}
|
||||||
@@ -159,12 +159,12 @@ func (c *ChannelGraph) handleTopologySubscriptions() {
|
|||||||
// populateCache loads the entire channel graph into the in-memory graph cache.
|
// populateCache loads the entire channel graph into the in-memory graph cache.
|
||||||
//
|
//
|
||||||
// NOTE: This should only be called if the graphCache has been constructed.
|
// NOTE: This should only be called if the graphCache has been constructed.
|
||||||
func (c *ChannelGraph) populateCache() error {
|
func (c *ChannelGraph) populateCache(ctx context.Context) error {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
log.Info("Populating in-memory channel graph, this might take a " +
|
log.Info("Populating in-memory channel graph, this might take a " +
|
||||||
"while...")
|
"while...")
|
||||||
|
|
||||||
err := c.V1Store.ForEachNodeCacheable(func(node route.Vertex,
|
err := c.V1Store.ForEachNodeCacheable(ctx, func(node route.Vertex,
|
||||||
features *lnwire.FeatureVector) error {
|
features *lnwire.FeatureVector) error {
|
||||||
|
|
||||||
c.graphCache.AddNodeFeatures(node, features)
|
c.graphCache.AddNodeFeatures(node, features)
|
||||||
@@ -245,14 +245,15 @@ func (c *ChannelGraph) GraphSession(cb func(graph NodeTraverser) error) error {
|
|||||||
// graph, executing the passed callback with each node encountered.
|
// graph, executing the passed callback with each node encountered.
|
||||||
//
|
//
|
||||||
// NOTE: The callback contents MUST not be modified.
|
// NOTE: The callback contents MUST not be modified.
|
||||||
func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
func (c *ChannelGraph) ForEachNodeCached(ctx context.Context,
|
||||||
chans map[uint64]*DirectedChannel) error) error {
|
cb func(node route.Vertex,
|
||||||
|
chans map[uint64]*DirectedChannel) error) error {
|
||||||
|
|
||||||
if c.graphCache != nil {
|
if c.graphCache != nil {
|
||||||
return c.graphCache.ForEachNode(cb)
|
return c.graphCache.ForEachNode(cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.V1Store.ForEachNodeCached(cb)
|
return c.V1Store.ForEachNodeCached(ctx, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddLightningNode adds a vertex/node to the graph database. If the node is not
|
// AddLightningNode adds a vertex/node to the graph database. If the node is not
|
||||||
|
|||||||
+33
-24
@@ -922,15 +922,20 @@ func TestEdgePolicyCRUD(t *testing.T) {
|
|||||||
// Use the ForEachChannel method to fetch the policies and
|
// Use the ForEachChannel method to fetch the policies and
|
||||||
// assert that the deserialized policies match the original
|
// assert that the deserialized policies match the original
|
||||||
// ones.
|
// ones.
|
||||||
err := graph.ForEachChannel(func(info *models.ChannelEdgeInfo,
|
err := graph.ForEachChannel(
|
||||||
policy1 *models.ChannelEdgePolicy,
|
ctx, func(info *models.ChannelEdgeInfo,
|
||||||
policy2 *models.ChannelEdgePolicy) error {
|
policy1 *models.ChannelEdgePolicy,
|
||||||
|
policy2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
require.NoError(t, compareEdgePolicies(edge1, policy1))
|
require.NoError(
|
||||||
require.NoError(t, compareEdgePolicies(edge2, policy2))
|
t, compareEdgePolicies(edge1, policy1),
|
||||||
|
)
|
||||||
|
require.NoError(
|
||||||
|
t, compareEdgePolicies(edge2, policy2),
|
||||||
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1311,7 +1316,7 @@ func TestForEachSourceNodeChannel(t *testing.T) {
|
|||||||
|
|
||||||
// Now, we'll use the ForEachSourceNodeChannel and assert that it
|
// Now, we'll use the ForEachSourceNodeChannel and assert that it
|
||||||
// returns the expected data in the call-back.
|
// returns the expected data in the call-back.
|
||||||
err := graph.ForEachSourceNodeChannel(func(chanPoint wire.OutPoint,
|
err := graph.ForEachSourceNodeChannel(ctx, func(chanPoint wire.OutPoint,
|
||||||
havePolicy bool, otherNode *models.LightningNode) error {
|
havePolicy bool, otherNode *models.LightningNode) error {
|
||||||
|
|
||||||
require.Contains(t, expectedSrcChans, chanPoint)
|
require.Contains(t, expectedSrcChans, chanPoint)
|
||||||
@@ -1332,6 +1337,7 @@ func TestForEachSourceNodeChannel(t *testing.T) {
|
|||||||
|
|
||||||
func TestGraphTraversal(t *testing.T) {
|
func TestGraphTraversal(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
graph := MakeTestGraph(t)
|
graph := MakeTestGraph(t)
|
||||||
|
|
||||||
@@ -1352,7 +1358,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
// set of channels (to force the fall back), we should find all the
|
// set of channels (to force the fall back), we should find all the
|
||||||
// channel as well as the nodes included.
|
// channel as well as the nodes included.
|
||||||
graph.graphCache = nil
|
graph.graphCache = nil
|
||||||
err := graph.ForEachNodeCached(func(node route.Vertex,
|
err := graph.ForEachNodeCached(ctx, func(node route.Vertex,
|
||||||
chans map[uint64]*DirectedChannel) error {
|
chans map[uint64]*DirectedChannel) error {
|
||||||
|
|
||||||
if _, ok := nodeIndex[node]; !ok {
|
if _, ok := nodeIndex[node]; !ok {
|
||||||
@@ -1373,7 +1379,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
// Iterate through all the known channels within the graph DB, once
|
// Iterate through all the known channels within the graph DB, once
|
||||||
// again if the map is empty that indicates that all edges have
|
// again if the map is empty that indicates that all edges have
|
||||||
// properly been reached.
|
// properly been reached.
|
||||||
err = graph.ForEachChannel(func(ei *models.ChannelEdgeInfo,
|
err = graph.ForEachChannel(ctx, func(ei *models.ChannelEdgeInfo,
|
||||||
_ *models.ChannelEdgePolicy,
|
_ *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -1387,7 +1393,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
// outgoing channels for a particular node.
|
// outgoing channels for a particular node.
|
||||||
numNodeChans := 0
|
numNodeChans := 0
|
||||||
firstNode, secondNode := nodeList[0], nodeList[1]
|
firstNode, secondNode := nodeList[0], nodeList[1]
|
||||||
err = graph.ForEachNodeChannel(firstNode.PubKeyBytes,
|
err = graph.ForEachNodeChannel(ctx, firstNode.PubKeyBytes,
|
||||||
func(_ *models.ChannelEdgeInfo, outEdge,
|
func(_ *models.ChannelEdgeInfo, outEdge,
|
||||||
inEdge *models.ChannelEdgePolicy) error {
|
inEdge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -1427,6 +1433,7 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
// working correctly.
|
// working correctly.
|
||||||
func TestGraphTraversalCacheable(t *testing.T) {
|
func TestGraphTraversalCacheable(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
graph := MakeTestGraph(t)
|
graph := MakeTestGraph(t)
|
||||||
|
|
||||||
@@ -1440,7 +1447,7 @@ func TestGraphTraversalCacheable(t *testing.T) {
|
|||||||
// Create a map of all nodes with the iteration we know works (because
|
// Create a map of all nodes with the iteration we know works (because
|
||||||
// it is tested in another test).
|
// it is tested in another test).
|
||||||
nodeMap := make(map[route.Vertex]struct{})
|
nodeMap := make(map[route.Vertex]struct{})
|
||||||
err := graph.ForEachNode(func(tx NodeRTx) error {
|
err := graph.ForEachNode(ctx, func(tx NodeRTx) error {
|
||||||
nodeMap[tx.Node().PubKeyBytes] = struct{}{}
|
nodeMap[tx.Node().PubKeyBytes] = struct{}{}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -1452,7 +1459,7 @@ func TestGraphTraversalCacheable(t *testing.T) {
|
|||||||
// iterating over each node, once again if the map is empty that
|
// iterating over each node, once again if the map is empty that
|
||||||
// indicates that all edges have properly been reached.
|
// indicates that all edges have properly been reached.
|
||||||
var nodes []route.Vertex
|
var nodes []route.Vertex
|
||||||
err = graph.ForEachNodeCacheable(func(node route.Vertex,
|
err = graph.ForEachNodeCacheable(ctx, func(node route.Vertex,
|
||||||
features *lnwire.FeatureVector) error {
|
features *lnwire.FeatureVector) error {
|
||||||
|
|
||||||
delete(nodeMap, node)
|
delete(nodeMap, node)
|
||||||
@@ -1570,7 +1577,7 @@ func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
|
|||||||
|
|
||||||
// Iterate over each node as returned by the graph, if all nodes are
|
// Iterate over each node as returned by the graph, if all nodes are
|
||||||
// reached, then the map created above should be empty.
|
// reached, then the map created above should be empty.
|
||||||
err := graph.ForEachNode(func(tx NodeRTx) error {
|
err := graph.ForEachNode(ctx, func(tx NodeRTx) error {
|
||||||
delete(nodeIndex, tx.Node().Alias)
|
delete(nodeIndex, tx.Node().Alias)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -1662,13 +1669,14 @@ 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(func(*models.ChannelEdgeInfo,
|
if err := graph.ForEachChannel(context.Background(),
|
||||||
*models.ChannelEdgePolicy,
|
func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error {
|
*models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
numChans++
|
numChans++
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
},
|
||||||
|
); err != nil {
|
||||||
_, _, line, _ := runtime.Caller(1)
|
_, _, line, _ := runtime.Caller(1)
|
||||||
t.Fatalf("line %v: unable to scan channels: %v", line, err)
|
t.Fatalf("line %v: unable to scan channels: %v", line, err)
|
||||||
}
|
}
|
||||||
@@ -1681,7 +1689,7 @@ func assertNumChans(t *testing.T, graph *ChannelGraph, n int) {
|
|||||||
|
|
||||||
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
func assertNumNodes(t *testing.T, graph *ChannelGraph, n int) {
|
||||||
numNodes := 0
|
numNodes := 0
|
||||||
err := graph.ForEachNode(func(tx NodeRTx) error {
|
err := graph.ForEachNode(context.Background(), func(tx NodeRTx) error {
|
||||||
numNodes++
|
numNodes++
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -3138,7 +3146,7 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
|||||||
expectedOut bool) {
|
expectedOut bool) {
|
||||||
|
|
||||||
calls := 0
|
calls := 0
|
||||||
err := graph.ForEachNodeChannel(node.PubKeyBytes,
|
err := graph.ForEachNodeChannel(ctx, node.PubKeyBytes,
|
||||||
func(_ *models.ChannelEdgeInfo, outEdge,
|
func(_ *models.ChannelEdgeInfo, outEdge,
|
||||||
inEdge *models.ChannelEdgePolicy) error {
|
inEdge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -4201,6 +4209,7 @@ func TestBatchedUpdateEdgePolicy(t *testing.T) {
|
|||||||
// allocations and the total memory consumed by the full graph traversal.
|
// allocations and the total memory consumed by the full graph traversal.
|
||||||
func BenchmarkForEachChannel(b *testing.B) {
|
func BenchmarkForEachChannel(b *testing.B) {
|
||||||
graph := MakeTestGraph(b)
|
graph := MakeTestGraph(b)
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
const numNodes = 100
|
const numNodes = 100
|
||||||
const numChannels = 4
|
const numChannels = 4
|
||||||
@@ -4215,7 +4224,7 @@ func BenchmarkForEachChannel(b *testing.B) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
var nodes []route.Vertex
|
var nodes []route.Vertex
|
||||||
err := graph.ForEachNodeCacheable(func(node route.Vertex,
|
err := graph.ForEachNodeCacheable(ctx, func(node route.Vertex,
|
||||||
vector *lnwire.FeatureVector) error {
|
vector *lnwire.FeatureVector) error {
|
||||||
|
|
||||||
nodes = append(nodes, node)
|
nodes = append(nodes, node)
|
||||||
@@ -4241,7 +4250,7 @@ func BenchmarkForEachChannel(b *testing.B) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := graph.ForEachNodeChannel(n, cb)
|
err := graph.ForEachNodeChannel(ctx, n, cb)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,9 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// node, executing the passed callback on each. The call-back is
|
// node, executing the passed callback on each. The call-back is
|
||||||
// provided with the channel's outpoint, whether we have a policy for
|
// provided with the channel's outpoint, whether we have a policy for
|
||||||
// the channel and the channel peer's node information.
|
// the channel and the channel peer's node information.
|
||||||
ForEachSourceNodeChannel(cb func(chanPoint wire.OutPoint,
|
ForEachSourceNodeChannel(ctx context.Context,
|
||||||
havePolicy bool, otherNode *models.LightningNode) error) error
|
cb func(chanPoint wire.OutPoint, havePolicy bool,
|
||||||
|
otherNode *models.LightningNode) error) error
|
||||||
|
|
||||||
// ForEachNodeChannel iterates through all channels of the given node,
|
// ForEachNodeChannel iterates through all channels of the given node,
|
||||||
// executing the passed callback with an edge info structure and the
|
// executing the passed callback with an edge info structure and the
|
||||||
@@ -82,7 +83,7 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// to the caller.
|
// to the caller.
|
||||||
//
|
//
|
||||||
// Unknown policies are passed into the callback as nil values.
|
// Unknown policies are passed into the callback as nil values.
|
||||||
ForEachNodeChannel(nodePub route.Vertex,
|
ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error
|
*models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
@@ -90,7 +91,7 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// DirectedChannel data to the call-back.
|
// DirectedChannel data to the call-back.
|
||||||
//
|
//
|
||||||
// NOTE: The callback contents MUST not be modified.
|
// NOTE: The callback contents MUST not be modified.
|
||||||
ForEachNodeCached(cb func(node route.Vertex,
|
ForEachNodeCached(ctx context.Context, cb func(node route.Vertex,
|
||||||
chans map[uint64]*DirectedChannel) error) error
|
chans map[uint64]*DirectedChannel) error) error
|
||||||
|
|
||||||
// ForEachNode iterates through all the stored vertices/nodes in the
|
// ForEachNode iterates through all the stored vertices/nodes in the
|
||||||
@@ -100,13 +101,13 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// passed to the call-back are executed under the same read transaction
|
// passed to the call-back are executed under the same read transaction
|
||||||
// and so, methods on the NodeTx object _MUST_ only be called from
|
// and so, methods on the NodeTx object _MUST_ only be called from
|
||||||
// within the call-back.
|
// within the call-back.
|
||||||
ForEachNode(cb func(tx NodeRTx) error) error
|
ForEachNode(ctx context.Context, cb func(tx NodeRTx) error) error
|
||||||
|
|
||||||
// ForEachNodeCacheable iterates through all the stored vertices/nodes
|
// ForEachNodeCacheable iterates through all the stored vertices/nodes
|
||||||
// in the graph, executing the passed callback with each node
|
// in the graph, executing the passed callback with each node
|
||||||
// encountered. If the callback returns an error, then the transaction
|
// encountered. If the callback returns an error, then the transaction
|
||||||
// is aborted and the iteration stops early.
|
// is aborted and the iteration stops early.
|
||||||
ForEachNodeCacheable(cb func(route.Vertex,
|
ForEachNodeCacheable(ctx context.Context, cb func(route.Vertex,
|
||||||
*lnwire.FeatureVector) error) error
|
*lnwire.FeatureVector) error) error
|
||||||
|
|
||||||
// LookupAlias attempts to return the alias as advertised by the target
|
// LookupAlias attempts to return the alias as advertised by the target
|
||||||
@@ -157,7 +158,7 @@ type V1Store interface { //nolint:interfacebloat
|
|||||||
// NOTE: If an edge can't be found, or wasn't advertised, then a nil
|
// NOTE: If an edge can't be found, or wasn't advertised, then a nil
|
||||||
// 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(cb func(*models.ChannelEdgeInfo,
|
ForEachChannel(ctx context.Context, cb func(*models.ChannelEdgeInfo,
|
||||||
*models.ChannelEdgePolicy,
|
*models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error
|
*models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
|
|||||||
+15
-10
@@ -404,8 +404,9 @@ func (c *KVStore) AddrsForNode(ctx context.Context,
|
|||||||
// NOTE: If an edge can't be found, or wasn't advertised, then a nil pointer
|
// NOTE: If an edge can't be found, or wasn't advertised, then a nil pointer
|
||||||
// for that particular channel edge routing policy will be passed into the
|
// for that particular channel edge routing policy will be passed into the
|
||||||
// callback.
|
// callback.
|
||||||
func (c *KVStore) ForEachChannel(cb func(*models.ChannelEdgeInfo,
|
func (c *KVStore) ForEachChannel(_ context.Context,
|
||||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return forEachChannel(c.db, cb)
|
return forEachChannel(c.db, cb)
|
||||||
}
|
}
|
||||||
@@ -666,8 +667,9 @@ func (c *KVStore) FetchNodeFeatures(nodePub route.Vertex) (
|
|||||||
// data to the call-back.
|
// data to the call-back.
|
||||||
//
|
//
|
||||||
// NOTE: The callback contents MUST not be modified.
|
// NOTE: The callback contents MUST not be modified.
|
||||||
func (c *KVStore) ForEachNodeCached(cb func(node route.Vertex,
|
func (c *KVStore) ForEachNodeCached(_ context.Context,
|
||||||
chans map[uint64]*DirectedChannel) error) error {
|
cb func(node route.Vertex,
|
||||||
|
chans map[uint64]*DirectedChannel) error) error {
|
||||||
|
|
||||||
// Otherwise call back to a version that uses the database directly.
|
// Otherwise call back to a version that uses the database directly.
|
||||||
// We'll iterate over each node, then the set of channels for each
|
// We'll iterate over each node, then the set of channels for each
|
||||||
@@ -788,7 +790,9 @@ func (c *KVStore) DisabledChannelIDs() ([]uint64, error) {
|
|||||||
// early. Any operations performed on the NodeTx passed to the call-back are
|
// early. Any operations performed on the NodeTx passed to the call-back are
|
||||||
// executed under the same read transaction and so, methods on the NodeTx object
|
// executed under the same read transaction and so, methods on the NodeTx object
|
||||||
// _MUST_ only be called from within the call-back.
|
// _MUST_ only be called from within the call-back.
|
||||||
func (c *KVStore) ForEachNode(cb func(tx NodeRTx) error) error {
|
func (c *KVStore) ForEachNode(_ context.Context,
|
||||||
|
cb func(tx NodeRTx) error) error {
|
||||||
|
|
||||||
return forEachNode(c.db, func(tx kvdb.RTx,
|
return forEachNode(c.db, func(tx kvdb.RTx,
|
||||||
node *models.LightningNode) error {
|
node *models.LightningNode) error {
|
||||||
|
|
||||||
@@ -841,8 +845,8 @@ func forEachNode(db kvdb.Backend,
|
|||||||
// graph, executing the passed callback with each node encountered. If the
|
// graph, executing the passed callback with each node encountered. If the
|
||||||
// callback returns an error, then the transaction is aborted and the iteration
|
// callback returns an error, then the transaction is aborted and the iteration
|
||||||
// stops early.
|
// stops early.
|
||||||
func (c *KVStore) ForEachNodeCacheable(cb func(route.Vertex,
|
func (c *KVStore) ForEachNodeCacheable(_ context.Context,
|
||||||
*lnwire.FeatureVector) error) error {
|
cb func(route.Vertex, *lnwire.FeatureVector) error) error {
|
||||||
|
|
||||||
traversal := func(tx kvdb.RTx) error {
|
traversal := func(tx kvdb.RTx) error {
|
||||||
// First grab the nodes bucket which stores the mapping from
|
// First grab the nodes bucket which stores the mapping from
|
||||||
@@ -3242,7 +3246,7 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
|||||||
// halted with the error propagated back up to the caller.
|
// halted with the error propagated back up to the caller.
|
||||||
//
|
//
|
||||||
// Unknown policies are passed into the callback as nil values.
|
// Unknown policies are passed into the callback as nil values.
|
||||||
func (c *KVStore) ForEachNodeChannel(nodePub route.Vertex,
|
func (c *KVStore) ForEachNodeChannel(_ context.Context, nodePub route.Vertex,
|
||||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
@@ -3258,8 +3262,9 @@ func (c *KVStore) ForEachNodeChannel(nodePub route.Vertex,
|
|||||||
// executing the passed callback on each. The callback is provided with the
|
// executing the passed callback on each. The callback is provided with the
|
||||||
// channel's outpoint, whether we have a policy for the channel and the channel
|
// channel's outpoint, whether we have a policy for the channel and the channel
|
||||||
// peer's node information.
|
// peer's node information.
|
||||||
func (c *KVStore) ForEachSourceNodeChannel(cb func(chanPoint wire.OutPoint,
|
func (c *KVStore) ForEachSourceNodeChannel(_ context.Context,
|
||||||
havePolicy bool, otherNode *models.LightningNode) error) error {
|
cb func(chanPoint wire.OutPoint, havePolicy bool,
|
||||||
|
otherNode *models.LightningNode) error) error {
|
||||||
|
|
||||||
return kvdb.View(c.db, func(tx kvdb.RTx) error {
|
return kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||||
nodes := tx.ReadBucket(nodeBucket)
|
nodes := tx.ReadBucket(nodeBucket)
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ func assertInSync(t *testing.T, kvDB *KVStore, sqlDB *SQLStore,
|
|||||||
func fetchAllNodes(t *testing.T, store V1Store) []*models.LightningNode {
|
func fetchAllNodes(t *testing.T, store V1Store) []*models.LightningNode {
|
||||||
nodes := make([]*models.LightningNode, 0)
|
nodes := make([]*models.LightningNode, 0)
|
||||||
|
|
||||||
err := store.ForEachNode(func(tx NodeRTx) error {
|
err := store.ForEachNode(context.Background(), func(tx NodeRTx) error {
|
||||||
node := tx.Node()
|
node := tx.Node()
|
||||||
|
|
||||||
// Call PubKey to ensure the objects cached pubkey is set so that
|
// Call PubKey to ensure the objects cached pubkey is set so that
|
||||||
|
|||||||
+15
-24
@@ -724,10 +724,9 @@ func (s *SQLStore) updateEdgeCache(e *models.ChannelEdgePolicy,
|
|||||||
// peer's node information.
|
// peer's node information.
|
||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachSourceNodeChannel(cb func(chanPoint wire.OutPoint,
|
func (s *SQLStore) ForEachSourceNodeChannel(ctx context.Context,
|
||||||
havePolicy bool, otherNode *models.LightningNode) error) error {
|
cb func(chanPoint wire.OutPoint, havePolicy bool,
|
||||||
|
otherNode *models.LightningNode) error) error {
|
||||||
var ctx = context.TODO()
|
|
||||||
|
|
||||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||||
nodeID, nodePub, err := s.getSourceNode(ctx, db, ProtocolV1)
|
nodeID, nodePub, err := s.getSourceNode(ctx, db, ProtocolV1)
|
||||||
@@ -784,12 +783,10 @@ func (s *SQLStore) ForEachSourceNodeChannel(cb func(chanPoint wire.OutPoint,
|
|||||||
// _MUST_ only be called from within the call-back.
|
// _MUST_ only be called from within the call-back.
|
||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachNode(cb func(tx NodeRTx) error) error {
|
func (s *SQLStore) ForEachNode(ctx context.Context,
|
||||||
var (
|
cb func(tx NodeRTx) error) error {
|
||||||
ctx = context.TODO()
|
|
||||||
lastID int64 = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
|
var lastID int64 = 0
|
||||||
handleNode := func(db SQLQueries, dbNode sqlc.Node) error {
|
handleNode := func(db SQLQueries, dbNode sqlc.Node) error {
|
||||||
node, err := buildNode(ctx, db, &dbNode)
|
node, err := buildNode(ctx, db, &dbNode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -924,10 +921,8 @@ func (s *SQLStore) ForEachNodeDirectedChannel(nodePub route.Vertex,
|
|||||||
// stops early.
|
// stops early.
|
||||||
//
|
//
|
||||||
// NOTE: This is a part of the V1Store interface.
|
// NOTE: This is a part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachNodeCacheable(cb func(route.Vertex,
|
func (s *SQLStore) ForEachNodeCacheable(ctx context.Context,
|
||||||
*lnwire.FeatureVector) error) error {
|
cb func(route.Vertex, *lnwire.FeatureVector) error) error {
|
||||||
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
err := s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||||
return forEachNodeCacheable(ctx, db, func(nodeID int64,
|
return forEachNodeCacheable(ctx, db, func(nodeID int64,
|
||||||
@@ -959,12 +954,10 @@ func (s *SQLStore) ForEachNodeCacheable(cb func(route.Vertex,
|
|||||||
// Unknown policies are passed into the callback as nil values.
|
// Unknown policies are passed into the callback as nil values.
|
||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachNodeChannel(nodePub route.Vertex,
|
func (s *SQLStore) ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
var ctx = context.TODO()
|
|
||||||
|
|
||||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||||
dbNode, err := db.GetNodeByPubKey(
|
dbNode, err := db.GetNodeByPubKey(
|
||||||
ctx, sqlc.GetNodeByPubKeyParams{
|
ctx, sqlc.GetNodeByPubKeyParams{
|
||||||
@@ -1109,10 +1102,9 @@ func (s *SQLStore) ChanUpdatesInHorizon(startTime,
|
|||||||
// NOTE: The callback contents MUST not be modified.
|
// NOTE: The callback contents MUST not be modified.
|
||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachNodeCached(cb func(node route.Vertex,
|
func (s *SQLStore) ForEachNodeCached(ctx context.Context,
|
||||||
chans map[uint64]*DirectedChannel) error) error {
|
cb func(node route.Vertex,
|
||||||
|
chans map[uint64]*DirectedChannel) error) error {
|
||||||
var ctx = context.TODO()
|
|
||||||
|
|
||||||
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
return s.db.ExecTx(ctx, sqldb.ReadTxOpt(), func(db SQLQueries) error {
|
||||||
return forEachNodeCacheable(ctx, db, func(nodeID int64,
|
return forEachNodeCacheable(ctx, db, func(nodeID int64,
|
||||||
@@ -1336,10 +1328,9 @@ func (s *SQLStore) ForEachChannelCacheable(cb func(*models.CachedEdgeInfo,
|
|||||||
// callback.
|
// callback.
|
||||||
//
|
//
|
||||||
// NOTE: part of the V1Store interface.
|
// NOTE: part of the V1Store interface.
|
||||||
func (s *SQLStore) ForEachChannel(cb func(*models.ChannelEdgeInfo,
|
func (s *SQLStore) ForEachChannel(ctx context.Context,
|
||||||
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
|
*models.ChannelEdgePolicy) error) error {
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
handleChannel := func(db SQLQueries,
|
handleChannel := func(db SQLQueries,
|
||||||
row sqlc.ListChannelsWithPoliciesPaginatedRow) error {
|
row sqlc.ListChannelsWithPoliciesPaginatedRow) error {
|
||||||
|
|||||||
+4
-3
@@ -70,8 +70,9 @@ type ChannelGraphSource interface {
|
|||||||
// ForAllOutgoingChannels is used to iterate over all channels
|
// ForAllOutgoingChannels is used to iterate over all channels
|
||||||
// emanating from the "source" node which is the center of the
|
// emanating from the "source" node which is the center of the
|
||||||
// star-graph.
|
// star-graph.
|
||||||
ForAllOutgoingChannels(cb func(c *models.ChannelEdgeInfo,
|
ForAllOutgoingChannels(ctx context.Context,
|
||||||
e *models.ChannelEdgePolicy) error) error
|
cb func(c *models.ChannelEdgeInfo,
|
||||||
|
e *models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
// CurrentBlockHeight returns the block height from POV of the router
|
// CurrentBlockHeight returns the block height from POV of the router
|
||||||
// subsystem.
|
// subsystem.
|
||||||
@@ -257,7 +258,7 @@ type DB interface {
|
|||||||
// to the caller.
|
// to the caller.
|
||||||
//
|
//
|
||||||
// Unknown policies are passed into the callback as nil values.
|
// Unknown policies are passed into the callback as nil values.
|
||||||
ForEachNodeChannel(nodePub route.Vertex,
|
ForEachNodeChannel(ctx context.Context, nodePub route.Vertex,
|
||||||
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
cb func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*models.ChannelEdgePolicy) error) error
|
*models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
|
|||||||
@@ -40,8 +40,9 @@ type Manager struct {
|
|||||||
|
|
||||||
// ForAllOutgoingChannels is required to iterate over all our local
|
// ForAllOutgoingChannels is required to iterate over all our local
|
||||||
// channels. The ChannelEdgePolicy parameter may be nil.
|
// channels. The ChannelEdgePolicy parameter may be nil.
|
||||||
ForAllOutgoingChannels func(cb func(*models.ChannelEdgeInfo,
|
ForAllOutgoingChannels func(ctx context.Context,
|
||||||
*models.ChannelEdgePolicy) error) error
|
cb func(*models.ChannelEdgeInfo,
|
||||||
|
*models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
// FetchChannel is used to query local channel parameters. Optionally an
|
// FetchChannel is used to query local channel parameters. Optionally an
|
||||||
// existing db tx can be supplied.
|
// existing db tx can be supplied.
|
||||||
@@ -151,7 +152,7 @@ func (r *Manager) UpdatePolicy(ctx context.Context,
|
|||||||
// Next, we'll loop over all the outgoing channels the router knows of.
|
// Next, we'll loop over all the outgoing channels the router knows of.
|
||||||
// If we have a filter then we'll only collect those channels, otherwise
|
// If we have a filter then we'll only collect those channels, otherwise
|
||||||
// we'll collect them all.
|
// we'll collect them all.
|
||||||
err := r.ForAllOutgoingChannels(processChan)
|
err := r.ForAllOutgoingChannels(ctx, processChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,8 +123,9 @@ func TestManager(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
forAllOutgoingChannels := func(cb func(*models.ChannelEdgeInfo,
|
forAllOutgoingChannels := func(_ context.Context,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
cb func(*models.ChannelEdgeInfo,
|
||||||
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
for _, c := range channelSet {
|
for _, c := range channelSet {
|
||||||
if err := cb(c.edgeInfo, ¤tPolicy); err != nil {
|
if err := cb(c.edgeInfo, ¤tPolicy); err != nil {
|
||||||
|
|||||||
+5
-5
@@ -6737,7 +6737,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
// First iterate through all the known nodes (connected or unconnected
|
// First iterate through all the known nodes (connected or unconnected
|
||||||
// within the graph), collating their current state into the RPC
|
// within the graph), collating their current state into the RPC
|
||||||
// response.
|
// response.
|
||||||
err := graph.ForEachNode(func(nodeTx graphdb.NodeRTx) error {
|
err := graph.ForEachNode(ctx, func(nodeTx graphdb.NodeRTx) error {
|
||||||
lnNode := marshalNode(nodeTx.Node())
|
lnNode := marshalNode(nodeTx.Node())
|
||||||
|
|
||||||
resp.Nodes = append(resp.Nodes, lnNode)
|
resp.Nodes = append(resp.Nodes, lnNode)
|
||||||
@@ -6751,7 +6751,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
// Next, for each active channel we know of within the graph, create a
|
// Next, for each active channel we know of within the graph, create a
|
||||||
// similar response which details both the edge information as well as
|
// similar response which details both the edge information as well as
|
||||||
// the routing policies of th nodes connecting the two edges.
|
// the routing policies of th nodes connecting the two edges.
|
||||||
err = graph.ForEachChannel(func(edgeInfo *models.ChannelEdgeInfo,
|
err = graph.ForEachChannel(ctx, func(edgeInfo *models.ChannelEdgeInfo,
|
||||||
c1, c2 *models.ChannelEdgePolicy) error {
|
c1, c2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// Do not include unannounced channels unless specifically
|
// Do not include unannounced channels unless specifically
|
||||||
@@ -7041,7 +7041,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
channels []*lnrpc.ChannelEdge
|
channels []*lnrpc.ChannelEdge
|
||||||
)
|
)
|
||||||
|
|
||||||
err = graph.ForEachNodeChannel(node.PubKeyBytes,
|
err = graph.ForEachNodeChannel(ctx, node.PubKeyBytes,
|
||||||
func(edge *models.ChannelEdgeInfo,
|
func(edge *models.ChannelEdgeInfo,
|
||||||
c1, c2 *models.ChannelEdgePolicy) error {
|
c1, c2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -7151,7 +7151,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
|||||||
// network, tallying up the total number of nodes, and also gathering
|
// network, tallying up the total number of nodes, and also gathering
|
||||||
// each node so we can measure the graph diameter and degree stats
|
// each node so we can measure the graph diameter and degree stats
|
||||||
// below.
|
// below.
|
||||||
err := graph.ForEachNodeCached(func(node route.Vertex,
|
err := graph.ForEachNodeCached(ctx, func(node route.Vertex,
|
||||||
edges map[uint64]*graphdb.DirectedChannel) error {
|
edges map[uint64]*graphdb.DirectedChannel) error {
|
||||||
|
|
||||||
// Increment the total number of nodes with each iteration.
|
// Increment the total number of nodes with each iteration.
|
||||||
@@ -7723,7 +7723,7 @@ func (r *rpcServer) FeeReport(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var feeReports []*lnrpc.ChannelFeeReport
|
var feeReports []*lnrpc.ChannelFeeReport
|
||||||
err = channelGraph.ForEachNodeChannel(selfNode.PubKeyBytes,
|
err = channelGraph.ForEachNodeChannel(ctx, selfNode.PubKeyBytes,
|
||||||
func(chanInfo *models.ChannelEdgeInfo,
|
func(chanInfo *models.ChannelEdgeInfo,
|
||||||
edgePolicy, _ *models.ChannelEdgePolicy) error {
|
edgePolicy, _ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
|||||||
@@ -1252,10 +1252,11 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
|
|||||||
s.localChanMgr = &localchans.Manager{
|
s.localChanMgr = &localchans.Manager{
|
||||||
SelfPub: nodeKeyDesc.PubKey,
|
SelfPub: nodeKeyDesc.PubKey,
|
||||||
DefaultRoutingPolicy: cc.RoutingPolicy,
|
DefaultRoutingPolicy: cc.RoutingPolicy,
|
||||||
ForAllOutgoingChannels: func(cb func(*models.ChannelEdgeInfo,
|
ForAllOutgoingChannels: func(ctx context.Context,
|
||||||
*models.ChannelEdgePolicy) error) error {
|
cb func(*models.ChannelEdgeInfo,
|
||||||
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return s.graphDB.ForEachNodeChannel(selfVertex,
|
return s.graphDB.ForEachNodeChannel(ctx, selfVertex,
|
||||||
func(c *models.ChannelEdgeInfo,
|
func(c *models.ChannelEdgeInfo,
|
||||||
e *models.ChannelEdgePolicy,
|
e *models.ChannelEdgePolicy,
|
||||||
_ *models.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
@@ -2607,7 +2608,7 @@ func (s *server) Start(ctx context.Context) error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.establishPersistentConnections(); err != nil {
|
if err := s.establishPersistentConnections(ctx); err != nil {
|
||||||
srvrLog.Errorf("Failed to establish persistent "+
|
srvrLog.Errorf("Failed to establish persistent "+
|
||||||
"connections: %v", err)
|
"connections: %v", err)
|
||||||
}
|
}
|
||||||
@@ -3594,7 +3595,7 @@ type nodeAddresses struct {
|
|||||||
// to all our direct channel collaborators. In order to promote liveness of our
|
// to all our direct channel collaborators. In order to promote liveness of our
|
||||||
// active channels, we instruct the connection manager to attempt to establish
|
// active channels, we instruct the connection manager to attempt to establish
|
||||||
// and maintain persistent connections to all our direct channel counterparties.
|
// and maintain persistent connections to all our direct channel counterparties.
|
||||||
func (s *server) establishPersistentConnections() error {
|
func (s *server) establishPersistentConnections(ctx context.Context) error {
|
||||||
// nodeAddrsMap stores the combination of node public keys and addresses
|
// nodeAddrsMap stores the combination of node public keys and addresses
|
||||||
// that we'll attempt to reconnect to. PubKey strings are used as keys
|
// that we'll attempt to reconnect to. PubKey strings are used as keys
|
||||||
// since other PubKey forms can't be compared.
|
// since other PubKey forms can't be compared.
|
||||||
@@ -3604,7 +3605,7 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
// attempt to connect to based on our set of previous connections. Set
|
// attempt to connect to based on our set of previous connections. Set
|
||||||
// the reconnection port to the default peer port.
|
// the reconnection port to the default peer port.
|
||||||
linkNodes, err := s.chanStateDB.LinkNodeDB().FetchAllLinkNodes()
|
linkNodes, err := s.chanStateDB.LinkNodeDB().FetchAllLinkNodes()
|
||||||
if err != nil && err != channeldb.ErrLinkNodesNotFound {
|
if err != nil && !errors.Is(err, channeldb.ErrLinkNodesNotFound) {
|
||||||
return fmt.Errorf("failed to fetch all link nodes: %w", err)
|
return fmt.Errorf("failed to fetch all link nodes: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3622,7 +3623,7 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
// that have been added via NodeAnnouncement messages.
|
// that have been added via NodeAnnouncement messages.
|
||||||
// TODO(roasbeef): instead iterate over link nodes and query graph for
|
// TODO(roasbeef): instead iterate over link nodes and query graph for
|
||||||
// each of the nodes.
|
// each of the nodes.
|
||||||
err = s.graphDB.ForEachSourceNodeChannel(func(chanPoint wire.OutPoint,
|
forEachSrcNodeChan := func(chanPoint wire.OutPoint,
|
||||||
havePolicy bool, channelPeer *models.LightningNode) error {
|
havePolicy bool, channelPeer *models.LightningNode) error {
|
||||||
|
|
||||||
// If the remote party has announced the channel to us, but we
|
// If the remote party has announced the channel to us, but we
|
||||||
@@ -3666,6 +3667,7 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
// addresses if Tor outbound support is enabled.
|
// addresses if Tor outbound support is enabled.
|
||||||
case *tor.OnionAddr:
|
case *tor.OnionAddr:
|
||||||
if s.cfg.Tor.Active {
|
if s.cfg.Tor.Active {
|
||||||
|
//nolint:ll
|
||||||
addrSet[lnAddress.String()] = lnAddress
|
addrSet[lnAddress.String()] = lnAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3688,7 +3690,8 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
|
|
||||||
nodeAddrsMap[pubStr] = n
|
nodeAddrsMap[pubStr] = n
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
|
err = s.graphDB.ForEachSourceNodeChannel(ctx, forEachSrcNodeChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srvrLog.Errorf("Failed to iterate over source node channels: "+
|
srvrLog.Errorf("Failed to iterate over source node channels: "+
|
||||||
"%v", err)
|
"%v", err)
|
||||||
|
|||||||
Reference in new issue
Block a user