diff options
author | Gregory Maxwell <greg@xiph.org> | 2015-04-28 17:00:50 -0700 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2015-05-12 14:07:43 +0200 |
commit | bba7c249296a9a2f444e1035fef8f8b593ba2aaf (patch) | |
tree | 2fdc6b37a42f5c6328abf836068c1c59eed52d2c | |
parent | 23254131a3fdaeae9c50dafca6d0addbbf235820 (diff) |
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.
-rw-r--r-- | src/miner.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/miner.cpp b/src/miner.cpp index 56a2c5828b..4bceb7d7b4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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); } // @@ -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) |