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 committed 2020-06-12 11:22:28 -07:00
1 parent 9b8d51231c
commit 9d9e54f83e
1 file changed
+7
+7
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)
}