diff --git a/core/rawdb/prunedfreezer.go b/core/rawdb/prunedfreezer.go index 1d2206463c..46e85ec44a 100644 --- a/core/rawdb/prunedfreezer.go +++ b/core/rawdb/prunedfreezer.go @@ -68,7 +68,6 @@ func newPrunedFreezer(datadir string, db ethdb.KeyValueStore, offset uint64) (*p // repair init frozen , compatible disk-ancientdb and pruner-block-tool. func (f *prunedfreezer) repair(datadir string) error { - offset := atomic.LoadUint64(&f.frozen) // compatible freezer minItems := uint64(math.MaxUint64) for name, disableSnappy := range chainFreezerNoSnappy { @@ -100,16 +99,19 @@ func (f *prunedfreezer) repair(datadir string) error { // If minItems is non-zero, it indicates that the chain freezer was previously enabled, and we should use minItems as the current frozen value. // If minItems is zero, it indicates that the pruneAncient was previously enabled, and we should continue using frozen // (retrieved from CurrentAncientFreezer) as the current frozen value. + var offset uint64 if minItems != 0 { offset = minItems + } else { + offset = atomic.LoadUint64(&f.frozen) } log.Info("Read ancientdb item counts", "items", minItems, "offset", offset) - if frozen := ReadFrozenOfAncientFreezer(f.db); frozen > offset { - offset = frozen - } + // FrozenOfAncientFreezer is the progress of the last prune-freezer freeze. + frozenInDB := ReadFrozenOfAncientFreezer(f.db) + maxOffset := max(offset, frozenInDB) - atomic.StoreUint64(&f.frozen, offset) + atomic.StoreUint64(&f.frozen, maxOffset) if err := f.Sync(); err != nil { return nil }