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.
This commit is contained in:
Wilmer Paulino 2020-06-10 13:15:38 -07:00
parent 9b8d51231c
commit 9d9e54f83e
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

View File

@ -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)
}