Skip to content

Commit

Permalink
lncli: new command wallet estimatefeerate
Browse files Browse the repository at this point in the history
`lncli wallet estimatefeerate` returns the fee rate estimate for on-chain
transactions in sat/kw and sat/vb to achieve a given confirmation target.
  • Loading branch information
feelancer21 committed Jun 11, 2024
1 parent 286ee95 commit fc90bc9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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 {
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

0 comments on commit fc90bc9

Please sign in to comment.