Skip to content

Commit 3e36adf

Browse files
committed
mulit: remove ListLeasedOutputs in LeaseOutput
This commit removes the call toe `ListLeasedOutputs` in `LeaseOutput` - the returned info from `ListLeasedOutputs` can easily be accessed via `FetchInputInfo` and this info is only used at one callsite. `ListLeasedOutputs` then becomes unnecessary here, plus it's very slow and needs to be refactored in `btcwallet` instead.
1 parent f70c919 commit 3e36adf

File tree

10 files changed

+17
-34
lines changed

10 files changed

+17
-34
lines changed

lnrpc/walletrpc/psbt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func lockInputs(w lnwallet.WalletController,
6262
return nil, fmt.Errorf("fetch outpoint info: %w", err)
6363
}
6464

65-
expiration, _, _, err := w.LeaseOutput(
65+
expiration, err := w.LeaseOutput(
6666
lock.LockID, lock.Outpoint,
6767
chanfunding.DefaultLockDuration,
6868
)

lnrpc/walletrpc/walletkit_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ func (w *WalletKit) LeaseOutput(ctx context.Context,
490490
// other concurrent processes attempting to lease the same UTXO.
491491
var expiration time.Time
492492
err = w.cfg.CoinSelectionLocker.WithCoinSelectLock(func() error {
493-
expiration, _, _, err = w.cfg.Wallet.LeaseOutput(
493+
expiration, err = w.cfg.Wallet.LeaseOutput(
494494
lockID, *op, duration,
495495
)
496496
return err

lntest/mock/walletcontroller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ func (w *WalletController) ListTransactionDetails(int32, int32,
195195

196196
// LeaseOutput returns the current time and a nil error.
197197
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
198-
time.Duration) (time.Time, []byte, btcutil.Amount, error) {
198+
time.Duration) (time.Time, error) {
199199

200-
return time.Now(), nil, 0, nil
200+
return time.Now(), nil
201201
}
202202

203203
// ReleaseOutput currently does nothing.

lnwallet/btcwallet/btcwallet.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,36 +1079,20 @@ func (b *BtcWallet) CreateSimpleTx(inputs fn.Set[wire.OutPoint],
10791079
//
10801080
// NOTE: This method requires the global coin selection lock to be held.
10811081
func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
1082-
duration time.Duration) (time.Time, []byte, btcutil.Amount, error) {
1082+
duration time.Duration) (time.Time, error) {
10831083

10841084
// Make sure we don't attempt to double lock an output that's been
10851085
// locked by the in-memory implementation.
10861086
if b.wallet.LockedOutpoint(op) {
1087-
return time.Time{}, nil, 0, wtxmgr.ErrOutputAlreadyLocked
1087+
return time.Time{}, wtxmgr.ErrOutputAlreadyLocked
10881088
}
10891089

10901090
lockedUntil, err := b.wallet.LeaseOutput(id, op, duration)
10911091
if err != nil {
1092-
return time.Time{}, nil, 0, err
1092+
return time.Time{}, err
10931093
}
10941094

1095-
// Get the pkScript and value for this lock from the list of all leased
1096-
// outputs.
1097-
allLeases, err := b.wallet.ListLeasedOutputs()
1098-
if err != nil {
1099-
return time.Time{}, nil, 0, err
1100-
}
1101-
1102-
for _, lease := range allLeases {
1103-
if lease.Outpoint == op {
1104-
return lockedUntil, lease.PkScript,
1105-
btcutil.Amount(lease.Value), nil
1106-
}
1107-
}
1108-
1109-
// We MUST find the leased output in the loop above, otherwise something
1110-
// is seriously wrong.
1111-
return time.Time{}, nil, 0, wtxmgr.ErrUnknownOutput
1095+
return lockedUntil, nil
11121096
}
11131097

11141098
// ListLeasedOutputs returns a list of all currently locked outputs.

lnwallet/chanfunding/assembler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type OutputLeaser interface {
4444
// LeaseOutput leases a target output, rendering it unusable for coin
4545
// selection.
4646
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
47-
time.Time, []byte, btcutil.Amount, error)
47+
time.Time, error)
4848

4949
// ReleaseOutput releases a target output, allowing it to be used for
5050
// coin selection once again.

lnwallet/chanfunding/wallet_assembler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
525525
for _, coin := range selectedCoins {
526526
outpoint := coin.OutPoint
527527

528-
_, _, _, err = w.cfg.CoinLeaser.LeaseOutput(
528+
_, err = w.cfg.CoinLeaser.LeaseOutput(
529529
LndInternalLockID, outpoint,
530530
DefaultReservationTimeout,
531531
)

lnwallet/interface.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,7 @@ type WalletController interface {
413413
//
414414
// NOTE: This method requires the global coin selection lock to be held.
415415
LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
416-
duration time.Duration) (time.Time, []byte, btcutil.Amount,
417-
error)
416+
duration time.Duration) (time.Time, error)
418417

419418
// ReleaseOutput unlocks an output, allowing it to be available for coin
420419
// selection if it remains unspent. The ID should match the one used to

lnwallet/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ func (w *mockWalletController) ListTransactionDetails(int32, int32,
201201

202202
// LeaseOutput returns the current time and a nil error.
203203
func (w *mockWalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
204-
time.Duration) (time.Time, []byte, btcutil.Amount, error) {
204+
time.Duration) (time.Time, error) {
205205

206-
return time.Now(), nil, 0, nil
206+
return time.Now(), nil
207207
}
208208

209209
// ReleaseOutput currently does nothing.

sweep/walletsweep.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ type OutputLeaser interface {
179179
// LeaseOutput leases a target output, rendering it unusable for coin
180180
// selection.
181181
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
182-
time.Time, []byte, btcutil.Amount, error)
182+
time.Time, error)
183183

184184
// ReleaseOutput releases a target output, allowing it to be used for
185185
// coin selection once again.
@@ -284,7 +284,7 @@ func CraftSweepAllTx(feeRate, maxFeeRate chainfee.SatPerKWeight,
284284
log.Tracef("[WithCoinSelectLock] leasing utxo: %v",
285285
utxo.OutPoint)
286286

287-
_, _, _, err = outputLeaser.LeaseOutput(
287+
_, err = outputLeaser.LeaseOutput(
288288
chanfunding.LndInternalLockID, utxo.OutPoint,
289289
chanfunding.DefaultLockDuration,
290290
)

sweep/walletsweep_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ func newMockOutputLeaser() *mockOutputLeaser {
199199
}
200200

201201
func (m *mockOutputLeaser) LeaseOutput(_ wtxmgr.LockID, o wire.OutPoint,
202-
t time.Duration) (time.Time, []byte, btcutil.Amount, error) {
202+
t time.Duration) (time.Time, error) {
203203

204204
m.leasedOutputs[o] = struct{}{}
205205

206-
return time.Now().Add(t), nil, 0, nil
206+
return time.Now().Add(t), nil
207207
}
208208

209209
func (m *mockOutputLeaser) ReleaseOutput(_ wtxmgr.LockID,

0 commit comments

Comments
 (0)