lnd icon indicating copy to clipboard operation
lnd copied to clipboard

Expose `cltv_expiry` flag of `addinvoice` to cli

Open davidgumberg opened this issue 1 year ago • 5 comments

This PR allows users of the lncli RPC interface to set the min_final_cltv_expiry_delta described in BOLT's 11, 7, and 2 by setting the cltv_expiry flag when calling either addinvoice or addholdinvoice.

It also fixes an error message in lnrpc/invoicesrpc/addinvoice.go which printed the user-set CltvExpiry and the minimum allowed CltvExpiry in the wrong order when a value that was too low was used.

I can add a release note if that seems like a good idea.

Steps to Test

To test this change, run addinvoice or addholdinvoice and set a cltv_expiry value.

Pull Request Checklist

Testing

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

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Summary by CodeRabbit

  • New Features
    • Introduced a new option for setting the minimum CLTV delta for the final hop on invoices, enhancing flexibility for users.
  • Bug Fixes
    • Improved the clarity and accuracy of error messages when setting a CLTV delta below the required minimum.
  • Tests
    • Added tests to validate the functionality and error handling of the new CLTV delta setting on invoices.

davidgumberg avatar Feb 19 '24 18:02 davidgumberg

[!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.

Walkthrough

The recent updates introduce a new cltv_expiry flag for invoice commands, enhancing the flexibility in setting the minimum CLTV delta for the final hop. This allows users to define a custom CLTV delta, adhering more closely to their needs or preferences. Additionally, error messaging for non-compliant CLTV deltas has been improved for better clarity. New test cases ensure the functionality works as expected, and an assertion function for error handling in tests has been added.

Changes

File Path Change Summary
cmd/lncli/cmd_invoice.go, lnrpc/invoicesrpc/addinvoice.go Introduced cltv_expiry flag for setting minimum CLTV delta; improved error messaging for CLTV delta constraints.
cmd/lncli/invoicesrpc_active.go Added cltv_expiry flag to addHoldInvoiceCommand for specifying minimum CLTV delta.
itest/list_on_test.go, itest/lnd_misc_test.go Added tests for the cltv_expiry flag functionality and error handling.
lntest/rpc/lnd.go Added AddInvoiceAssertErr function for error assertion in RPC calls.

Related issues

  • lightningnetwork/lnd#8323: The changes in this PR could be linked to this issue as both involve CLTV deltas, albeit in different contexts. The issue discusses adopting a specific CLTV delta for incoming HTLCs as per BOLT-02, which is related to the broader theme of CLTV management and customization in the PR.

Poem

In the land of code, where the bits do hop,
A rabbit tweaked the time, not with a clock, but a hop!
🕒🐰 With flags anew, in the ledger's stew,
Errors clear, and tests to cheer, through and through.
"Hop with care, and time to spare," it said with glee,
For a smoother path, in the crypto sea. 🌊🥕


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

coderabbitai[bot] avatar Feb 19 '24 18:02 coderabbitai[bot]

@coderabbitai review

davidgumberg avatar Feb 19 '24 18:02 davidgumberg

@ellemouton Thank you very much for the review! I've tried to address all your points except for whether or not the test I've added should be an itest or a unit test. Repeating what I mentioned above, since there aren't any existing unit tests for invoicesrpc.AddInvoice some setup and mocking is needed to make a unit test for this PR, just wondering if that is outside of the scope of this PR. Sorry if I'm being obtuse, I'm new here! Let me know what you think the best approach is.

davidgumberg avatar Mar 12 '24 16:03 davidgumberg

@yyforyongyu Rebased on master

davidgumberg avatar Apr 25 '24 16:04 davidgumberg

@davidgumberg, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar May 17 '24 04:05 lightninglabs-deploy

@davidgumberg, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar May 31 '24 05:05 lightninglabs-deploy

@ellemouton Rebased and added a release note

davidgumberg avatar Jun 02 '24 15:06 davidgumberg

Thanks for the fix. Can you rebase to squash the fixup commit please? Then we're good to go.

guggero avatar Jun 04 '24 07:06 guggero

Thanks for the fix. Can you rebase to squash the fixup commit please? Then we're good to go.

Done!

davidgumberg avatar Jun 04 '24 10:06 davidgumberg