diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2277,6 +2277,10 @@ uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); } + if (ShutdownRequested()) { + return false; + } + // Step 11: start node int chain_active_height; diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2936,10 +2936,6 @@ SyncWithValidationInterfaceQueue(); } - if (ShutdownRequested()) { - break; - } - const CBlockIndex *pindexFork; bool fInitialDownload; { @@ -3006,6 +3002,15 @@ 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); const CChainParams ¶ms = config.GetChainParams();