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

lncli: new command wallet estimatefeerate #8730

Merged
Merged
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
52 changes: 52 additions & 0 deletions cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"sort"
"strconv"
"strings"
Expand All @@ -22,6 +23,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/urfave/cli"
)
Expand Down Expand Up @@ -77,6 +79,7 @@ func walletCommands() []cli.Command {
Usage: "Interact with the wallet.",
Description: "",
Subcommands: []cli.Command{
estimateFeeRateCommand,
pendingSweepsCommand,
bumpFeeCommand,
bumpCloseFeeCommand,
Expand Down Expand Up @@ -124,6 +127,55 @@ func getWalletClient(ctx *cli.Context) (walletrpc.WalletKitClient, func()) {
return walletrpc.NewWalletKitClient(conn), cleanUp
}

var estimateFeeRateCommand = cli.Command{
Name: "estimatefeerate",
Usage: "Estimates the on-chain fee rate to achieve a confirmation " +
"target.",
ArgsUsage: "conf_target",
Description: `
Returns the fee rate estimate for on-chain transactions in sat/kw and
sat/vb to achieve a given confirmation target. The source of the fee
rate depends on the configuration and is either the on-chain backend or
alternatively an external URL.
`,
Action: actionDecorator(estimateFeeRate),
}

func estimateFeeRate(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getWalletClient(ctx)
defer cleanUp()

confTarget, err := strconv.ParseInt(ctx.Args().First(), 10, 64)
if err != nil {
return cli.ShowCommandHelp(ctx, "estimatefeerate")
}

if confTarget <= 0 || confTarget > math.MaxInt32 {
ellemouton marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("conf_target out of range")
}

resp, err := client.EstimateFee(ctxc, &walletrpc.EstimateFeeRequest{
ConfTarget: int32(confTarget),
})
if err != nil {
return err
}

rateKW := chainfee.SatPerKWeight(resp.SatPerKw)
rateVB := rateKW.FeePerVByte()

printJSON(struct {
SatPerKw int64 `json:"sat_per_kw"`
SatPerVByte int64 `json:"sat_per_vbyte"`
}{
SatPerKw: int64(rateKW),
SatPerVByte: int64(rateVB),
})

return nil
}

var pendingSweepsCommand = cli.Command{
Name: "pendingsweeps",
Usage: "List all outputs that are pending to be swept within lnd.",
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.18.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
`min_final_cltv_expiry_delta`

* The [`lncli wallet estimatefeerate`](https://github.com/lightningnetwork/lnd/pull/8730)
command returns the fee rate estimate for on-chain transactions in sat/kw and
sat/vb to achieve a given confirmation target.

# Improvements
## Functional Updates
## RPC Updates
Expand Down
Loading