Skip to content

Commit 563f09a

Browse files
fix(db): skip expired checkpoints to avoid recovery from corrupted databases
1 parent 13bf1a0 commit 563f09a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

chainbase/src/main/java/org/tron/core/db2/core/SnapshotManager.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ private void pruneCheckpoint() {
471471
if (cpList.size() < 3) {
472472
return;
473473
}
474+
long latestTimestamp = Long.parseLong(cpList.get(cpList.size()-1));
474475
for (String cp: cpList.subList(0, cpList.size()-3)) {
475476
long timestamp = Long.parseLong(cp);
476-
if (System.currentTimeMillis() - timestamp < ONE_MINUTE_MILLS*2) {
477+
if (latestTimestamp - timestamp <= ONE_MINUTE_MILLS*2) {
477478
break;
478479
}
479480
String checkpointPath = Paths.get(StorageUtils.getOutputDirectoryByDbName(CHECKPOINT_V2_DIR),
@@ -522,7 +523,12 @@ private void checkV2() {
522523
return;
523524
}
524525

526+
long latestTimestamp = Long.parseLong(cpList.get(cpList.size()-1));
525527
for (String cp: cpList) {
528+
long timestamp = Long.parseLong(cp);
529+
if (latestTimestamp - timestamp > ONE_MINUTE_MILLS*2) {
530+
continue;
531+
}
526532
TronDatabase<byte[]> checkPointV2Store = getCheckpointDB(cp);
527533
recover(checkPointV2Store);
528534
checkPointV2Store.close();

0 commit comments

Comments
 (0)