mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
core/rawdb: fix underflow in freezer inspect for empty ancients
This commit is contained in:
parent
5e6f7374de
commit
030f628ca7
1 changed files with 15 additions and 6 deletions
|
|
@ -31,15 +31,19 @@ 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
|
||||
name string // The identifier of freezer
|
||||
ancients uint64 // The total number of stored items in the 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
|
||||
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
|
||||
if info.ancients <= info.tail {
|
||||
return 0
|
||||
}
|
||||
return info.ancients - info.tail
|
||||
}
|
||||
|
||||
// size returns the storage size of the entire freezer.
|
||||
|
|
@ -65,7 +69,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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue