From 1712adbe0b084b6907b82db350a51ab44f8c3117 Mon Sep 17 00:00:00 2001 From: jtimon Date: Fri, 7 Mar 2014 17:59:30 -0800 Subject: [PATCH] Add MiningRequiresPeers chain parameter --- src/chainparams.cpp | 1 + src/chainparams.h | 2 ++ src/miner.cpp | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f5cf846a01..ff104e7c84 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -246,6 +246,7 @@ public: } virtual bool RequireRPCPassword() const { return false; } + virtual bool MiningRequiresPeers() const { return false; } virtual Network NetworkID() const { return CChainParams::REGTEST; } }; static CRegTestParams regTestParams; diff --git a/src/chainparams.h b/src/chainparams.h index 5600b904cc..a73279fe67 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -59,6 +59,8 @@ public: int SubsidyHalvingInterval() const { return nSubsidyHalvingInterval; } virtual const CBlock& GenesisBlock() const = 0; virtual bool RequireRPCPassword() const { return true; } + /* Make miner wait to have peers to avoid wasting work */ + virtual bool MiningRequiresPeers() const { return true; } const string& DataDir() const { return strDataDir; } virtual Network NetworkID() const = 0; const vector& DNSSeeds() const { return vSeeds; } diff --git a/src/miner.cpp b/src/miner.cpp index 94fc8e3888..3d46a0d83e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -512,7 +512,7 @@ void static BitcoinMiner(CWallet *pwallet) unsigned int nExtraNonce = 0; try { while (true) { - if (Params().NetworkID() != CChainParams::REGTEST) { + if (Params().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()) @@ -620,7 +620,8 @@ void static BitcoinMiner(CWallet *pwallet) // Check for stop or if block needs to be rebuilt boost::this_thread::interruption_point(); - if (vNodes.empty() && Params().NetworkID() != CChainParams::REGTEST) + // Regtest mode doesn't require peers + if (vNodes.empty() && Params().MiningRequiresPeers()) break; if (nBlockNonce >= 0xffff0000) break;