Skip to content

Commit

Permalink
Avoid crash on start in TestBlockValidity with gen=1.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gmaxwell authored and laanwj committed May 12, 2015
1 parent 2325413 commit bba7c24
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,16 @@ void static BitcoinMiner(CWallet *pwallet)
if (chainparams.MiningRequiresPeers()) {
// Busy-wait for the network to come online so we don't waste time mining
// on an obsolete chain. In regtest mode we expect to fly solo.
while (vNodes.empty())
do {
bool fvNodesEmpty;
{
LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty();
}
if (!fvNodesEmpty && !IsInitialBlockDownload())
break;
MilliSleep(1000);
} while (true);
}

//
Expand Down Expand Up @@ -533,6 +541,11 @@ void static BitcoinMiner(CWallet *pwallet)
LogPrintf("BitcoinMiner terminated\n");
throw;
}
catch (const std::runtime_error &e)
{
LogPrintf("BitcoinMiner runtime error: %s\n", e.what());
return;
}
}

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

0 comments on commit bba7c24

Please sign in to comment.