Merge pull request #2521 from joostjager/sendtosingleroute

lnrpc: deprecate SendToRoute with more than one route
This commit is contained in:
Olaoluwa Osuntokun 2019-02-05 18:06:01 -08:00 committed by GitHub
commit e5d660daf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 623 additions and 585 deletions

File diff suppressed because it is too large Load Diff

View File

@ -781,8 +781,16 @@ message SendToRouteRequest {
/// An optional hex-encoded payment hash to be used for the HTLC.
string payment_hash_string = 2;
/// The set of routes that should be used to attempt to complete the payment.
repeated Route routes = 3;
/**
Deprecated. The set of routes that should be used to attempt to complete the
payment. The possibility to pass in multiple routes is deprecated and
instead the single route field below should be used in combination with the
streaming variant of SendToRoute.
*/
repeated Route routes = 3 [deprecated = true];
/// Route that should be used to attempt to complete the payment.
Route route = 4;
}
message ChannelPoint {

View File

@ -2911,7 +2911,11 @@
"items": {
"$ref": "#/definitions/lnrpcRoute"
},
"description": "/ The set of routes that should be used to attempt to complete the payment."
"description": "*\nDeprecated. The set of routes that should be used to attempt to complete the\npayment. The possibility to pass in multiple routes is deprecated and \ninstead the single route field below should be used in combination with the \nstreaming variant of SendToRoute."
},
"route": {
"$ref": "#/definitions/lnrpcRoute",
"description": "/ Route that should be used to attempt to complete the payment."
}
}
},

View File

@ -2565,25 +2565,7 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
graph := r.server.chanDB.ChannelGraph()
if len(req.Routes) == 0 {
return nil, fmt.Errorf("unable to send, no routes provided")
}
routes := make([]*routing.Route, len(req.Routes))
for i, rpcroute := range req.Routes {
route, err := r.unmarshallRoute(rpcroute, graph)
if err != nil {
return nil, err
}
routes[i] = route
}
return &rpcPaymentRequest{
SendRequest: &lnrpc.SendRequest{
PaymentHash: req.PaymentHash,
},
routes: routes,
}, nil
return unmarshallSendToRouteRequest(req, graph)
},
send: func(r *lnrpc.SendResponse) error {
// Calling stream.Send concurrently is not safe.
@ -2594,6 +2576,43 @@ func (r *rpcServer) SendToRoute(stream lnrpc.Lightning_SendToRouteServer) error
})
}
// unmarshallSendToRouteRequest unmarshalls an rpc sendtoroute request
func unmarshallSendToRouteRequest(req *lnrpc.SendToRouteRequest,
graph *channeldb.ChannelGraph) (*rpcPaymentRequest, error) {
switch {
case len(req.Routes) == 0 && req.Route == nil:
return nil, fmt.Errorf("unable to send, no routes provided")
case len(req.Routes) > 0 && req.Route != nil:
return nil, fmt.Errorf("cannot use both route and routes field")
}
var routes []*routing.Route
if len(req.Routes) > 0 {
routes = make([]*routing.Route, len(req.Routes))
for i, rpcroute := range req.Routes {
route, err := unmarshallRoute(rpcroute, graph)
if err != nil {
return nil, err
}
routes[i] = route
}
} else {
route, err := unmarshallRoute(req.Route, graph)
if err != nil {
return nil, err
}
routes = []*routing.Route{route}
}
return &rpcPaymentRequest{
SendRequest: &lnrpc.SendRequest{
PaymentHash: req.PaymentHash,
},
routes: routes,
}, nil
}
// rpcPaymentIntent is a small wrapper struct around the of values we can
// receive from a client over RPC if they wish to send a payment. We'll either
// extract these fields from a payment request (which may include routing
@ -3027,21 +3046,12 @@ func (r *rpcServer) SendToRouteSync(ctx context.Context,
graph := r.server.chanDB.ChannelGraph()
routes := make([]*routing.Route, len(req.Routes))
for i, route := range req.Routes {
route, err := r.unmarshallRoute(route, graph)
if err != nil {
return nil, err
}
routes[i] = route
paymentRequest, err := unmarshallSendToRouteRequest(req, graph)
if err != nil {
return nil, err
}
return r.sendPaymentSync(ctx, &rpcPaymentRequest{
SendRequest: &lnrpc.SendRequest{
PaymentHashString: req.PaymentHashString,
},
routes: routes,
})
return r.sendPaymentSync(ctx, paymentRequest)
}
// sendPaymentSync is the synchronous variant of sendPayment. It will block and
@ -4024,7 +4034,7 @@ func unmarshallHop(graph *channeldb.ChannelGraph, hop *lnrpc.Hop,
// unmarshallRoute unmarshalls an rpc route. For hops that don't specify a
// pubkey, the channel graph is queried.
func (r *rpcServer) unmarshallRoute(rpcroute *lnrpc.Route,
func unmarshallRoute(rpcroute *lnrpc.Route,
graph *channeldb.ChannelGraph) (*routing.Route, error) {
sourceNode, err := graph.SourceNode()