Skip to content
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
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.20.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@

## Functional Enhancements

* RPCs `walletrpc.EstimateFee` and `walletrpc.FundPsbt` now
[allow](https://github.com/lightningnetwork/lnd/pull/10087)
`conf_target=1`. Previously they required `conf_target >= 2`.

## RPC Additions
* When querying [`ForwardingEvents`](https://github.com/lightningnetwork/lnd/pull/9813)
logs, the response now include the incoming and outgoing htlc indices of the payment
Expand Down
4 changes: 4 additions & 0 deletions itest/list_on_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,10 @@ var allTestCases = []*lntest.TestCase{
Name: "delete canceled invoice",
TestFunc: testDeleteCanceledInvoice,
},
{
Name: "estimate fee",
TestFunc: testEstimateFee,
},
}

// appendPrefixed is used to add a prefix to each test name in the subtests
Expand Down
47 changes: 47 additions & 0 deletions itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"os"
"testing"

"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
Expand Down Expand Up @@ -1593,3 +1594,49 @@ func testReorgNotifications(ht *lntest.HarnessTest) {
require.NotNil(ht, spendDetails)
require.Equal(ht, txid2a[:], spendDetails.SpendingTxHash)
}

// testEstimateFee tests walletrpc.EstimateFee API.
func testEstimateFee(ht *lntest.HarnessTest) {
alice := ht.NewNode("Alice", nil)

ctx := context.Background()

testCases := []struct {
name string
confTarget int32
errContains string
}{
{
name: "conf target 1",
confTarget: 1,
},
{
name: "conf target 0",
confTarget: 0,
errContains: "must be greater than 0",
},
{
name: "conf target -1",
confTarget: -1,
errContains: "must be greater than 0",
},
}

for _, tc := range testCases {
ht.Run(tc.name, func(t *testing.T) {
req := &walletrpc.EstimateFeeRequest{
ConfTarget: tc.confTarget,
}
resp, err := alice.RPC.WalletKit.EstimateFee(ctx, req)

if tc.errContains != "" {
require.ErrorContains(t, err, tc.errContains)
return
}

require.NoError(t, err)
require.NotZero(t, resp.SatPerKw)
require.NotZero(t, resp.MinRelayFeeSatPerKw)
})
}
}
4 changes: 2 additions & 2 deletions itest/lnd_psbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1253,8 +1253,8 @@ func fundPsbtCoinSelect(t testing.TB, node *node.HarnessNode,
Template: &walletrpc.FundPsbtRequest_CoinSelect{
CoinSelect: cs,
},
Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{
SatPerVbyte: 50,
Fees: &walletrpc.FundPsbtRequest_TargetConf{
TargetConf: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Commit msg says testing this scenario, tho I don't think it's tested here - the branch below was not executed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted the change in lnrpc/walletrpc/walletkit_server.go and ran make itest icase='fund_psbt'. It failed:

=== RUN   TestLightningNetworkDaemon/tranche00/67-of-309/btcd/fund_psbt
    harness_node.go:395: Starting node (name=Alice) with PID=971348
    harness_node.go:395: Starting node (name=Bob) with PID=971361
    harness_rpc.go:100: 
                Error Trace:    /home/user/lnd/lntest/rpc/harness_rpc.go:100
                                                        /home/user/lnd/lntest/rpc/wallet_kit.go:66
                                                        /home/user/lnd/itest/lnd_psbt_test.go:1252
                                                        /home/user/lnd/itest/lnd_psbt_test.go:1140
                                                        /home/user/lnd/lntest/harness.go:315
                                                        /home/user/lnd/itest/lnd_test.go:130
                Error:          Received unexpected error:
                                rpc error: code = Unknown desc = confirmation target must be greater than 1
                Messages:       Alice: failed to call FundPsbt
    harness.go:393: finished test: fund_psbt, start height=438, end height=440, mined blocks=2
    harness.go:352: test failed, skipped cleanup

},
})

Expand Down
12 changes: 5 additions & 7 deletions lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,12 +843,10 @@ func (w *WalletKit) SendOutputs(ctx context.Context,
func (w *WalletKit) EstimateFee(ctx context.Context,
req *EstimateFeeRequest) (*EstimateFeeResponse, error) {

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

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

feeSatPerKW, err = w.cfg.FeeEstimator.EstimateFeePerKW(
Expand Down
Loading