diff --git a/common/src/main/java/haveno/common/persistence/PersistenceManager.java b/common/src/main/java/haveno/common/persistence/PersistenceManager.java index b9d38bd82f..88269082fb 100644 --- a/common/src/main/java/haveno/common/persistence/PersistenceManager.java +++ b/common/src/main/java/haveno/common/persistence/PersistenceManager.java @@ -433,12 +433,14 @@ public class PersistenceManager { private void maybeStartTimerForPersistence() { // We write to disk with a delay to avoid frequent write operations. Depending on the priority those delays // can be rather long. - if (timer == null) { - timer = UserThread.runAfter(() -> { - persistNow(null); - UserThread.execute(() -> timer = null); - }, source.delay, TimeUnit.MILLISECONDS); - } + UserThread.execute(() -> { + if (timer == null) { + timer = UserThread.runAfter(() -> { + persistNow(null); + UserThread.execute(() -> timer = null); + }, source.delay, TimeUnit.MILLISECONDS); + } + }); } public void forcePersistNow() { diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index e05536deec..9243f2f4f5 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -813,12 +813,14 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { while (!isFullyInitialized) HavenoUtils.waitFor(100); // TODO: use proper notification and refactor isInitialized, fullyInitialized, and arbitrator idling } + // TODO: throw if trade manager is null public void requestPersistence() { if (processModel.getTradeManager() != null) processModel.getTradeManager().requestPersistence(); } + // TODO: throw if trade manager is null public void persistNow(@Nullable Runnable completeHandler) { - processModel.getTradeManager().persistNow(completeHandler); + if (processModel.getTradeManager() != null) processModel.getTradeManager().persistNow(completeHandler); } public TradeProtocol getProtocol() { @@ -1099,7 +1101,6 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { synchronized (HavenoUtils.getWalletFunctionLock()) { MoneroTxWallet tx = wallet.createTx(txConfig); exportMultisigHex(); - saveWallet(); return tx; } } @@ -1108,7 +1109,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { public void exportMultisigHex() { synchronized (walletLock) { getSelf().setUpdatedMultisigHex(wallet.exportMultisigHex()); - requestPersistence(); + saveWallet(); } } @@ -1889,7 +1890,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } this.state = state; - requestPersistence(); + persistNow(null); UserThread.execute(() -> { stateProperty.set(state); phaseProperty.set(state.getPhase()); @@ -1921,7 +1922,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } this.payoutState = payoutState; - requestPersistence(); + persistNow(null); UserThread.execute(() -> payoutStateProperty.set(payoutState)); } @@ -1937,6 +1938,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } this.disputeState = disputeState; + persistNow(null); UserThread.execute(() -> { disputeStateProperty.set(disputeState); });