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.
This commit is contained in:
10 files changed
+17
-34
No files matched your search
@@ -62,7 +62,7 @@ func lockInputs(w lnwallet.WalletController,
|
|||||||
return nil, fmt.Errorf("fetch outpoint info: %w", err)
|
return nil, fmt.Errorf("fetch outpoint info: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expiration, _, _, err := w.LeaseOutput(
|
expiration, err := w.LeaseOutput(
|
||||||
lock.LockID, lock.Outpoint,
|
lock.LockID, lock.Outpoint,
|
||||||
chanfunding.DefaultLockDuration,
|
chanfunding.DefaultLockDuration,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -490,7 +490,7 @@ func (w *WalletKit) LeaseOutput(ctx context.Context,
|
|||||||
// other concurrent processes attempting to lease the same UTXO.
|
// other concurrent processes attempting to lease the same UTXO.
|
||||||
var expiration time.Time
|
var expiration time.Time
|
||||||
err = w.cfg.CoinSelectionLocker.WithCoinSelectLock(func() error {
|
err = w.cfg.CoinSelectionLocker.WithCoinSelectLock(func() error {
|
||||||
expiration, _, _, err = w.cfg.Wallet.LeaseOutput(
|
expiration, err = w.cfg.Wallet.LeaseOutput(
|
||||||
lockID, *op, duration,
|
lockID, *op, duration,
|
||||||
)
|
)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -195,9 +195,9 @@ func (w *WalletController) ListTransactionDetails(int32, int32,
|
|||||||
|
|
||||||
// LeaseOutput returns the current time and a nil error.
|
// LeaseOutput returns the current time and a nil error.
|
||||||
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
|
func (w *WalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
|
||||||
time.Duration) (time.Time, []byte, btcutil.Amount, error) {
|
time.Duration) (time.Time, error) {
|
||||||
|
|
||||||
return time.Now(), nil, 0, nil
|
return time.Now(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReleaseOutput currently does nothing.
|
// ReleaseOutput currently does nothing.
|
||||||
|
|||||||
@@ -1079,36 +1079,20 @@ func (b *BtcWallet) CreateSimpleTx(inputs fn.Set[wire.OutPoint],
|
|||||||
//
|
//
|
||||||
// NOTE: This method requires the global coin selection lock to be held.
|
// NOTE: This method requires the global coin selection lock to be held.
|
||||||
func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
||||||
duration time.Duration) (time.Time, []byte, btcutil.Amount, error) {
|
duration time.Duration) (time.Time, error) {
|
||||||
|
|
||||||
// Make sure we don't attempt to double lock an output that's been
|
// Make sure we don't attempt to double lock an output that's been
|
||||||
// locked by the in-memory implementation.
|
// locked by the in-memory implementation.
|
||||||
if b.wallet.LockedOutpoint(op) {
|
if b.wallet.LockedOutpoint(op) {
|
||||||
return time.Time{}, nil, 0, wtxmgr.ErrOutputAlreadyLocked
|
return time.Time{}, wtxmgr.ErrOutputAlreadyLocked
|
||||||
}
|
}
|
||||||
|
|
||||||
lockedUntil, err := b.wallet.LeaseOutput(id, op, duration)
|
lockedUntil, err := b.wallet.LeaseOutput(id, op, duration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return time.Time{}, nil, 0, err
|
return time.Time{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the pkScript and value for this lock from the list of all leased
|
return lockedUntil, nil
|
||||||
// outputs.
|
|
||||||
allLeases, err := b.wallet.ListLeasedOutputs()
|
|
||||||
if err != nil {
|
|
||||||
return time.Time{}, nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, lease := range allLeases {
|
|
||||||
if lease.Outpoint == op {
|
|
||||||
return lockedUntil, lease.PkScript,
|
|
||||||
btcutil.Amount(lease.Value), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We MUST find the leased output in the loop above, otherwise something
|
|
||||||
// is seriously wrong.
|
|
||||||
return time.Time{}, nil, 0, wtxmgr.ErrUnknownOutput
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListLeasedOutputs returns a list of all currently locked outputs.
|
// ListLeasedOutputs returns a list of all currently locked outputs.
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ type OutputLeaser interface {
|
|||||||
// LeaseOutput leases a target output, rendering it unusable for coin
|
// LeaseOutput leases a target output, rendering it unusable for coin
|
||||||
// selection.
|
// selection.
|
||||||
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
|
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
|
||||||
time.Time, []byte, btcutil.Amount, error)
|
time.Time, error)
|
||||||
|
|
||||||
// ReleaseOutput releases a target output, allowing it to be used for
|
// ReleaseOutput releases a target output, allowing it to be used for
|
||||||
// coin selection once again.
|
// coin selection once again.
|
||||||
|
|||||||
@@ -525,7 +525,7 @@ func (w *WalletAssembler) ProvisionChannel(r *Request) (Intent, error) {
|
|||||||
for _, coin := range selectedCoins {
|
for _, coin := range selectedCoins {
|
||||||
outpoint := coin.OutPoint
|
outpoint := coin.OutPoint
|
||||||
|
|
||||||
_, _, _, err = w.cfg.CoinLeaser.LeaseOutput(
|
_, err = w.cfg.CoinLeaser.LeaseOutput(
|
||||||
LndInternalLockID, outpoint,
|
LndInternalLockID, outpoint,
|
||||||
DefaultReservationTimeout,
|
DefaultReservationTimeout,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -413,8 +413,7 @@ type WalletController interface {
|
|||||||
//
|
//
|
||||||
// NOTE: This method requires the global coin selection lock to be held.
|
// NOTE: This method requires the global coin selection lock to be held.
|
||||||
LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
LeaseOutput(id wtxmgr.LockID, op wire.OutPoint,
|
||||||
duration time.Duration) (time.Time, []byte, btcutil.Amount,
|
duration time.Duration) (time.Time, error)
|
||||||
error)
|
|
||||||
|
|
||||||
// ReleaseOutput unlocks an output, allowing it to be available for coin
|
// ReleaseOutput unlocks an output, allowing it to be available for coin
|
||||||
// selection if it remains unspent. The ID should match the one used to
|
// selection if it remains unspent. The ID should match the one used to
|
||||||
|
|||||||
+2
-2
@@ -201,9 +201,9 @@ func (w *mockWalletController) ListTransactionDetails(int32, int32,
|
|||||||
|
|
||||||
// LeaseOutput returns the current time and a nil error.
|
// LeaseOutput returns the current time and a nil error.
|
||||||
func (w *mockWalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
|
func (w *mockWalletController) LeaseOutput(wtxmgr.LockID, wire.OutPoint,
|
||||||
time.Duration) (time.Time, []byte, btcutil.Amount, error) {
|
time.Duration) (time.Time, error) {
|
||||||
|
|
||||||
return time.Now(), nil, 0, nil
|
return time.Now(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReleaseOutput currently does nothing.
|
// ReleaseOutput currently does nothing.
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ type OutputLeaser interface {
|
|||||||
// LeaseOutput leases a target output, rendering it unusable for coin
|
// LeaseOutput leases a target output, rendering it unusable for coin
|
||||||
// selection.
|
// selection.
|
||||||
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
|
LeaseOutput(i wtxmgr.LockID, o wire.OutPoint, d time.Duration) (
|
||||||
time.Time, []byte, btcutil.Amount, error)
|
time.Time, error)
|
||||||
|
|
||||||
// ReleaseOutput releases a target output, allowing it to be used for
|
// ReleaseOutput releases a target output, allowing it to be used for
|
||||||
// coin selection once again.
|
// coin selection once again.
|
||||||
@@ -284,7 +284,7 @@ func CraftSweepAllTx(feeRate, maxFeeRate chainfee.SatPerKWeight,
|
|||||||
log.Tracef("[WithCoinSelectLock] leasing utxo: %v",
|
log.Tracef("[WithCoinSelectLock] leasing utxo: %v",
|
||||||
utxo.OutPoint)
|
utxo.OutPoint)
|
||||||
|
|
||||||
_, _, _, err = outputLeaser.LeaseOutput(
|
_, err = outputLeaser.LeaseOutput(
|
||||||
chanfunding.LndInternalLockID, utxo.OutPoint,
|
chanfunding.LndInternalLockID, utxo.OutPoint,
|
||||||
chanfunding.DefaultLockDuration,
|
chanfunding.DefaultLockDuration,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -199,11 +199,11 @@ func newMockOutputLeaser() *mockOutputLeaser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockOutputLeaser) LeaseOutput(_ wtxmgr.LockID, o wire.OutPoint,
|
func (m *mockOutputLeaser) LeaseOutput(_ wtxmgr.LockID, o wire.OutPoint,
|
||||||
t time.Duration) (time.Time, []byte, btcutil.Amount, error) {
|
t time.Duration) (time.Time, error) {
|
||||||
|
|
||||||
m.leasedOutputs[o] = struct{}{}
|
m.leasedOutputs[o] = struct{}{}
|
||||||
|
|
||||||
return time.Now().Add(t), nil, 0, nil
|
return time.Now().Add(t), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockOutputLeaser) ReleaseOutput(_ wtxmgr.LockID,
|
func (m *mockOutputLeaser) ReleaseOutput(_ wtxmgr.LockID,
|
||||||
|
|||||||
Reference in new issue
Block a user