Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/blockchain : reindex tx from ancients after crashing #25892

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
if bc.empty() {
rawdb.InitDatabaseFromFreezer(bc.db)
}
var txIndexBlock uint64
frozen, _ := bc.db.Ancients()
if frozen > 0 {
txIndexBlock = frozen
}
// Load blockchain states from disk
if err := bc.loadLastState(); err != nil {
return nil, err
Expand Down Expand Up @@ -433,7 +438,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
bc.txLookupLimit = *txLookupLimit

bc.wg.Add(1)
go bc.maintainTxIndex()
go bc.maintainTxIndex(txIndexBlock)
}
return bc, nil
}
Expand Down Expand Up @@ -2330,9 +2335,17 @@ func (bc *BlockChain) indexBlocks(tail *uint64, head uint64, done chan struct{})
// The user can adjust the txlookuplimit value for each launch after sync,
// Geth will automatically construct the missing indices or delete the extra
// indices.
func (bc *BlockChain) maintainTxIndex() {
func (bc *BlockChain) maintainTxIndex(ancients uint64) {
defer bc.wg.Done()

if ancients > 0 && ancients > bc.txLookupLimit {
var from = uint64(0)
if bc.txLookupLimit != 0 {
from = ancients - bc.txLookupLimit
}
rawdb.IndexTransactions(bc.db, from, ancients, bc.quit)
}

// Listening to chain events and manipulate the transaction indexes.
var (
done chan struct{} // Non-nil if background unindexing or reindexing routine is active.
Expand Down