lnrpc+lnrpc/routerrpc: add a new TLV record field to the Hop proto

In this commit, we add a new field to the Hop proto to allow callers to
be able to specify TLV records for the SendToRoute call, and also to be
able to display TLV records that were used during regular path finding.

We also update SendPayment to support dest TLV records.
This commit is contained in:
Olaoluwa Osuntokun committed 2019-08-22 18:53:03 -07:00
1 parent 4697cfde30
commit 763cb6c09d
9 files changed
+850 -636

No files matched your search

+29 -4
View File
@@ -17,6 +17,7 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/lightningnetwork/lnd/tlv"
"github.com/lightningnetwork/lnd/watchtower"
"github.com/btcsuite/btcd/blockchain"
@@ -2926,6 +2927,8 @@ type rpcPaymentIntent struct {
outgoingChannelID *uint64
payReq []byte
destTLV []tlv.Record
route *route.Route
}
@@ -2968,6 +2971,16 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
payIntent.cltvLimit = &rpcPayReq.CltvLimit
}
if len(rpcPayReq.DestTlv) != 0 {
var err error
payIntent.destTLV, err = tlv.MapToRecords(
rpcPayReq.DestTlv,
)
if err != nil {
return payIntent, err
}
}
// If the payment request field isn't blank, then the details of the
// invoice are encoded entirely within the encoded payReq. So we'll
// attempt to decode it, populating the payment accordingly.
@@ -3123,6 +3136,7 @@ func (r *rpcServer) dispatchPaymentIntent(
OutgoingChannelID: payIntent.outgoingChannelID,
PaymentRequest: payIntent.payReq,
PayAttemptTimeout: routing.DefaultPayAttemptTimeout,
FinalDestRecords: payIntent.destTLV,
}
preImage, route, routerErr = r.server.chanRouter.SendPayment(
@@ -3293,10 +3307,16 @@ func (r *rpcServer) sendPayment(stream *paymentStream) error {
return
}
marshalledRouted := r.routerBackend.
MarshallRoute(resp.Route)
backend := r.routerBackend
marshalledRouted, err := backend.MarshallRoute(
resp.Route,
)
if err != nil {
errChan <- err
return
}
err := stream.send(&lnrpc.SendResponse{
err = stream.send(&lnrpc.SendResponse{
PaymentHash: payIntent.rHash[:],
PaymentPreimage: resp.Preimage[:],
PaymentRoute: marshalledRouted,
@@ -3375,10 +3395,15 @@ func (r *rpcServer) sendPaymentSync(ctx context.Context,
}, nil
}
rpcRoute, err := r.routerBackend.MarshallRoute(resp.Route)
if err != nil {
return nil, err
}
return &lnrpc.SendResponse{
PaymentHash: payIntent.rHash[:],
PaymentPreimage: resp.Preimage[:],
PaymentRoute: r.routerBackend.MarshallRoute(resp.Route),
PaymentRoute: rpcRoute,
}, nil
}