Browse Source

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.

Github-Pull: #12367
Rebased-From: dd2de47c6288654abb2c3eef29edcd1cc5f39fc9
Tree-SHA512: c2465be25aee327d16d460c9b58d25a5aeedec309f539898e78419bea76dbbe9cde9cc88ec393af38a82e6013d71cce85f4223c9bf04e7244ed619f20f734aa4
0.16
Matt Corallo 7 years ago committed by Wladimir J. van der Laan
parent
commit
0f207c488a
No known key found for this signature in database
GPG Key ID: 1E4AED62986CD25D
  1. 10
      src/validation.cpp

10
src/validation.cpp

@ -2581,9 +2581,6 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
SyncWithValidationInterfaceQueue(); SyncWithValidationInterfaceQueue();
} }
if (ShutdownRequested())
break;
const CBlockIndex *pindexFork; const CBlockIndex *pindexFork;
bool fInitialDownload; bool fInitialDownload;
{ {
@ -2630,6 +2627,13 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
} }
if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown(); if (nStopAtHeight && pindexNewTip && pindexNewTip->nHeight >= nStopAtHeight) StartShutdown();
// We check shutdown only after giving ActivateBestChainStep a chance to run once so that we
// never shutdown before connecting the genesis block during LoadChainTip(). Previously this
// caused an assert() failure during shutdown in such cases as the UTXO DB flushing checks
// that the best block hash is non-null.
if (ShutdownRequested())
break;
} while (pindexNewTip != pindexMostWork); } while (pindexNewTip != pindexMostWork);
CheckBlockIndex(chainparams.GetConsensus()); CheckBlockIndex(chainparams.GetConsensus());

Loading…
Cancel
Save