diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index 40bcde56..a032ab42 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -708,7 +708,6 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe Offer offer = openOffer.getOffer(); if (offer.getOfferPayload().getReserveTxKeyImages() != null) { xmrWalletService.thawOutputs(offer.getOfferPayload().getReserveTxKeyImages()); - xmrWalletService.saveMainWallet(); } offer.setState(Offer.State.REMOVED); openOffer.setState(OpenOffer.State.CANCELED); diff --git a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java index 892900f5..0b7bb675 100644 --- a/core/src/main/java/haveno/core/support/dispute/DisputeManager.java +++ b/core/src/main/java/haveno/core/support/dispute/DisputeManager.java @@ -849,9 +849,8 @@ public abstract class DisputeManager> extends Sup // import multisig hex trade.importMultisigHex(); - // sync and save wallet + // sync and poll trade.syncAndPollWallet(); - trade.saveWallet(); // create unsigned dispute payout tx if not already published if (!trade.isPayoutPublished()) { diff --git a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java index eac5a6c9..280d68d3 100644 --- a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java @@ -276,10 +276,7 @@ public final class ArbitrationManager extends DisputeManager saveWallet()); // save wallet off main thread + } + public void saveWallet() { synchronized (walletLock) { if (wallet == null) throw new RuntimeException("Trade wallet is not open for trade " + getId()); @@ -1064,6 +1069,7 @@ public abstract class Trade implements Tradable, Model { .setPriority(XmrWalletService.PROTOCOL_FEE_PRIORITY)); // update state + saveWallet(); BigInteger payoutTxFeeSplit = payoutTx.getFee().divide(BigInteger.valueOf(2)); getBuyer().setPayoutTxFee(payoutTxFeeSplit); getBuyer().setPayoutAmount(HavenoUtils.getDestination(buyerPayoutAddress, payoutTx).getAmount()); diff --git a/core/src/main/java/haveno/core/trade/TradeManager.java b/core/src/main/java/haveno/core/trade/TradeManager.java index 06dc5c8a..9157f369 100644 --- a/core/src/main/java/haveno/core/trade/TradeManager.java +++ b/core/src/main/java/haveno/core/trade/TradeManager.java @@ -1299,7 +1299,6 @@ public class TradeManager implements PersistedDataHost, DecryptedDirectMessageLi // unreserve taker key images if (trade instanceof TakerTrade && trade.getSelf().getReserveTxKeyImages() != null) { xmrWalletService.thawOutputs(trade.getSelf().getReserveTxKeyImages()); - xmrWalletService.saveMainWallet(); trade.getSelf().setReserveTxKeyImages(null); } 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 5be3e220..8a1544d2 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 @@ -87,9 +87,6 @@ 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 88af8894..b02c1663 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 @@ -66,9 +66,6 @@ public class ProcessDepositsConfirmedMessage extends TradeTask { // import multisig hex trade.importMultisigHex(); - // save wallet off thread - trade.saveWallet(); - // persist and complete processModel.getTradeManager().requestPersistence(); complete(); diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java index f8283be0..64fe582f 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java @@ -135,7 +135,6 @@ public class ProcessPaymentReceivedMessage extends TradeTask { // update wallet trade.importMultisigHex(); trade.syncAndPollWallet(); - trade.saveWallet(); // handle if payout tx not published if (!trade.isPayoutPublished()) { 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 4f0eb0d4..6aee0ef2 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 @@ -64,9 +64,6 @@ public class ProcessPaymentSentMessage extends TradeTask { // import multisig hex trade.importMultisigHex(); - // save wallet - trade.saveWallet(); - // update state trade.advanceState(Trade.State.BUYER_SENT_PAYMENT_SENT_MSG); trade.requestPersistence(); diff --git a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java index c9df98f8..bd1c9773 100644 --- a/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java +++ b/core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java @@ -246,6 +246,10 @@ public class XmrWalletService { saveWallet(getWallet(), backup); } + public void requestSaveMainWallet() { + ThreadUtils.submitToPool(() -> saveMainWallet()); // save wallet off main thread + } + public boolean isWalletAvailable() { try { return getWallet() != null; @@ -402,6 +406,7 @@ public class XmrWalletService { try { MoneroTxWallet tx = wallet.createTx(new MoneroTxConfig().setAccountIndex(0).setDestinations(destinations).setRelay(false).setCanSplit(false)); //printTxs("XmrWalletService.createTx", tx); + requestSaveMainWallet(); return tx; } catch (Exception e) { throw e; @@ -455,7 +460,7 @@ public class XmrWalletService { public void freezeOutputs(Collection keyImages) { synchronized (walletLock) { for (String keyImage : keyImages) wallet.freezeOutput(keyImage); - saveMainWallet(); + requestSaveMainWallet(); cacheWalletState(); } updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output @@ -469,7 +474,7 @@ public class XmrWalletService { public void thawOutputs(Collection keyImages) { synchronized (walletLock) { for (String keyImage : keyImages) wallet.thawOutput(keyImage); - saveMainWallet(); + requestSaveMainWallet(); cacheWalletState(); } updateBalanceListeners(); // TODO (monero-java): balance listeners not notified on freeze/thaw output @@ -590,7 +595,6 @@ public class XmrWalletService { List keyImages = new ArrayList(); for (MoneroOutput input : tradeTx.getInputs()) keyImages.add(input.getKeyImage().getHex()); freezeOutputs(keyImages); - saveMainWallet(); return tradeTx; }