core/rawdb: log tx index pruning progress

This commit is contained in:
Felix Lange 2025-03-18 21:16:40 +01:00
parent 1100dba965
commit bbedddb7d5

View file

@ -377,9 +377,14 @@ func PruneTransactionIndex(db ethdb.Database, pruneBlock uint64) {
// There are transactions below pruneBlock in the index. Iterate the entire index to // There are transactions below pruneBlock in the index. Iterate the entire index to
// remove the entries. Note if this fails, the index is messed up, but tail still // remove the entries. Note if this fails, the index is messed up, but tail still
// points to the old tail. // points to the old tail.
iter := db.NewIterator(txLookupPrefix, nil) var (
iter = db.NewIterator(txLookupPrefix, nil)
count int
removed int
)
defer iter.Release() defer iter.Release()
for iter.Next() { for iter.Next() {
count++
v := iter.Value() v := iter.Value()
if len(v) > 8 { if len(v) > 8 {
log.Error("Skipping prune legacy tx index entry", "hash", fmt.Sprintf("%x", iter.Key())) log.Error("Skipping prune legacy tx index entry", "hash", fmt.Sprintf("%x", iter.Key()))
@ -390,8 +395,16 @@ func PruneTransactionIndex(db ethdb.Database, pruneBlock uint64) {
if err := db.Delete(iter.Key()); err != nil { if err := db.Delete(iter.Key()); err != nil {
log.Crit("Error deleting tx lookup entry", "hash", fmt.Sprintf("%x", iter.Key())) log.Crit("Error deleting tx lookup entry", "hash", fmt.Sprintf("%x", iter.Key()))
} }
removed++
}
if count%10000 == 0 {
log.Info("Pruning tx index", "count", count, "removed", removed)
} }
} }
if iter.Error() != nil {
log.Error("Tx index pruning iterator error", "err", iter.Error())
}
WriteTxIndexTail(db, pruneBlock) WriteTxIndexTail(db, pruneBlock)
} }