Merge pull request #5853 from nuttycom/bug/miner_guard_chainactive

Ensure pindexPrev is not null before mining against it.
This commit is contained in:
Charlie O'Keefe 2022-04-08 18:38:07 -06:00 committed by GitHub
commit d0a30cd0d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 1 deletions

View File

@ -922,7 +922,17 @@ void static BitcoinMiner(const CChainParams& chainparams)
// Create new block
//
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrev = chainActive.Tip();
CBlockIndex* pindexPrev;
{
LOCK(cs_main);
pindexPrev = chainActive.Tip();
}
// If we don't have a valid chain tip to work from, wait and try again.
if (pindexPrev == nullptr) {
MilliSleep(1000);
continue;
}
unique_ptr<CBlockTemplate> pblocktemplate(CreateNewBlock(chainparams, minerAddress));
if (!pblocktemplate.get())