Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception: heightOfLastBlock must match chainHeight #6018

Merged
merged 1 commit into from Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

import lombok.extern.slf4j.Slf4j;

import static com.google.common.base.Preconditions.checkArgument;

/**
* Manages persistence of the daoState.
*/
Expand Down Expand Up @@ -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());
Expand Down