From 8e1ba0658d10a620b0d1e382ebc751170eb23f34 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 18 Sep 2022 10:27:48 -0400 Subject: [PATCH] Ensure pindexPrev is not null before mining against it in both BitcoinMiner and RandomXMiner --- src/miner.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 16c18146b..72d6d04df 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1102,6 +1102,14 @@ void static RandomXMiner() // Create new block unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.LastTip(); + + // If we don't have a valid chain tip to work from, wait and try again. + if (pindexPrev == nullptr) { + fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__); + MilliSleep(1000); + continue; + } + if ( Mining_height != pindexPrev->GetHeight()+1 ) { Mining_height = pindexPrev->GetHeight()+1; @@ -1460,6 +1468,14 @@ void static BitcoinMiner() // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.LastTip(); + + // If we don't have a valid chain tip to work from, wait and try again. + if (pindexPrev == nullptr) { + fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__); + MilliSleep(1000); + continue; + } + if ( Mining_height != pindexPrev->GetHeight()+1 ) { Mining_height = pindexPrev->GetHeight()+1;