Skip to content

Commit 3b9bf0e

Browse files
committed
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.
1 parent 32e9453 commit 3b9bf0e

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/rpc/mining.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
103103

104104
static UniValue generateBlocks(const CScript& coinbase_script, int nGenerate, uint64_t nMaxTries)
105105
{
106-
static const int nInnerLoopCount = 0x10000;
107106
int nHeightEnd = 0;
108107
int nHeight = 0;
109108

@@ -124,14 +123,14 @@ static UniValue generateBlocks(const CScript& coinbase_script, int nGenerate, ui
124123
LOCK(cs_main);
125124
IncrementExtraNonce(pblock, ::ChainActive().Tip(), nExtraNonce);
126125
}
127-
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
126+
while (nMaxTries > 0 && pblock->nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus()) && !ShutdownRequested()) {
128127
++pblock->nNonce;
129128
--nMaxTries;
130129
}
131-
if (nMaxTries == 0) {
130+
if (nMaxTries == 0 || ShutdownRequested()) {
132131
break;
133132
}
134-
if (pblock->nNonce == nInnerLoopCount) {
133+
if (pblock->nNonce == std::numeric_limits<uint32_t>::max()) {
135134
continue;
136135
}
137136
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);

0 commit comments

Comments
 (0)