shut down trade when moved to failed

This commit is contained in:
woodser 2025-09-23 02:31:49 -04:00
parent 9b179f4b10
commit 7779236f24
No known key found for this signature in database
GPG key ID: 55A10DD48ADEE5EF
2 changed files with 22 additions and 9 deletions

View file

@ -1733,14 +1733,16 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
}
public void onShutDownStarted() {
if (wallet != null) log.info("Preparing to shut down {} {}", getClass().getSimpleName(), getId());
isShutDownStarted = true;
stopPolling();
if (!isShutDownStarted) {
if (wallet != null) log.info("Preparing to shut down {} {}", getClass().getSimpleName(), getId());
isShutDownStarted = true;
stopPolling();
}
}
public void shutDown() {
if (isShutDown) return; // ignore if already shut down
isShutDownStarted = true;
onShutDownStarted();
if (!isPayoutFinalized()) log.info("Shutting down {} {}", getClass().getSimpleName(), getId());
// unregister p2p message listener

View file

@ -1102,6 +1102,15 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
// If trade is in already in critical state (if taker role: taker fee; both roles: after deposit published)
// we move the trade to FailedTradesManager
public void onMoveInvalidTradeToFailedTrades(Trade trade) {
if (trade.isInitialized()) {
ThreadUtils.execute(() -> {
try {
trade.shutDown();
} catch (Exception e) {
log.warn("Error shutting down {} {} on move to failed trades", trade.getClass().getSimpleName(), trade.getShortId(), e);
}
}, trade.getId() + "_init");
}
failedTradesManager.add(trade);
removeTrade(trade);
xmrWalletService.fixReservedOutputs();
@ -1125,11 +1134,13 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
private void addTradeToPendingTrades(Trade trade) {
if (!trade.isInitialized()) {
try {
initTrade(trade);
} catch (Exception e) {
log.warn("Error initializing {} {} on move to pending trades", trade.getClass().getSimpleName(), trade.getShortId(), e);
}
ThreadUtils.execute(() -> {
try {
initTrade(trade);
} catch (Exception e) {
log.warn("Error initializing {} {} on move to pending trades", trade.getClass().getSimpleName(), trade.getShortId(), e);
}
}, trade.getId() + "_init");
}
addTrade(trade);
}