mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-29 16:13:47 +00:00
add flag for controlling whether blocks should be pruned during undexing transactions
This commit is contained in:
parent
0a0a8733ab
commit
46e99e460b
3 changed files with 9 additions and 9 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue