rpc: optimize GetNetworkInfo by using the channel graph cache
This commit is contained in:
1 file changed
+6
-8
+6
-8
@@ -5708,7 +5708,9 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
// network, tallying up the total number of nodes, and also gathering
|
||||
// each node so we can measure the graph diameter and degree stats
|
||||
// below.
|
||||
if err := graph.ForEachNode(func(tx kvdb.RTx, node *channeldb.LightningNode) error {
|
||||
err := graph.ForEachNodeCached(func(node route.Vertex,
|
||||
edges map[uint64]*channeldb.DirectedChannel) error {
|
||||
|
||||
// Increment the total number of nodes with each iteration.
|
||||
numNodes++
|
||||
|
||||
@@ -5718,9 +5720,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
// through the db transaction from the outer view so we can
|
||||
// re-use it within this inner view.
|
||||
var outDegree uint32
|
||||
if err := node.ForEachChannel(tx, func(_ kvdb.RTx,
|
||||
edge *channeldb.ChannelEdgeInfo, _, _ *channeldb.ChannelEdgePolicy) error {
|
||||
|
||||
for _, edge := range edges {
|
||||
// Bump up the out degree for this node for each
|
||||
// channel encountered.
|
||||
outDegree++
|
||||
@@ -5751,9 +5751,6 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
|
||||
seenChans[edge.ChannelID] = struct{}{}
|
||||
allChans = append(allChans, edge.Capacity)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Finally, if the out degree of this node is greater than what
|
||||
@@ -5763,7 +5760,8 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user