graph/db: let ForEachNodeCached maybe fetch node addresses
Here we adjust the ForEachNodeCached graph DB method to pass in a node's addresses into the provided call-back if requested. This will allow us to improve the performance of node/channel iteration in the autopilot subserver.
This commit is contained in:
9 files changed
+96
-26
No files matched your search
+20
-1
@@ -252,6 +252,24 @@ func TestNodeInsertionAndDeletion(t *testing.T) {
|
||||
dbNode, err = graph.FetchLightningNode(ctx, testPub)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, expAddrs, dbNode.Addresses)
|
||||
|
||||
// Also check that the withAddr param of ForEachNodeCached correctly
|
||||
// returns the addresses we expect for this node.
|
||||
err = graph.ForEachNodeCached(
|
||||
ctx, true, func(ctx context.Context, node route.Vertex,
|
||||
addrs []net.Addr,
|
||||
chans map[uint64]*DirectedChannel) error {
|
||||
|
||||
if node != dbNode.PubKeyBytes {
|
||||
return nil
|
||||
}
|
||||
|
||||
require.Equal(t, expAddrs, addrs)
|
||||
|
||||
return nil
|
||||
}, func() {},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
// TestPartialNode checks that we can add and retrieve a LightningNode where
|
||||
@@ -1359,7 +1377,8 @@ func TestGraphTraversal(t *testing.T) {
|
||||
// set of channels (to force the fall back), we should find all the
|
||||
// channel as well as the nodes included.
|
||||
graph.graphCache = nil
|
||||
err := graph.ForEachNodeCached(ctx, func(node route.Vertex,
|
||||
err := graph.ForEachNodeCached(ctx, false, func(_ context.Context,
|
||||
node route.Vertex, _ []net.Addr,
|
||||
chans map[uint64]*DirectedChannel) error {
|
||||
|
||||
if _, ok := nodeIndex[node]; !ok {
|
||||
|
||||
Reference in new issue
Block a user