Skip to content

add sats_per_kweight option when crafting a transaction (continue) #10067

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

MPins
Copy link
Contributor

@MPins MPins commented Jul 10, 2025

This PR continues the work started in #7454 by @ziggie1984

The goal is to allow callers to specify a custom sats_per_kweight value when crafting transactions, enabling finer control over fee rates. This is particularly useful for advanced channel management.

Original PR:

#7454

Happy to continue the discussion and iterate on this.

This commit has to include all these subsystems because
the rpc value sat_per_byte is replaced with the
sat_per_kweight option and otherwise the commit would not
be compilable by itself.

lnrpc:
For OpenChannelRequest, BatchOpenChannelRequest, SendCoinsRequest
SendManyRequest, CloseChannelRequest and EstimateFeeResponse
the sat_per_kweight field is added or replaced for the
deprecated sat_per_byte field where applicable. This allows
for more fine granular control of transaction fees.

lnd:
Fee calculation for sendcoins, sendmany, openchannel,
closechannel has now the option sat_per_kweight.
The option sat_per_byte is replaced by sat_per_kweight.
In addition a safety check is added to prevent very high fees.
For the estimatefee cmd the fee in sat_per_kweight is added
to the response.

lncli,itest,lntest:
remove usage of sat_per_byte option.
Add the sat_per_kweight for the rpc calls FundPsbt,
BumpFee and Pendingsweeps. Where applicable the
sat_per_byte option is replaced by the sat_per_kweight
option.
Adopt the option sat_per_kweight for batch channel openings.
Add new itests for openchannel,sendcoins,sendmany,
fund psbt and bumpfee rpc calls.

In addition the RBF logic is now tested in the itests (bumpfee)
resolving an outstanding TODO.
The deprecated option sat_per_byte is replaced by the
new sat_per_kweight option where applicable otherwise it is added.

Add the sat_per_kweight option for the lnrpc cmds
sendcoins, sendmany, openchannel, batchopenchannel, closechannel.
Also return the sat_per_kweight for estimatefee in the response.

Add sat_per_kweight option for walletrpc cmds "wallet psbt fund"
and "wallet bumpfee".
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.

Summary of Changes

Hello @MPins, 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 fee rate control within the system by introducing a sats_per_kweight option for various on-chain and channel-related transactions. This change provides more granular control over transaction fees, which is particularly beneficial for advanced users managing Lightning channels. The update involves modifications to the command-line interface, RPC definitions, internal fee calculation logic, and comprehensive integration tests to ensure correctness and prevent conflicting fee specifications.

Highlights

  • New Fee Rate Option: Introduced a new --sat_per_kweight option across various lncli commands and walletrpc calls, allowing users to specify transaction fees in satoshis per kiloweight (sat/kweight). This provides finer control over fee rates, especially useful for advanced channel management.
  • API and Protocol Updates: Updated lnrpc/lightning.proto and lnrpc/walletrpc/walletkit.proto to include the new sat_per_kweight field, replacing the deprecated sat_per_byte field. Corresponding Swagger and generated Go files have been updated.
  • Fee Calculation Logic Enhancement: Modified the internal CalculateFeeRate utility to properly handle the new sat_per_kweight input, ensuring that only one fee rate type (sat_per_vbyte or sat_per_kweight) can be specified at a time. A security measure was also added to cap the effective fee rate at a default maximum.
  • Expanded Command Support: The --sat_per_kweight option is now available for lncli openchannel, batchopenchannel, sendcoins, sendmany, and closechannel commands, as well as walletrpc FundPsbt and BumpFee calls.
  • Integration Test Coverage: Added new integration tests to verify the correct application of sat_per_kweight for channel opening, sending coins, and sending to multiple addresses, including tests for mutual exclusivity with sat_per_vbyte.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 is currently in preview and 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 to provide feedback.

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.

@MPins MPins changed the title Kweight selection add sats_per_kweight option when crafting a transaction (continue) Jul 10, 2025
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 introduces a sats_per_kweight option for more granular fee control in various transaction-related commands. The changes are extensive, touching lncli commands, RPC definitions, and wallet logic. I've added several new integration tests to validate this new functionality.

My review focuses on ensuring consistency in argument validation across different commands, adherence to the style guide, and clarity in documentation and error messages. I've identified a few places where command-line argument validation can be improved and some documentation that could be more precise. Overall, the implementation is solid, and the new feature is a great addition.

Comment on lines +861 to +866
_, err := checkNotBothSet(
ctx, "sat_per_vbyte", "sat_per_kweight",
)
if err != nil {
return err
}

Choose a reason for hiding this comment

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

medium

Similar to the openchannel command, the batchopenchannel command should also validate that conf_target is not used at the same time as sat_per_vbyte or sat_per_kweight to avoid ambiguity in fee specification.

// Make sure only one fee preference is specified.
	feeRate, err := checkNotBothSet(
		ctx, "conf_target", "sat_per_vbyte",
	)
	if err != nil {
		return err
	}
	_, err = checkNotBothSet(
		ctx, feeRate, "sat_per_kweight",
	)
	if err != nil {
		return err
	}

Comment on lines +213 to +217
* [Add sat_per_kweight option for more fine granular control of transaction
fees](https://github.com/lightningnetwork/lnd/pull/7454). For the commands
SendCoins, SendMany, OpenChannel, BatchOpenChannel, CloseChannel this option
is added. Also the walletrpc calls FundPsbt, BumpFee and PendingSweeps
support the new fee rate option.

Choose a reason for hiding this comment

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

medium

The wording in this release note could be improved for clarity and conciseness.

Suggested change
* [Add sat_per_kweight option for more fine granular control of transaction
fees](https://github.com/lightningnetwork/lnd/pull/7454). For the commands
SendCoins, SendMany, OpenChannel, BatchOpenChannel, CloseChannel this option
is added. Also the walletrpc calls FundPsbt, BumpFee and PendingSweeps
support the new fee rate option.
* [Add `sat_per_kweight` option for finer-grained control of transaction
fees](https://github.com/lightningnetwork/lnd/pull/7454). This option
is added for the `SendCoins`, `SendMany`, `OpenChannel`,
`BatchOpenChannel`, and `CloseChannel` commands. The `walletrpc` calls
`FundPsbt`, `BumpFee`, and `PendingSweeps` also support the new fee rate
option.

Comment on lines +293 to +295
err := bob.RPC.BumpFeeErr(bumpFeeReq)
require.ErrorContains(ht, err, "either SatPerKweight or SatPerVbyte "+
"should be set")

Choose a reason for hiding this comment

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

medium

The error message being checked here seems incomplete. The actual error message returned when both SatPerKweight and SatPerVbyte are set should include "but not both". Please update the expected error string to match the actual error for a more accurate test.

Suggested change
err := bob.RPC.BumpFeeErr(bumpFeeReq)
require.ErrorContains(ht, err, "either SatPerKweight or SatPerVbyte "+
"should be set")
err := bob.RPC.BumpFeeErr(bumpFeeReq)
require.ErrorContains(ht, err, "either SatPerKweight or SatPerVbyte "+
"should be set, but not both")

Comment on lines 1209 to 1211
default:
return nil, fmt.Errorf("fee definition missing, need to " +
"specify either target_conf or sat_per_vbyte")

Choose a reason for hiding this comment

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

medium

The error message in this default case is now outdated with the addition of sat_per_kweight. It should be updated to include the new fee option to provide a more accurate message to the user.

	default:
		return nil, fmt.Errorf("fee definition missing, need to " +
			"specify either target_conf, sat_per_vbyte, or "+
			"sat_per_kweight")

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.

2 participants