channeldb: add new ForEachNode method using the channel graph cache

This commit, adds a new ForEachNode method to the channel graph cache
that assumes the contents won't be modified. This is generally useful,
and will be used in a later commit to optimize some heavy RPC calls.
This commit is contained in:
Olaoluwa Osuntokun
2021-10-19 16:04:23 -07:00
parent a6f22c6185
commit fae470293f
4 changed files with 136 additions and 0 deletions

View File

@@ -120,6 +120,24 @@ func TestGraphCacheAddNode(t *testing.T) {
require.Equal(t, inPolicy1 != nil, toChannels[0].OutPolicySet)
assertCachedPolicyEqual(t, outPolicy1, toChannels[0].InPolicy)
// Now that we've inserted two nodes into the graph, check that
// we'll recover the same set of channels during ForEachNode.
nodes := make(map[route.Vertex]struct{})
chans := make(map[uint64]struct{})
_ = cache.ForEachNode(func(node route.Vertex,
edges map[uint64]*DirectedChannel) error {
nodes[node] = struct{}{}
for chanID := range edges {
chans[chanID] = struct{}{}
}
return nil
})
require.Len(t, nodes, 2)
require.Len(t, chans, 1)
}
runTest(pubKey1, pubKey2)