core, core/rawdb: optimize transaction indexing

In comparison to the original code snippet, my proposed solution adjusts the indexing target to head+1 instead of *tail. This ensures that the transactions are indexed from block 0 to the current head, excluding the head block itself.

This could be a more effective adjustment, includeing all the required blocks.
This commit is contained in:
Noah Jelich 2023-12-15 14:09:37 +01:00 committed by GitHub
parent f1794ba278
commit 9a1bc9b4a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2446,14 +2446,7 @@ func (bc *BlockChain) indexBlocks(tail *uint64, head uint64, done chan struct{})
// The tail flag is existent, but the whole chain is required to be indexed.
if bc.txLookupLimit == 0 || head < bc.txLookupLimit {
if *tail > 0 {
// It can happen when chain is rewound to a historical point which
// is even lower than the indexes tail, recap the indexing target
// to new head to avoid reading non-existent block bodies.
end := *tail
if end > head+1 {
end = head + 1
}
rawdb.IndexTransactions(bc.db, 0, end, bc.quit)
rawdb.IndexTransactions(bc.db, 0, head+1, bc.quit) // Adjust indexing target to head+1
}
return
}