mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-03-02 09:33:46 +00:00
core: update callers for new ReadTxLookupEntry signature
ReadTxLookupEntry now returns (blockNumber, txIndex) instead of just blockNumber.
This commit is contained in:
parent
6873d1806d
commit
aee8c1505f
4 changed files with 15 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue