Skip to content

Commit 67e689e

Browse files
authored
triedb/pathdb: fix off-by-one for last state history ID and handle empty ranges
1 parent 3954259 commit 67e689e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

triedb/pathdb/history_inspect.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ func sanitizeRange(start, end uint64, freezer ethdb.AncientReader) (uint64, uint
5050
if err != nil {
5151
return 0, 0, err
5252
}
53-
last := head - 1
53+
last := head
5454
if end != 0 && end < last {
5555
last = end
5656
}
5757
// Make sure the range is valid
58-
if first >= last {
58+
if first > last {
5959
return 0, 0, fmt.Errorf("range is invalid, first: %d, last: %d", first, last)
6060
}
6161
return first, last, nil
@@ -143,7 +143,11 @@ func historyRange(freezer ethdb.AncientReader) (uint64, uint64, error) {
143143
if err != nil {
144144
return 0, 0, err
145145
}
146-
last := head - 1
146+
// If there is no history available, return an explicit error.
147+
if head == tail {
148+
return 0, 0, fmt.Errorf("no history available")
149+
}
150+
last := head
147151

148152
fh, err := readStateHistory(freezer, first)
149153
if err != nil {

0 commit comments

Comments
 (0)