Ensure pindexPrev is not null before mining against it in both BitcoinMiner and RandomXMiner

This commit is contained in:
Duke Leto
2022-09-18 10:27:48 -04:00
parent 9b1b6fdc2e
commit 8e1ba0658d

View File

@@ -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;