Add heightsOfLastAppliedSnapshots list and resync in case we tried to apply 3 times with same height

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2024-06-28 19:45:45 +07:00
parent 04ea4ae053
commit 1f131b346e
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307

View File

@ -39,6 +39,7 @@ import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@ -78,7 +79,7 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
private int daoRequiresRestartHandlerAttempts = 0;
private boolean readyForPersisting = true;
private boolean isParseBlockChainComplete;
private final List<Integer> heightsOfLastAppliedSnapshots = new ArrayList<>();
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -285,6 +286,16 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
}
int chainHeightOfPersistedDaoState = persistedDaoState.getChainHeight();
int numSameAppliedSnapshots = (int) heightsOfLastAppliedSnapshots.stream()
.filter(height -> height == chainHeightOfPersistedDaoState)
.count();
if (numSameAppliedSnapshots >= 3) {
log.warn("We got called applySnapshot the 3rd time with the same snapshot height. " +
"We abort and call resyncDaoStateFromResources.");
resyncDaoStateFromResources();
return;
}
heightsOfLastAppliedSnapshots.add(chainHeightOfPersistedDaoState);
if (persistedDaoState.getBlocks().isEmpty()) {
if (fromInitialize) {