fix reinitializing trade when moved from failed back to pending (#1991)

This commit is contained in:
woodser 2025-09-29 09:40:07 -04:00 committed by GitHub
parent f252f0b40c
commit aefa803971
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View file

@ -643,6 +643,10 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
public void initialize(ProcessModelServiceProvider serviceProvider) {
if (isInitialized) throw new IllegalStateException(getClass().getSimpleName() + " " + getId() + " is already initialized");
// reset shut down state
isShutDownStarted = false;
isShutDown = false;
// skip initialization if trade is complete
// starting in v1.0.19, seller resends payment received message until acked or stored in mailbox
if (isFinished()) {
@ -2738,7 +2742,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
// set daemon connection (must restart monero-wallet-rpc if proxy uri changed)
String oldProxyUri = wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getProxyUri();
String newProxyUri = connection == null ? null : connection.getProxyUri();
log.info("Setting daemon connection for trade wallet {}: uri={}, proxyUri={}", getId() , connection == null ? null : connection.getUri(), newProxyUri);
log.info("Setting daemon connection for {} {}: uri={}, proxyUri={}", getClass().getSimpleName(), getId() , connection == null ? null : connection.getUri(), newProxyUri);
if (xmrWalletService.isProxyApplied(wasWalletSynced) && wallet instanceof MoneroWalletRpc && !StringUtils.equals(oldProxyUri, newProxyUri)) {
log.info("Restarting trade wallet {} because proxy URI has changed, old={}, new={}", getId(), oldProxyUri, newProxyUri);
closeWallet();
@ -2751,6 +2755,8 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
if (isInitialized && connection != null && !Boolean.FALSE.equals(xmrConnectionService.isConnected())) {
ThreadUtils.execute(() -> maybeInitSyncing(), getId());
}
log.info("Done setting daemon connection for {} {}", getClass().getSimpleName(), getId());
}
}

View file

@ -418,6 +418,12 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
}
}
private void unregisterTradeProtocol(Trade trade) {
synchronized (tradeProtocolByTradeId) {
tradeProtocolByTradeId.remove(trade.getUid());
}
}
public TradeProtocol createTradeProtocol(Trade trade) {
synchronized (tradeProtocolByTradeId) {
TradeProtocol tradeProtocol = TradeProtocolFactory.getNewTradeProtocol(trade);
@ -1102,14 +1108,16 @@ 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) {
log.warn("Moving {} {} to failed trades", trade.getClass().getSimpleName(), trade.getShortId());
if (trade.isInitialized()) {
ThreadUtils.execute(() -> {
ThreadUtils.submitToPool(() -> {
try {
trade.shutDown();
unregisterTradeProtocol(trade);
} 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);
@ -1140,7 +1148,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
} catch (Exception e) {
log.warn("Error initializing {} {} on move to pending trades", trade.getClass().getSimpleName(), trade.getShortId(), e);
}
}, trade.getId() + "_init");
}, trade.getId());
}
addTrade(trade);
}