Skip to content

Conversation

@feelancer21
Copy link
Owner

Add two new optional parameters to the lncli queryroutes command:
--source: Allows specifying the source node for the route query.
--last_hop: Allows specifying the penultimate node in the payment path.

Change Description

Description of change / link to associated issue.

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Add two new optional parameters to the lncli queryroutes command:
 --source:   Allows specifying the source node for the route query.
 --last_hop: Allows specifying the penultimate node in the payment path.
Copilot AI review requested due to automatic review settings September 30, 2025 12:07
@gemini-code-assist
Copy link

Summary of Changes

Hello @feelancer21, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the lncli queryroutes command by introducing two new optional parameters, --source and --last_hop. These additions provide users with greater flexibility and control when querying routes on the Lightning Network, allowing for more precise specification of the payment's origin and the penultimate node in its path. This improves the utility of the command for advanced routing scenarios and debugging.

Highlights

  • New queryroutes parameters: The lncli queryroutes command now supports two new optional parameters: --source and --last_hop.
  • Specify Source Node: The --source parameter allows users to specify the 33-byte hex-encoded public key for the payment source, defaulting to the self node if not provided.
  • Specify Last Hop: The --last_hop parameter enables specifying the 33-byte hex-encoded public key for the penultimate node in the payment path, offering more control over route construction.
  • Release Notes Update: Documentation has been updated in docs/release-notes/release-notes-0.20.0.md to reflect the addition of these new queryroutes parameters.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds two new optional command-line parameters to the lncli queryroutes command to provide more granular control over route finding by allowing specification of the source node and penultimate hop in the payment path.

  • Added --source parameter to specify the source node for route queries
  • Added --last_hop parameter to specify the penultimate node in the payment path
  • Updated release notes to document the new functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cmd/commands/cmd_payments.go Implements the new CLI flags and request field mapping for source and last_hop parameters
docs/release-notes/release-notes-0.20.0.md Documents the new queryroutes parameters and adds contributor credit

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

lastHop, err := hex.DecodeString(ctx.String("last_hop"))
if err != nil {
return fmt.Errorf("invalid last_hop argument: %w", err)
}
Copy link

Copilot AI Sep 30, 2025

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.

Suggested change
}
}
if len(lastHop) != 33 {
return fmt.Errorf("last_hop must be 33 bytes (compressed pubkey), got %d bytes", len(lastHop))
}

Copilot uses AI. Check for mistakes.
Comment on lines 1282 to +1284
req := &lnrpc.QueryRoutesRequest{
PubKey: dest,
SourcePubKey: ctx.String("source"),
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source parameter should have hex decoding validation similar to last_hop, rather than passing the raw string directly to the request. This ensures consistent input validation for public key parameters.

Suggested change
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 uses AI. Check for mistakes.
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds --source and --last_hop parameters to the lncli queryroutes command, enhancing its flexibility. The changes are well-implemented, but I have a couple of suggestions to improve code consistency and robustness. Specifically, I've pointed out a duplicated flag definition and a missing validation check for a public key.

Comment on lines +1302 to +1306
lastHop, err := hex.DecodeString(ctx.String("last_hop"))
if err != nil {
return fmt.Errorf("invalid last_hop argument: %w", err)
}
req.LastHopPubkey = lastHop

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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[:]

Comment on lines +1171 to +1176
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",
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This new last_hop flag duplicates the functionality of the existing global lastHopFlag defined on line 46. To improve maintainability and avoid code duplication, consider reusing the existing flag here. The Usage string in this new flag is more descriptive, so it might be a good idea to update the global lastHopFlag with this improved text and use it in both places.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 18129288550

Details

  • 0 of 7 (0.0%) changed or added relevant lines in 1 file are covered.
  • 69 unchanged lines in 14 files lost coverage.
  • Overall coverage increased (+0.005%) to 66.603%

Changes Missing Coverage Covered Lines Changed/Added Lines %
cmd/commands/cmd_payments.go 0 7 0.0%
Files with Coverage Reduction New Missed Lines %
chainntnfs/btcdnotify/btcd.go 1 82.09%
funding/manager.go 2 73.88%
htlcswitch/mailbox.go 2 93.55%
htlcswitch/mock.go 2 73.93%
invoices/invoiceregistry.go 2 86.05%
lntest/port/port.go 2 71.25%
peer/brontide.go 2 78.27%
lnwire/channel_ready.go 3 86.75%
lnwire/dyn_commit.go 3 79.76%
watchtower/wtdb/migration4/range_index.go 3 51.72%
Totals Coverage Status
Change from base Build 18129273091: 0.005%
Covered Lines: 136758
Relevant Lines: 205332

💛 - Coveralls

@feelancer21 feelancer21 closed this Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants