mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-30 09:40:24 +02:00
rpc: update graph topology related RPC's to recent db API change
This commit updates all the RPC’s that deal with querying for data stored within the graph to the latest version of the public API for the graph itself.
This commit is contained in:
parent
d8d7dab258
commit
dc5eb8de37
66
rpcserver.go
66
rpcserver.go
@ -1387,8 +1387,10 @@ func (r *rpcServer) DescribeGraph(context.Context,
|
|||||||
// Next, for each active channel we know of within the graph, create a
|
// Next, for each active channel we know of within the graph, create a
|
||||||
// similar response which details both the edge information as well as
|
// similar response which details both the edge information as well as
|
||||||
// the routing policies of th nodes connecting the two edges.
|
// the routing policies of th nodes connecting the two edges.
|
||||||
err = graph.ForEachChannel(func(c1, c2 *channeldb.ChannelEdge) error {
|
err = graph.ForEachChannel(func(edgeInfo *channeldb.ChannelEdgeInfo,
|
||||||
edge := marshalDbEdge(c1, c2)
|
c1, c2 *channeldb.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
|
edge := marshalDbEdge(edgeInfo, c1, c2)
|
||||||
resp.Edges = append(resp.Edges, edge)
|
resp.Edges = append(resp.Edges, edge)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -1399,43 +1401,33 @@ func (r *rpcServer) DescribeGraph(context.Context,
|
|||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalDbEdge(c1, c2 *channeldb.ChannelEdge) *lnrpc.ChannelEdge {
|
func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
|
||||||
|
c1, c2 *channeldb.ChannelEdgePolicy) *lnrpc.ChannelEdge {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
node1Pub, node2Pub []byte
|
lastUpdate int64
|
||||||
capacity btcutil.Amount
|
|
||||||
lastUpdate int64
|
|
||||||
chanID uint64
|
|
||||||
chanPoint string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if c2 != nil {
|
if c2 != nil {
|
||||||
node1Pub = c2.Node.PubKey.SerializeCompressed()
|
|
||||||
lastUpdate = c2.LastUpdate.Unix()
|
lastUpdate = c2.LastUpdate.Unix()
|
||||||
capacity = c2.Capacity
|
|
||||||
chanID = c2.ChannelID
|
|
||||||
chanPoint = c2.ChannelPoint.String()
|
|
||||||
}
|
}
|
||||||
if c1 != nil {
|
if c1 != nil {
|
||||||
node2Pub = c1.Node.PubKey.SerializeCompressed()
|
|
||||||
lastUpdate = c1.LastUpdate.Unix()
|
lastUpdate = c1.LastUpdate.Unix()
|
||||||
capacity = c1.Capacity
|
|
||||||
chanID = c1.ChannelID
|
|
||||||
chanPoint = c1.ChannelPoint.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
edge := &lnrpc.ChannelEdge{
|
edge := &lnrpc.ChannelEdge{
|
||||||
ChannelId: chanID,
|
ChannelId: edgeInfo.ChannelID,
|
||||||
ChanPoint: chanPoint,
|
ChanPoint: edgeInfo.ChannelPoint.String(),
|
||||||
// TODO(roasbeef): update should be on edge info itself
|
// TODO(roasbeef): update should be on edge info itself
|
||||||
LastUpdate: uint32(lastUpdate),
|
LastUpdate: uint32(lastUpdate),
|
||||||
Node1Pub: hex.EncodeToString(node1Pub),
|
Node1Pub: hex.EncodeToString(edgeInfo.NodeKey1.SerializeCompressed()),
|
||||||
Node2Pub: hex.EncodeToString(node2Pub),
|
Node2Pub: hex.EncodeToString(edgeInfo.NodeKey2.SerializeCompressed()),
|
||||||
Capacity: int64(capacity),
|
Capacity: int64(edgeInfo.Capacity),
|
||||||
}
|
}
|
||||||
|
|
||||||
if c1 != nil {
|
if c1 != nil {
|
||||||
edge.Node1Policy = &lnrpc.RoutingPolicy{
|
edge.Node1Policy = &lnrpc.RoutingPolicy{
|
||||||
TimeLockDelta: uint32(c1.Expiry),
|
TimeLockDelta: uint32(c1.TimeLockDelta),
|
||||||
MinHtlc: int64(c1.MinHTLC),
|
MinHtlc: int64(c1.MinHTLC),
|
||||||
FeeBaseMsat: int64(c1.FeeBaseMSat),
|
FeeBaseMsat: int64(c1.FeeBaseMSat),
|
||||||
FeeRateMilliMsat: int64(c1.FeeProportionalMillionths),
|
FeeRateMilliMsat: int64(c1.FeeProportionalMillionths),
|
||||||
@ -1444,7 +1436,7 @@ func marshalDbEdge(c1, c2 *channeldb.ChannelEdge) *lnrpc.ChannelEdge {
|
|||||||
|
|
||||||
if c2 != nil {
|
if c2 != nil {
|
||||||
edge.Node2Policy = &lnrpc.RoutingPolicy{
|
edge.Node2Policy = &lnrpc.RoutingPolicy{
|
||||||
TimeLockDelta: uint32(c2.Expiry),
|
TimeLockDelta: uint32(c2.TimeLockDelta),
|
||||||
MinHtlc: int64(c2.MinHTLC),
|
MinHtlc: int64(c2.MinHTLC),
|
||||||
FeeBaseMsat: int64(c2.FeeBaseMSat),
|
FeeBaseMsat: int64(c2.FeeBaseMSat),
|
||||||
FeeRateMilliMsat: int64(c2.FeeProportionalMillionths),
|
FeeRateMilliMsat: int64(c2.FeeProportionalMillionths),
|
||||||
@ -1461,7 +1453,7 @@ func marshalDbEdge(c1, c2 *channeldb.ChannelEdge) *lnrpc.ChannelEdge {
|
|||||||
func (r *rpcServer) GetChanInfo(_ context.Context, in *lnrpc.ChanInfoRequest) (*lnrpc.ChannelEdge, error) {
|
func (r *rpcServer) GetChanInfo(_ context.Context, in *lnrpc.ChanInfoRequest) (*lnrpc.ChannelEdge, error) {
|
||||||
graph := r.server.chanDB.ChannelGraph()
|
graph := r.server.chanDB.ChannelGraph()
|
||||||
|
|
||||||
edge1, edge2, err := graph.FetchChannelEdgesByID(in.ChanId)
|
edgeInfo, edge1, edge2, err := graph.FetchChannelEdgesByID(in.ChanId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1469,7 +1461,7 @@ func (r *rpcServer) GetChanInfo(_ context.Context, in *lnrpc.ChanInfoRequest) (*
|
|||||||
// Convert the database's edge format into the network/RPC edge format
|
// Convert the database's edge format into the network/RPC edge format
|
||||||
// which couples the edge itself along with the directional node
|
// which couples the edge itself along with the directional node
|
||||||
// routing policies of each node involved within the channel.
|
// routing policies of each node involved within the channel.
|
||||||
channelEdge := marshalDbEdge(edge1, edge2)
|
channelEdge := marshalDbEdge(edgeInfo, edge1, edge2)
|
||||||
|
|
||||||
return channelEdge, nil
|
return channelEdge, nil
|
||||||
}
|
}
|
||||||
@ -1505,7 +1497,9 @@ func (r *rpcServer) GetNodeInfo(_ context.Context, in *lnrpc.NodeInfoRequest) (*
|
|||||||
numChannels uint32
|
numChannels uint32
|
||||||
totalCapcity btcutil.Amount
|
totalCapcity btcutil.Amount
|
||||||
)
|
)
|
||||||
if err := node.ForEachChannel(nil, func(edge *channeldb.ChannelEdge) error {
|
if err := node.ForEachChannel(nil, func(edge *channeldb.ChannelEdgeInfo,
|
||||||
|
_ *channeldb.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
numChannels++
|
numChannels++
|
||||||
totalCapcity += edge.Capacity
|
totalCapcity += edge.Capacity
|
||||||
return nil
|
return nil
|
||||||
@ -1617,7 +1611,9 @@ func (r *rpcServer) GetNetworkInfo(context.Context, *lnrpc.NetworkInfoRequest) (
|
|||||||
// node.
|
// node.
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
var outDegree uint32
|
var outDegree uint32
|
||||||
err := node.ForEachChannel(nil, func(c *channeldb.ChannelEdge) error {
|
err := node.ForEachChannel(nil, func(_ *channeldb.ChannelEdgeInfo,
|
||||||
|
_ *channeldb.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
outDegree++
|
outDegree++
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -1632,18 +1628,10 @@ func (r *rpcServer) GetNetworkInfo(context.Context, *lnrpc.NetworkInfoRequest) (
|
|||||||
|
|
||||||
// Finally, we traverse each channel visiting both channel edges at
|
// Finally, we traverse each channel visiting both channel edges at
|
||||||
// once to avoid double counting any stats we're attempting to gather.
|
// once to avoid double counting any stats we're attempting to gather.
|
||||||
if err := graph.ForEachChannel(func(c1, c2 *channeldb.ChannelEdge) error {
|
if err := graph.ForEachChannel(func(edge *channeldb.ChannelEdgeInfo,
|
||||||
var chanCapacity btcutil.Amount
|
_, _ *channeldb.ChannelEdgePolicy) error {
|
||||||
switch {
|
|
||||||
case c1 == nil:
|
chanCapacity := edge.Capacity
|
||||||
chanCapacity = c2.Capacity
|
|
||||||
case c2 == nil:
|
|
||||||
chanCapacity = c1.Capacity
|
|
||||||
case c1 == nil && c2 == nil:
|
|
||||||
return nil
|
|
||||||
default:
|
|
||||||
chanCapacity = c1.Capacity
|
|
||||||
}
|
|
||||||
|
|
||||||
if chanCapacity < minChannelSize {
|
if chanCapacity < minChannelSize {
|
||||||
minChannelSize = chanCapacity
|
minChannelSize = chanCapacity
|
||||||
|
Loading…
x
Reference in New Issue
Block a user