From b0e9a4b79f6429dd444f8dccd0a7be77f2e47360 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 17 Jul 2025 11:18:56 -0300 Subject: [PATCH 1/4] walletrpc: allow conf_target=1 in EstimateFee See https://github.com/lightningnetwork/lnd/pull/9611#issuecomment-3082770038 --- lnrpc/walletrpc/walletkit_server.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index e8f0a79e536..d92c09dffbc 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -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( From cd6e648a7f2eccdb0bcbefd433768f459c3d6e94 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 17 Jul 2025 11:19:41 -0300 Subject: [PATCH 2/4] itest: add test for walletrpc.EstimateFee Make sure conf_target=1 is accepted, but conf_target=0 is not. --- itest/list_on_test.go | 4 ++++ itest/lnd_misc_test.go | 47 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/itest/list_on_test.go b/itest/list_on_test.go index b0ab5777416..851662f13f8 100644 --- a/itest/list_on_test.go +++ b/itest/list_on_test.go @@ -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 diff --git a/itest/lnd_misc_test.go b/itest/lnd_misc_test.go index 23112137de4..30b6b77f7e8 100644 --- a/itest/lnd_misc_test.go +++ b/itest/lnd_misc_test.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "fmt" "os" + "testing" "github.com/btcsuite/btcd/btcutil" "github.com/btcsuite/btcd/chaincfg/chainhash" @@ -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) + }) + } +} From c22768283cbc623d695c6d3f0c710b8207c91566 Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Fri, 1 Aug 2025 17:12:15 -0300 Subject: [PATCH 3/4] walletrpc: allow conf_target=1 in FundPsbt Modified 'fund_psbt' itest to test this scenario. --- itest/lnd_psbt_test.go | 4 ++-- lnrpc/walletrpc/walletkit_server.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/itest/lnd_psbt_test.go b/itest/lnd_psbt_test.go index 6090784a096..4b2f9629aa4 100644 --- a/itest/lnd_psbt_test.go +++ b/itest/lnd_psbt_test.go @@ -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, }, }) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index d92c09dffbc..9efc730a4a8 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -1555,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( From aacb94c6d384bb7c61765bba067204053456f24a Mon Sep 17 00:00:00 2001 From: Boris Nagaev Date: Thu, 17 Jul 2025 11:42:10 -0300 Subject: [PATCH 4/4] doc: add release note (EstimateFee conf_target 1) --- docs/release-notes/release-notes-0.20.0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/release-notes/release-notes-0.20.0.md b/docs/release-notes/release-notes-0.20.0.md index 1485fd996fa..af512597eb8 100644 --- a/docs/release-notes/release-notes-0.20.0.md +++ b/docs/release-notes/release-notes-0.20.0.md @@ -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