mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 20:32:35 -03:00
Merge #12367: Fix two fast-shutdown bugs
dd2de47
Fix fast-shutdown crash if genesis block was not loaded (Matt Corallo)1c9394a
Fix fast-shutdown hang on ThreadImport+GenesisWait (Matt Corallo) Pull request description: The second commit is a much simpler alternative fix for the issue fixed in #12349. To test I made ShutdownRequested() always StartShutdown() after a certain number of calls, which turned up one other hang, fixed in the first commit. Tree-SHA512: 86bde6ac4b8b4e2cb99fff87dafeed02c0d9514acee6d94455637fb2da9ffc274b5ad31b0a6b9f5bd7b700ae35395f28ddb14ffc65ddda3619aa28df28a5607d
This commit is contained in:
commit
7217ea2cc8
2 changed files with 16 additions and 5 deletions
11
src/init.cpp
11
src/init.cpp
|
@ -1645,12 +1645,19 @@ bool AppInitMain()
|
||||||
// Wait for genesis block to be processed
|
// Wait for genesis block to be processed
|
||||||
{
|
{
|
||||||
WaitableLock lock(cs_GenesisWait);
|
WaitableLock lock(cs_GenesisWait);
|
||||||
while (!fHaveGenesis) {
|
// We previously could hang here if StartShutdown() is called prior to
|
||||||
condvar_GenesisWait.wait(lock);
|
// ThreadImport getting started, so instead we just wait on a timer to
|
||||||
|
// check ShutdownRequested() regularly.
|
||||||
|
while (!fHaveGenesis && !ShutdownRequested()) {
|
||||||
|
condvar_GenesisWait.wait_for(lock, std::chrono::milliseconds(500));
|
||||||
}
|
}
|
||||||
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
|
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ShutdownRequested()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ********************************************************* Step 11: start node
|
// ********************************************************* Step 11: start node
|
||||||
|
|
||||||
int chain_active_height;
|
int chain_active_height;
|
||||||
|
|
|
@ -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…
Reference in a new issue