Skip to content

Commit 447945e

Browse files
core/rawdb: add logging and fix comments around AncientRange function. (#28379)
This adds warning logs when the read does not match the expected count. We can also remove the size limit since the function documentation explicitly states that callers should limit the count.
1 parent ea2e66a commit 447945e

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

core/rawdb/accessors_chain.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,18 @@ func ReadHeaderRange(db ethdb.Reader, number uint64, count uint64) []rlp.RawValu
334334
return rlpHeaders
335335
}
336336
// read remaining from ancients
337-
max := count * 700
338-
data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, max)
339-
if err == nil && uint64(len(data)) == count {
340-
// the data is on the order [h, h+1, .., n] -- reordering needed
341-
for i := range data {
342-
rlpHeaders = append(rlpHeaders, data[len(data)-1-i])
343-
}
337+
data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, 0)
338+
if err != nil {
339+
log.Error("Failed to read headers from freezer", "err", err)
340+
return rlpHeaders
341+
}
342+
if uint64(len(data)) != count {
343+
log.Warn("Incomplete read of headers from freezer", "wanted", count, "read", len(data))
344+
return rlpHeaders
345+
}
346+
// The data is on the order [h, h+1, .., n] -- reordering needed
347+
for i := range data {
348+
rlpHeaders = append(rlpHeaders, data[len(data)-1-i])
344349
}
345350
return rlpHeaders
346351
}

core/rawdb/freezer_resettable.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ func (f *ResettableFreezer) Ancient(kind string, number uint64) ([]byte, error)
119119

120120
// AncientRange retrieves multiple items in sequence, starting from the index 'start'.
121121
// It will return
122-
// - at most 'max' items,
123-
// - at least 1 item (even if exceeding the maxByteSize), but will otherwise
124-
// return as many items as fit into maxByteSize
122+
// - at most 'count' items,
123+
// - if maxBytes is specified: at least 1 item (even if exceeding the maxByteSize),
124+
// but will otherwise return as many items as fit into maxByteSize.
125+
// - if maxBytes is not specified, 'count' items will be returned if they are present.
125126
func (f *ResettableFreezer) AncientRange(kind string, start, count, maxBytes uint64) ([][]byte, error) {
126127
f.lock.RLock()
127128
defer f.lock.RUnlock()

0 commit comments

Comments
 (0)