rpcserver: calculate and populate medianChanSizeSat in NetworkInfo
This commit is contained in:
parent
f96dbd2377
commit
d6d66e631a
11
rpcserver.go
11
rpcserver.go
@ -3959,6 +3959,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
totalNetworkCapacity btcutil.Amount
|
||||
minChannelSize btcutil.Amount = math.MaxInt64
|
||||
maxChannelSize btcutil.Amount
|
||||
medianChanSize btcutil.Amount
|
||||
)
|
||||
|
||||
// We'll use this map to de-duplicate channels during our traversal.
|
||||
@ -3966,6 +3967,10 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
// edges for each channel within the graph.
|
||||
seenChans := make(map[uint64]struct{})
|
||||
|
||||
// We also keep a list of all encountered capacities, in order to
|
||||
// calculate the median channel size.
|
||||
var allChans []btcutil.Amount
|
||||
|
||||
// We'll run through all the known nodes in the within our view of the
|
||||
// network, tallying up the total number of nodes, and also gathering
|
||||
// each node so we can measure the graph diameter and degree stats
|
||||
@ -4012,6 +4017,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
numChannels++
|
||||
|
||||
seenChans[edge.ChannelID] = struct{}{}
|
||||
allChans = append(allChans, edge.Capacity)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
@ -4028,6 +4034,9 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Find the median.
|
||||
medianChanSize = autopilot.Median(allChans)
|
||||
|
||||
// If we don't have any channels, then reset the minChannelSize to zero
|
||||
// to avoid outputting NaN in encoded JSON.
|
||||
if numChannels == 0 {
|
||||
@ -4037,7 +4046,6 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
// TODO(roasbeef): graph diameter
|
||||
|
||||
// TODO(roasbeef): also add oldest channel?
|
||||
// * also add median channel size
|
||||
netInfo := &lnrpc.NetworkInfo{
|
||||
MaxOutDegree: maxChanOut,
|
||||
AvgOutDegree: float64(numChannels) / float64(numNodes),
|
||||
@ -4048,6 +4056,7 @@ func (r *rpcServer) GetNetworkInfo(ctx context.Context,
|
||||
|
||||
MinChannelSize: int64(minChannelSize),
|
||||
MaxChannelSize: int64(maxChannelSize),
|
||||
MedianChannelSizeSat: int64(medianChanSize),
|
||||
}
|
||||
|
||||
// Similarly, if we don't have any channels, then we'll also set the
|
||||
|
Loading…
Reference in New Issue
Block a user