From 796603f82b90933ba92aa0e036035a6941caebf5 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 23 May 2024 18:17:27 -0400 Subject: [PATCH] thaw reserved outputs within task if canceled --- .../tasks/MakerReserveOfferFunds.java | 39 ++++++++++++------- .../tasks/TakerReserveTradeFunds.java | 3 +- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java b/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java index 7dba9971..61cafd65 100644 --- a/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java +++ b/core/src/main/java/haveno/core/offer/placeoffer/tasks/MakerReserveOfferFunds.java @@ -79,22 +79,33 @@ public class MakerReserveOfferFunds extends Task { Integer preferredSubaddressIndex = fundingEntry == null ? null : fundingEntry.getSubaddressIndex(); // attempt creating reserve tx - synchronized (HavenoUtils.getWalletFunctionLock()) { - for (int i = 0; i < TradeProtocol.MAX_ATTEMPTS; i++) { - try { - //if (true) throw new RuntimeException("Pretend error"); - reserveTx = model.getXmrWalletService().createReserveTx(penaltyFee, makerFee, sendAmount, securityDeposit, returnAddress, openOffer.isReserveExactAmount(), preferredSubaddressIndex); - } catch (Exception e) { - log.warn("Error creating reserve tx, attempt={}/{}, offerId={}, error={}", i + 1, TradeProtocol.MAX_ATTEMPTS, openOffer.getShortId(), e.getMessage()); - if (i == TradeProtocol.MAX_ATTEMPTS - 1) throw e; - model.getProtocol().startTimeoutTimer(); // reset protocol timeout - HavenoUtils.waitFor(TradeProtocol.REPROCESS_DELAY_MS); // wait before retrying + try { + synchronized (HavenoUtils.getWalletFunctionLock()) { + for (int i = 0; i < TradeProtocol.MAX_ATTEMPTS; i++) { + try { + //if (true) throw new RuntimeException("Pretend error"); + reserveTx = model.getXmrWalletService().createReserveTx(penaltyFee, makerFee, sendAmount, securityDeposit, returnAddress, openOffer.isReserveExactAmount(), preferredSubaddressIndex); + } catch (Exception e) { + log.warn("Error creating reserve tx, attempt={}/{}, offerId={}, error={}", i + 1, TradeProtocol.MAX_ATTEMPTS, openOffer.getShortId(), e.getMessage()); + if (i == TradeProtocol.MAX_ATTEMPTS - 1) throw e; + model.getProtocol().startTimeoutTimer(); // reset protocol timeout + HavenoUtils.waitFor(TradeProtocol.REPROCESS_DELAY_MS); // wait before retrying + } + + // verify still open + verifyScheduled(); + if (reserveTx != null) break; } - - // verify still open - verifyScheduled(); - 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 diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java b/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java index 6b90c5ce..6e0719c1 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/TakerReserveTradeFunds.java @@ -81,7 +81,8 @@ public class TakerReserveTradeFunds extends TradeTask { } } catch (Exception e) { - // thaw reserved inputs + // reset state with wallet lock + model.getXmrWalletService().resetAddressEntriesForTrade(trade.getId()); if (reserveTx != null) { model.getXmrWalletService().thawOutputs(HavenoUtils.getInputKeyImages(reserveTx)); trade.getSelf().setReserveTxKeyImages(null);