Merge pull request #11396 from yyforyongyu/task-lease-policy
What changed, and why it matters
This commit changes how LND's wallet locks (leases) unspent coins through its RPC interface. It removes a recently added 'release after N confirmations' option and replaces it with an explicit 'no expiry' flag. Old clients that still send the removed option now get a clear error instead of silently falling back to a timed lease. The change is a deliberate API cleanup with security-relevant hardening against silent downgrade, but it is not a fix for an active vulnerability.
Operators and integrators using `LeaseOutput` or `FundPsbt` should migrate before upgrading: replace any use of `release_after_spend_confs` / `input_release_after_spend_confs` with `no_expiry` / `input_lease_no_expiry`, ensure a persisted custom lock ID is used for no-expiry input leases, and verify the returned `no_expiry` acknowledgement. Review any logic that relied on leases surviving a reorg or being released after N confirmations, because no-expiry leases now release at first confirmed spend and do not survive reorgs.
Security signals we found
Breaking API change that reserves removed protobuf fields to prevent accidental reintroduction
Explicit rejection of legacy `release_after_spend_confs` parameters from old clients instead of silent fallback
Validation prevents conflicting no-expiry + duration lease settings before wallet state is touched
Custom lock ID required for no-expiry input leases to prevent accidental shared ownership
Reorg behavior changed: no-expiry leases are removed at first confirmed spend and are not restored by a reorg
Evidence from the diff
The patch retires the release_after_spend_confs / input_release_after_spend_confs fields from LeaseOutput, FundPsbt, and UtxoLease, reserving their protobuf field numbers so they cannot be reused. It introduces no_expiry / input_lease_no_expiry booleans that map to the wallet’s existing depth-1 no-timeout lease policy (cleanup at first confirmed spend or owner release). Server-side validation now rejects: (1) old protobuf clients sending the retired fields via unknown-field scanning, (2) combining no-expiry with a positive duration, and (3) no-expiry input leases without a valid non-zero, non-reserved custom lock ID. Responses expose the no-expiry policy as a boolean. Integration tests are updated to cover restart durability, owner release, and first-confirmed-spend cleanup.
Changed components
lnrpc/walletrpc/walletkit.protolnrpc/walletrpc/walletkit.pb.golnrpc/walletrpc/walletkit.swagger.jsonlnrpc/walletrpc/walletkit_grpc.pb.golnrpc/walletrpc/walletkit_server.goitest/lnd_psbt_test.goInspect captured patch +663 / −402
### docs/release-notes/unreleased/11396.md
@@ -0,0 +1,34 @@
+# New Features
+
+## RPC Additions
+
+* WalletKit [adds explicit no-expiry
+ leases](https://github.com/lightningnetwork/lnd/pull/11396). Set
+ `LeaseOutput.no_expiry` or `FundPsbt.input_lease_no_expiry` to reserve unused
+ outputs without a timeout. The owner can release the reservation, and the
+ wallet removes the lease at the first confirmed spend.
+ New no-expiry leases therefore do not expose confirmation progress through
+ `confirmed_spend_height`.
+
+# Improvements
+
+## Breaking Changes
+
+* WalletKit [replaces the confirmation-count RPC
+ parameters](https://github.com/lightningnetwork/lnd/pull/11396)
+ `LeaseOutput.release_after_spend_confs` and
+ `FundPsbt.input_release_after_spend_confs` with the explicit no-expiry flags
+ and removes the `release_after_spend_confs` response fields from
+ `LeaseOutputResponse` and `UtxoLease`.
+ The retired fields were introduced in v0.21.4-beta by
+ [#11125](https://github.com/lightningnetwork/lnd/pull/11125).
+ Callers must migrate and verify the returned `no_expiry` acknowledgement;
+ requests using the retired count parameters now fail explicitly, including
+ requests from old protobuf clients, instead of falling back to timed leases.
+ After a confirmed spend, a reorg does not restore the removed lease. If the
+ spending transaction is later removed, an otherwise unspent input can become
+ selectable again.
+ Any pre-upgrade leases with a confirmation depth above one retain that policy
+ and ignore expiration, despite `ListLeases` reporting `no_expiry=false`.
+ The owner can release them with `ReleaseOutput`; an unspent output can also
+ be re-leased with `no_expiry=true` to adopt first-confirmed-spend cleanup.
### itest/list_on_test.go
@@ -327,8 +327,8 @@ var allTestCases = []*lntest.TestCase{
TestFunc: testFundPsbtCustomLock,
},
{
- Name: "fund psbt confirmation lease",
- TestFunc: testFundPsbtConfirmationLease,
+ Name: "fund psbt no expiry lease",
+ TestFunc: testFundPsbtNoExpiryLease,
},
{
Name: "resolution handoff",
### itest/lnd_psbt_test.go
@@ -3,8 +3,6 @@ package itest
import (
"bytes"
"encoding/hex"
- "errors"
- "fmt"
"testing"
"time"
@@ -26,7 +24,6 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lntest"
"github.com/lightningnetwork/lnd/lntest/node"
- "github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/stretchr/testify/require"
)
@@ -2045,21 +2042,21 @@ func testFundPsbtCustomLock(ht *lntest.HarnessTest) {
require.Empty(ht, leasesRespAfter.LockedUtxos)
}
-// testFundPsbtConfirmationLease verifies the complete persisted lease
-// lifecycle. The lease must survive wall-clock expiry before confirmation, a
-// shallow reorg, and a node restart, then release at its requested spend depth.
-func testFundPsbtConfirmationLease(ht *lntest.HarnessTest) {
- const (
- releaseDepth = uint32(3)
- lockDurationSecond = uint64(1)
- )
-
- alice := ht.NewNodeWithCoins("Alice", nil)
+// testFundPsbtNoExpiryLease verifies that an unused input stays reserved across
+// restart, can be owner-released, and needs no lease after its first spend.
+func testFundPsbtNoExpiryLease(ht *lntest.HarnessTest) {
+ // Arrange one confirmed input so its absence from eligible candidates
+ // proves reservation, and its reappearance proves owner cancellation.
+ alice := ht.NewNode("Alice", nil)
+ ht.FundNumCoins(alice, 1)
+ input := ht.AssertNumUTXOsConfirmed(alice, 1)[0].Outpoint
lockID := ht.Random32Bytes()
aliceAddr := alice.RPC.NewAddress(&lnrpc.NewAddressRequest{
Type: lnrpc.AddressType_WITNESS_PUBKEY_HASH,
})
+ // Act by funding without a timeout or a user-supplied confirmation
+ // count. The selected input remains unused until the later publication.
fundResp := alice.RPC.FundPsbt(&walletrpc.FundPsbtRequest{
Template: &walletrpc.FundPsbtRequest_Raw{
Raw: &walletrpc.TxTemplate{
@@ -2071,121 +2068,67 @@ func testFundPsbtConfirmationLease(ht *lntest.HarnessTest) {
Fees: &walletrpc.FundPsbtRequest_SatPerVbyte{
SatPerVbyte: 2,
},
- MinConfs: 1,
- CustomLockId: lockID,
- LockExpirationSeconds: lockDurationSecond,
- InputReleaseAfterSpendConfs: releaseDepth,
+ MinConfs: 1,
+ CustomLockId: lockID,
+ InputLeaseNoExpiry: true,
})
- require.NotEmpty(ht, fundResp.LockedUtxos)
- for _, lease := range fundResp.LockedUtxos {
- require.Equal(ht, releaseDepth, lease.ReleaseAfterSpendConfs)
- require.Zero(ht, lease.ConfirmedSpendHeight)
- }
- // assertLeaseState waits for every lease created by this request to
- // report the expected persisted spend height.
- assertLeaseState := func(expectedSpendHeight int32) {
- err := wait.NoError(func() error {
- leases := alice.RPC.ListLeases().LockedUtxos
- if len(leases) != len(fundResp.LockedUtxos) {
- return fmt.Errorf("expected %d leases, got %d",
- len(fundResp.LockedUtxos), len(leases))
- }
-
- for _, lease := range leases {
- if !bytes.Equal(lockID, lease.Id) {
- return fmt.Errorf(
- "lease ID %x", lease.Id,
- )
- }
- if lease.Expiration == 0 {
- return errors.New("zero expiration")
- }
- if lease.ReleaseAfterSpendConfs !=
- releaseDepth {
-
- return fmt.Errorf(
- "depth: want %d, got %d",
- releaseDepth,
- lease.ReleaseAfterSpendConfs,
- )
- }
- if lease.ConfirmedSpendHeight !=
- expectedSpendHeight {
-
- return fmt.Errorf(
- "height: want %d, got %d",
- expectedSpendHeight,
- lease.ConfirmedSpendHeight,
- )
- }
- }
-
- return nil
- }, defaultTimeout)
- require.NoError(ht, err)
- }
-
- // assertLeaseReleased waits until spend maturity removes every lease
- // created by this request.
- assertLeaseReleased := func() {
- err := wait.NoError(func() error {
- leases := alice.RPC.ListLeases().LockedUtxos
- if len(leases) != 0 {
- return fmt.Errorf("expected no leases, got %d",
- len(leases))
- }
-
- return nil
- }, defaultTimeout)
- require.NoError(ht, err)
- }
-
- // Let the wall-clock deadline pass before broadcasting. A
- // confirmation-controlled lease must remain active for this entire gap.
- time.Sleep(2 * time.Second)
- assertLeaseState(0)
+ // Assert the funding response reports the selected input's policy, and
+ // restarting before broadcast preserves both the policy and exclusion.
+ require.Len(ht, fundResp.LockedUtxos, 1)
+ require.True(ht, fundResp.LockedUtxos[0].NoExpiry)
+ require.Equal(
+ ht, lntest.LnrpcOutpointToStr(input),
+ lntest.LnrpcOutpointToStr(fundResp.LockedUtxos[0].Outpoint),
+ )
+ ht.RestartNode(alice)
+ leases := alice.RPC.ListLeases().LockedUtxos
+ require.Len(ht, leases, 1)
+ require.True(ht, leases[0].NoExpiry)
+ require.Equal(ht, lockID, leases[0].Id)
+ ht.AssertNumUTXOsConfirmed(alice, 0)
+
+ // Act through owner cancellation while the input is still unspent. This
+ // must restore eligibility without waiting for a block or a deadline.
+ _, err := alice.RPC.WalletKit.ReleaseOutput(
+ ht.Context(), &walletrpc.ReleaseOutputRequest{
+ Id: lockID,
+ Outpoint: input,
+ },
+ )
+ require.NoError(ht, err)
+ ht.AssertUTXOInWallet(alice, input, "")
+ require.Empty(ht, alice.RPC.ListLeases().LockedUtxos)
- finalizeResp := alice.RPC.FinalizePsbt(
- &walletrpc.FinalizePsbtRequest{
- FundedPsbt: fundResp.FundedPsbt,
+ // Reacquire the input through LeaseOutput before spending the original
+ // PSBT, covering both entry points without creating a second lifetime.
+ leaseResp, err := alice.RPC.WalletKit.LeaseOutput(
+ ht.Context(), &walletrpc.LeaseOutputRequest{
+ Id: lockID,
+ Outpoint: input,
+ NoExpiry: true,
},
)
+ require.NoError(ht, err)
+ require.True(ht, leaseResp.NoExpiry)
+ ht.AssertNumUTXOsConfirmed(alice, 0)
+ finalizeResp := alice.RPC.FinalizePsbt(&walletrpc.FinalizePsbtRequest{
+ FundedPsbt: fundResp.FundedPsbt,
+ })
alice.RPC.PublishTransaction(&walletrpc.Transaction{
TxHex: finalizeResp.RawFinalTx,
})
+ ht.MineBlocksAndAssertNumTxes(1, 1)
- var finalTx wire.MsgTx
- err := finalTx.Deserialize(bytes.NewReader(finalizeResp.RawFinalTx))
- require.NoError(ht, err)
-
- spendBlock := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
- spendHeight := int32(ht.CurrentHeight())
- ht.AssertTxInBlock(spendBlock, finalTx.TxHash())
- assertLeaseState(spendHeight)
-
- // Disconnect the spending block and extend the replacement chain
- // without the transaction. The lease must retain its disconnected-spend
- // marker.
- spendBlockHash := spendBlock.BlockHash()
- require.NoError(ht, ht.Miner().InvalidateBlock(&spendBlockHash))
- ht.MineEmptyBlocks(2)
- assertLeaseState(-1)
-
- // The disconnected state is durable across process restart.
- ht.RestartNode(alice)
- assertLeaseState(-1)
-
- // Reconfirm the transaction. The lease remains through depth two and is
- // released when the third confirmation connects.
- reconfirmedBlock := ht.MineBlocksAndAssertNumTxes(1, 1)[0]
- reconfirmedHeight := int32(ht.CurrentHeight())
- ht.AssertTxInBlock(reconfirmedBlock, finalTx.TxHash())
- assertLeaseState(reconfirmedHeight)
-
- ht.MineEmptyBlocks(1)
- assertLeaseState(reconfirmedHeight)
-
- ht.MineEmptyBlocks(1)
- assertLeaseReleased()
+ // Assert after wallet synchronization that the first confirmed spend
+ // removes the lease. Only the spending transaction's output and change
+ // are selectable; spend tracking excludes the original input without a
+ // retained reservation.
+ for _, utxo := range ht.AssertNumUTXOsConfirmed(alice, 2) {
+ require.NotEqual(
+ ht, lntest.LnrpcOutpointToStr(input),
+ lntest.LnrpcOutpointToStr(utxo.Outpoint),
+ )
+ }
+ require.Empty(ht, alice.RPC.ListLeases().LockedUtxos)
}
### lnrpc/walletrpc/walletkit.pb.go
@@ -599,17 +599,16 @@ type LeaseOutputRequest struct {
// The identifying outpoint of the output being leased.
Outpoint *lnrpc.OutPoint `protobuf:"bytes,2,opt,name=outpoint,proto3" json:"outpoint,omitempty"`
// The time in seconds before a time-controlled lock expires. If set to
- // zero, the default lock duration is used. A non-zero
- // release_after_spend_confs makes this deadline informational only.
+ // zero, the default lock duration is used. Cannot be combined with
+ // no_expiry.
ExpirationSeconds uint64 `protobuf:"varint,3,opt,name=expiration_seconds,json=expirationSeconds,proto3" json:"expiration_seconds,omitempty"`
- // Keep the lease until the transaction spending the output reaches this
- // confirmation count or the owner explicitly releases it. A reorganization
- // that disconnects the spending block resets maturity progress. A non-zero
- // value ignores expiration_seconds; zero preserves the time-controlled
- // lease behavior.
- ReleaseAfterSpendConfs uint32 `protobuf:"varint,4,opt,name=release_after_spend_confs,json=releaseAfterSpendConfs,proto3" json:"release_after_spend_confs,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // Reserve the unused output without a timeout until owner release or its
+ // first confirmed spend. Cannot be combined with a non-zero
+ // expiration_seconds. Omission preserves the existing lifetime; it does
+ // not convert the lease to a timed lease.
+ NoExpiry bool `protobuf:"varint,5,opt,name=no_expiry,json=noExpiry,proto3" json:"no_expiry,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *LeaseOutputRequest) Reset() {
@@ -663,27 +662,25 @@ func (x *LeaseOutputRequest) GetExpirationSeconds() uint64 {
return 0
}
-func (x *LeaseOutputRequest) GetReleaseAfterSpendConfs() uint32 {
+func (x *LeaseOutputRequest) GetNoExpiry() bool {
if x != nil {
- return x.ReleaseAfterSpendConfs
+ return x.NoExpiry
}
- return 0
+ return false
}
type LeaseOutputResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
//
//The absolute expiration of a time-controlled output lease represented as a
- //unix timestamp. Confirmation-controlled leases return the stored value for
- //compatibility but do not apply it.
+ //unix timestamp. No-expiry leases do not use this timestamp.
Expiration uint64 `protobuf:"varint,1,opt,name=expiration,proto3" json:"expiration,omitempty"`
- // The effective persisted spend maturity depth. A zero-depth renewal
- // returns the retained non-zero depth of an existing
- // confirmation-controlled lease. If that informational lookup fails after
- // the lease succeeds, this field is zero and ListLeases can refresh it.
- ReleaseAfterSpendConfs uint32 `protobuf:"varint,2,opt,name=release_after_spend_confs,json=releaseAfterSpendConfs,proto3" json:"release_after_spend_confs,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // The effective no-timeout policy with cleanup at the first confirmed
+ // spend. If renewal readback fails, ListLeases can refresh this
+ // informational value.
+ NoExpiry bool `protobuf:"varint,3,opt,name=no_expiry,json=noExpiry,proto3" json:"no_expiry,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *LeaseOutputResponse) Reset() {
@@ -723,11 +720,11 @@ func (x *LeaseOutputResponse) GetExpiration() uint64 {
return 0
}
-func (x *LeaseOutputResponse) GetReleaseAfterSpendConfs() uint32 {
+func (x *LeaseOutputResponse) GetNoExpiry() bool {
if x != nil {
- return x.ReleaseAfterSpendConfs
+ return x.NoExpiry
}
- return 0
+ return false
}
type ReleaseOutputRequest struct {
@@ -4075,23 +4072,22 @@ type FundPsbtRequest struct {
MaxFeeRatio float64 `protobuf:"fixed64,12,opt,name=max_fee_ratio,json=maxFeeRatio,proto3" json:"max_fee_ratio,omitempty"`
// The custom lock ID to use for the inputs in the funded PSBT. The value
// if set must be exactly 32 bytes long. If empty, the default lock ID will
- // be used. This field is required when input_release_after_spend_confs is
- // non-zero. In that mode it must not be all zero or LND's reserved
- // internal lock ID. The caller must persist this ID before funding and use
- // ReleaseOutput to unlock an abandoned PSBT whose spend never confirms.
+ // be used. This field is required when input_lease_no_expiry is true and
+ // must not be all zero or LND's reserved internal lock ID. Persist it
+ // before funding and use ReleaseOutput to unlock an abandoned PSBT whose
+ // spend never confirms.
CustomLockId []byte `protobuf:"bytes,13,opt,name=custom_lock_id,json=customLockId,proto3" json:"custom_lock_id,omitempty"`
// If set, then time-controlled input leases in the funded PSBT will be
// locked for the specified duration in seconds. If not set, the default
- // lock duration is used. A non-zero input_release_after_spend_confs makes
- // this deadline informational only.
+ // lock duration is used. Cannot be combined with input_lease_no_expiry.
LockExpirationSeconds uint64 `protobuf:"varint,14,opt,name=lock_expiration_seconds,json=lockExpirationSeconds,proto3" json:"lock_expiration_seconds,omitempty"`
- // Keep each acquired input lease until its spending transaction reaches
- // this confirmation count or the owner explicitly releases it. A
- // reorganization resets maturity progress. A non-zero value ignores
- // lock_expiration_seconds; zero preserves time-controlled lease behavior.
- InputReleaseAfterSpendConfs uint32 `protobuf:"varint,15,opt,name=input_release_after_spend_confs,json=inputReleaseAfterSpendConfs,proto3" json:"input_release_after_spend_confs,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // Reserve each newly acquired input without a timeout until owner release
+ // or its first confirmed spend. Requires a persisted custom_lock_id and
+ // cannot be combined with lock_expiration_seconds. Pre-existing input
+ // leases are unchanged.
+ InputLeaseNoExpiry bool `protobuf:"varint,16,opt,name=input_lease_no_expiry,json=inputLeaseNoExpiry,proto3" json:"input_lease_no_expiry,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *FundPsbtRequest) Reset() {
@@ -4248,11 +4244,11 @@ func (x *FundPsbtRequest) GetLockExpirationSeconds() uint64 {
return 0
}
-func (x *FundPsbtRequest) GetInputReleaseAfterSpendConfs() uint32 {
+func (x *FundPsbtRequest) GetInputLeaseNoExpiry() bool {
if x != nil {
- return x.InputReleaseAfterSpendConfs
+ return x.InputLeaseNoExpiry
}
- return 0
+ return false
}
type isFundPsbtRequest_Template interface {
@@ -4583,26 +4579,24 @@ type UtxoLease struct {
Outpoint *lnrpc.OutPoint `protobuf:"bytes,2,opt,name=outpoint,proto3" json:"outpoint,omitempty"`
//
//The absolute expiration of a time-controlled output lease represented as a
- //unix timestamp. Confirmation-controlled leases retain this value for
- //compatibility but do not apply it.
+ //unix timestamp. No-expiry leases do not use this timestamp.
Expiration uint64 `protobuf:"varint,3,opt,name=expiration,proto3" json:"expiration,omitempty"`
//
//The public key script of the leased output.
PkScript []byte `protobuf:"bytes,4,opt,name=pk_script,json=pkScript,proto3" json:"pk_script,omitempty"`
//
//The value of the leased output in satoshis.
Value uint64 `protobuf:"varint,5,opt,name=value,proto3" json:"value,omitempty"`
- // The spend maturity depth recorded for this lease. FundPsbt returns it
- // only after the wallet successfully applies the requested option.
- ReleaseAfterSpendConfs uint32 `protobuf:"varint,6,opt,name=release_after_spend_confs,json=releaseAfterSpendConfs,proto3" json:"release_after_spend_confs,omitempty"`
// The block height where the spending transaction first confirmed. Zero
// means no confirmed spend was observed. A negative value means a
// previously observed spend was disconnected and is awaiting
// reconfirmation. The only negative value emitted is -1; its magnitude
// carries no additional information.
ConfirmedSpendHeight int32 `protobuf:"varint,7,opt,name=confirmed_spend_height,json=confirmedSpendHeight,proto3" json:"confirmed_spend_height,omitempty"`
- unknownFields protoimpl.UnknownFields
- sizeCache protoimpl.SizeCache
+ // True for no-timeout leases removed at the first confirmed spend.
+ NoExpiry bool `protobuf:"varint,8,opt,name=no_expiry,json=noExpiry,proto3" json:"no_expiry,omitempty"`
+ unknownFields protoimpl.UnknownFields
+ sizeCache protoimpl.SizeCache
}
func (x *UtxoLease) Reset() {
@@ -4670,18 +4664,18 @@ func (x *UtxoLease) GetValue() uint64 {
return 0
}
-func (x *UtxoLease) GetReleaseAfterSpendConfs() uint32 {
+func (x *UtxoLease) GetConfirmedSpendHeight() int32 {
if x != nil {
- return x.ReleaseAfterSpendConfs
+ return x.ConfirmedSpendHeight
}
return 0
}
-func (x *UtxoLease) GetConfirmedSpendHeight() int32 {
+func (x *UtxoLease) GetNoExpiry() bool {
if x != nil {
- return x.ConfirmedSpendHeight
+ return x.NoExpiry
}
- return 0
+ return false
}
type SignPsbtRequest struct {
@@ -5038,17 +5032,17 @@ const file_walletrpc_walletkit_proto_rawDesc = "" +
"\aaccount\x18\x03 \x01(\tR\aaccount\x12)\n" +
"\x10unconfirmed_only\x18\x04 \x01(\bR\x0funconfirmedOnly\"8\n" +
"\x13ListUnspentResponse\x12!\n" +
- "\x05utxos\x18\x01 \x03(\v2\v.lnrpc.UtxoR\x05utxos\"\xbb\x01\n" +
+ "\x05utxos\x18\x01 \x03(\v2\v.lnrpc.UtxoR\x05utxos\"\xbe\x01\n" +
"\x12LeaseOutputRequest\x12\x0e\n" +
"\x02id\x18\x01 \x01(\fR\x02id\x12+\n" +
"\boutpoint\x18\x02 \x01(\v2\x0f.lnrpc.OutPointR\boutpoint\x12-\n" +
- "\x12expiration_seconds\x18\x03 \x01(\x04R\x11expirationSeconds\x129\n" +
- "\x19release_after_spend_confs\x18\x04 \x01(\rR\x16releaseAfterSpendConfs\"p\n" +
+ "\x12expiration_seconds\x18\x03 \x01(\x04R\x11expirationSeconds\x12\x1b\n" +
+ "\tno_expiry\x18\x05 \x01(\bR\bnoExpiryJ\x04\b\x04\x10\x05R\x19release_after_spend_confs\"s\n" +
"\x13LeaseOutputResponse\x12\x1e\n" +
"\n" +
"expiration\x18\x01 \x01(\x04R\n" +
- "expiration\x129\n" +
- "\x19release_after_spend_confs\x18\x02 \x01(\rR\x16releaseAfterSpendConfs\"S\n" +
+ "expiration\x12\x1b\n" +
+ "\tno_expiry\x18\x03 \x01(\bR\bnoExpiryJ\x04\b\x02\x10\x03R\x19release_after_spend_confs\"S\n" +
"\x14ReleaseOutputRequest\x12\x0e\n" +
"\x02id\x18\x01 \x01(\fR\x02id\x12+\n" +
"\boutpoint\x18\x02 \x01(\v2\x0f.lnrpc.OutPointR\boutpoint\"/\n" +
@@ -5257,7 +5251,7 @@ const file_walletrpc_walletkit_proto_rawDesc = "" +
"\x05label\x18\x02 \x01(\tR\x05label\x12\x1c\n" +
"\toverwrite\x18\x03 \x01(\bR\toverwrite\"2\n" +
"\x18LabelTransactionResponse\x12\x16\n" +
- "\x06status\x18\x01 \x01(\tR\x06status\"\xce\x05\n" +
+ "\x06status\x18\x01 \x01(\tR\x06status\"\xe2\x05\n" +
"\x0fFundPsbtRequest\x12\x14\n" +
"\x04psbt\x18\x01 \x01(\fH\x00R\x04psbt\x12)\n" +
"\x03raw\x18\x02 \x01(\v2\x15.walletrpc.TxTemplateH\x00R\x03raw\x12<\n" +
@@ -5277,11 +5271,11 @@ const file_walletrpc_walletkit_proto_rawDesc = "" +
" \x01(\x0e2\x1c.lnrpc.CoinSelectionStrategyR\x15coinSelectionStrategy\x12\"\n" +
"\rmax_fee_ratio\x18\f \x01(\x01R\vmaxFeeRatio\x12$\n" +
"\x0ecustom_lock_id\x18\r \x01(\fR\fcustomLockId\x126\n" +
- "\x17lock_expiration_seconds\x18\x0e \x01(\x04R\x15lockExpirationSeconds\x12D\n" +
- "\x1finput_release_after_spend_confs\x18\x0f \x01(\rR\x1binputReleaseAfterSpendConfsB\n" +
+ "\x17lock_expiration_seconds\x18\x0e \x01(\x04R\x15lockExpirationSeconds\x121\n" +
+ "\x15input_lease_no_expiry\x18\x10 \x01(\bR\x12inputLeaseNoExpiryB\n" +
"\n" +
"\btemplateB\x06\n" +
- "\x04fees\"\x9c\x01\n" +
+ "\x04feesJ\x04\b\x0f\x10\x10R\x1finput_release_after_spend_confs\"\x9c\x01\n" +
"\x10FundPsbtResponse\x12\x1f\n" +
"\vfunded_psbt\x18\x01 \x01(\fR\n" +
"fundedPsbt\x12.\n" +
@@ -5298,17 +5292,17 @@ const file_walletrpc_walletkit_proto_rawDesc = "" +
"\x04psbt\x18\x01 \x01(\fR\x04psbt\x124\n" +
"\x15existing_output_index\x18\x02 \x01(\x05H\x00R\x13existingOutputIndex\x12\x12\n" +
"\x03add\x18\x03 \x01(\bH\x00R\x03addB\x0f\n" +
- "\rchange_output\"\x8c\x02\n" +
+ "\rchange_output\"\x8f\x02\n" +
"\tUtxoLease\x12\x0e\n" +
"\x02id\x18\x01 \x01(\fR\x02id\x12+\n" +
"\boutpoint\x18\x02 \x01(\v2\x0f.lnrpc.OutPointR\boutpoint\x12\x1e\n" +
"\n" +
"expiration\x18\x03 \x01(\x04R\n" +
"expiration\x12\x1b\n" +
"\tpk_script\x18\x04 \x01(\fR\bpkScript\x12\x14\n" +
- "\x05value\x18\x05 \x01(\x04R\x05value\x129\n" +
- "\x19release_after_spend_confs\x18\x06 \x01(\rR\x16releaseAfterSpendConfs\x124\n" +
- "\x16confirmed_spend_height\x18\a \x01(\x05R\x14confirmedSpendHeight\"2\n" +
+ "\x05value\x18\x05 \x01(\x04R\x05value\x124\n" +
+ "\x16confirmed_spend_height\x18\a \x01(\x05R\x14confirmedSpendHeight\x12\x1b\n" +
+ "\tno_expiry\x18\b \x01(\bR\bnoExpiryJ\x04\b\x06\x10\aR\x19release_after_spend_confs\"2\n" +
"\x0fSignPsbtRequest\x12\x1f\n" +
"\vfunded_psbt\x18\x01 \x01(\fR\n" +
"fundedPsbt\"X\n" +
### lnrpc/walletrpc/walletkit.proto
@@ -43,11 +43,12 @@ service WalletKit {
successive invocations of this RPC. Outputs can be unlocked before their
expiration through `ReleaseOutput`.
- A non-zero release_after_spend_confs selects a confirmation-controlled
- lifetime. Such a lease ignores its wall-clock expiration and releases at
- the requested spend depth or through ReleaseOutput. The RPC fails if the
- wallet cannot apply this option. Renewing the same lease with the same ID
- and a zero depth preserves an existing non-zero depth.
+ Set no_expiry to reserve an unused output without a timeout. The owner
+ must release an abandoned reservation; the first confirmed spend removes
+ it automatically. This requires wallet support for the requested lifetime.
+
+ Renewing the same lease with the same ID and no_expiry unset preserves
+ its existing lifetime.
*/
rpc LeaseOutput (LeaseOutputRequest) returns (LeaseOutputResponse);
@@ -399,13 +400,13 @@ service WalletKit {
After either selecting or verifying the inputs, all input UTXOs are locked
with an internal app ID.
- A non-zero input_release_after_spend_confs applies a
- confirmation-controlled lifetime to every input lease this RPC acquires.
- Those leases ignore wall-clock expiration and release at the requested
- spend depth or through ReleaseOutput. The RPC fails if the wallet cannot
- apply this option. Wallet capability is checked even when coin selection
- does not need to acquire an input lease. A custom_lock_id is required for a
- confirmation-controlled lease.
+ Set input_lease_no_expiry to reserve acquired inputs without a timeout
+ until owner release or their first confirmed spend. A custom_lock_id is
+ required and must be persisted before funding so abandoned inputs can be
+ released. This requires wallet support for the requested lifetime.
+
+ Wallet capability is checked even when coin selection does not need to
+ acquire an input lease.
NOTE: If this method returns without an error, it is the caller's
responsibility to either spend the locked UTXOs (by finalizing and then
@@ -470,6 +471,10 @@ message ListUnspentResponse {
}
message LeaseOutputRequest {
+ // Preserve the wire identity of the retired count-based lifetime option.
+ reserved 4;
+ reserved "release_after_spend_confs";
+
/*
An ID of 32 random bytes that must be unique for each distinct application
using this RPC which will be used to bound the output lease to.
@@ -480,31 +485,32 @@ message LeaseOutputRequest {
lnrpc.OutPoint outpoint = 2;
// The time in seconds before a time-controlled lock expires. If set to
- // zero, the default lock duration is used. A non-zero
- // release_after_spend_confs makes this deadline informational only.
+ // zero, the default lock duration is used. Cannot be combined with
+ // no_expiry.
uint64 expiration_seconds = 3;
- // Keep the lease until the transaction spending the output reaches this
- // confirmation count or the owner explicitly releases it. A reorganization
- // that disconnects the spending block resets maturity progress. A non-zero
- // value ignores expiration_seconds; zero preserves the time-controlled
- // lease behavior.
- uint32 release_after_spend_confs = 4;
+ // Reserve the unused output without a timeout until owner release or its
+ // first confirmed spend. Cannot be combined with a non-zero
+ // expiration_seconds. Omission preserves the existing lifetime; it does
+ // not convert the lease to a timed lease.
+ bool no_expiry = 5;
}
message LeaseOutputResponse {
+ // Prevent reuse of the removed count-based policy readback.
+ reserved 2;
+ reserved "release_after_spend_confs";
+
/*
The absolute expiration of a time-controlled output lease represented as a
- unix timestamp. Confirmation-controlled leases return the stored value for
- compatibility but do not apply it.
+ unix timestamp. No-expiry leases do not use this timestamp.
*/
uint64 expiration = 1;
- // The effective persisted spend maturity depth. A zero-depth renewal
- // returns the retained non-zero depth of an existing
- // confirmation-controlled lease. If that informational lookup fails after
- // the lease succeeds, this field is zero and ListLeases can refresh it.
- uint32 release_after_spend_confs = 2;
+ // The effective no-timeout policy with cleanup at the first confirmed
+ // spend. If renewal readback fails, ListLeases can refresh this
+ // informational value.
+ bool no_expiry = 3;
}
message ReleaseOutputRequest {
@@ -1588,6 +1594,10 @@ enum ChangeAddressType {
}
message FundPsbtRequest {
+ // Preserve the wire identity of the retired count-based lifetime option.
+ reserved 15;
+ reserved "input_release_after_spend_confs";
+
oneof template {
/*
Use an existing PSBT packet as the template for the funded PSBT.
@@ -1673,23 +1683,22 @@ message FundPsbtRequest {
// The custom lock ID to use for the inputs in the funded PSBT. The value
// if set must be exactly 32 bytes long. If empty, the default lock ID will
- // be used. This field is required when input_release_after_spend_confs is
- // non-zero. In that mode it must not be all zero or LND's reserved
- // internal lock ID. The caller must persist this ID before funding and use
- // ReleaseOutput to unlock an abandoned PSBT whose spend never confirms.
+ // be used. This field is required when input_lease_no_expiry is true and
+ // must not be all zero or LND's reserved internal lock ID. Persist it
+ // before funding and use ReleaseOutput to unlock an abandoned PSBT whose
+ // spend never confirms.
bytes custom_lock_id = 13;
// If set, then time-controlled input leases in the funded PSBT will be
// locked for the specified duration in seconds. If not set, the default
- // lock duration is used. A non-zero input_release_after_spend_confs makes
- // this deadline informational only.
+ // lock duration is used. Cannot be combined with input_lease_no_expiry.
uint64 lock_expiration_seconds = 14;
- // Keep each acquired input lease until its spending transaction reaches
- // this confirmation count or the owner explicitly releases it. A
- // reorganization resets maturity progress. A non-zero value ignores
- // lock_expiration_seconds; zero preserves time-controlled lease behavior.
- uint32 input_release_after_spend_confs = 15;
+ // Reserve each newly acquired input without a timeout until owner release
+ // or its first confirmed spend. Requires a persisted custom_lock_id and
+ // cannot be combined with lock_expiration_seconds. Pre-existing input
+ // leases are unchanged.
+ bool input_lease_no_expiry = 16;
}
message FundPsbtResponse {
/*
@@ -1761,6 +1770,10 @@ message PsbtCoinSelect {
}
message UtxoLease {
+ // Prevent reuse of the removed count-based policy readback.
+ reserved 6;
+ reserved "release_after_spend_confs";
+
/*
A 32 byte random ID that identifies the lease.
*/
@@ -1771,8 +1784,7 @@ message UtxoLease {
/*
The absolute expiration of a time-controlled output lease represented as a
- unix timestamp. Confirmation-controlled leases retain this value for
- compatibility but do not apply it.
+ unix timestamp. No-expiry leases do not use this timestamp.
*/
uint64 expiration = 3;
@@ -1786,16 +1798,15 @@ message UtxoLease {
*/
uint64 value = 5;
- // The spend maturity depth recorded for this lease. FundPsbt returns it
- // only after the wallet successfully applies the requested option.
- uint32 release_after_spend_confs = 6;
-
// The block height where the spending transaction first confirmed. Zero
// means no confirmed spend was observed. A negative value means a
// previously observed spend was disconnected and is awaiting
// reconfirmation. The only negative value emitted is -1; its magnitude
// carries no additional information.
int32 confirmed_spend_height = 7;
+
+ // True for no-timeout leases removed at the first confirmed spend.
+ bool no_expiry = 8;
}
message SignPsbtRequest {
### lnrpc/walletrpc/walletkit.swagger.json
@@ -508,7 +508,7 @@
"/v2/wallet/psbt/fund": {
"post": {
"summary": "lncli: `wallet psbt fund`\nFundPsbt creates a fully populated PSBT that contains enough inputs to fund\nthe outputs specified in the template. There are three ways a user can\nspecify what we call the template (a list of inputs and outputs to use in\nthe PSBT): Either as a PSBT packet directly with no coin selection (using\nthe legacy \"psbt\" field), a PSBT with advanced coin selection support (using\nthe new \"coin_select\" field) or as a raw RPC message (using the \"raw\"\nfield).\nThe legacy \"psbt\" and \"raw\" modes, the following restrictions apply:\n1. If there are no inputs specified in the template, coin selection is\nperformed automatically.\n2. If the template does contain any inputs, it is assumed that full\ncoin selection happened externally and no additional inputs are added. If\nthe specified inputs aren't enough to fund the outputs with the given fee\nrate, an error is returned.",
- "description": "The new \"coin_select\" mode does not have these restrictions and allows the\nuser to specify a PSBT with inputs and outputs and still perform coin\nselection on top of that.\nFor all modes this RPC requires any inputs that are specified to be locked\nby the user (if they belong to this node in the first place).\n\nAfter either selecting or verifying the inputs, all input UTXOs are locked\nwith an internal app ID.\n\nA non-zero input_release_after_spend_confs applies a\nconfirmation-controlled lifetime to every input lease this RPC acquires.\nThose leases ignore wall-clock expiration and release at the requested\nspend depth or through ReleaseOutput. The RPC fails if the wallet cannot\napply this option. Wallet capability is checked even when coin selection\ndoes not need to acquire an input lease. A custom_lock_id is required for a\nconfirmation-controlled lease.\n\nNOTE: If this method returns without an error, it is the caller's\nresponsibility to either spend the locked UTXOs (by finalizing and then\npublishing the transaction) or to unlock/release the locked UTXOs in case of\nan error on the caller's side.",
+ "description": "The new \"coin_select\" mode does not have these restrictions and allows the\nuser to specify a PSBT with inputs and outputs and still perform coin\nselection on top of that.\nFor all modes this RPC requires any inputs that are specified to be locked\nby the user (if they belong to this node in the first place).\n\nAfter either selecting or verifying the inputs, all input UTXOs are locked\nwith an internal app ID.\n\nSet input_lease_no_expiry to reserve acquired inputs without a timeout\nuntil owner release or their first confirmed spend. A custom_lock_id is\nrequired and must be persisted before funding so abandoned inputs can be\nreleased. This requires wallet support for the requested lifetime.\n\nWallet capability is checked even when coin selection does not need to\nacquire an input lease.\n\nNOTE: If this method returns without an error, it is the caller's\nresponsibility to either spend the locked UTXOs (by finalizing and then\npublishing the transaction) or to unlock/release the locked UTXOs in case of\nan error on the caller's side.",
"operationId": "WalletKit_FundPsbt",
"responses": {
"200": {
@@ -935,7 +935,7 @@
"/v2/wallet/utxos/lease": {
"post": {
"summary": "lncli: `wallet leaseoutput`\nLeaseOutput locks an output to the given ID, preventing it from being\navailable for any future coin selection attempts. The absolute time of the\nlock's expiration is returned. The expiration of the lock can be extended by\nsuccessive invocations of this RPC. Outputs can be unlocked before their\nexpiration through `ReleaseOutput`.",
- "description": "A non-zero release_after_spend_confs selects a confirmation-controlled\nlifetime. Such a lease ignores its wall-clock expiration and releases at\nthe requested spend depth or through ReleaseOutput. The RPC fails if the\nwallet cannot apply this option. Renewing the same lease with the same ID\nand a zero depth preserves an existing non-zero depth.",
+ "description": "Set no_expiry to reserve an unused output without a timeout. The owner\nmust release an abandoned reservation; the first confirmed spend removes\nit automatically. This requires wallet support for the requested lifetime.\n\nRenewing the same lease with the same ID and no_expiry unset preserves\nits existing lifetime.",
"operationId": "WalletKit_LeaseOutput",
"responses": {
"200": {
@@ -1688,17 +1688,16 @@
"custom_lock_id": {
"type": "string",
"format": "byte",
- "description": "The custom lock ID to use for the inputs in the funded PSBT. The value\nif set must be exactly 32 bytes long. If empty, the default lock ID will\nbe used. This field is required when input_release_after_spend_confs is\nnon-zero. In that mode it must not be all zero or LND's reserved\ninternal lock ID. The caller must persist this ID before funding and use\nReleaseOutput to unlock an abandoned PSBT whose spend never confirms."
+ "description": "The custom lock ID to use for the inputs in the funded PSBT. The value\nif set must be exactly 32 bytes long. If empty, the default lock ID will\nbe used. This field is required when input_lease_no_expiry is true and\nmust not be all zero or LND's reserved internal lock ID. Persist it\nbefore funding and use ReleaseOutput to unlock an abandoned PSBT whose\nspend never confirms."
},
"lock_expiration_seconds": {
"type": "string",
"format": "uint64",
- "description": "If set, then time-controlled input leases in the funded PSBT will be\nlocked for the specified duration in seconds. If not set, the default\nlock duration is used. A non-zero input_release_after_spend_confs makes\nthis deadline informational only."
+ "description": "If set, then time-controlled input leases in the funded PSBT will be\nlocked for the specified duration in seconds. If not set, the default\nlock duration is used. Cannot be combined with input_lease_no_expiry."
},
- "input_release_after_spend_confs": {
- "type": "integer",
- "format": "int64",
- "description": "Keep each acquired input lease until its spending transaction reaches\nthis confirmation count or the owner explicitly releases it. A\nreorganization resets maturity progress. A non-zero value ignores\nlock_expiration_seconds; zero preserves time-controlled lease behavior."
+ "input_lease_no_expiry": {
+ "type": "boolean",
+ "description": "Reserve each newly acquired input without a timeout until owner release\nor its first confirmed spend. Requires a persisted custom_lock_id and\ncannot be combined with lock_expiration_seconds. Pre-existing input\nleases are unchanged."
}
}
},
@@ -1899,12 +1898,11 @@
"expiration_seconds": {
"type": "string",
"format": "uint64",
- "description": "The time in seconds before a time-controlled lock expires. If set to\nzero, the default lock duration is used. A non-zero\nrelease_after_spend_confs makes this deadline informational only."
+ "description": "The time in seconds before a time-controlled lock expires. If set to\nzero, the default lock duration is used. Cannot be combined with\nno_expiry."
},
- "release_after_spend_confs": {
- "type": "integer",
- "format": "int64",
- "description": "Keep the lease until the transaction spending the output reaches this\nconfirmation count or the owner explicitly releases it. A reorganization\nthat disconnects the spending block resets maturity progress. A non-zero\nvalue ignores expiration_seconds; zero preserves the time-controlled\nlease behavior."
+ "no_expiry": {
+ "type": "boolean",
+ "description": "Reserve the unused output without a timeout until owner release or its\nfirst confirmed spend. Cannot be combined with a non-zero\nexpiration_seconds. Omission preserves the existing lifetime; it does\nnot convert the lease to a timed lease."
}
}
},
@@ -1914,12 +1912,11 @@
"expiration": {
"type": "string",
"format": "uint64",
- "description": "The absolute expiration of a time-controlled output lease represented as a\nunix timestamp. Confirmation-controlled leases return the stored value for\ncompatibility but do not apply it."
+ "description": "The absolute expiration of a time-controlled output lease represented as a\nunix timestamp. No-expiry leases do not use this timestamp."
},
- "release_after_spend_confs": {
- "type": "integer",
- "format": "int64",
- "description": "The effective persisted spend maturity depth. A zero-depth renewal\nreturns the retained non-zero depth of an existing\nconfirmation-controlled lease. If that informational lookup fails after\nthe lease succeeds, this field is zero and ListLeases can refresh it."
+ "no_expiry": {
+ "type": "boolean",
+ "description": "The effective no-timeout policy with cleanup at the first confirmed\nspend. If renewal readback fails, ListLeases can refresh this\ninformational value."
}
}
},
@@ -2413,7 +2410,7 @@
"expiration": {
"type": "string",
"format": "uint64",
- "description": "The absolute expiration of a time-controlled output lease represented as a\nunix timestamp. Confirmation-controlled leases retain this value for\ncompatibility but do not apply it."
+ "description": "The absolute expiration of a time-controlled output lease represented as a\nunix timestamp. No-expiry leases do not use this timestamp."
},
"pk_script": {
"type": "string",
@@ -2425,15 +2422,14 @@
"format": "uint64",
"description": "The value of the leased output in satoshis."
},
- "release_after_spend_confs": {
- "type": "integer",
- "format": "int64",
- "description": "The spend maturity depth recorded for this lease. FundPsbt returns it\nonly after the wallet successfully applies the requested option."
- },
"confirmed_spend_height": {
"type": "integer",
"format": "int32",
"description": "The block height where the spending transaction first confirmed. Zero\nmeans no confirmed spend was observed. A negative value means a\npreviously observed spend was disconnected and is awaiting\nreconfirmation. The only negative value emitted is -1; its magnitude\ncarries no additional information."
+ },
+ "no_expiry": {
+ "type": "boolean",
+ "description": "True for no-timeout leases removed at the first confirmed spend."
}
}
},
### lnrpc/walletrpc/walletkit_grpc.pb.go
@@ -33,11 +33,12 @@ type WalletKitClient interface {
//successive invocations of this RPC. Outputs can be unlocked before their
//expiration through `ReleaseOutput`.
//
- //A non-zero release_after_spend_confs selects a confirmation-controlled
- //lifetime. Such a lease ignores its wall-clock expiration and releases at
- //the requested spend depth or through ReleaseOutput. The RPC fails if the
- //wallet cannot apply this option. Renewing the same lease with the same ID
- //and a zero depth preserves an existing non-zero depth.
+ //Set no_expiry to reserve an unused output without a timeout. The owner
+ //must release an abandoned reservation; the first confirmed spend removes
+ //it automatically. This requires wallet support for the requested lifetime.
+ //
+ //Renewing the same lease with the same ID and no_expiry unset preserves
+ //its existing lifetime.
LeaseOutput(ctx context.Context, in *LeaseOutputRequest, opts ...grpc.CallOption) (*LeaseOutputResponse, error)
// lncli: `wallet releaseoutput`
//ReleaseOutput unlocks an output, allowing it to be available for coin
@@ -329,13 +330,13 @@ type WalletKitClient interface {
//After either selecting or verifying the inputs, all input UTXOs are locked
//with an internal app ID.
//
- //A non-zero input_release_after_spend_confs applies a
- //confirmation-controlled lifetime to every input lease this RPC acquires.
- //Those leases ignore wall-clock expiration and release at the requested
- //spend depth or through ReleaseOutput. The RPC fails if the wallet cannot
- //apply this option. Wallet capability is checked even when coin selection
- //does not need to acquire an input lease. A custom_lock_id is required for a
- //confirmation-controlled lease.
+ //Set input_lease_no_expiry to reserve acquired inputs without a timeout
+ //until owner release or their first confirmed spend. A custom_lock_id is
+ //required and must be persisted before funding so abandoned inputs can be
+ //released. This requires wallet support for the requested lifetime.
+ //
+ //Wallet capability is checked even when coin selection does not need to
+ //acquire an input lease.
//
//NOTE: If this method returns without an error, it is the caller's
//responsibility to either spend the locked UTXOs (by finalizing and then
@@ -665,11 +666,12 @@ type WalletKitServer interface {
//successive invocations of this RPC. Outputs can be unlocked before their
//expiration through `ReleaseOutput`.
//
- //A non-zero release_after_spend_confs selects a confirmation-controlled
- //lifetime. Such a lease ignores its wall-clock expiration and releases at
- //the requested spend depth or through ReleaseOutput. The RPC fails if the
- //wallet cannot apply this option. Renewing the same lease with the same ID
- //and a zero depth preserves an existing non-zero depth.
+ //Set no_expiry to reserve an unused output without a timeout. The owner
+ //must release an abandoned reservation; the first confirmed spend removes
+ //it automatically. This requires wallet support for the requested lifetime.
+ //
+ //Renewing the same lease with the same ID and no_expiry unset preserves
+ //its existing lifetime.
LeaseOutput(context.Context, *LeaseOutputRequest) (*LeaseOutputResponse, error)
// lncli: `wallet releaseoutput`
//ReleaseOutput unlocks an output, allowing it to be available for coin
@@ -961,13 +963,13 @@ type WalletKitServer interface {
//After either selecting or verifying the inputs, all input UTXOs are locked
//with an internal app ID.
//
- //A non-zero input_release_after_spend_confs applies a
- //confirmation-controlled lifetime to every input lease this RPC acquires.
- //Those leases ignore wall-clock expiration and release at the requested
- //spend depth or through ReleaseOutput. The RPC fails if the wallet cannot
- //apply this option. Wallet capability is checked even when coin selection
- //does not need to acquire an input lease. A custom_lock_id is required for a
- //confirmation-controlled lease.
+ //Set input_lease_no_expiry to reserve acquired inputs without a timeout
+ //until owner release or their first confirmed spend. A custom_lock_id is
+ //required and must be persisted before funding so abandoned inputs can be
+ //released. This requires wallet support for the requested lifetime.
+ //
+ //Wallet capability is checked even when coin selection does not need to
+ //acquire an input lease.
//
//NOTE: If this method returns without an error, it is the caller's
//responsibility to either spend the locked UTXOs (by finalizing and then
### lnrpc/walletrpc/walletkit_server.go
@@ -49,10 +49,43 @@ import (
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/sweep"
"google.golang.org/grpc"
+ "google.golang.org/protobuf/encoding/protowire"
"gopkg.in/macaroon-bakery.v2/bakery"
)
+// noExpiryLeaseDepth reuses the wallet's no-timeout lifetime with cleanup at
+// the first confirmed spend, without adding another persisted lease policy.
+const noExpiryLeaseDepth uint32 = 1
+
var (
+ // errLeaseSpendConfsUnsupported prevents retired request parameters
+ // from silently choosing timed leases after their fields were removed.
+ errLeaseSpendConfsUnsupported = errors.New(
+ "release_after_spend_confs and " +
+ "input_release_after_spend_confs are no longer " +
+ "supported; use no_expiry or input_lease_no_expiry",
+ )
+
+ // errLeaseLifetimeConflict gives both handlers a stable identity for
+ // no-expiry requests that also select a competing duration.
+ errLeaseLifetimeConflict = errors.New("no-expiry cannot be combined " +
+ "with a duration")
+
+ // errMissingCustomLockID keeps missing-owner rejection independent of
+ // the diagnostic wording returned to RPC clients.
+ errMissingCustomLockID = errors.New("custom lock ID required for " +
+ "no-expiry input leases")
+
+ // errZeroCustomLockID keeps zero-owner rejection identifiable when its
+ // diagnostic wording changes.
+ errZeroCustomLockID = errors.New("custom lock ID must not be all " +
+ "zeros for no-expiry input leases")
+
+ // errReservedCustomLockID gives reserved-owner rejection a stable
+ // identity distinct from missing and zero owner IDs.
+ errReservedCustomLockID = errors.New("reserved custom lock ID cannot " +
+ "be used for no-expiry input leases")
+
// macaroonOps are the set of capabilities that our minted macaroon (if
// it doesn't already exist) will have.
macaroonOps = []bakery.Op{
@@ -476,13 +509,23 @@ func (w *WalletKit) ListUnspent(ctx context.Context,
// lock's expiration is returned. The expiration of the lock can be extended by
// successive invocations of this call. Outputs can be unlocked before their
// expiration through `ReleaseOutput`.
+// NoExpiry instead reserves the unused output without a timeout until owner
+// release or its first confirmed spend.
//
// If the output is not known, wtxmgr.ErrUnknownOutput is returned. If the
// output has already been locked to a different ID, then
// wtxmgr.ErrOutputAlreadyLocked is returned.
func (w *WalletKit) LeaseOutput(ctx context.Context,
req *LeaseOutputRequest) (*LeaseOutputResponse, error) {
+ // Older clients still send reserved field 4 as unknown protobuf data.
+ // Fail before an unsupported policy can fall through to a timed lease.
+ if err := rejectRetiredLeaseSpendConfs(
+ req.ProtoReflect().GetUnknown(), 4,
+ ); err != nil {
+ return nil, err
+ }
+
if len(req.Id) != 32 {
return nil, errors.New("id must be 32 random bytes")
}
@@ -510,7 +553,16 @@ func (w *WalletKit) LeaseOutput(ctx context.Context,
if req.ExpirationSeconds != 0 {
duration = time.Duration(req.ExpirationSeconds) * time.Second
}
- releaseAfterSpendConfs := req.ReleaseAfterSpendConfs
+
+ // Only the explicit flag selects the wallet's depth-one no-timeout
+ // lifetime. Reject durations that imply an expiry for this mode.
+ var releaseAfterSpendConfs uint32
+ if req.NoExpiry {
+ if req.ExpirationSeconds != 0 {
+ return nil, errLeaseLifetimeConflict
+ }
+ releaseAfterSpendConfs = noExpiryLeaseDepth
+ }
// Acquire the global coin selection lock to ensure there aren't any
// other concurrent processes attempting to lease the same UTXO.
@@ -543,28 +595,49 @@ func (w *WalletKit) LeaseOutput(ctx context.Context,
return nil, err
}
- // A zero-depth same-owner renewal preserves any existing confirmation
- // depth. Read it after the lease succeeds so this informational field
- // cannot prevent a legacy lease or extend the coin selection lock.
+ // A same-owner renewal preserves an existing no-expiry lifetime. Read
+ // it after success so informational readback cannot prevent acquisition
+ // or extend the coin selection lock.
if releaseAfterSpendConfs == 0 {
depth, err := storedLeaseDepth(w.cfg.Wallet, lockID, *op)
if err != nil {
- log.Warnf("Unable to report retained confirmation "+
- "depth for lease %v: %v", op, err)
+ log.Warnf("Unable to report no-expiry policy "+
+ "for lease %v: %v", op, err)
} else {
releaseAfterSpendConfs = depth
}
}
return &LeaseOutputResponse{
- Expiration: uint64(expiration.Unix()),
- ReleaseAfterSpendConfs: releaseAfterSpendConfs,
+ Expiration: uint64(expiration.Unix()),
+ NoExpiry: releaseAfterSpendConfs ==
+ noExpiryLeaseDepth,
}, nil
}
-// storedLeaseDepth returns the confirmation depth of an existing lease owned
-// by lockID. It lets a zero-depth renewal report the depth that the legacy
-// wallet lease method preserves.
+// rejectRetiredLeaseSpendConfs checks preserved protobuf data for a removed
+// lifetime request so older clients receive an explicit migration error.
+func rejectRetiredLeaseSpendConfs(unknown []byte,
+ retiredField protowire.Number) error {
+
+ // Consume complete encoded fields using the codec's framing rules;
+ // unrelated unknown fields must not select or invalidate a lifetime.
+ for len(unknown) > 0 {
+ number, _, n := protowire.ConsumeField(unknown)
+ if n < 0 {
+ return protowire.ParseError(n)
+ }
+ if number == retiredField {
+ return errLeaseSpendConfsUnsupported
+ }
+ unknown = unknown[n:]
+ }
+
+ return nil
+}
+
+// storedLeaseDepth returns the wallet lifetime of an existing lease owned by
+// lockID so a renewal can acknowledge a preserved no-expiry reservation.
func storedLeaseDepth(wallet lnwallet.WalletController, lockID wtxmgr.LockID,
op wire.OutPoint) (uint32, error) {
@@ -1694,6 +1767,24 @@ func (w *WalletKit) LabelTransaction(ctx context.Context,
func (w *WalletKit) FundPsbt(_ context.Context,
req *FundPsbtRequest) (*FundPsbtResponse, error) {
+ // The removed input policy still arrives under field 15 from old
+ // protobuf clients. Reject it before funding can acquire timed leases.
+ if err := rejectRetiredLeaseSpendConfs(
+ req.ProtoReflect().GetUnknown(), 15,
+ ); err != nil {
+ return nil, err
+ }
+
+ // Normalize the explicit no-timeout option once so every funding mode
+ // uses the existing capability, owner checks, and acquisition rollback.
+ var releaseAfterSpendConfs uint32
+ if req.InputLeaseNoExpiry {
+ if req.LockExpirationSeconds != 0 {
+ return nil, errLeaseLifetimeConflict
+ }
+ releaseAfterSpendConfs = noExpiryLeaseDepth
+ }
+
var customLockID *wtxmgr.LockID
if len(req.CustomLockId) > 0 {
lockID := wtxmgr.LockID{}
@@ -1706,23 +1797,16 @@ func (w *WalletKit) FundPsbt(_ context.Context,
customLockID = &lockID
}
- if req.InputReleaseAfterSpendConfs > 0 {
+ if releaseAfterSpendConfs > 0 {
switch {
case customLockID == nil:
- return nil, errors.New("custom lock ID required for " +
- "confirmation-controlled input leases")
+ return nil, errMissingCustomLockID
case *customLockID == (wtxmgr.LockID{}):
- return nil, errors.New(
- "custom lock ID must not be all zeros for " +
- "confirmation-controlled input leases",
- )
+ return nil, errZeroCustomLockID
case *customLockID == chanfunding.LndInternalLockID:
- return nil, errors.New(
- "reserved custom lock ID cannot be used for " +
- "confirmation-controlled input leases",
- )
+ return nil, errReservedCustomLockID
}
}
@@ -1809,7 +1893,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
account, keyScopeFromChangeAddressType(req.ChangeType),
packet, minConfs, feeSatPerKW, coinSelectionStrategy,
customLockID, customLockDuration,
- req.InputReleaseAfterSpendConfs,
+ releaseAfterSpendConfs,
)
// The template is specified as a PSBT with the intention to perform
@@ -1902,7 +1986,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
account, changeIndex, packet, minConfs, changeType,
feeSatPerKW, coinSelectionStrategy, maxFeeRatio,
customLockID, customLockDuration,
- req.InputReleaseAfterSpendConfs,
+ releaseAfterSpendConfs,
)
// The template is specified as a RPC message. We need to create a new
@@ -1961,7 +2045,7 @@ func (w *WalletKit) FundPsbt(_ context.Context,
account, keyScopeFromChangeAddressType(req.ChangeType),
packet, minConfs, feeSatPerKW, coinSelectionStrategy,
customLockID, customLockDuration,
- req.InputReleaseAfterSpendConfs,
+ releaseAfterSpendConfs,
)
default:
@@ -2371,11 +2455,12 @@ func (w *WalletKit) lockAndCreateFundingResponse(packet *psbt.Packet,
return nil, fmt.Errorf("could not lock inputs: %w", err)
}
- // Convert the lock leases to the RPC format.
- rpcLocks := marshallLeases(locks)
- for _, lock := range rpcLocks {
+ // Newly acquired results lack the configured depth. Populate it before
+ // marshalling so FundPsbt and ListLeases share one readback path.
+ for _, lock := range locks {
lock.ReleaseAfterSpendConfs = releaseAfterSpendConfs
}
+ rpcLocks := marshallLeases(locks)
return &FundPsbtResponse{
FundedPsbt: buf.Bytes(),
@@ -2453,7 +2538,8 @@ func (w *WalletKit) handleChange(packet *psbt.Packet, changeIndex int32,
return newChangeIndex, nil
}
-// marshallLeases converts the lock leases to the RPC format.
+// marshallLeases converts lease results to RPC metadata, acknowledging the
+// wallet's first-confirmed-spend lifetime through the no-expiry boolean.
func marshallLeases(locks []*base.ListLeasedOutputResult) []*UtxoLease {
rpcLocks := make([]*UtxoLease, len(locks))
for idx, lock := range locks {
@@ -2463,11 +2549,12 @@ func marshallLeases(locks []*base.ListLeasedOutputResult) []*UtxoLease {
Outpoint: lnrpc.MarshalOutPoint(
&lock.Outpoint,
),
- Expiration: uint64(lock.Expiration.Unix()),
- PkScript: lock.PkScript,
- Value: uint64(lock.Value),
- ReleaseAfterSpendConfs: lock.ReleaseAfterSpendConfs,
- ConfirmedSpendHeight: lock.ConfirmedSpendHeight,
+ Expiration: uint64(lock.Expiration.Unix()),
+ PkScript: lock.PkScript,
+ Value: uint64(lock.Value),
+ ConfirmedSpendHeight: lock.ConfirmedSpendHeight,
+ NoExpiry: lock.ReleaseAfterSpendConfs ==
+ noExpiryLeaseDepth,
}
}
### lnrpc/walletrpc/walletkit_server_test.go
@@ -26,37 +26,65 @@ import (
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
+ testifymock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
+ "google.golang.org/protobuf/encoding/protowire"
+ "google.golang.org/protobuf/proto"
)
-// TestMarshallLeasesIncludesSpendProgress verifies that ListLeases exposes
-// each confirmation-controlled lease's persisted spend progress.
+// TestMarshallLeasesIncludesSpendProgress verifies that lease responses
+// report the no-expiry lifetime alongside the stored spend height.
func TestMarshallLeasesIncludesSpendProgress(t *testing.T) {
t.Parallel()
- testCases := []int32{0, 123, -1}
- for _, spendHeight := range testCases {
- testName := fmt.Sprintf("height %d", spendHeight)
+ testCases := []struct {
+ depth uint32
+ spendHeight int32
+ noExpiry bool
+ }{
+ {
+ depth: 0,
+ spendHeight: 0,
+ noExpiry: false,
+ },
+ {
+ depth: 1,
+ spendHeight: 123,
+ noExpiry: true,
+ },
+ }
+ for _, testCase := range testCases {
+ testName := fmt.Sprintf("depth %d", testCase.depth)
t.Run(testName, func(t *testing.T) {
t.Parallel()
+ // Arrange timed and no-expiry wallet lifetimes so their
+ // response flags can distinguish them without a count.
lockedOutput := &wtxmgr.LockedOutput{
Outpoint: wire.OutPoint{Index: 2},
LockID: wtxmgr.LockID{1},
Expiration: time.Unix(123, 0),
- ReleaseAfterSpendConfs: 6,
- ConfirmedSpendHeight: spendHeight,
+ ReleaseAfterSpendConfs: testCase.depth,
+ ConfirmedSpendHeight: testCase.spendHeight,
}
locks := []*wallet.ListLeasedOutputResult{{
LockedOutput: lockedOutput,
Value: 1000,
PkScript: []byte{0x51},
}}
+ // Act by converting the same lease metadata returned by
+ // funding and listing through their shared marshaller.
rpcLocks := marshallLeases(locks)
+
+ // Assert the boolean reports the lifetime and preserves
+ // the independent spend-height readback.
require.Len(t, rpcLocks, 1)
require.Equal(
- t, spendHeight,
+ t, testCase.noExpiry, rpcLocks[0].NoExpiry,
+ )
+ require.Equal(
+ t, testCase.spendHeight,
rpcLocks[0].ConfirmedSpendHeight,
)
})
@@ -104,20 +132,138 @@ type mockCoinSelectionLocker struct {
fail bool
}
-// renewalWallet returns a persisted lease after extending it through the
-// legacy lease method.
-type renewalWallet struct {
- *leaseOptionsWallet
+// noExpiryLeaseWallet checks lease acquisition and renewal through the public
+// handler without substituting another implementation of lease lifetime rules.
+type noExpiryLeaseWallet struct {
+ lnwallet.WalletController
+ testifymock.Mock
+}
+
+var _ lnwallet.OutputLeaserWithOptions = (*noExpiryLeaseWallet)(nil)
+
+// LeaseOutput models renewal through the existing zero-option wallet path.
+func (w *noExpiryLeaseWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
+ duration time.Duration) (time.Time, error) {
+
+ args := w.Called(id, op, duration)
+ expiration, _ := args.Get(0).(time.Time)
+ return expiration, args.Error(1)
+}
+
+// LeaseOutputWithOptions checks the persisted lifetime requested by the RPC.
+func (w *noExpiryLeaseWallet) LeaseOutputWithOptions(id wtxmgr.LockID,
+ op wire.OutPoint, duration time.Duration,
+ opts lnwallet.LeaseOutputOptions) (time.Time, error) {
- leases []*wallet.ListLeasedOutputResult
- listErr error
+ args := w.Called(id, op, duration, opts)
+ expiration, _ := args.Get(0).(time.Time)
+ return expiration, args.Error(1)
}
-// ListLeasedOutputs returns the persisted leases visible after renewal.
-func (w *renewalWallet) ListLeasedOutputs() (
+// ListLeasedOutputs provides the effective policy after a same-owner renewal.
+func (w *noExpiryLeaseWallet) ListLeasedOutputs() (
[]*wallet.ListLeasedOutputResult, error) {
- return w.leases, w.listErr
+ args := w.Called()
+ leases, _ := args.Get(0).([]*wallet.ListLeasedOutputResult)
+ return leases, args.Error(1)
+}
+
+// TestLeaseOutputNoExpiry verifies the explicit flag acquires the wallet's
+// no-timeout lifetime and reports that policy to clients.
+func TestLeaseOutputNoExpiry(t *testing.T) {
+ t.Parallel()
+
+ // Arrange an exact wallet expectation and use the real coin-selection
+ // mutex so only the optional wallet capability needs to be mocked.
+ id := wtxmgr.LockID{1}
+ op := wire.OutPoint{Index: 1}
+ controller := &noExpiryLeaseWallet{}
+ defer controller.AssertExpectations(t)
+ controller.On(
+ "LeaseOutputWithOptions", id, op,
+ chanfunding.DefaultLockDuration,
+ lnwallet.LeaseOutputOptions{ReleaseAfterSpendConfs: 1},
+ ).Return(time.Unix(123, 0), nil).Once()
+ server := &WalletKit{cfg: &Config{
+ Wallet: controller,
+ CoinSelectionLocker: &lnwallet.LightningWallet{},
+ }}
+
+ // Act with no duration: the flag alone chooses the
+ // persisted reservation, without requiring a user-supplied count.
+ resp, err := server.LeaseOutput(t.Context(), &LeaseOutputRequest{
+ Id: id[:],
+ Outpoint: &lnrpc.OutPoint{
+ TxidBytes: op.Hash[:],
+ OutputIndex: op.Index,
+ },
+ NoExpiry: true,
+ })
+
+ // Assert the new response field acknowledges the installed policy;
+ // deferred mock verification checks the exact owner and lifetime once.
+ require.NoError(t, err)
+ require.True(t, resp.NoExpiry)
+}
+
+// TestLeaseOutputRejectsNoExpiryConflicts verifies both lease RPCs reject
+// competing lifetime settings before touching wallet state.
+func TestLeaseOutputRejectsNoExpiryConflicts(t *testing.T) {
+ t.Parallel()
+
+ // Arrange without a wallet so validation must reject the conflicting
+ // lifetimes before either handler can acquire a reservation.
+ server := &WalletKit{cfg: &Config{}}
+
+ // Act through both public request forms with a duration that cannot
+ // apply to the explicitly requested no-expiry lifetime.
+ _, leaseErr := server.LeaseOutput(t.Context(), &LeaseOutputRequest{
+ Id: bytes.Repeat([]byte{1}, 32),
+ Outpoint: &lnrpc.OutPoint{
+ TxidBytes: make([]byte, 32),
+ },
+ NoExpiry: true,
+ ExpirationSeconds: 1,
+ })
+ _, fundErr := server.FundPsbt(t.Context(), &FundPsbtRequest{
+ InputLeaseNoExpiry: true,
+ LockExpirationSeconds: 1,
+ })
+
+ // Assert both handlers expose the shared identity, so clients and
+ // regression coverage do not depend on diagnostic wording.
+ require.ErrorIs(t, leaseErr, errLeaseLifetimeConflict)
+ require.ErrorIs(t, fundErr, errLeaseLifetimeConflict)
+}
+
+// TestLeaseOutputRejectsRetiredSpendConfs verifies old protobuf requests
+// fail explicitly at both lease entry points instead of selecting timed locks.
+func TestLeaseOutputRejectsRetiredSpendConfs(t *testing.T) {
+ t.Parallel()
+
+ // Arrange the old count value at each retired wire number. Ordinary
+ // decoding retains these bytes even though the fields are now reserved;
+ // no wallet is configured: rejection must need no acquisition.
+ leaseReq := &LeaseOutputRequest{}
+ leaseWire := protowire.AppendTag(nil, 4, protowire.VarintType)
+ leaseWire = protowire.AppendVarint(leaseWire, 3)
+ require.NoError(t, proto.Unmarshal(leaseWire, leaseReq))
+ fundReq := &FundPsbtRequest{}
+ fundWire := protowire.AppendTag(nil, 15, protowire.VarintType)
+ fundWire = protowire.AppendVarint(fundWire, 3)
+ require.NoError(t, proto.Unmarshal(fundWire, fundReq))
+ server := &WalletKit{cfg: &Config{}}
+
+ // Act through both public handlers with the decoded old requests, as
+ // gRPC would deliver them from clients using the removed parameters.
+ _, leaseErr := server.LeaseOutput(t.Context(), leaseReq)
+ _, fundErr := server.FundPsbt(t.Context(), fundReq)
+
+ // Assert the shared migration error before other validation or wallet
+ // work; error identity keeps this independent of diagnostic wording.
+ require.ErrorIs(t, leaseErr, errLeaseSpendConfsUnsupported)
+ require.ErrorIs(t, fundErr, errLeaseSpendConfsUnsupported)
}
// WithCoinSelectLock runs the callback and optionally returns a test error.
@@ -138,139 +284,187 @@ func (m *mockCoinSelectionLocker) WithCoinSelectLock(f func() error) error {
func TestLeaseOutputRejectsUnsupportedOptions(t *testing.T) {
t.Parallel()
- wallet := &legacyLeaseWallet{
- WalletController: &mock.WalletController{},
- }
- rpcServer, _, err := New(&Config{
- Wallet: &lnwallet.LightningWallet{
- WalletController: wallet,
- },
- CoinSelectionLocker: &mockCoinSelectionLocker{},
- })
- require.NoError(t, err)
+ // Arrange a concrete wallet with no underlying optional leaser. The
+ // existing resolver must reject it without invoking a wallet method.
+ rpcServer := &WalletKit{cfg: &Config{
+ Wallet: &lnwallet.LightningWallet{},
+ CoinSelectionLocker: &lnwallet.LightningWallet{},
+ }}
- _, err = rpcServer.LeaseOutput(t.Context(), &LeaseOutputRequest{
+ // Act with only the no-expiry flag so a competing duration cannot
+ // obscure the missing wallet capability.
+ _, err := rpcServer.LeaseOutput(t.Context(), &LeaseOutputRequest{
Id: bytes.Repeat([]byte{1}, 32),
Outpoint: &lnrpc.OutPoint{
TxidBytes: make([]byte, 32),
OutputIndex: 1,
},
- ExpirationSeconds: 60,
- ReleaseAfterSpendConfs: 6,
+ NoExpiry: true,
})
+
+ // Assert the capability error rather than accepting a timed fallback;
+ // the unconfigured wallet would fail if the handler called through it.
require.ErrorIs(t, err, errOutputLeaseOptionsUnsupported)
- require.Zero(t, wallet.leaseCalls,
- "unsupported options must not create a shorter legacy lease")
}
-// TestLeaseOutputReturnsEffectiveRenewalDepth verifies that renewing an
-// existing confirmation-controlled lease through the legacy zero-depth path
-// reports the non-zero depth retained by the wallet.
+// TestLeaseOutputReturnsEffectiveRenewalDepth verifies a same-owner renewal
+// acknowledges the timed or no-expiry lifetime preserved by the wallet.
func TestLeaseOutputReturnsEffectiveRenewalDepth(t *testing.T) {
t.Parallel()
- lockID := wtxmgr.LockID{1}
- outpoint := wire.OutPoint{Index: 1}
- controller := &renewalWallet{
- leaseOptionsWallet: &leaseOptionsWallet{
- WalletController: &mock.WalletController{},
+ testCases := []struct {
+ depth uint32
+ noExpiry bool
+ }{
+ {
+ depth: 1,
+ noExpiry: true,
+ },
+ {
+ depth: 0,
+ noExpiry: false,
},
- leases: []*wallet.ListLeasedOutputResult{{
- LockedOutput: &wtxmgr.LockedOutput{
+ }
+ for _, testCase := range testCases {
+ name := fmt.Sprintf("depth %d", testCase.depth)
+ t.Run(name, func(t *testing.T) {
+ t.Parallel()
+
+ // Arrange a zero-option renewal and one readback of its
+ // stored lifetime, with the real coin-selection mutex.
+ lockID := wtxmgr.LockID{1}
+ outpoint := wire.OutPoint{Index: 1}
+ controller := &noExpiryLeaseWallet{}
+ defer controller.AssertExpectations(t)
+ controller.On(
+ "LeaseOutput", lockID, outpoint, time.Minute,
+ ).Return(time.Unix(123, 0), nil).Once()
+ lockedOutput := &wtxmgr.LockedOutput{
Outpoint: outpoint,
LockID: lockID,
- ReleaseAfterSpendConfs: 6,
- },
- }},
- }
- rpcServer, _, err := New(&Config{
- Wallet: controller,
- CoinSelectionLocker: &mockCoinSelectionLocker{},
- })
- require.NoError(t, err)
+ ReleaseAfterSpendConfs: testCase.depth,
+ }
+ leases := []*wallet.ListLeasedOutputResult{
+ {
+ LockedOutput: lockedOutput,
+ },
+ }
+ controller.On("ListLeasedOutputs").Return(
+ leases, nil,
+ ).Once()
+ locker := &lnwallet.LightningWallet{}
+ server := &WalletKit{cfg: &Config{
+ Wallet: controller,
+ CoinSelectionLocker: locker,
+ }}
- resp, err := rpcServer.LeaseOutput(t.Context(), &LeaseOutputRequest{
- Id: lockID[:],
- Outpoint: &lnrpc.OutPoint{
- TxidBytes: make([]byte, 32),
- OutputIndex: outpoint.Index,
- },
- ExpirationSeconds: 60,
- })
- require.NoError(t, err)
- require.Equal(t, uint32(6), resp.ReleaseAfterSpendConfs)
- require.Equal(t, 1, controller.legacyCalls)
+ // Act without a new policy: the existing lease
+ // must keep its persisted lifetime on this renewal.
+ resp, err := server.LeaseOutput(
+ t.Context(), &LeaseOutputRequest{
+ Id: lockID[:],
+ Outpoint: &lnrpc.OutPoint{
+ TxidBytes: outpoint.Hash[:],
+ OutputIndex: outpoint.Index,
+ },
+ ExpirationSeconds: 60,
+ },
+ )
+
+ // Assert the boolean describes the retained lifetime,
+ // even though the renewal omitted the no-expiry flag.
+ require.NoError(t, err)
+ require.Equal(t, testCase.noExpiry, resp.NoExpiry)
+ })
+ }
}
-// TestLeaseOutputIgnoresRenewalDepthReadError verifies an informational depth
-// lookup cannot prevent a successful legacy lease.
+// TestLeaseOutputIgnoresRenewalDepthReadError verifies that failed policy
+// readback cannot turn successful lease acquisition into an RPC failure.
func TestLeaseOutputIgnoresRenewalDepthReadError(t *testing.T) {
t.Parallel()
+ // Arrange a successful renewal followed by failed policy readback.
+ // Reuse the wallet mock so both calls are checked without another
+ // implementation of the wallet interface.
lockID := wtxmgr.LockID{1}
- controller := &renewalWallet{
- leaseOptionsWallet: &leaseOptionsWallet{
- WalletController: &mock.WalletController{},
- },
- listErr: errors.New("list leases failed"),
- }
- rpcServer, _, err := New(&Config{
+ outpoint := wire.OutPoint{}
+ controller := &noExpiryLeaseWallet{}
+ defer controller.AssertExpectations(t)
+ controller.On(
+ "LeaseOutput", lockID, outpoint, time.Minute,
+ ).Return(time.Unix(123, 0), nil).Once()
+ controller.On("ListLeasedOutputs").Return(
+ []*wallet.ListLeasedOutputResult(nil),
+ errors.New("list leases failed"),
+ ).Once()
+ rpcServer := &WalletKit{cfg: &Config{
Wallet: controller,
- CoinSelectionLocker: &mockCoinSelectionLocker{},
- })
- require.NoError(t, err)
+ CoinSelectionLocker: &lnwallet.LightningWallet{},
+ }}
+ // Act through the timed renewal path, which reads the retained policy
+ // after the wallet has successfully acquired or extended the lease.
resp, err := rpcServer.LeaseOutput(t.Context(), &LeaseOutputRequest{
Id: lockID[:],
Outpoint: &lnrpc.OutPoint{
- TxidBytes: make([]byte, 32),
+ TxidBytes: outpoint.Hash[:],
},
ExpirationSeconds: 60,
})
+
+ // Assert acquisition still succeeds without claiming an unverified
+ // no-expiry policy; deferred verification checks each wallet call once.
require.NoError(t, err)
- require.Zero(t, resp.ReleaseAfterSpendConfs)
- require.Equal(t, 1, controller.legacyCalls)
+ require.False(t, resp.NoExpiry)
}
-// TestFundPsbtRequiresCustomLockID verifies confirmation-controlled input
+// TestFundPsbtRequiresCustomLockID verifies no-expiry input
// leases require an external, caller-specific owner ID.
func TestFundPsbtRequiresCustomLockID(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
lockID []byte
- expected string
+ expected error
}{
{
- name: "missing",
- expected: "custom lock ID required for " +
- "confirmation-controlled",
+ name: "missing",
+ expected: errMissingCustomLockID,
},
{
name: "all zero",
lockID: make([]byte, 32),
- expected: "custom lock ID must not be all zeros",
+ expected: errZeroCustomLockID,
},
{
name: "reserved internal",
lockID: chanfunding.LndInternalLockID[:],
- expected: "reserved custom lock ID cannot be used",
+ expected: errReservedCustomLockID,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
+ // Arrange a no-expiry request with an unsafe owner and
+ // no wallet, requiring rejection before acquisition.
server := &WalletKit{cfg: &Config{}}
req := &FundPsbtRequest{
- InputReleaseAfterSpendConfs: 6,
+ InputLeaseNoExpiry: true,
+ CustomLockId: testCase.lockID,
}
- req.CustomLockId = testCase.lockID
+ // Act before template validation or funding can obscure
+ // the owner-ID rejection.
_, err := server.FundPsbt(t.Context(), req)
- require.ErrorContains(t, err, testCase.expected)
+
+ // Assert each invalid identity is rejected, requiring a
+ // caller-specific owner for a persistent reservation.
+ // Compare identities without matching message text.
+ require.ErrorIs(t, err, testCase.expected)
})
}
}Why this scored 35/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.