diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index b940d910402..9e00bae4f16 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -31,15 +31,11 @@ type tableSize struct { // freezerInfo contains the basic information of the freezer. type freezerInfo struct { - name string // The identifier of freezer - head uint64 // The number of last stored item in the freezer - tail uint64 // The number of first stored item in the freezer - sizes []tableSize // The storage size per table -} - -// count returns the number of stored items in the freezer. -func (info *freezerInfo) count() uint64 { - return info.head - info.tail + 1 + name string // The identifier of freezer + head uint64 // The number of last stored item in the freezer, valid only if ancients > 0 + tail uint64 // The number of first stored item in the freezer + count uint64 // The number of stored items in the freezer + sizes []tableSize // The storage size per table } // size returns the storage size of the entire freezer. @@ -65,7 +61,12 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci if err != nil { return freezerInfo{}, err } - info.head = ancients - 1 + info.ancients = ancients + if ancients > 0 { + info.head = ancients - 1 + } else { + info.head = 0 + } // Retrieve the number of first stored item tail, err := reader.Tail() @@ -73,6 +74,11 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci return freezerInfo{}, err } info.tail = tail + if ancients == 0 { + info.count = 0 + } else { + info.count = info.head - info.tail + 1 + } return info, nil } diff --git a/core/rawdb/database.go b/core/rawdb/database.go index d5c0f0aab29..448922d9bd7 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -644,7 +644,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)), strings.Title(table.name), table.size.String(), - fmt.Sprintf("%d", ancient.count()), + fmt.Sprintf("%d", ancient.count), }) } total.Add(uint64(ancient.size()))