fixes to persisted trades initialization

This commit is contained in:
woodser 2023-07-14 13:06:03 -04:00
parent 9f3b0c96c4
commit 5c814700fb

View file

@ -407,6 +407,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
Set<Runnable> tasks = new HashSet<Runnable>();
Set<String> uids = new HashSet<String>();
Set<Trade> tradesToSkip = new HashSet<Trade>();
Set<Trade> tradesToMaybeRemoveOnError = new HashSet<Trade>();
for (Trade trade : trades) {
tasks.add(() -> {
try {
@ -423,9 +424,10 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
// remove trade if protocol didn't initialize
if (getOpenTradeByUid(trade.getUid()).isPresent() && !trade.isDepositsPublished()) {
maybeRemoveTradeOnError(trade);
tradesToMaybeRemoveOnError.add(trade);
}
} catch (Exception e) {
e.printStackTrace();
log.warn("Error initializing {} {}: {}", trade.getClass().getSimpleName(), trade.getId(), e.getMessage());
trade.setInitError(e);
}
@ -458,6 +460,11 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
EasyBind.subscribe(HavenoUtils.havenoSetup.getAppStartupState().applicationFullyInitializedProperty(), appInitialized -> {
if (!appInitialized) return;
// maybe remove trades on error
for (Trade trade : tradesToMaybeRemoveOnError) {
maybeRemoveTradeOnError(trade);
}
// thaw unreserved outputs
thawUnreservedOutputs();
@ -468,8 +475,19 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
log.warn("Swapping pending {} entries at startup. offerId={}", addressEntry.getContext(), addressEntry.getOfferId());
xmrWalletService.swapTradeEntryToAvailableEntry(addressEntry.getOfferId(), addressEntry.getContext());
});
onTradesInitiailizedAndAppFullyInitialized();
});
} else {
onTradesInitiailizedAndAppFullyInitialized();
}
}).start();
// allow execution to start
GenUtils.waitFor(100);
}
private void onTradesInitiailizedAndAppFullyInitialized() {
// notify that persisted trades initialized
persistedTradesInitialized.set(true);
@ -481,10 +499,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi
String referralId = referralIdService.getOptionalReferralId().orElse(null);
boolean isTorNetworkNode = p2PService.getNetworkNode() instanceof TorNetworkNode;
tradeStatisticsManager.maybeRepublishTradeStatistics(nonFailedTrades, referralId, isTorNetworkNode);
}).start();
// allow execution to start
GenUtils.waitFor(100);
}
private void initPersistedTrade(Trade trade) {