mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Refactor applySnapshot method: early return
Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
8f4deb09ba
commit
cc27f9dd70
1 changed files with 37 additions and 37 deletions
|
@ -279,44 +279,44 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
|
|||
|
||||
public void applySnapshot(boolean fromInitialize) {
|
||||
DaoState persistedBsqState = daoStateStorageService.getPersistedBsqState();
|
||||
LinkedList<DaoStateHash> persistedDaoStateHashChain = daoStateStorageService.getPersistedDaoStateHashChain();
|
||||
if (persistedBsqState != null) {
|
||||
int chainHeightOfPersisted = persistedBsqState.getChainHeight();
|
||||
if (!persistedBsqState.getBlocks().isEmpty()) {
|
||||
int heightOfLastBlock = persistedBsqState.getLastBlock().getHeight();
|
||||
if (heightOfLastBlock != chainHeightOfPersisted) {
|
||||
log.warn("chainHeightOfPersisted must be same as heightOfLastBlock. heightOfLastBlock={}, chainHeightOfPersisted={}",
|
||||
heightOfLastBlock, chainHeightOfPersisted);
|
||||
resyncDaoStateFromResources();
|
||||
return;
|
||||
}
|
||||
if (isHeightAtLeastGenesisHeight(heightOfLastBlock)) {
|
||||
if (chainHeightOfLastAppliedSnapshot != chainHeightOfPersisted) {
|
||||
chainHeightOfLastAppliedSnapshot = chainHeightOfPersisted;
|
||||
daoStateService.applySnapshot(persistedBsqState);
|
||||
daoStateMonitoringService.applySnapshot(persistedDaoStateHashChain);
|
||||
daoStateStorageService.releaseMemory();
|
||||
} else {
|
||||
// The reorg might have been caused by the previous parsing which might contains a range of
|
||||
// blocks.
|
||||
log.warn("We applied already a snapshot with chainHeight {}. " +
|
||||
"We remove all dao store files and shutdown. After a restart resource files will " +
|
||||
"be applied if available.",
|
||||
chainHeightOfLastAppliedSnapshot);
|
||||
resyncDaoStateFromResources();
|
||||
}
|
||||
}
|
||||
} else if (fromInitialize) {
|
||||
log.info("No Bsq blocks in DaoState. Expected if no data are provided yet from resources or persisted data.");
|
||||
} else {
|
||||
log.info("We got a reorg and we want to apply the snapshot but it is empty. " +
|
||||
"That is expected in the first blocks until the first snapshot has been created. " +
|
||||
"We remove all dao store files and shutdown. " +
|
||||
"After a restart resource files will be applied if available.");
|
||||
resyncDaoStateFromResources();
|
||||
}
|
||||
} else {
|
||||
if (persistedBsqState == null) {
|
||||
log.info("Try to apply snapshot but no stored snapshot available. That is expected at first blocks.");
|
||||
return;
|
||||
}
|
||||
LinkedList<DaoStateHash> persistedDaoStateHashChain = daoStateStorageService.getPersistedDaoStateHashChain();
|
||||
int chainHeightOfPersisted = persistedBsqState.getChainHeight();
|
||||
if (!persistedBsqState.getBlocks().isEmpty()) {
|
||||
int heightOfLastBlock = persistedBsqState.getLastBlock().getHeight();
|
||||
if (heightOfLastBlock != chainHeightOfPersisted) {
|
||||
log.warn("chainHeightOfPersisted must be same as heightOfLastBlock. heightOfLastBlock={}, chainHeightOfPersisted={}",
|
||||
heightOfLastBlock, chainHeightOfPersisted);
|
||||
resyncDaoStateFromResources();
|
||||
return;
|
||||
}
|
||||
if (isHeightAtLeastGenesisHeight(heightOfLastBlock)) {
|
||||
if (chainHeightOfLastAppliedSnapshot != chainHeightOfPersisted) {
|
||||
chainHeightOfLastAppliedSnapshot = chainHeightOfPersisted;
|
||||
daoStateService.applySnapshot(persistedBsqState);
|
||||
daoStateMonitoringService.applySnapshot(persistedDaoStateHashChain);
|
||||
daoStateStorageService.releaseMemory();
|
||||
} else {
|
||||
// The reorg might have been caused by the previous parsing which might contains a range of
|
||||
// blocks.
|
||||
log.warn("We applied already a snapshot with chainHeight {}. " +
|
||||
"We remove all dao store files and shutdown. After a restart resource files will " +
|
||||
"be applied if available.",
|
||||
chainHeightOfLastAppliedSnapshot);
|
||||
resyncDaoStateFromResources();
|
||||
}
|
||||
}
|
||||
} else if (fromInitialize) {
|
||||
log.info("No Bsq blocks in DaoState. Expected if no data are provided yet from resources or persisted data.");
|
||||
} else {
|
||||
log.info("We got a reorg and we want to apply the snapshot but it is empty. " +
|
||||
"That is expected in the first blocks until the first snapshot has been created. " +
|
||||
"We remove all dao store files and shutdown. " +
|
||||
"After a restart resource files will be applied if available.");
|
||||
resyncDaoStateFromResources();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue