Merge pull request #2308 from chokoboko/channels-in-getnodeinfo

rpcserver: add channels to GetNodeInfo response
This commit is contained in:
Olaoluwa Osuntokun
2019-05-23 18:01:12 -07:00
committed by GitHub
4 changed files with 531 additions and 491 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1735,8 +1735,14 @@ message NodeInfo {
*/ */
LightningNode node = 1 [json_name = "node"]; LightningNode node = 1 [json_name = "node"];
/// The total number of channels for the node.
uint32 num_channels = 2 [json_name = "num_channels"]; uint32 num_channels = 2 [json_name = "num_channels"];
/// The sum of all channels capacity for the node, denominated in satoshis.
int64 total_capacity = 3 [json_name = "total_capacity"]; int64 total_capacity = 3 [json_name = "total_capacity"];
/// A list of all public channels for the node.
repeated ChannelEdge channels = 4 [json_name = "channels"];
} }
/** /**

View File

@ -2617,11 +2617,20 @@
}, },
"num_channels": { "num_channels": {
"type": "integer", "type": "integer",
"format": "int64" "format": "int64",
"description": "/ The total number of channels for the node."
}, },
"total_capacity": { "total_capacity": {
"type": "string", "type": "string",
"format": "int64" "format": "int64",
"description": "/ The sum of all channels capacity for the node, denominated in satoshis."
},
"channels": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcChannelEdge"
},
"description": "/ A list of all public channels for the node."
} }
} }
}, },

View File

@ -3820,12 +3820,25 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
var ( var (
numChannels uint32 numChannels uint32
totalCapacity btcutil.Amount totalCapacity btcutil.Amount
channels []*lnrpc.ChannelEdge
) )
if err := node.ForEachChannel(nil, func(_ *bbolt.Tx, edge *channeldb.ChannelEdgeInfo, if err := node.ForEachChannel(nil, func(_ *bbolt.Tx, edge *channeldb.ChannelEdgeInfo,
_, _ *channeldb.ChannelEdgePolicy) error { c1, c2 *channeldb.ChannelEdgePolicy) error {
numChannels++ numChannels++
totalCapacity += edge.Capacity totalCapacity += edge.Capacity
// Do not include unannounced channels - private channels or public
// channels whose authentication proof were not confirmed yet.
if edge.AuthProof == nil {
return nil
}
// Convert the database's edge format into the network/RPC edge format.
channelEdge := marshalDbEdge(edge, c1, c2)
channels = append(channels, channelEdge)
return nil return nil
}); err != nil { }); err != nil {
return nil, err return nil, err
@ -3839,7 +3852,6 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
} }
nodeAddrs = append(nodeAddrs, nodeAddr) nodeAddrs = append(nodeAddrs, nodeAddr)
} }
// TODO(roasbeef): list channels as well?
return &lnrpc.NodeInfo{ return &lnrpc.NodeInfo{
Node: &lnrpc.LightningNode{ Node: &lnrpc.LightningNode{
@ -3851,6 +3863,7 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
}, },
NumChannels: numChannels, NumChannels: numChannels,
TotalCapacity: int64(totalCapacity), TotalCapacity: int64(totalCapacity),
Channels: channels,
}, nil }, nil
} }