Make sure exception is caught by Future inside of UtxoHandling.unmarkUTXOsAsReserved() (#3816)

This commit is contained in:
Chris Stewart 2021-11-11 15:22:45 -06:00 committed by GitHub
parent 31ce7cbd77
commit 31e8324522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package org.bitcoins.dlc.wallet
import com.typesafe.config.ConfigFactory
import org.bitcoins.core.number.UInt32
import org.bitcoins.core.wallet.fee.SatoshisPerVirtualByte
import org.bitcoins.core.wallet.utxo.TxoState
import org.bitcoins.server.BitcoinSAppConfig
import org.bitcoins.testkit.BitcoinSTestAppConfig
import org.bitcoins.testkit.keymanager.KeyManagerTestUtil.bip39PasswordOpt
@ -61,4 +62,30 @@ class MultiWalletDLCTest extends BitcoinSWalletTest {
assert(dlcsA != dlcsB)
}
}
it must "create an offer, out of band unreserve the utxo, and then cancel the offer" in {
fundedWallet: FundedDLCWallet =>
//see: https://github.com/bitcoin-s/bitcoin-s/issues/3813#issue-1051117559
val wallet = fundedWallet.wallet
val offerF = wallet.createDLCOffer(contractInfo = sampleContractInfo,
collateral = half,
feeRateOpt =
Some(SatoshisPerVirtualByte.one),
locktime = UInt32.zero,
refundLocktime = UInt32.one)
//now unreserve the utxo
val reservedUtxoF = for {
_ <- offerF
utxos <- wallet.listUtxos(TxoState.Reserved)
_ <- wallet.unmarkUTXOsAsReserved(utxos)
} yield ()
//now cancel the offer
for {
offer <- offerF
_ <- reservedUtxoF
_ <- wallet.cancelDLC(offer.dlcId)
} yield succeed
}
}

View File

@ -334,14 +334,21 @@ private[wallet] trait UtxoHandling extends WalletLogger {
override def unmarkUTXOsAsReserved(
utxos: Vector[SpendingInfoDb]): Future[Vector[SpendingInfoDb]] = {
val unreserved = utxos.filterNot(_.state == TxoState.Reserved)
require(unreserved.isEmpty, s"Some utxos are not reserved, got $unreserved")
val updatedUtxosF = Future {
//make sure exception isn't thrown outside of a future to fix
//see: https://github.com/bitcoin-s/bitcoin-s/issues/3813
val unreserved = utxos.filterNot(_.state == TxoState.Reserved)
require(unreserved.isEmpty,
s"Some utxos are not reserved, got $unreserved")
// unmark all utxos are reserved
val updatedUtxos = utxos
.map(_.copyWithState(TxoState.PendingConfirmationsReceived))
// unmark all utxos are reserved
val updatedUtxos = utxos
.map(_.copyWithState(TxoState.PendingConfirmationsReceived))
updatedUtxos
}
for {
updatedUtxos <- updatedUtxosF
// update the confirmed utxos
updatedConfirmed <- updateUtxoConfirmedStates(updatedUtxos)