From b9524bd19eed54b02275628bcf0076b235890cc4 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 3 Apr 2023 10:39:01 -0400 Subject: [PATCH] initialize persisted trades when all services initialized --- .../java/haveno/core/trade/TradeManager.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/TradeManager.java b/core/src/main/java/haveno/core/trade/TradeManager.java index 1450bcb0f5..9f33e9054f 100644 --- a/core/src/main/java/haveno/core/trade/TradeManager.java +++ b/core/src/main/java/haveno/core/trade/TradeManager.java @@ -67,7 +67,6 @@ import haveno.core.user.User; import haveno.core.util.Validator; import haveno.core.xmr.model.XmrAddressEntry; import haveno.core.xmr.wallet.XmrWalletService; -import haveno.network.p2p.BootstrapListener; import haveno.network.p2p.DecryptedDirectMessageListener; import haveno.network.p2p.DecryptedMessageWithPubKey; import haveno.network.p2p.NodeAddress; @@ -282,16 +281,9 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi } private void initialize() { - if (p2PService.isBootstrapped()) { - new Thread(() -> initPersistedTrades()).start(); // initialize trades off main thread - } else { - p2PService.addP2PServiceListener(new BootstrapListener() { - @Override - public void onUpdatedDataReceived() { - initPersistedTrades(); - } - }); - } + + // initialize trades off main thread + new Thread(() -> initPersistedTrades()).start(); getObservableList().addListener((ListChangeListener) change -> onTradesChanged()); onTradesChanged(); @@ -324,7 +316,12 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi log.warn("Error closing trade subprocess. Was Haveno stopped manually with ctrl+c?"); } }); - HavenoUtils.executeTasks(tasks); + try { + HavenoUtils.executeTasks(tasks); + } catch (Exception e) { + log.warn("Error shutting down trades: {}", e.getMessage()); + e.printStackTrace(); + } } private void thawUnreservedOutputs() { @@ -390,6 +387,7 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi } }); }; + log.info("Initializing persisted trades"); HavenoUtils.executeTasks(tasks, threadPoolSize); // reset any available address entries