diff --git a/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java b/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java index 5ee7111249a..37b2476ac5f 100644 --- a/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java +++ b/core/src/main/java/bisq/core/dao/state/DaoStateSnapshotService.java @@ -29,6 +29,7 @@ import bisq.core.trade.DelayedPayoutAddressProvider; import bisq.core.user.Preferences; +import bisq.common.UserThread; import bisq.common.config.Config; import bisq.common.util.GcUtil; @@ -48,8 +49,6 @@ import javax.annotation.Nullable; -import static com.google.common.base.Preconditions.checkArgument; - /** * Manages periodical snapshots of the DaoState. * At startup we apply a snapshot if available. @@ -79,6 +78,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene @Setter @Nullable private Runnable daoRequiresRestartHandler; + private int daoRequiresRestartHandlerAttempts = 0; private boolean readyForPersisting = true; private boolean isParseBlockChainComplete; @@ -281,8 +281,11 @@ public void applySnapshot(boolean fromReorg) { int chainHeightOfPersisted = persistedBsqState.getChainHeight(); if (!persistedBsqState.getBlocks().isEmpty()) { int heightOfLastBlock = persistedBsqState.getLastBlock().getHeight(); - checkArgument(heightOfLastBlock == chainHeightOfPersisted, - "chainHeightOfPersisted must be same as heightOfLastBlock"); + if (heightOfLastBlock != chainHeightOfPersisted) { + log.warn("chainHeightOfPersisted must be same as heightOfLastBlock"); + resyncDaoStateFromResources(); + return; + } if (isValidHeight(heightOfLastBlock)) { if (chainHeightOfLastApplySnapshot != chainHeightOfPersisted) { chainHeightOfLastApplySnapshot = chainHeightOfPersisted; @@ -324,10 +327,18 @@ private boolean isValidHeight(int heightOfLastBlock) { private void resyncDaoStateFromResources() { log.info("resyncDaoStateFromResources called"); + if (daoRequiresRestartHandler == null && ++daoRequiresRestartHandlerAttempts <= 3) { + log.warn("daoRequiresRestartHandler has not been initialized yet, will try again in 10 seconds"); + UserThread.runAfter(this::resyncDaoStateFromResources, 10); // a delay for the app to init + return; + } try { daoStateStorageService.resyncDaoStateFromResources(storageDir); - - if (daoRequiresRestartHandler != null) { + // the restart handler informs the user of the need to restart bisq (in desktop mode) + if (daoRequiresRestartHandler == null) { + log.error("daoRequiresRestartHandler COULD NOT be called as it has not been initialized yet"); + } else { + log.info("calling daoRequiresRestartHandler..."); daoRequiresRestartHandler.run(); } } catch (IOException e) { diff --git a/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java b/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java index dfb78ac4c83..dc44deb90b3 100644 --- a/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java +++ b/core/src/main/java/bisq/core/dao/state/storage/DaoStateStorageService.java @@ -48,8 +48,6 @@ import lombok.extern.slf4j.Slf4j; -import static com.google.common.base.Preconditions.checkArgument; - /** * Manages persistence of the daoState. */ @@ -154,8 +152,10 @@ protected void readFromResources(String postFix, Runnable completeHandler) { list = bsqBlocksStorageService.readBlocks(chainHeight); if (!list.isEmpty()) { int heightOfLastBlock = list.getLast().getHeight(); - checkArgument(heightOfLastBlock == chainHeight, - "heightOfLastBlock must match chainHeight"); + if (heightOfLastBlock != chainHeight) { + log.warn("heightOfLastBlock {} must match chainHeight {}", heightOfLastBlock, chainHeight); + // this error scenario is handled by DaoStateSnapshotService, it will resync from resources & reboot + } } } else { list = bsqBlocksStorageService.migrateBlocks(daoStateAsProto.getBlocksList());