mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-11 09:21:37 +00:00
core/rawdb: fix underflow in freezer inspect for empty ancients (#33203)
This commit is contained in:
parent
a6191d8272
commit
2a4847a7d1
2 changed files with 13 additions and 7 deletions
|
|
@ -34,14 +34,10 @@ type freezerInfo struct {
|
||||||
name string // The identifier of freezer
|
name string // The identifier of freezer
|
||||||
head uint64 // The number of last stored item in the freezer
|
head uint64 // The number of last stored item in the freezer
|
||||||
tail uint64 // The number of first stored item in the freezer
|
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
|
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
|
|
||||||
}
|
|
||||||
|
|
||||||
// size returns the storage size of the entire freezer.
|
// size returns the storage size of the entire freezer.
|
||||||
func (info *freezerInfo) size() common.StorageSize {
|
func (info *freezerInfo) size() common.StorageSize {
|
||||||
var total common.StorageSize
|
var total common.StorageSize
|
||||||
|
|
@ -65,7 +61,11 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return freezerInfo{}, err
|
return freezerInfo{}, err
|
||||||
}
|
}
|
||||||
info.head = ancients - 1
|
if ancients > 0 {
|
||||||
|
info.head = ancients - 1
|
||||||
|
} else {
|
||||||
|
info.head = 0
|
||||||
|
}
|
||||||
|
|
||||||
// Retrieve the number of first stored item
|
// Retrieve the number of first stored item
|
||||||
tail, err := reader.Tail()
|
tail, err := reader.Tail()
|
||||||
|
|
@ -73,6 +73,12 @@ func inspect(name string, order map[string]freezerTableConfig, reader ethdb.Anci
|
||||||
return freezerInfo{}, err
|
return freezerInfo{}, err
|
||||||
}
|
}
|
||||||
info.tail = tail
|
info.tail = tail
|
||||||
|
|
||||||
|
if ancients == 0 {
|
||||||
|
info.count = 0
|
||||||
|
} else {
|
||||||
|
info.count = info.head - info.tail + 1
|
||||||
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -644,7 +644,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)),
|
fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)),
|
||||||
strings.Title(table.name),
|
strings.Title(table.name),
|
||||||
table.size.String(),
|
table.size.String(),
|
||||||
fmt.Sprintf("%d", ancient.count()),
|
fmt.Sprintf("%d", ancient.count),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
total.Add(uint64(ancient.size()))
|
total.Add(uint64(ancient.size()))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue