diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index ab82d9efc0..de6db2c2ba 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -103,6 +103,7 @@ import javax.annotation.Nullable; @Singleton public class BisqSetup { private static final String VERSION_FILE_NAME = "version"; + private static final String RESYNC_SPV_FILE_NAME = "resyncSpv"; public interface BisqSetupListener { default void onInitP2pNetwork() { @@ -325,7 +326,7 @@ public class BisqSetup { private void maybeReSyncSPVChain() { // We do the delete of the spv file at startup before BitcoinJ is initialized to avoid issues with locked files under Windows. - if (preferences.isResyncSpvRequested()) { + if (getResyncSpvSemaphore()) { try { walletsSetup.reSyncSPVChain(); @@ -424,7 +425,7 @@ public class BisqSetup { walletsManager.setAesKey(aesKey); walletsSetup.getWalletConfig().maybeAddSegwitKeychain(walletsSetup.getWalletConfig().btcWallet(), aesKey); - if (preferences.isResyncSpvRequested()) { + if (getResyncSpvSemaphore()) { if (showFirstPopupIfResyncSPVRequestedHandler != null) showFirstPopupIfResyncSPVRequestedHandler.run(); } else { @@ -438,6 +439,7 @@ public class BisqSetup { }; walletAppSetup.init(chainFileLockedExceptionHandler, spvFileCorruptedHandler, + getResyncSpvSemaphore(), showFirstPopupIfResyncSPVRequestedHandler, showPopupIfInvalidBtcConfigHandler, walletPasswordHandler, @@ -542,6 +544,33 @@ public class BisqSetup { return null; } + @Nullable + public static boolean getResyncSpvSemaphore() { + File resyncSpvSemaphore = new File(Config.appDataDir(), RESYNC_SPV_FILE_NAME); + return resyncSpvSemaphore.exists(); + } + + public static void setResyncSpvSemaphore(boolean isResyncSpvRequested) { + File resyncSpvSemaphore = new File(Config.appDataDir(), RESYNC_SPV_FILE_NAME); + if (isResyncSpvRequested) { + if (!resyncSpvSemaphore.exists()) { + try { + if (!resyncSpvSemaphore.createNewFile()) { + log.error("ResyncSpv file could not be created"); + } + } catch (IOException e) { + e.printStackTrace(); + log.error("ResyncSpv file could not be created. {}", e.toString()); + } + } + } else { + resyncSpvSemaphore.delete(); + } + } + + + + private static File getVersionFile() { return new File(Config.appDataDir(), VERSION_FILE_NAME); } diff --git a/core/src/main/java/bisq/core/app/WalletAppSetup.java b/core/src/main/java/bisq/core/app/WalletAppSetup.java index 8f0fd15f1d..b54e6706ad 100644 --- a/core/src/main/java/bisq/core/app/WalletAppSetup.java +++ b/core/src/main/java/bisq/core/app/WalletAppSetup.java @@ -105,6 +105,7 @@ public class WalletAppSetup { void init(@Nullable Consumer chainFileLockedExceptionHandler, @Nullable Consumer spvFileCorruptedHandler, + boolean isSpvResyncRequested, @Nullable Runnable showFirstPopupIfResyncSPVRequestedHandler, @Nullable Runnable showPopupIfInvalidBtcConfigHandler, Runnable walletPasswordHandler, @@ -179,7 +180,7 @@ public class WalletAppSetup { if (walletsManager.areWalletsEncrypted() && !coreContext.isApiUser()) { walletPasswordHandler.run(); } else { - if (preferences.isResyncSpvRequested() && !coreContext.isApiUser()) { + if (isSpvResyncRequested && !coreContext.isApiUser()) { if (showFirstPopupIfResyncSPVRequestedHandler != null) showFirstPopupIfResyncSPVRequestedHandler.run(); } else { diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 1a97544c14..e787e6ad22 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -575,7 +575,7 @@ public class MainViewModel implements ViewModel, BisqSetup.BisqSetupListener { private void showSecondPopupIfResyncSPVRequested(Popup firstPopup) { firstPopup.hide(); - preferences.setResyncSpvRequested(false); + BisqSetup.setResyncSpvSemaphore(false); new Popup().information(Res.get("settings.net.reSyncSPVAfterRestartCompleted")) .hideCloseButton() .useShutDownButton() diff --git a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java index 1cd240f5a9..8f4beb8c12 100644 --- a/desktop/src/main/java/bisq/desktop/util/GUIUtil.java +++ b/desktop/src/main/java/bisq/desktop/util/GUIUtil.java @@ -30,6 +30,7 @@ import bisq.desktop.main.overlays.popups.Popup; import bisq.core.account.witness.AccountAgeWitness; import bisq.core.account.witness.AccountAgeWitnessService; +import bisq.core.app.BisqSetup; import bisq.core.btc.setup.WalletsSetup; import bisq.core.locale.Country; import bisq.core.locale.CountryUtil; @@ -823,7 +824,7 @@ public class GUIUtil { .useShutDownButton() .actionButtonText(Res.get("shared.shutDown")) .onAction(() -> { - preferences.setResyncSpvRequested(true); + BisqSetup.setResyncSpvSemaphore(true); UserThread.runAfter(BisqApp.getShutDownHandler(), 100, TimeUnit.MILLISECONDS); }) .closeButtonText(Res.get("shared.cancel"))