Skip to content

Commit bba7c24

Browse files
gmaxwelllaanwj
authored andcommitted
Avoid crash on start in TestBlockValidity with gen=1.
When the internal miner is enabled at the start of a new node, there is an near instant assert in TestBlockValidity because its attempting to mine a block before the top checkpoint. Also avoids a data race around vNodes.
1 parent 2325413 commit bba7c24

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/miner.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,16 @@ void static BitcoinMiner(CWallet *pwallet)
453453
if (chainparams.MiningRequiresPeers()) {
454454
// Busy-wait for the network to come online so we don't waste time mining
455455
// on an obsolete chain. In regtest mode we expect to fly solo.
456-
while (vNodes.empty())
456+
do {
457+
bool fvNodesEmpty;
458+
{
459+
LOCK(cs_vNodes);
460+
fvNodesEmpty = vNodes.empty();
461+
}
462+
if (!fvNodesEmpty && !IsInitialBlockDownload())
463+
break;
457464
MilliSleep(1000);
465+
} while (true);
458466
}
459467

460468
//
@@ -533,6 +541,11 @@ void static BitcoinMiner(CWallet *pwallet)
533541
LogPrintf("BitcoinMiner terminated\n");
534542
throw;
535543
}
544+
catch (const std::runtime_error &e)
545+
{
546+
LogPrintf("BitcoinMiner runtime error: %s\n", e.what());
547+
return;
548+
}
536549
}
537550

538551
void GenerateBitcoins(bool fGenerate, CWallet* pwallet, int nThreads)

0 commit comments

Comments
 (0)