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
|
// 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.
|
||||||
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.
|
// Increment the total number of nodes with each iteration.
|
||||||
numNodes++
|
numNodes++
|
||||||
|
|
||||||
@@ -5718,9 +5720,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
|||||||
// through the db transaction from the outer view so we can
|
// through the db transaction from the outer view so we can
|
||||||
// re-use it within this inner view.
|
// re-use it within this inner view.
|
||||||
var outDegree uint32
|
var outDegree uint32
|
||||||
if err := node.ForEachChannel(tx, func(_ kvdb.RTx,
|
for _, edge := range edges {
|
||||||
edge *channeldb.ChannelEdgeInfo, _, _ *channeldb.ChannelEdgePolicy) error {
|
|
||||||
|
|
||||||
// Bump up the out degree for this node for each
|
// Bump up the out degree for this node for each
|
||||||
// channel encountered.
|
// channel encountered.
|
||||||
outDegree++
|
outDegree++
|
||||||
@@ -5751,9 +5751,6 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
|||||||
|
|
||||||
seenChans[edge.ChannelID] = struct{}{}
|
seenChans[edge.ChannelID] = struct{}{}
|
||||||
allChans = append(allChans, edge.Capacity)
|
allChans = append(allChans, edge.Capacity)
|
||||||
return nil
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, if the out degree of this node is greater than what
|
// 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
|
return nil
|
||||||
}); err != nil {
|
})
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user