From aee8c1505faab30258b8f4bcad72243982ec41b1 Mon Sep 17 00:00:00 2001 From: Longs Pemun Gotar Date: Fri, 28 Nov 2025 21:54:21 +0100 Subject: [PATCH] core: update callers for new ReadTxLookupEntry signature ReadTxLookupEntry now returns (blockNumber, txIndex) instead of just blockNumber. --- core/rawdb/chain_iterator.go | 13 ++++++++++--- core/rawdb/chain_iterator_test.go | 6 +++--- core/txindexer.go | 2 +- core/txindexer_test.go | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/rawdb/chain_iterator.go b/core/rawdb/chain_iterator.go index e7c89ca8d9..0a92f7770e 100644 --- a/core/rawdb/chain_iterator.go +++ b/core/rawdb/chain_iterator.go @@ -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 diff --git a/core/rawdb/chain_iterator_test.go b/core/rawdb/chain_iterator_test.go index 75bd5a9a94..8913bb00ff 100644 --- a/core/rawdb/chain_iterator_test.go +++ b/core/rawdb/chain_iterator_test.go @@ -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) } diff --git a/core/txindexer.go b/core/txindexer.go index b2a94a6ead..929972f700 100644 --- a/core/txindexer.go +++ b/core/txindexer.go @@ -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) diff --git a/core/txindexer_test.go b/core/txindexer_test.go index 71c78d506b..f718ceeda0 100644 --- a/core/txindexer_test.go +++ b/core/txindexer_test.go @@ -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()) }