diff --git a/core/blockchain.go b/core/blockchain.go index 3d38b5f9f3..753a9602df 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -2302,7 +2302,7 @@ func (bc *BlockChain) maintainTxIndex(ancients uint64) { } else { // Prune all stale tx indices and record the tx index tail log.Info("Scheduled blocks & transactions unindexing", "from block", 0, "to", head-bc.txLookupLimit+1) - rawdb.UnindexTransactions(bc.db, 0, head-bc.txLookupLimit+1, bc.quit) + rawdb.UnindexTransactions(bc.db, 0, head-bc.txLookupLimit+1, bc.quit, bc.cacheConfig.AncientPrune) } return } @@ -2327,7 +2327,7 @@ func (bc *BlockChain) maintainTxIndex(ancients uint64) { } else { // Unindex a part of stale indices and forward index tail to HEAD-limit log.Info("Scheduled blocks & transactions unindexing", "from block", *tail, "to", head-bc.txLookupLimit+1) - rawdb.UnindexTransactions(bc.db, *tail, head-bc.txLookupLimit+1, bc.quit) + rawdb.UnindexTransactions(bc.db, *tail, head-bc.txLookupLimit+1, bc.quit, bc.cacheConfig.AncientPrune) } } diff --git a/core/rawdb/chain_iterator.go b/core/rawdb/chain_iterator.go index 4d4e42b9dc..04f10036d7 100644 --- a/core/rawdb/chain_iterator.go +++ b/core/rawdb/chain_iterator.go @@ -273,7 +273,7 @@ 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) { +func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool, unindexBlock bool) { // short circuit for invalid range if from >= to { return @@ -308,7 +308,7 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch DeleteTxLookupEntries(batch, delivery.hashes) txs += len(delivery.hashes) // Delete all about the block - if delivery.number != 0 { // never delete the genesis block + if unindexBlock && delivery.number != 0 { // never delete the genesis block DeleteBlock(batch, delivery.blockHash, delivery.number) } blocks++ @@ -352,11 +352,11 @@ func unindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt ch // // 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{}) { - unindexTransactions(db, from, to, interrupt, nil) +func UnindexTransactions(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, unindexBlock bool) { + unindexTransactions(db, from, to, interrupt, nil, unindexBlock) } // unindexTransactionsForTesting is the internal debug version with an additional hook. func unindexTransactionsForTesting(db ethdb.Database, from uint64, to uint64, interrupt chan struct{}, hook func(uint64) bool) { - unindexTransactions(db, from, to, interrupt, hook) + unindexTransactions(db, from, to, interrupt, hook, false) } diff --git a/core/rawdb/chain_iterator_test.go b/core/rawdb/chain_iterator_test.go index e1f5159753..15d94598fa 100644 --- a/core/rawdb/chain_iterator_test.go +++ b/core/rawdb/chain_iterator_test.go @@ -169,11 +169,11 @@ func TestIndexTransactions(t *testing.T) { IndexTransactions(chainDb, 0, 5, nil) verify(0, 11, true, 0) - UnindexTransactions(chainDb, 0, 5, nil) + UnindexTransactions(chainDb, 0, 5, nil, false) verify(5, 11, true, 5) verify(0, 5, false, 5) - UnindexTransactions(chainDb, 5, 11, nil) + UnindexTransactions(chainDb, 5, 11, nil, false) verify(0, 11, false, 11) // Testing corner cases