Skip to content
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

[walletrpc]: add sat_per_kw fee option to FundPsbt RPC #9013

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,8 @@ var fundPsbtCommand = cli.Command{
Name: "fund",
Usage: "Fund a Partially Signed Bitcoin Transaction (PSBT).",
ArgsUsage: "[--template_psbt=T | [--outputs=O [--inputs=I]]] " +
"[--conf_target=C | --sat_per_vbyte=S] [--change_type=A]",
"[--conf_target=C | --sat_per_vbyte=S | --sat_per_kw=K] " +
"[--change_type=A]",
Description: `
The fund command creates a fully populated PSBT that contains enough
inputs to fund the outputs specified in either the PSBT or the
Expand Down Expand Up @@ -1222,6 +1223,11 @@ var fundPsbtCommand = cli.Command{
Usage: "a manual fee expressed in sat/vbyte that " +
"should be used when creating the transaction",
},
cli.Uint64Flag{
Name: "sat_per_kw",
Usage: "a manual fee expressed in sat/kw that " +
"should be used when creating the transaction",
},
cli.StringFlag{
Name: "account",
Usage: "(optional) the name of the account to use to " +
Expand Down Expand Up @@ -1302,10 +1308,11 @@ func fundPsbt(ctx *cli.Context) error {
)

if len(ctx.String("outputs")) > 0 {
// Parse the address to amount map as JSON now. At least one
// entry must be present.
// Parse the address to amount map as JSON now. At least
// one entry must be present.
jsonMap := []byte(ctx.String("outputs"))
if err := json.Unmarshal(jsonMap, &amountToAddr); err != nil {
err := json.Unmarshal(jsonMap, &amountToAddr)
if err != nil {
return fmt.Errorf("error parsing outputs "+
"JSON: %w", err)
}
Expand All @@ -1317,7 +1324,8 @@ func fundPsbt(ctx *cli.Context) error {
var inputs []string

jsonList := []byte(ctx.String("inputs"))
if err := json.Unmarshal(jsonList, &inputs); err != nil {
err := json.Unmarshal(jsonList, &inputs)
if err != nil {
return fmt.Errorf("error parsing inputs JSON: "+
"%v", err)
}
Expand All @@ -1344,15 +1352,23 @@ func fundPsbt(ctx *cli.Context) error {

// Parse fee flags.
switch {
case ctx.IsSet("conf_target") && ctx.IsSet("sat_per_vbyte"):
return fmt.Errorf("cannot set conf_target and sat_per_vbyte " +
"at the same time")
case ctx.IsSet("conf_target") && ctx.IsSet("sat_per_vbyte") ||
ctx.IsSet("conf_target") && ctx.IsSet("sat_per_kw") ||
ctx.IsSet("sat_per_vbyte") && ctx.IsSet("sat_per_kw"):

return fmt.Errorf("only one of conf_target, sat_per_vbyte, " +
"or sat_per_kw can be set at the same time")

case ctx.Uint64("sat_per_vbyte") > 0:
req.Fees = &walletrpc.FundPsbtRequest_SatPerVbyte{
SatPerVbyte: ctx.Uint64("sat_per_vbyte"),
}

case ctx.Uint64("sat_per_kw") > 0:
req.Fees = &walletrpc.FundPsbtRequest_SatPerKw{
SatPerKw: ctx.Uint64("sat_per_kw"),
}

// Check conf_target last because it has a default value.
case ctx.Uint64("conf_target") > 0:
req.Fees = &walletrpc.FundPsbtRequest_TargetConf{
Expand Down
8 changes: 8 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@
`BumpForceCloseFee` which moves the functionality soley available in the
`lncli` to LND hence making it more universal.

* [The `walletrpc.FundPsbt` RPC method now has an option to specify the fee as
`sat_per_kw` which allows for more precise
fees](https://github.com/lightningnetwork/lnd/pull/9013).

## lncli Additions

* [The `lncli wallet fundpsbt` sub command now has a `--sat_per_kw` flag to
specify more precise fee
rates](https://github.com/lightningnetwork/lnd/pull/9013).

# Improvements
## Functional Updates

Expand Down
23 changes: 21 additions & 2 deletions lnrpc/walletrpc/walletkit.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions lnrpc/walletrpc/walletkit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,12 @@ message FundPsbtRequest {
input with.
*/
uint64 sat_per_vbyte = 4;

/*
The fee rate, expressed in sat/kWU, that should be used to spend the
input with.
*/
uint64 sat_per_kw = 11;
}

/*
Expand Down
5 changes: 5 additions & 0 deletions lnrpc/walletrpc/walletkit.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,11 @@
"format": "uint64",
"description": "The fee rate, expressed in sat/vbyte, that should be used to spend the\ninput with."
},
"sat_per_kw": {
"type": "string",
"format": "uint64",
"description": "The fee rate, expressed in sat/kWU, that should be used to spend the\ninput with."
},
"account": {
"type": "string",
"description": "The name of the account to fund the PSBT with. If empty, the default wallet\naccount is used."
Expand Down
6 changes: 5 additions & 1 deletion lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1502,9 +1502,13 @@ func (w *WalletKit) FundPsbt(_ context.Context,
req.GetSatPerVbyte() * 1000,
).FeePerKWeight()

case req.GetSatPerKw() != 0:
feeSatPerKW = chainfee.SatPerKWeight(req.GetSatPerKw())

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

// Then, we'll extract the minimum number of confirmations that each
Expand Down
Loading