From 35dd5f354d44691991a9bc6a694947e710377e02 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 18 Dec 2019 23:57:38 -0800 Subject: [PATCH] routerrpc: parse dest_features bits for manual SendPayment --- lnrpc/routerrpc/router_backend.go | 23 +++++++++++++++++++++++ rpcserver.go | 8 ++++++++ 2 files changed, 31 insertions(+) diff --git a/lnrpc/routerrpc/router_backend.go b/lnrpc/routerrpc/router_backend.go index 383180a3..acd3125a 100644 --- a/lnrpc/routerrpc/router_backend.go +++ b/lnrpc/routerrpc/router_backend.go @@ -633,6 +633,14 @@ func (r *RouterBackend) extractIntentFromSendRequest( // Payment hash. copy(payIntent.PaymentHash[:], rpcPayReq.PaymentHash) + + // Parse destination feature bits. + features, err := UnmarshalFeatures(rpcPayReq.DestFeatures) + if err != nil { + return nil, err + } + + payIntent.DestFeatures = features } // Currently, within the bootstrap phase of the network, we limit the @@ -699,6 +707,21 @@ func unmarshallHopHint(rpcHint *lnrpc.HopHint) (zpay32.HopHint, error) { }, nil } +// UnmarshalFeatures converts a list of uint32's into a valid feature vector. +// This method checks that feature bit pairs aren't assigned toegether, and +// validates transitive depdencies. +func UnmarshalFeatures(rpcFeatures []lnrpc.FeatureBit) (*lnwire.FeatureVector, error) { + raw := lnwire.NewRawFeatureVector() + for _, bit := range rpcFeatures { + err := raw.SafeSet(lnwire.FeatureBit(bit)) + if err != nil { + return nil, err + } + } + + return lnwire.NewFeatureVector(raw, lnwire.Features), nil +} + // ValidatePayReqExpiry checks if the passed payment request has expired. In // the case it has expired, an error will be returned. func ValidatePayReqExpiry(payReq *zpay32.Invoice) error { diff --git a/rpcserver.go b/rpcserver.go index 1e5e71b1..239df76d 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3442,6 +3442,14 @@ func (r *rpcServer) extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPayme copy(payIntent.rHash[:], rpcPayReq.PaymentHash) } + // Unmarshal any custom destination features. + payIntent.destFeatures, err = routerrpc.UnmarshalFeatures( + rpcPayReq.DestFeatures, + ) + if err != nil { + return payIntent, err + } + // Currently, within the bootstrap phase of the network, we limit the // largest payment size allotted to (2^32) - 1 mSAT or 4.29 million // satoshis.