Skip to content

Commit 39a1421

Browse files
authored
Merge pull request #10296 from hieblmi/estimate-inputs
estimatefee: tx fee estimate for selected inputs
2 parents d5d151c + 202e473 commit 39a1421

12 files changed

Lines changed: 3649 additions & 3303 deletions

cmd/commands/cmd_open_channel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/btcsuite/btcd/btcutil"
1717
"github.com/btcsuite/btcd/chaincfg/chainhash"
1818
"github.com/btcsuite/btcd/wire"
19+
"github.com/lightningnetwork/lnd"
1920
"github.com/lightningnetwork/lnd/lnrpc"
2021
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
2122
"github.com/urfave/cli"
@@ -406,7 +407,7 @@ func openChannel(ctx *cli.Context) error {
406407
if ctx.IsSet("utxo") {
407408
utxos := ctx.StringSlice("utxo")
408409

409-
outpoints, err := UtxosToOutpoints(utxos)
410+
outpoints, err := lnd.UtxosToOutpoints(utxos)
410411
if err != nil {
411412
return fmt.Errorf("unable to decode utxos: %w", err)
412413
}

cmd/commands/commands.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,14 @@ var estimateFeeCommand = cli.Command{
402402
"transaction *should* confirm in",
403403
},
404404
coinSelectionStrategyFlag,
405+
cli.StringSliceFlag{
406+
Name: "utxo",
407+
Usage: "a utxo specified as outpoint(tx:idx) which " +
408+
"will be used as input for the transaction " +
409+
"to be estimated. This flag can be " +
410+
"repeatedly used to specify multiple utxos " +
411+
"as inputs.",
412+
},
405413
},
406414
Action: actionDecorator(estimateFees),
407415
}
@@ -423,10 +431,21 @@ func estimateFees(ctx *cli.Context) error {
423431
client, cleanUp := getClient(ctx)
424432
defer cleanUp()
425433

434+
var inputs []*lnrpc.OutPoint
435+
if ctx.IsSet("utxo") {
436+
utxos := ctx.StringSlice("utxo")
437+
438+
inputs, err = lnd.UtxosToOutpoints(utxos)
439+
if err != nil {
440+
return fmt.Errorf("unable to decode utxos: %w", err)
441+
}
442+
}
443+
426444
resp, err := client.EstimateFee(ctxc, &lnrpc.EstimateFeeRequest{
427445
AddrToAmount: amountToAddr,
428446
TargetConf: int32(ctx.Int64("conf_target")),
429447
CoinSelectionStrategy: coinSelectionStrategy,
448+
Inputs: inputs,
430449
})
431450
if err != nil {
432451
return err
@@ -607,7 +626,7 @@ func sendCoins(ctx *cli.Context) error {
607626
if ctx.IsSet("utxo") {
608627
utxos := ctx.StringSlice("utxo")
609628

610-
outpoints, err = UtxosToOutpoints(utxos)
629+
outpoints, err = lnd.UtxosToOutpoints(utxos)
611630
if err != nil {
612631
return fmt.Errorf("unable to decode utxos: %w", err)
613632
}
@@ -784,12 +803,12 @@ func listUnspent(ctx *cli.Context) error {
784803
// to stdout. At the moment, this filters out the raw txid bytes from
785804
// each utxo's outpoint and only prints the txid string.
786805
var listUnspentResp = struct {
787-
Utxos []*Utxo `json:"utxos"`
806+
Utxos []*lnd.Utxo `json:"utxos"`
788807
}{
789-
Utxos: make([]*Utxo, 0, len(resp.Utxos)),
808+
Utxos: make([]*lnd.Utxo, 0, len(resp.Utxos)),
790809
}
791810
for _, protoUtxo := range resp.Utxos {
792-
utxo := NewUtxoFromProto(protoUtxo)
811+
utxo := lnd.NewUtxoFromProto(protoUtxo)
793812
listUnspentResp.Utxos = append(listUnspentResp.Utxos, utxo)
794813
}
795814

@@ -2789,12 +2808,14 @@ func updateChannelPolicy(ctx *cli.Context) error {
27892808
// to stdout. At the moment, this filters out the raw txid bytes from
27902809
// each failed update's outpoint and only prints the txid string.
27912810
var listFailedUpdateResp = struct {
2792-
FailedUpdates []*FailedUpdate `json:"failed_updates"`
2811+
FailedUpdates []*lnd.FailedUpdate `json:"failed_updates"`
27932812
}{
2794-
FailedUpdates: make([]*FailedUpdate, 0, len(resp.FailedUpdates)),
2813+
FailedUpdates: make(
2814+
[]*lnd.FailedUpdate, 0, len(resp.FailedUpdates),
2815+
),
27952816
}
27962817
for _, protoUpdate := range resp.FailedUpdates {
2797-
failedUpdate := NewFailedUpdateFromProto(protoUpdate)
2818+
failedUpdate := lnd.NewFailedUpdateFromProto(protoUpdate)
27982819
listFailedUpdateResp.FailedUpdates = append(
27992820
listFailedUpdateResp.FailedUpdates, failedUpdate)
28002821
}

cmd/commands/walletrpc_active.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/btcsuite/btcd/chaincfg/chainhash"
2121
"github.com/btcsuite/btcd/txscript"
2222
"github.com/btcsuite/btcd/wire"
23+
"github.com/lightningnetwork/lnd"
2324
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2425
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2526
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
@@ -330,7 +331,7 @@ func bumpFee(ctx *cli.Context) error {
330331
}
331332

332333
// Validate and parse the relevant arguments/flags.
333-
protoOutPoint, err := NewProtoOutPoint(ctx.Args().Get(0))
334+
protoOutPoint, err := lnd.NewProtoOutPoint(ctx.Args().Get(0))
334335
if err != nil {
335336
return err
336337
}
@@ -812,11 +813,11 @@ func removeTransaction(ctx *cli.Context) error {
812813

813814
// utxoLease contains JSON annotations for a lease on an unspent output.
814815
type utxoLease struct {
815-
ID string `json:"id"`
816-
OutPoint OutPoint `json:"outpoint"`
817-
Expiration uint64 `json:"expiration"`
818-
PkScript []byte `json:"pk_script"`
819-
Value uint64 `json:"value"`
816+
ID string `json:"id"`
817+
OutPoint lnd.OutPoint `json:"outpoint"`
818+
Expiration uint64 `json:"expiration"`
819+
PkScript []byte `json:"pk_script"`
820+
Value uint64 `json:"value"`
820821
}
821822

822823
// fundPsbtResponse is a struct that contains JSON annotations for nice result
@@ -1358,7 +1359,7 @@ func fundPsbt(ctx *cli.Context) error {
13581359
}
13591360

13601361
for idx, input := range inputs {
1361-
op, err := NewProtoOutPoint(input)
1362+
op, err := lnd.NewProtoOutPoint(input)
13621363
if err != nil {
13631364
return fmt.Errorf("error parsing "+
13641365
"UTXO outpoint %d: %v", idx,
@@ -1447,7 +1448,7 @@ func marshallLocks(lockedUtxos []*walletrpc.UtxoLease) []*utxoLease {
14471448
for idx, lock := range lockedUtxos {
14481449
jsonLocks[idx] = &utxoLease{
14491450
ID: hex.EncodeToString(lock.Id),
1450-
OutPoint: NewOutPointFromProto(lock.Outpoint),
1451+
OutPoint: lnd.NewOutPointFromProto(lock.Outpoint),
14511452
Expiration: lock.Expiration,
14521453
PkScript: lock.PkScript,
14531454
Value: lock.Value,
@@ -1578,7 +1579,7 @@ func leaseOutput(ctx *cli.Context) error {
15781579
}
15791580

15801581
outpointStr := ctx.String("outpoint")
1581-
outpoint, err := NewProtoOutPoint(outpointStr)
1582+
outpoint, err := lnd.NewProtoOutPoint(outpointStr)
15821583
if err != nil {
15831584
return fmt.Errorf("error parsing outpoint: %w", err)
15841585
}
@@ -1663,7 +1664,7 @@ func releaseOutput(ctx *cli.Context) error {
16631664
return fmt.Errorf("outpoint argument missing")
16641665
}
16651666

1666-
outpoint, err := NewProtoOutPoint(outpointStr)
1667+
outpoint, err := lnd.NewProtoOutPoint(outpointStr)
16671668
if err != nil {
16681669
return fmt.Errorf("error parsing outpoint: %w", err)
16691670
}

cmd/commands/walletrpc_types.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package commands
22

3-
import "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
3+
import (
4+
"github.com/lightningnetwork/lnd"
5+
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
6+
)
47

58
// PendingSweep is a CLI-friendly type of the walletrpc.PendingSweep proto. We
69
// use this to show more useful string versions of byte slices and enums.
@@ -9,16 +12,16 @@ import "github.com/lightningnetwork/lnd/lnrpc/walletrpc"
912
// here. Instead, we should rely on the struct defined in the proto
1013
// `PendingSweepsResponse` only.
1114
type PendingSweep struct {
12-
OutPoint OutPoint `json:"outpoint"`
13-
WitnessType string `json:"witness_type"`
14-
AmountSat uint32 `json:"amount_sat"`
15-
SatPerVByte uint32 `json:"sat_per_vbyte"`
16-
BroadcastAttempts uint32 `json:"broadcast_attempts"`
17-
RequestedSatPerVByte uint32 `json:"requested_sat_per_vbyte"`
18-
Immediate bool `json:"immediate"`
19-
Budget uint64 `json:"budget"`
20-
DeadlineHeight uint32 `json:"deadline_height"`
21-
MaturityHeight uint32 `json:"maturity_height"`
15+
OutPoint lnd.OutPoint `json:"outpoint"`
16+
WitnessType string `json:"witness_type"`
17+
AmountSat uint32 `json:"amount_sat"`
18+
SatPerVByte uint32 `json:"sat_per_vbyte"`
19+
BroadcastAttempts uint32 `json:"broadcast_attempts"`
20+
RequestedSatPerVByte uint32 `json:"requested_sat_per_vbyte"`
21+
Immediate bool `json:"immediate"`
22+
Budget uint64 `json:"budget"`
23+
DeadlineHeight uint32 `json:"deadline_height"`
24+
MaturityHeight uint32 `json:"maturity_height"`
2225

2326
NextBroadcastHeight uint32 `json:"next_broadcast_height"`
2427
RequestedConfTarget uint32 `json:"requested_conf_target"`
@@ -29,7 +32,9 @@ type PendingSweep struct {
2932
// its corresponding CLI-friendly type.
3033
func NewPendingSweepFromProto(pendingSweep *walletrpc.PendingSweep) *PendingSweep {
3134
return &PendingSweep{
32-
OutPoint: NewOutPointFromProto(pendingSweep.Outpoint),
35+
OutPoint: lnd.NewOutPointFromProto(
36+
pendingSweep.Outpoint,
37+
),
3338
WitnessType: pendingSweep.WitnessType.String(),
3439
AmountSat: pendingSweep.AmountSat,
3540
SatPerVByte: uint32(pendingSweep.SatPerVbyte),

docs/release-notes/release-notes-0.21.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,16 @@
6464
it becomes available. These methods provide an alternative to the standard
6565
`MuSig2RegisterNonces` workflow and are only supported in MuSig2 v1.0.0rc2.
6666

67+
* The `EstimateFee` RPC now supports [explicit input
68+
selection](https://github.com/lightningnetwork/lnd/pull/10296). Users can
69+
specify a list of inputs to use as transaction inputs via the new
70+
`inputs` field in `EstimateFeeRequest`.
71+
6772
## lncli Additions
6873

74+
* The `estimatefee` command now supports the `--utxos` flag to specify explicit
75+
inputs for fee estimation.
76+
6977
# Improvements
7078
## Functional Updates
7179

@@ -138,6 +146,7 @@
138146
* Boris Nagaev
139147
* Elle Mouton
140148
* Erick Cestari
149+
* hieblmi
141150
* Mohamed Awnallah
142151
* Nishant Bansal
143152
* Pins

itest/list_on_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,14 @@ var allTestCases = []*lntest.TestCase{
759759
Name: "estimate fee",
760760
TestFunc: testEstimateFee,
761761
},
762+
{
763+
Name: "estimate on chain fee with selected inputs",
764+
TestFunc: testEstimateOnChainFeeWithSelectedInputs,
765+
},
766+
{
767+
Name: "estimate on chain fee auto selected inputs",
768+
TestFunc: testEstimateOnChainFeeAutoSelectedInputs,
769+
},
762770
}
763771

764772
// appendPrefixed is used to add a prefix to each test name in the subtests

0 commit comments

Comments
 (0)