-
Notifications
You must be signed in to change notification settings - Fork 2.3k
routerrpc: add more failure reasons and route hints #3156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ae46fb0
7bc56f5
5ce0409
1e79ddc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import ( | |
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/btcsuite/btcd/btcec" | ||
|
|
||
| "github.com/btcsuite/btcd/chaincfg" | ||
| "github.com/btcsuite/btcutil" | ||
| "github.com/lightningnetwork/lnd/lnrpc" | ||
|
|
@@ -382,6 +384,15 @@ func (r *RouterBackend) extractIntentFromSendRequest( | |
| payIntent.PayAttemptTimeout = time.Second * | ||
| time.Duration(rpcPayReq.TimeoutSeconds) | ||
|
|
||
| // Route hints. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't attempt to also parse the route hints from the regular payment request.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Payment request route hints are appended to the list of hints further down. This allows you to augment the encoded hints with a few more. |
||
| routeHints, err := unmarshallRouteHints( | ||
| rpcPayReq.RouteHints, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| payIntent.RouteHints = routeHints | ||
|
|
||
| // 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. | ||
|
|
@@ -443,7 +454,9 @@ func (r *RouterBackend) extractIntentFromSendRequest( | |
| copy(payIntent.Target[:], destKey) | ||
|
|
||
| payIntent.FinalCLTVDelta = uint16(payReq.MinFinalCLTVExpiry()) | ||
| payIntent.RouteHints = payReq.RouteHints | ||
| payIntent.RouteHints = append( | ||
| payIntent.RouteHints, payReq.RouteHints..., | ||
| ) | ||
| } else { | ||
| // Otherwise, If the payment request field was not specified | ||
| // (and a custom route wasn't specified), construct the payment | ||
|
|
@@ -493,6 +506,50 @@ func (r *RouterBackend) extractIntentFromSendRequest( | |
| return payIntent, nil | ||
| } | ||
|
|
||
| // unmarshallRouteHints unmarshalls a list of route hints. | ||
| func unmarshallRouteHints(rpcRouteHints []*lnrpc.RouteHint) ( | ||
| [][]zpay32.HopHint, error) { | ||
|
|
||
| routeHints := make([][]zpay32.HopHint, 0, len(rpcRouteHints)) | ||
| for _, rpcRouteHint := range rpcRouteHints { | ||
| routeHint := make( | ||
| []zpay32.HopHint, 0, len(rpcRouteHint.HopHints), | ||
| ) | ||
| for _, rpcHint := range rpcRouteHint.HopHints { | ||
| hint, err := unmarshallHopHint(rpcHint) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| routeHint = append(routeHint, hint) | ||
| } | ||
| routeHints = append(routeHints, routeHint) | ||
| } | ||
|
|
||
| return routeHints, nil | ||
| } | ||
|
|
||
| // unmarshallHopHint unmarshalls a single hop hint. | ||
| func unmarshallHopHint(rpcHint *lnrpc.HopHint) (zpay32.HopHint, error) { | ||
| pubBytes, err := hex.DecodeString(rpcHint.NodeId) | ||
| if err != nil { | ||
| return zpay32.HopHint{}, err | ||
| } | ||
|
|
||
| pubkey, err := btcec.ParsePubKey(pubBytes, btcec.S256()) | ||
| if err != nil { | ||
| return zpay32.HopHint{}, err | ||
| } | ||
|
|
||
| return zpay32.HopHint{ | ||
| NodeID: pubkey, | ||
| ChannelID: rpcHint.ChanId, | ||
| FeeBaseMSat: rpcHint.FeeBaseMsat, | ||
| FeeProportionalMillionths: rpcHint.FeeProportionalMillionths, | ||
| CLTVExpiryDelta: uint16(rpcHint.CltvExpiryDelta), | ||
| }, 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 { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.