Skip to content

Commit 149a819

Browse files
authored
Merge pull request #10087 from starius/estimate-feerate-allow-1
walletrpc: allow conf_target=1 in EstimateFee and FundPsbt
2 parents 37523b6 + aacb94c commit 149a819

File tree

5 files changed

+62
-9
lines changed

5 files changed

+62
-9
lines changed

docs/release-notes/release-notes-0.20.0.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545

4646
## Functional Enhancements
4747

48+
* RPCs `walletrpc.EstimateFee` and `walletrpc.FundPsbt` now
49+
[allow](https://github.com/lightningnetwork/lnd/pull/10087)
50+
`conf_target=1`. Previously they required `conf_target >= 2`.
51+
4852
## RPC Additions
4953
* When querying [`ForwardingEvents`](https://github.com/lightningnetwork/lnd/pull/9813)
5054
logs, the response now include the incoming and outgoing htlc indices of the payment

itest/list_on_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@ var allTestCases = []*lntest.TestCase{
731731
Name: "delete canceled invoice",
732732
TestFunc: testDeleteCanceledInvoice,
733733
},
734+
{
735+
Name: "estimate fee",
736+
TestFunc: testEstimateFee,
737+
},
734738
}
735739

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

itest/lnd_misc_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/hex"
66
"fmt"
77
"os"
8+
"testing"
89

910
"github.com/btcsuite/btcd/btcutil"
1011
"github.com/btcsuite/btcd/chaincfg/chainhash"
@@ -1593,3 +1594,49 @@ func testReorgNotifications(ht *lntest.HarnessTest) {
15931594
require.NotNil(ht, spendDetails)
15941595
require.Equal(ht, txid2a[:], spendDetails.SpendingTxHash)
15951596
}
1597+
1598+
// testEstimateFee tests walletrpc.EstimateFee API.
1599+
func testEstimateFee(ht *lntest.HarnessTest) {
1600+
alice := ht.NewNode("Alice", nil)
1601+
1602+
ctx := context.Background()
1603+
1604+
testCases := []struct {
1605+
name string
1606+
confTarget int32
1607+
errContains string
1608+
}{
1609+
{
1610+
name: "conf target 1",
1611+
confTarget: 1,
1612+
},
1613+
{
1614+
name: "conf target 0",
1615+
confTarget: 0,
1616+
errContains: "must be greater than 0",
1617+
},
1618+
{
1619+
name: "conf target -1",
1620+
confTarget: -1,
1621+
errContains: "must be greater than 0",
1622+
},
1623+
}
1624+
1625+
for _, tc := range testCases {
1626+
ht.Run(tc.name, func(t *testing.T) {
1627+
req := &walletrpc.EstimateFeeRequest{
1628+
ConfTarget: tc.confTarget,
1629+
}
1630+
resp, err := alice.RPC.WalletKit.EstimateFee(ctx, req)
1631+
1632+
if tc.errContains != "" {
1633+
require.ErrorContains(t, err, tc.errContains)
1634+
return
1635+
}
1636+
1637+
require.NoError(t, err)
1638+
require.NotZero(t, resp.SatPerKw)
1639+
require.NotZero(t, resp.MinRelayFeeSatPerKw)
1640+
})
1641+
}
1642+
}

itest/lnd_psbt_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,8 @@ func fundPsbtCoinSelect(t testing.TB, node *node.HarnessNode,
12531253
Template: &walletrpc.FundPsbtRequest_CoinSelect{
12541254
CoinSelect: cs,
12551255
},
1256-
Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{
1257-
SatPerVbyte: 50,
1256+
Fees: &walletrpc.FundPsbtRequest_TargetConf{
1257+
TargetConf: 1,
12581258
},
12591259
})
12601260

lnrpc/walletrpc/walletkit_server.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,10 @@ func (w *WalletKit) SendOutputs(ctx context.Context,
843843
func (w *WalletKit) EstimateFee(ctx context.Context,
844844
req *EstimateFeeRequest) (*EstimateFeeResponse, error) {
845845

846-
switch {
847-
// A confirmation target of zero doesn't make any sense. Similarly, we
848-
// reject confirmation targets of 1 as they're unreasonable.
849-
case req.ConfTarget == 0 || req.ConfTarget == 1:
846+
// A confirmation target of zero or lower doesn't make any sense.
847+
if req.ConfTarget <= 0 {
850848
return nil, fmt.Errorf("confirmation target must be greater " +
851-
"than 1")
849+
"than 0")
852850
}
853851

854852
satPerKw, err := w.cfg.FeeEstimator.EstimateFeePerKW(
@@ -1557,9 +1555,9 @@ func (w *WalletKit) FundPsbt(_ context.Context,
15571555
// Estimate the fee by the target number of blocks to confirmation.
15581556
case req.GetTargetConf() != 0:
15591557
targetConf := req.GetTargetConf()
1560-
if targetConf < 2 {
1558+
if targetConf < 1 {
15611559
return nil, fmt.Errorf("confirmation target must be " +
1562-
"greater than 1")
1560+
"greater than 0")
15631561
}
15641562

15651563
feeSatPerKW, err = w.cfg.FeeEstimator.EstimateFeePerKW(

0 commit comments

Comments
 (0)