Skip to content

lncli: reject negative sat_per_vbyte in close/open channel commands (fixes #9834)#10663

Open
ThomsenDrake wants to merge 1 commit intolightningnetwork:masterfrom
ThomsenDrake:fix/validate-sat-per-vbyte-negative
Open

lncli: reject negative sat_per_vbyte in close/open channel commands (fixes #9834)#10663
ThomsenDrake wants to merge 1 commit intolightningnetwork:masterfrom
ThomsenDrake:fix/validate-sat-per-vbyte-negative

Conversation

@ThomsenDrake
Copy link
Copy Markdown

Fixes #9834

Problem

The --sat_per_vbyte flag was declared as cli.Int64Flag but read via ctx.Uint64(), causing negative values to wrap to huge positive numbers (e.g., -1 becomes 2^63 - 1). This affects four commands:

  • lncli closechannel
  • lncli closeallchannels
  • lncli openchannel
  • lncli batchopenchannel

A user passing --sat_per_vbyte=-1 would get a transaction with an absurdly high fee rate instead of an error.

Fix

Changed cli.Int64Flagcli.Uint64Flag for sat_per_vbyte in all four commands. The urfave/cli library rejects negative values at parse time when the flag is Uint64, producing a clear error message.

Testing

  • Existing unit tests pass (no test changes needed — the flag type change only affects CLI parsing)
  • Verified: urfave/cli Uint64Flag rejects negative inputs with "invalid value "-1" for flag -sat_per_vbyte: parse error"

Files Changed

  • cmd/commands/cmd_open_channel.go (2 changes: openchannel + batchopenchannel)
  • cmd/commands/commands.go (2 changes: closechannel + closeallchannels)

The --sat_per_vbyte flag was declared as cli.Int64Flag, allowing
negative values. When read via ctx.Uint64(), negative values silently
wrapped to very large uint64 values (e.g., -1 → 18446744073709551615),
producing absurdly high fee rates without any error.

This was reported in lightningnetwork#9834 where `lncli closechannel --sat_per_vbyte=-1`
silently initiated a close with a massive fee rate.

Change the flag type from cli.Int64Flag to cli.Uint64Flag in:
- closeChannelCommand
- closeAllChannelsCommand
- openChannelCommand
- batchOpenChannelCommand

urfave/cli rejects negative values at parse time for Uint64Flag,
preventing the silent wrap-around entirely.

Fixes lightningnetwork#9834

Storm Knight <storm-knight@openclaw.ai>
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 addresses a critical issue where negative fee rate inputs for channel operations could lead to unintended and excessively high transaction fees. By correctly typing the sat_per_vbyte flag as an unsigned integer, the system now robustly rejects invalid negative inputs at the command-line parsing stage, enhancing user experience and preventing costly errors during channel opening and closing.

Highlights

  • Prevents negative sat_per_vbyte values: The sat_per_vbyte flag, previously an Int64Flag but read as Uint64, caused negative inputs to wrap to extremely large positive numbers, resulting in absurdly high transaction fees for channel operations.
  • Improved input validation: The flag type for sat_per_vbyte has been changed from cli.Int64Flag to cli.Uint64Flag in openchannel, batchopenchannel, closechannel, and closeallchannels commands. This leverages urfave/cli's built-in validation to reject negative values at parse time, providing clear error messages.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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
Copy Markdown

@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 updates the sat_per_vbyte flag type from cli.Int64Flag to cli.Uint64Flag for the openChannelCommand, batchOpenChannelCommand, closeChannelCommand, and closeAllChannelsCommand. This change correctly represents fee values as unsigned integers. There is no feedback to provide.

@lightninglabs-deploy
Copy link
Copy Markdown
Collaborator

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

@ThomsenDrake
Copy link
Copy Markdown
Author

@saubyk As requested by the CI bot — re-requesting your review on this PR when you have a moment. The change is minimal (Int64Flag → Uint64Flag for fee rate inputs) and addresses issue #9834 which is assigned to you.

Changes:

  • openChannelCommand: cli.Int64Flagcli.Uint64Flag
  • batchOpenChannelCommand: cli.Int64Flagcli.Uint64Flag
  • closeChannelCommand: cli.Int64Flagcli.Uint64Flag
  • closeAllChannelsCommand: cli.Int64Flagcli.Uint64Flag

All existing tests pass. The Gemini Code Assist bot review found no issues.

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.

[bug]: lncli closechannel accepts a negative sat_per_vbyte value

2 participants