-
Notifications
You must be signed in to change notification settings - Fork 0
lncli: add source and last_hop params to queryroutes #4
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1163,6 +1163,17 @@ | |||||||||||||||||||||||||||||||
| "to use as the first hop. This flag can be " + | ||||||||||||||||||||||||||||||||
| "specified multiple times in the same command.", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| cli.StringFlag{ | ||||||||||||||||||||||||||||||||
| Name: "source", | ||||||||||||||||||||||||||||||||
| Usage: "(optional) the 33-byte hex-encoded public key for the " + | ||||||||||||||||||||||||||||||||
| "payment source. If empty, self is assumed", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| cli.StringFlag{ | ||||||||||||||||||||||||||||||||
| Name: "last_hop", | ||||||||||||||||||||||||||||||||
| Usage: "(optional) the 33-byte hex-encoded public key " + | ||||||||||||||||||||||||||||||||
| "for the last hop (penultimate node in the path) " + | ||||||||||||||||||||||||||||||||
| "to route through for this payment", | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| cli.StringSliceFlag{ | ||||||||||||||||||||||||||||||||
| Name: "ignore_pair", | ||||||||||||||||||||||||||||||||
| Usage: "ignore directional node pair " + | ||||||||||||||||||||||||||||||||
|
|
@@ -1270,6 +1281,7 @@ | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| req := &lnrpc.QueryRoutesRequest{ | ||||||||||||||||||||||||||||||||
| PubKey: dest, | ||||||||||||||||||||||||||||||||
| SourcePubKey: ctx.String("source"), | ||||||||||||||||||||||||||||||||
|
Comment on lines
1282
to
+1284
|
||||||||||||||||||||||||||||||||
| req := &lnrpc.QueryRoutesRequest{ | |
| PubKey: dest, | |
| SourcePubKey: ctx.String("source"), | |
| // Validate the source parameter if provided. | |
| source := ctx.String("source") | |
| if source != "" { | |
| _, err := hex.DecodeString(source) | |
| if err != nil { | |
| return fmt.Errorf("invalid source pubkey: %v", err) | |
| } | |
| } | |
| req := &lnrpc.QueryRoutesRequest{ | |
| PubKey: dest, | |
| SourcePubKey: source, |
Copilot
AI
Sep 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hex decoding validation for last_hop should include a length check to ensure it's exactly 33 bytes, similar to how other public key validations are typically handled in the codebase.
| } | |
| } | |
| if len(lastHop) != 33 { | |
| return fmt.Errorf("last_hop must be 33 bytes (compressed pubkey), got %d bytes", len(lastHop)) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The public key for last_hop is decoded from hex, but its length is not validated. This could lead to malformed data being sent to the backend if a key with an incorrect length is provided. For consistency with how other public keys are handled in this file (e.g., for sendpayment), and to ensure correctness, I suggest using route.NewVertexFromStr. This function handles both hex decoding and length validation.
| lastHop, err := hex.DecodeString(ctx.String("last_hop")) | |
| if err != nil { | |
| return fmt.Errorf("invalid last_hop argument: %w", err) | |
| } | |
| req.LastHopPubkey = lastHop | |
| lastHop, err := route.NewVertexFromStr(ctx.String("last_hop")) | |
| if err != nil { | |
| return fmt.Errorf("invalid last_hop argument: %w", err) | |
| } | |
| req.LastHopPubkey = lastHop[:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new
last_hopflag duplicates the functionality of the existing globallastHopFlagdefined on line 46. To improve maintainability and avoid code duplication, consider reusing the existing flag here. TheUsagestring in this new flag is more descriptive, so it might be a good idea to update the globallastHopFlagwith this improved text and use it in both places.