Skip to content

Commit c9136ca

Browse files
committed
validation: fix issue with an interrupted -reindex
If a reindex was interrupted while it was iterating through the block files, genesis will already be connected when the reindex resumes at the next startup. In this case, a call to ActivateBestChainState() is not only unnecessary, but it would connect multiple blocks without applying -assumevalid, which is much slower. This is because assumevalid requires us to have a header above the minimum chainwork, but that header is unknown to us if it's in a later blockfile not indexed yet.
1 parent a267589 commit c9136ca

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/validation.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5157,7 +5157,13 @@ void ChainstateManager::LoadExternalBlockFile(
51575157
}
51585158

51595159
// Activate the genesis block so normal node progress can continue
5160-
if (hash == params.GetConsensus().hashGenesisBlock) {
5160+
// During first -reindex, this will only connect Genesis since
5161+
// ActivateBestChain only connects blocks which are in the block tree db,
5162+
// which only contains blocks whose parents are in it.
5163+
// But do this only if genesis isn't activated yet, to avoid connecting many blocks
5164+
// without assumevalid in the case of a continuation of a reindex that
5165+
// was interrupted by the user.
5166+
if (hash == params.GetConsensus().hashGenesisBlock && WITH_LOCK(::cs_main, return ActiveHeight()) == -1) {
51615167
BlockValidationState state;
51625168
if (!ActiveChainstate().ActivateBestChain(state, nullptr)) {
51635169
break;

0 commit comments

Comments
 (0)