From 6436146b15d4f43ec3de471cd2355fdc75135184 Mon Sep 17 00:00:00 2001 From: Chris Li <271678682li@gmail.com> Date: Tue, 16 Jul 2024 17:38:21 +0800 Subject: [PATCH] fix: change some code styles --- core/rawdb/prunedfreezer.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 }