triedb/pathdb: fix off-by-one for last state history ID and handle empty ranges

This commit is contained in:
Forostovec 2025-11-05 10:33:34 +02:00 committed by GitHub
parent 395425902d
commit 67e689e161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,12 +50,12 @@ func sanitizeRange(start, end uint64, freezer ethdb.AncientReader) (uint64, uint
if err != nil {
return 0, 0, err
}
last := head - 1
last := head
if end != 0 && end < last {
last = end
}
// Make sure the range is valid
if first >= last {
if first > last {
return 0, 0, fmt.Errorf("range is invalid, first: %d, last: %d", first, last)
}
return first, last, nil
@ -143,7 +143,11 @@ func historyRange(freezer ethdb.AncientReader) (uint64, uint64, error) {
if err != nil {
return 0, 0, err
}
last := head - 1
// If there is no history available, return an explicit error.
if head == tail {
return 0, 0, fmt.Errorf("no history available")
}
last := head
fh, err := readStateHistory(freezer, first)
if err != nil {