Skip to content

feat(lncli): Add --route_hints flag to sendpayment --keysend and queryroutes #9721

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

appilon
Copy link

@appilon appilon commented Apr 15, 2025

Change Description

This PR implements the --route_hints flag for the lncli sendpayment --keysend and lncli queryroutes commands, addressing issue #6601. Testing revealed route hinting did not work for standard payments (w/ or w/o --pay_addr). CLI should error if --keysend is not present.

I had a lot of difficulty in testing initially because I was trying have an integration test perform hinting with a standard payment. I'm too much of a newbie to know why, but it seems there just isn't enough context on the backend for standard manual payments (Gemini thought maybe something to do with feature flags and onion routing, all new terms for me, much to learn still). I did manage to get it to work with keysend and amp. The added integration tests are aimed at "emulating" the logic seen in cmd_payments.go in constructing a SendPayment request despite them not covering the pretty trivial argparsing that was actually added in this PR (I just wanted to be sure it worked, which proved valuable given the failed scenarios).

Closes #6601

Steps to Test

  1. Verify lncli argument parsing:

    • No --keysend flags present expect error. (use dummy values)
    • $ lncli --network=simnet --no-macaroons sendpayment --dest=03aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --amt=1000 --payment_hash=0000000000000000000000000000000000000000000000000000000000000000 --final_cltv_delta=40 --route_hints='[]'
    • --keysend, expect a connection error, indicating parsing succeeded. (use dummy values)
    • $ lncli --network=simnet --no-macaroons sendpayment --keysend --dest=03aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa --amt=1000 --final_cltv_delta=40 --route_hints='[{"hop_hints":[{"node_id":"02bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb","chan_id":12345,"fee_base_msat":100,"fee_proportional_millionths":10,"cltv_expiry_delta":18}]}]'
    • Run the same command but with invalid JSON in --route_hints (e.g., remove a quote). Expect a JSON parsing error.
    • Repeat similar basic parsing checks for lncli queryroutes --route_hints='...'.
  2. Run the new integration tests:

    • make itest ITEST_FLAGS='-test.run=TestLightningNetworkDaemon/tranche00/80-of-296/btcd/query_routes_routehints'
    • make itest ITEST_FLAGS='-test.run=TestLightningNetworkDaemon/tranche00/102-of-296/btcd/send_payment_routehints_keysend'

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.

Copy link
Contributor

coderabbitai bot commented Apr 15, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@appilon appilon force-pushed the appilon/6601 branch 2 times, most recently from 842cca7 to 5207897 Compare April 15, 2025 16:59
@saubyk saubyk added lncli payments Related to invoices/payments labels Apr 15, 2025
@saubyk saubyk added this to the v0.20.0 milestone Apr 15, 2025
@appilon
Copy link
Author

appilon commented Apr 16, 2025

@saubyk I fixed the linting errors I believe (strange though cmd_payments.go does not have strict 80 char limit everywhere? I don't mind following the rule of course). As for the unit test failures, I don't see them locally? I did have a commit earlier that caused some failures but I dropped it, perhaps the unit tests didn't re-run or are flakey.

@appilon appilon force-pushed the appilon/6601 branch 4 times, most recently from 8cf6aca to 978d4cf Compare April 16, 2025 02:03
@saubyk saubyk added the good first review Pull Requests that are suitable for new contributors that want to learn code review label Apr 16, 2025
@appilon appilon changed the title feat(lncli): Add --route_hints flag to sendpayment and queryroutes feat(lncli): Add --route_hints flag to sendpayment --keysend/--amp and queryroutes Apr 17, 2025
@appilon appilon force-pushed the appilon/6601 branch 2 times, most recently from 31fe6a6 to 4b9fac7 Compare April 17, 2025 15:52
@appilon
Copy link
Author

appilon commented Apr 17, 2025

@saubyk PR should be ready for review and re-running of CI.

@appilon
Copy link
Author

appilon commented Apr 17, 2025

Sorry about lint error 🤦 forgot to re-rerun locally. fixed now

@saubyk
Copy link
Collaborator

saubyk commented Apr 17, 2025

@saubyk PR should be ready for review and re-running of CI.

Hi @appilon we are currently busy with wrapping up release 0.19. Should be able to get someone to look at the pr in the coming weeks. Meanwhile, anyone else who has bandwidth & interest should feel free to pick this one up

Copy link
Contributor

@MPins MPins left a comment

Choose a reason for hiding this comment

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

Good Job 👍

I’ve successfully run the integration tests and also performed some manual tests using a regtest environment — including sendpayment with keysend and queryroutes.

The only thing missing now are the manual AMP tests, which I’ll be running in the next few days. Everything seems to be working properly so far, but I noticed a logic issue related to when a pay_req is provided — I believe it should be handled a bit differently.

@appilon appilon force-pushed the appilon/6601 branch 2 times, most recently from c216bdc to d54268d Compare April 19, 2025 23:45
@appilon appilon requested review from Lokeshranjan8 and MPins April 19, 2025 23:46
@appilon
Copy link
Author

appilon commented Apr 19, 2025

@MPins @Lokeshranjan8 All review comments have been addressed, thank you for your time reviewing.

@MPins
Copy link
Contributor

MPins commented Apr 21, 2025

@MPins @Lokeshranjan8 All review comments have been addressed, thank you for your time reviewing.

Hello @appilon,

Looking deeper into the --amp case, I believe it should be treated like a regular invoice, where route hints are included at creation time, as defined in BOLT #11.

Therefore, we should keep this change limited to sendpayment --keysend and queryroutes.

It would be great to get @saubyk 's input on this as well.

@appilon
Copy link
Author

appilon commented Apr 25, 2025

@MPins I'm a lot less familiar with the specs and protocols so if AMP payments already handle route hinting similar to a bolt 11 pay req then yes I agree I can limit the flag to just support --keysend, I'd love a core contributor to weigh in @saubyk . Thank you everyone. I'll prep a release note in the meantime until we wait for the final decision.

Copy link
Contributor

@MPins MPins left a comment

Choose a reason for hiding this comment

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

Hello, I just ran a test with AMP invoices, and they do accept route hints when creating the invoice.
Therefore, I think you should move forward and limit this change to sendpayment --keysend and queryroutes only.

Also, I recommend reading the ideal git commit structure guide to improve the commit style.

…tningnetwork#6601)

Adds --route_hints flag to sendpayment for --keysend payments.
Hints should be JSON encoded (see usage for example).

Adds --route_hints flag to queryroutes (no restrictions).

Adds integration tests for query routes over RPC, and manual
keysend over RPC to emulate the new feature. Testing revealed route
hinting did not work for standard payment (w/ or w/o --pay_addr).
@appilon appilon requested a review from MPins May 1, 2025 17:20
@appilon appilon changed the title feat(lncli): Add --route_hints flag to sendpayment --keysend/--amp and queryroutes feat(lncli): Add --route_hints flag to sendpayment --keysend and queryroutes May 1, 2025
@appilon
Copy link
Author

appilon commented May 1, 2025

@MPins Addressed, as for the commit, is style in general (like tense or how I broke up the sentences/paragraphs) an issue or the fact that it's one commit? I know the header is > 50 chars, I kept it under 72, If 50 chars is some hard mandate I'll try my best to compress it.

Copy link
Contributor

@MPins MPins left a comment

Choose a reason for hiding this comment

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

Consider splitting this commit into three commits:
– the functional change
– the test coverage
– the documentation update

Comment on lines +260 to +265
Usage: "route hints for reaching the destination of a" +
" manual --keysend payment. eg: " +
`[{"hop_hints":[{"node_id":"A","chan_id":1,` +
`"fee_base_msat":2,` +
`"fee_proportional_millionths":3,` +
`"cltv_expiry_delta":4}]}]`,
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider avoiding starting the line with a space, mixing " and ` in the same string concatenation, and preserving the single quotes (') around the example shown to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first review Pull Requests that are suitable for new contributors that want to learn code review lncli payments Related to invoices/payments
Projects
Status: Low Priority
Development

Successfully merging this pull request may close these issues.

lncli: No routehints argument defined for sendpayment & queryroutes
4 participants