aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Strateman <patrick.strateman@gmail.com>2019-06-21 13:27:00 -0400
committerPatrick Strateman <patrick.strateman@gmail.com>2019-06-23 20:51:02 -0400
commit3b9bf0eb0e0d69f112ce905078018d8351c73e26 (patch)
tree5c2511317309107e9851edde11690aeaf37802f2 /src
parent32e94538185b61fe64bd16de2459e763ec46b4da (diff)
rpc: Allow shutdown while in generateblocks
By checking the shutdown flag every loop we can use the entire nonce space instead of breaking every 16 bits to check the shutdown flag. This has been possible since the shutdown flag was switched to an atomic, before that change it was controlled by a condition variable and lock.
Diffstat (limited to 'src')
-rw-r--r--src/rpc/mining.cpp7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 477f05f46c..1dfaecc951 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -103,7 +103,6 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
static UniValue generateBlocks(const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
{
- static const int nInnerLoopCount = 0x10000;
int nHeightEnd = 0;
int nHeight = 0;
@@ -124,14 +123,14 @@ static UniValue generateBlocks(const CScript& coinbase_script, int nGenerate, ui
LOCK(cs_main);
IncrementExtraNonce(pblock, ::ChainActive().Tip(), nExtraNonce);
}
- while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
+ while (nMaxTries > 0 && pblock->nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus()) && !ShutdownRequested()) {
++pblock->nNonce;
--nMaxTries;
}
- if (nMaxTries == 0) {
+ if (nMaxTries == 0 || ShutdownRequested()) {
break;
}
- if (pblock->nNonce == nInnerLoopCount) {
+ if (pblock->nNonce == std::numeric_limits<uint32_t>::max()) {
continue;
}
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);