core: update callers for new ReadTxLookupEntry signature

ReadTxLookupEntry now returns (blockNumber, txIndex) instead of just blockNumber.
This commit is contained in:
Longs Pemun Gotar 2025-11-28 21:54:21 +01:00
parent 6873d1806d
commit aee8c1505f
4 changed files with 15 additions and 8 deletions

View file

@ -378,11 +378,18 @@ func PruneTransactionIndex(db ethdb.Database, pruneBlock uint64) {
if count%10000000 == 0 {
log.Info("Pruning tx index", "count", count, "removed", removed)
}
if len(v) > 8 {
log.Error("Skipping legacy tx index entry", "hash", txhash)
var bn uint64
// Database v7: block number (8 bytes) + tx index (8 bytes) = 16 bytes
if len(v) == 16 {
bn = binary.BigEndian.Uint64(v[:8])
} else if len(v) <= 8 {
// Database v6 or earlier
bn = decodeNumber(v)
} else {
// Unknown format
log.Error("Skipping unknown tx index entry format", "hash", txhash, "len", len(v))
return false
}
bn := decodeNumber(v)
if bn < pruneBlock {
removed++
return true

View file

@ -160,7 +160,7 @@ func TestIndexTransactions(t *testing.T) {
if i == 0 {
continue
}
number := ReadTxLookupEntry(chainDB, txs[i-1].Hash())
number, _ := ReadTxLookupEntry(chainDB, txs[i-1].Hash())
if exist && number == nil {
t.Fatalf("Transaction index %d missing", i)
}
@ -229,7 +229,7 @@ func TestPruneTransactionIndex(t *testing.T) {
// Check all transactions are in index.
for _, block := range blocks {
for _, tx := range block.Transactions() {
num := ReadTxLookupEntry(chainDB, tx.Hash())
num, _ := ReadTxLookupEntry(chainDB, tx.Hash())
if num == nil || *num != block.NumberU64() {
t.Fatalf("wrong TxLookup entry: %x -> %v", tx.Hash(), num)
}
@ -241,7 +241,7 @@ func TestPruneTransactionIndex(t *testing.T) {
// Check transactions from old blocks not included.
for _, block := range blocks {
for _, tx := range block.Transactions() {
num := ReadTxLookupEntry(chainDB, tx.Hash())
num, _ := ReadTxLookupEntry(chainDB, tx.Hash())
if block.NumberU64() < pruneBlock && num != nil {
t.Fatalf("TxLookup entry not removed: %x -> %v", tx.Hash(), num)
}

View file

@ -204,7 +204,7 @@ func (indexer *txIndexer) repair(head uint64) {
indexer.tail.Store(&indexer.cutoff)
rawdb.WriteTxIndexTail(indexer.db, indexer.cutoff)
rawdb.DeleteAllTxLookupEntries(indexer.db, func(txhash common.Hash, blob []byte) bool {
n := rawdb.DecodeTxLookupEntry(blob, indexer.db)
n, _ := rawdb.DecodeTxLookupEntry(blob, indexer.db)
return n != nil && *n < indexer.cutoff
})
log.Warn("Purge transaction indexes below cutoff", "tail", *tail, "cutoff", indexer.cutoff)

View file

@ -31,7 +31,7 @@ import (
func verifyIndexes(t *testing.T, db ethdb.Database, block *types.Block, exist bool) {
for _, tx := range block.Transactions() {
lookup := rawdb.ReadTxLookupEntry(db, tx.Hash())
lookup, _ := rawdb.ReadTxLookupEntry(db, tx.Hash())
if exist && lookup == nil {
t.Fatalf("missing %d %x", block.NumberU64(), tx.Hash().Hex())
}