lnrpc+routing: remove k shortest path finding

This commit is contained in:
Joost Jager committed 2019-05-07 19:54:06 +02:00
1 parent c4415f0400
commit 7a5bd29a69
13 files changed
+714 -1228

No files matched your search

+10 -29
View File
@@ -28,10 +28,9 @@ type RouterBackend struct {
// FindRoutes is a closure that abstracts away how we locate/query for
// routes.
FindRoutes func(source, target route.Vertex,
FindRoute func(source, target route.Vertex,
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
numPaths uint32, finalExpiry ...uint16) (
[]*route.Route, error)
finalExpiry ...uint16) (*route.Route, error)
}
// QueryRoutes attempts to query the daemons' Channel Router for a possible
@@ -122,53 +121,35 @@ func (r *RouterBackend) QueryRoutes(ctx context.Context,
IgnoredEdges: ignoredEdges,
}
// numRoutes will default to 10 if not specified explicitly.
numRoutesIn := uint32(in.NumRoutes)
if numRoutesIn == 0 {
numRoutesIn = 10
}
// Query the channel router for a possible path to the destination that
// can carry `in.Amt` satoshis _including_ the total fee required on
// the route.
var (
routes []*route.Route
route *route.Route
findErr error
)
if in.FinalCltvDelta == 0 {
routes, findErr = r.FindRoutes(
route, findErr = r.FindRoute(
sourcePubKey, targetPubKey, amtMSat, restrictions,
numRoutesIn,
)
} else {
routes, findErr = r.FindRoutes(
route, findErr = r.FindRoute(
sourcePubKey, targetPubKey, amtMSat, restrictions,
numRoutesIn, uint16(in.FinalCltvDelta),
uint16(in.FinalCltvDelta),
)
}
if findErr != nil {
return nil, findErr
}
// As the number of returned routes can be less than the number of
// requested routes, we'll clamp down the length of the response to the
// minimum of the two.
numRoutes := uint32(len(routes))
if numRoutesIn < numRoutes {
numRoutes = numRoutesIn
}
// For each valid route, we'll convert the result into the format
// required by the RPC system.
rpcRoute := r.MarshallRoute(route)
routeResp := &lnrpc.QueryRoutesResponse{
Routes: make([]*lnrpc.Route, 0, in.NumRoutes),
}
for i := uint32(0); i < numRoutes; i++ {
routeResp.Routes = append(
routeResp.Routes,
r.MarshallRoute(routes[i]),
)
Routes: []*lnrpc.Route{rpcRoute},
}
return routeResp, nil
+4 -12
View File
@@ -42,7 +42,6 @@ func TestQueryRoutes(t *testing.T) {
request := &lnrpc.QueryRoutesRequest{
PubKey: destKey,
Amt: 100000,
NumRoutes: 1,
FinalCltvDelta: 100,
FeeLimit: &lnrpc.FeeLimit{
Limit: &lnrpc.FeeLimit_Fixed{
@@ -58,19 +57,14 @@ func TestQueryRoutes(t *testing.T) {
rt := &route.Route{}
findRoutes := func(source, target route.Vertex,
findRoute := func(source, target route.Vertex,
amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
numPaths uint32, finalExpiry ...uint16) (
[]*route.Route, error) {
finalExpiry ...uint16) (*route.Route, error) {
if int64(amt) != request.Amt*1000 {
t.Fatal("unexpected amount")
}
if numPaths != 1 {
t.Fatal("unexpected number of routes")
}
if source != sourceKey {
t.Fatal("unexpected source key")
}
@@ -101,14 +95,12 @@ func TestQueryRoutes(t *testing.T) {
t.Fatal("unexpected ignored node")
}
return []*route.Route{
rt,
}, nil
return rt, nil
}
backend := &RouterBackend{
MaxPaymentMSat: lnwire.NewMSatFromSatoshis(1000000),
FindRoutes: findRoutes,
FindRoute: findRoute,
SelfNode: route.Vertex{1, 2, 3},
FetchChannelCapacity: func(chanID uint64) (
btcutil.Amount, error) {
+4 -8
View File
@@ -247,22 +247,18 @@ func (s *Server) EstimateRouteFee(ctx context.Context,
// Finally, we'll query for a route to the destination that can carry
// that target amount, we'll only request a single route.
routes, err := s.cfg.Router.FindRoutes(
route, err := s.cfg.Router.FindRoute(
s.cfg.RouterBackend.SelfNode, destNode, amtMsat,
&routing.RestrictParams{
FeeLimit: feeLimit,
}, 1,
},
)
if err != nil {
return nil, err
}
if len(routes) == 0 {
return nil, fmt.Errorf("unable to find route to dest: %v", err)
}
return &RouteFeeResponse{
RoutingFeeMsat: int64(routes[0].TotalFees),
TimeLockDelay: int64(routes[0].TotalTimeLock),
RoutingFeeMsat: int64(route.TotalFees),
TimeLockDelay: int64(route.TotalTimeLock),
}, nil
}
+623 -636
View File
File diff suppressed because it is too large. Load diff
+1 -5
View File
@@ -1606,11 +1606,7 @@ message QueryRoutesRequest {
/// The amount to send expressed in satoshis
int64 amt = 2;
/**
Deprecated. The max number of routes to return. In the future, QueryRoutes
will only return a single route.
*/
int32 num_routes = 3 [deprecated = true];
reserved 3;
/// An optional CLTV delta from the current height that should be used for the timelock of the final hop
int32 final_cltv_delta = 4;
-8
View File
@@ -673,14 +673,6 @@
"type": "string",
"format": "int64"
},
{
"name": "num_routes",
"description": "*\nDeprecated. The max number of routes to return. In the future, QueryRoutes\nwill only return a single route.",
"in": "query",
"required": false,
"type": "integer",
"format": "int32"
},
{
"name": "final_cltv_delta",
"description": "/ An optional CLTV delta from the current height that should be used for the timelock of the final hop.",