Refactor: Extract statement to var and return early

Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
HenrikJannsen 2024-06-29 13:28:07 +07:00
parent 318803e4d9
commit 143d1e9cc6
No known key found for this signature in database
GPG Key ID: 02AA2BAE387C8307

View File

@ -220,29 +220,32 @@ public class DaoStateSnapshotService implements DaoSetupService, DaoStateListene
// Either we don't have a snapshot candidate yet, or if we have one the height at that snapshot candidate must be
// different to our current height.
if (daoStateCandidate == null || snapshotHeight != chainHeight) {
// We protect to get called while we are not completed with persisting the daoState. This can take about
// 20 seconds, and it is not expected that we get triggered another snapshot event in that period, but this
// check guards that we would skip such calls.
if (persistingBlockInProgress) {
if (preferences.isUseFullModeDaoMonitor()) {
// In case we don't use isUseFullModeDaoMonitor we might get called here too often as the parsing is much
// faster than the persistence, and we likely create only 1 snapshot during initial parsing, so
// we log only if isUseFullModeDaoMonitor is true as then parsing is likely slower, and we would
// expect that we do a snapshot at each trigger block.
log.info("We try to persist a daoState but the previous call has not completed yet. " +
"We ignore that call and skip that snapshot. " +
"Snapshot will be created at next snapshot height again. This is not to be expected with live " +
"blockchain data.");
}
return;
}
boolean noSnapshotCandidateOrDifferentHeight = daoStateCandidate == null || snapshotHeight != chainHeight;
if (!noSnapshotCandidateOrDifferentHeight) {
return;
}
if (daoStateCandidate != null) {
persist();
} else {
createSnapshot();
// We protect to get called while we are not completed with persisting the daoState. This can take about
// 20 seconds, and it is not expected that we get triggered another snapshot event in that period, but this
// check guards that we would skip such calls.
if (persistingBlockInProgress) {
if (preferences.isUseFullModeDaoMonitor()) {
// In case we don't use isUseFullModeDaoMonitor we might get called here too often as the parsing is much
// faster than the persistence, and we likely create only 1 snapshot during initial parsing, so
// we log only if isUseFullModeDaoMonitor is true as then parsing is likely slower, and we would
// expect that we do a snapshot at each trigger block.
log.info("We try to persist a daoState but the previous call has not completed yet. " +
"We ignore that call and skip that snapshot. " +
"Snapshot will be created at next snapshot height again. This is not to be expected with live " +
"blockchain data.");
}
return;
}
if (daoStateCandidate != null) {
persist();
} else {
createSnapshot();
}
}