routing+routerrpc: add capacity in rpcs

FetchPairCapacity is used by the following endpoints to introduce the
capacity for probability calculations:

* QueryProbability
* QueryRoutes
This commit is contained in:
bitromortac
2022-08-23 12:00:54 +02:00
parent 66ffc64776
commit 454c115b6e
9 changed files with 117 additions and 34 deletions

View File

@ -689,6 +689,7 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
return err
}
graph := s.graphDB
routerBackend := &routerrpc.RouterBackend{
SelfNode: selfNode.PubKeyBytes,
FetchChannelCapacity: func(chanID uint64) (btcutil.Amount,
@ -700,6 +701,28 @@ func (r *rpcServer) addDeps(s *server, macService *macaroons.Service,
}
return info.Capacity, nil
},
FetchAmountPairCapacity: func(nodeFrom, nodeTo route.Vertex,
amount lnwire.MilliSatoshi) (btcutil.Amount, error) {
routingGraph, err := routing.NewCachedGraph(
selfNode, graph,
)
if err != nil {
return 0, err
}
defer func() {
closeErr := routingGraph.Close()
if closeErr != nil {
rpcsLog.Errorf("not able to close "+
"routing graph tx: %v",
closeErr)
}
}()
return routingGraph.FetchAmountPairCapacity(
nodeFrom, nodeTo, amount,
)
},
FetchChannelEndpoints: func(chanID uint64) (route.Vertex,
route.Vertex, error) {