Skip to content

Commit dd2de47

Browse files
committed
Fix fast-shutdown crash if genesis block was not loaded
If the ShutdownRequested() check at the top of ActivateBestChain() returns false during initial genesis block load we will fail an assertion in UTXO DB flush as the best block hash IsNull(). To work around this, we move the check until after one round of ActivateBestChainStep(), ensuring the genesis block gets connected.
1 parent 1c9394a commit dd2de47

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/validation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,9 +2581,6 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
25812581
SyncWithValidationInterfaceQueue();
25822582
}
25832583

2584-
if (ShutdownRequested())
2585-
break;
2586-
25872584
const CBlockIndex *pindexFork;
25882585
bool fInitialDownload;
25892586
{
@@ -2630,6 +2627,13 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
26302627
}
26312628

26322629
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
2630+
2631+
// We check shutdown only after giving ActivateBestChainStep a chance to run once so that we
2632+
// never shutdown before connecting the genesis block during LoadChainTip(). Previously this
2633+
// caused an assert() failure during shutdown in such cases as the UTXO DB flushing checks
2634+
// that the best block hash is non-null.
2635+
if (ShutdownRequested())
2636+
break;
26332637
} while (pindexNewTip != pindexMostWork);
26342638
CheckBlockIndex(chainparams.GetConsensus());
26352639

0 commit comments

Comments
 (0)