From 9d9e54f83e5a86bc741d610abacd51fc9abc30c9 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Wed, 10 Jun 2020 13:15:38 -0700 Subject: [PATCH] btcwallet: ensure output isn't locked by in-memory impl in LeaseOutput The current implementation of LeaseOutput already checked whether the output had already been leased by the persisted implementation, but not the in-memory one used by lnd internally. Without this check, we could potentially end up with a double spend error if lnd acquired the UTXO internally before the LeaseOutput call. --- lnwallet/btcwallet/btcwallet.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index e1176933..757b7574 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -379,6 +379,13 @@ func (b *BtcWallet) UnlockOutpoint(o wire.OutPoint) { // wtxmgr.ErrOutputAlreadyLocked is returned. func (b *BtcWallet) LeaseOutput(id wtxmgr.LockID, op wire.OutPoint) (time.Time, error) { + + // Make sure we don't attempt to double lock an output that's been + // locked by the in-memory implementation. + if b.wallet.LockedOutpoint(op) { + return time.Time{}, wtxmgr.ErrOutputAlreadyLocked + } + return b.wallet.LeaseOutput(id, op) }