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: ensure txindex will be triggered at least once #27847

Merged
merged 7 commits into from
Aug 22, 2023
Merged
Changes from 2 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
11 changes: 10 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,9 @@ func (bc *BlockChain) skipBlock(err error, it *insertIterator) bool {

// indexBlocks reindexes or unindexes transactions depending on user configuration
func (bc *BlockChain) indexBlocks(tail *uint64, head uint64, done chan struct{}) {
defer func() { close(done) }()
if done != nil {
defer func() { close(done) }()
}

// The tail flag is not existent, it means the node is just initialized
// and all blocks(may from ancient store) are not indexed yet.
Expand Down Expand Up @@ -2383,6 +2385,13 @@ func (bc *BlockChain) indexBlocks(tail *uint64, head uint64, done chan struct{})
func (bc *BlockChain) maintainTxIndex() {
defer bc.wg.Done()

// Geth should always index/uninindex the unfinished chain segments,
// in case the chain has no progress for a long time.
head := rawdb.ReadHeadBlock(bc.db)
if head != nil {
bc.indexBlocks(rawdb.ReadTxIndexTail(bc.db), head.NumberU64(), nil)
}

jsvisa marked this conversation as resolved.
Show resolved Hide resolved
// 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