Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/rawdb: handle ancient pruner offset in indexing #1411

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions core/rawdb/chain_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ func InitDatabaseFromFreezer(db ethdb.Database) {
log.Info("Initialized database from freezer", "blocks", frozen, "elapsed", common.PrettyDuration(time.Since(start)))
}

// adjustRangeForBor updates the range to index transactions if the ancient data was pruned before. This is
// to avoid indexing/unindexing data which is already pruned (i.e. before the `offset` block number).
func adjustRangeForBor(db ethdb.Database, from uint64) uint64 {
if offset := db.AncientOffSet(); offset > from {
from = offset
}

return from
}

type blockTxHashes struct {
number uint64
hashes []common.Hash
Expand All @@ -108,10 +118,6 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
rlp rlp.RawValue
}

if offset := db.AncientOffSet(); offset > from {
from = offset
}

if to <= from {
return nil
}
Expand Down Expand Up @@ -206,6 +212,9 @@ func iterateTransactions(db ethdb.Database, from uint64, to uint64, reverse bool
// There is a passed channel, the whole procedure will be interrupted if any
// signal received.
func indexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
// Adjust range if needed
from = adjustRangeForBor(db, from)

// short circuit for invalid range
if from >= to {
return
Expand Down Expand Up @@ -309,6 +318,9 @@ func indexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, inte
// There is a passed channel, the whole procedure will be interrupted if any
// signal received.
func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, report bool) {
// Adjust range if needed
from = adjustRangeForBor(db, from)

// short circuit for invalid range
if from >= to {
return
Expand Down
Loading