From a7ab31d44ea062d06a3cc3a20d1e47f3003dbe4d Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 21 Apr 2023 09:31:07 -0400 Subject: [PATCH] save and back up trade wallets off thread at key steps --- core/src/main/java/haveno/core/trade/Trade.java | 2 +- .../trade/protocol/tasks/BuyerPreparePaymentSentMessage.java | 3 +++ .../trade/protocol/tasks/ProcessDepositsConfirmedMessage.java | 3 +++ .../core/trade/protocol/tasks/ProcessInitMultisigRequest.java | 2 +- .../core/trade/protocol/tasks/ProcessPaymentSentMessage.java | 3 +++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index d740902bc1..00ddb715d5 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -1162,7 +1162,7 @@ public abstract class Trade implements Tradable, Model { isShutDown = true; synchronized (walletLock) { if (wallet != null) { - saveWallet(); + xmrWalletService.saveWallet(wallet, false); // skip backup stopWallet(); } } diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java index 7e685950a2..d108ec0870 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/BuyerPreparePaymentSentMessage.java @@ -70,6 +70,9 @@ public class BuyerPreparePaymentSentMessage extends TradeTask { MoneroTxWallet payoutTx = trade.createPayoutTx(); trade.setPayoutTx(payoutTx); trade.setPayoutTxHex(payoutTx.getTxSet().getMultisigTxHex()); + + // save wallet off thread + new Thread(() -> trade.saveWallet()).start(); } complete(); diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java index 55b60f9eac..3020f54d75 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessDepositsConfirmedMessage.java @@ -69,6 +69,9 @@ public class ProcessDepositsConfirmedMessage extends TradeTask { e.printStackTrace(); } + // save wallet off thread + new Thread(() -> trade.saveWallet()).start(); + // persist and complete processModel.getTradeManager().requestPersistence(); complete(); diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessInitMultisigRequest.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessInitMultisigRequest.java index 816b85d7bd..d75859568b 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessInitMultisigRequest.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessInitMultisigRequest.java @@ -110,7 +110,7 @@ public class ProcessInitMultisigRequest extends TradeTask { log.info("Importing exchanged multisig hex for trade {}", trade.getId()); MoneroMultisigInitResult result = multisigWallet.exchangeMultisigKeys(Arrays.asList(peers[0].getExchangedMultisigHex(), peers[1].getExchangedMultisigHex()), xmrWalletService.getWalletPassword()); processModel.setMultisigAddress(result.getAddress()); - trade.saveWallet(); // save multisig wallet on completion + new Thread(() -> trade.saveWallet()).start(); // save multisig wallet off thread on completion trade.setStateIfValidTransitionTo(Trade.State.MULTISIG_COMPLETED); trade.updateWalletRefreshPeriod(); // starts syncing } diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java index 854004aa02..1379077b87 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentSentMessage.java @@ -69,6 +69,9 @@ public class ProcessPaymentSentMessage extends TradeTask { e.printStackTrace(); } + // save wallet off thread + new Thread(() -> trade.saveWallet()).start(); + // update state trade.advanceState(Trade.State.BUYER_SENT_PAYMENT_SENT_MSG); trade.requestPersistence();