thaw reserved outputs within task if canceled

This commit is contained in:
woodser 2024-05-23 18:17:27 -04:00
parent f2f5a6fd24
commit 796603f82b
2 changed files with 27 additions and 15 deletions

View file

@ -79,22 +79,33 @@ public class MakerReserveOfferFunds extends Task<PlaceOfferModel> {
Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex(); Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex();
// attempt creating reserve tx // attempt creating reserve tx
synchronized (HavenoUtils.getWalletFunctionLock()) { try {
for (int i = 0; i < TradeProtocol.MAX_ATTEMPTS; i++) { synchronized (HavenoUtils.getWalletFunctionLock()) {
try { for (int i = 0; i < TradeProtocol.MAX_ATTEMPTS; i++) {
//if (true) throw new RuntimeException("Pretend error"); try {
reserveTx = model.getXmrWalletService().createReserveTx(penaltyFee, makerFee, sendAmount, securityDeposit, returnAddress, openOffer.isReserveExactAmount(), preferredSubaddressIndex); //if (true) throw new RuntimeException("Pretend error");
} catch (Exception e) { reserveTx = model.getXmrWalletService().createReserveTx(penaltyFee, makerFee, sendAmount, securityDeposit, returnAddress, openOffer.isReserveExactAmount(), preferredSubaddressIndex);
log.warn("Error creating reserve tx, attempt={}/{}, offerId={}, error={}", i + 1, TradeProtocol.MAX_ATTEMPTS, openOffer.getShortId(), e.getMessage()); } catch (Exception e) {
if (i == TradeProtocol.MAX_ATTEMPTS - 1) throw e; log.warn("Error creating reserve tx, attempt={}/{}, offerId={}, error={}", i + 1, TradeProtocol.MAX_ATTEMPTS, openOffer.getShortId(), e.getMessage());
model.getProtocol().startTimeoutTimer(); // reset protocol timeout if (i == TradeProtocol.MAX_ATTEMPTS - 1) throw e;
HavenoUtils.waitFor(TradeProtocol.REPROCESS_DELAY_MS); // wait before retrying model.getProtocol().startTimeoutTimer(); // reset protocol timeout
} HavenoUtils.waitFor(TradeProtocol.REPROCESS_DELAY_MS); // wait before retrying
}
// verify still open // verify still open
verifyScheduled(); verifyScheduled();
if (reserveTx != null) break; if (reserveTx != null) break;
}
} }
} catch (Exception e) {
// reset state with wallet lock
model.getXmrWalletService().resetAddressEntriesForOpenOffer(offer.getId());
if (reserveTx != null) {
model.getXmrWalletService().thawOutputs(HavenoUtils.getInputKeyImages(reserveTx));
}
throw e;
} }
// reset protocol timeout // reset protocol timeout

View file

@ -81,7 +81,8 @@ public class TakerReserveTradeFunds extends TradeTask {
} }
} catch (Exception e) { } catch (Exception e) {
// thaw reserved inputs // reset state with wallet lock
model.getXmrWalletService().resetAddressEntriesForTrade(trade.getId());
if (reserveTx != null) { if (reserveTx != null) {
model.getXmrWalletService().thawOutputs(HavenoUtils.getInputKeyImages(reserveTx)); model.getXmrWalletService().thawOutputs(HavenoUtils.getInputKeyImages(reserveTx));
trade.getSelf().setReserveTxKeyImages(null); trade.getSelf().setReserveTxKeyImages(null);