Skip to content

Commit

Permalink
Merge pull request #1784 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
core/rawdb: add logging and fix comments around AncientRange function…
  • Loading branch information
ucwong authored Nov 1, 2023
2 parents 1285ca2 + 144e45a commit 3035d42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
19 changes: 12 additions & 7 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,18 @@ func ReadHeaderRange(db ctxcdb.Reader, number uint64, count uint64) []rlp.RawVal
return rlpHeaders
}
// read remaining from ancients
max := count * 700
data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, max)
if err == nil && uint64(len(data)) == count {
// the data is on the order [h, h+1, .., n] -- reordering needed
for i := range data {
rlpHeaders = append(rlpHeaders, data[len(data)-1-i])
}
data, err := db.AncientRange(ChainFreezerHeaderTable, i+1-count, count, 0)
if err != nil {
log.Error("Failed to read headers from freezer", "err", err)
return rlpHeaders
}
if uint64(len(data)) != count {
log.Warn("Incomplete read of headers from freezer", "wanted", count, "read", len(data))
return rlpHeaders
}
// The data is on the order [h, h+1, .., n] -- reordering needed
for i := range data {
rlpHeaders = append(rlpHeaders, data[len(data)-1-i])
}
return rlpHeaders
}
Expand Down
7 changes: 4 additions & 3 deletions core/rawdb/freezer_resettable.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ func (f *ResettableFreezer) Ancient(kind string, number uint64) ([]byte, error)

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

0 comments on commit 3035d42

Please sign in to comment.