Skip to content

Commit 030f628

Browse files
authored
core/rawdb: fix underflow in freezer inspect for empty ancients
1 parent 5e6f737 commit 030f628

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

core/rawdb/ancient_utils.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,19 @@ type tableSize struct {
3131

3232
// freezerInfo contains the basic information of the freezer.
3333
type freezerInfo struct {
34-
name string // The identifier of freezer
35-
head uint64 // The number of last stored item in the freezer
36-
tail uint64 // The number of first stored item in the freezer
37-
sizes []tableSize // The storage size per table
34+
name string // The identifier of freezer
35+
ancients uint64 // The total number of stored items in the freezer
36+
head uint64 // The number of last stored item in the freezer, valid only if ancients > 0
37+
tail uint64 // The number of first stored item in the freezer
38+
sizes []tableSize // The storage size per table
3839
}
3940

4041
// count returns the number of stored items in the freezer.
4142
func (info *freezerInfo) count() uint64 {
42-
return info.head - info.tail + 1
43+
if info.ancients <= info.tail {
44+
return 0
45+
}
46+
return info.ancients - info.tail
4347
}
4448

4549
// size returns the storage size of the entire freezer.
@@ -65,7 +69,12 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci
6569
if err != nil {
6670
return freezerInfo{}, err
6771
}
68-
info.head = ancients - 1
72+
info.ancients = ancients
73+
if ancients > 0 {
74+
info.head = ancients - 1
75+
} else {
76+
info.head = 0
77+
}
6978

7079
// Retrieve the number of first stored item
7180
tail, err := reader.Tail()

0 commit comments

Comments
 (0)