From 443c2f4cdbe77e4767d7d07c45bbe792f4ba0c05 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 5 Aug 2024 12:23:31 -0400 Subject: [PATCH] sync on wallet lock before checking if wallet is behind --- .../main/java/haveno/core/trade/Trade.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/haveno/core/trade/Trade.java b/core/src/main/java/haveno/core/trade/Trade.java index a001ed7c38..40121bd203 100644 --- a/core/src/main/java/haveno/core/trade/Trade.java +++ b/core/src/main/java/haveno/core/trade/Trade.java @@ -2412,13 +2412,15 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { private void syncWallet(boolean pollWallet) { MoneroRpcConnection sourceConnection = xmrConnectionService.getConnection(); try { - if (getWallet() == null) throw new RuntimeException("Cannot sync trade wallet because it doesn't exist for " + getClass().getSimpleName() + ", " + getId()); - if (getWallet().getDaemonConnection() == null) throw new RuntimeException("Cannot sync trade wallet because it's not connected to a Monero daemon for " + getClass().getSimpleName() + ", " + getId()); - if (isWalletBehind()) { - log.info("Syncing wallet for {} {}", getClass().getSimpleName(), getShortId()); - long startTime = System.currentTimeMillis(); - syncWalletIfBehind(); - log.info("Done syncing wallet for {} {} in {} ms", getClass().getSimpleName(), getShortId(), System.currentTimeMillis() - startTime); + synchronized (walletLock) { + if (getWallet() == null) throw new RuntimeException("Cannot sync trade wallet because it doesn't exist for " + getClass().getSimpleName() + ", " + getId()); + if (getWallet().getDaemonConnection() == null) throw new RuntimeException("Cannot sync trade wallet because it's not connected to a Monero daemon for " + getClass().getSimpleName() + ", " + getId()); + if (isWalletBehind()) { + log.info("Syncing wallet for {} {}", getClass().getSimpleName(), getShortId()); + long startTime = System.currentTimeMillis(); + syncWalletIfBehind(); + log.info("Done syncing wallet for {} {} in {} ms", getClass().getSimpleName(), getShortId(), System.currentTimeMillis() - startTime); + } } // apply tor after wallet synced depending on configuration @@ -2627,8 +2629,8 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model { } private void syncWalletIfBehind() { - if (isWalletBehind()) { - synchronized (walletLock) { + synchronized (walletLock) { + if (isWalletBehind()) { syncWithProgress(); } }