From cc8b3f96571ea31fc69925298734cb36b07b3b28 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Fri, 8 Apr 2022 14:54:23 -0600 Subject: [PATCH] Ensure pindexPrev is not null before mining against it. --- src/miner.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 500ab7636..677411b43 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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 pblocktemplate(CreateNewBlock(chainparams, minerAddress)); if (!pblocktemplate.get())