Skip to content

Commit

Permalink
skip reset address entries when failed trade is scheduled for deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Mar 10, 2025
1 parent 8b1d2aa commit bf97fbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/main/java/haveno/core/trade/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,8 @@ public void onTakeOffer(BigInteger amount,
requestPersistence();
}, errorMessage -> {
log.warn("Taker error during trade initialization: " + errorMessage);
xmrWalletService.resetAddressEntriesForOpenOffer(trade.getId()); // TODO: move to maybe remove on error
trade.onProtocolError();
xmrWalletService.resetAddressEntriesForOpenOffer(trade.getId()); // TODO: move this into protocol error handling
errorMessageHandler.handleErrorMessage(errorMessage);
});

Expand Down Expand Up @@ -1285,6 +1285,12 @@ public boolean hasOpenTrade(Trade trade) {
}
}

public boolean hasFailedScheduledTrade(String offerId) {
synchronized (failedTradesManager) {
return failedTradesManager.getTradeById(offerId).isPresent() && failedTradesManager.getTradeById(offerId).get().isProtocolErrorHandlingScheduled();
}
}

public Optional<Trade> getOpenTradeByUid(String tradeUid) {
synchronized (tradableList) {
return tradableList.stream().filter(e -> e.getUid().equals(tradeUid)).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,13 @@ public synchronized void swapAddressEntryToAvailable(String offerId, XmrAddressE

public synchronized void resetAddressEntriesForOpenOffer(String offerId) {
log.info("resetAddressEntriesForOpenOffer offerId={}", offerId);

// skip if failed trade is scheduled for processing // TODO: do not call this function in this case?
if (tradeManager.hasFailedScheduledTrade(offerId)) {
log.warn("Refusing to reset address entries because trade is scheduled for deletion with offerId={}", offerId);
return;
}

swapAddressEntryToAvailable(offerId, XmrAddressEntry.Context.OFFER_FUNDING);

// swap trade payout to available if applicable
Expand Down

0 comments on commit bf97fbc

Please sign in to comment.