Skip to content

Commit 7d7b832

Browse files
committed
Merge #16262: rpc: Allow shutdown while in generateblocks
3b9bf0e rpc: Allow shutdown while in generateblocks (Patrick Strateman) Pull request description: By checking the shutdown flag every loop we can use the entire 32 bit nonce space instead of breaking every 16 bits to check the flag. This is possible now because the shutdown flag is an atomic where before it was controlled by a condition variable and lock. ACKs for top commit: kallewoof: Re-ACK 3b9bf0e Tree-SHA512: d0664201a55215130c2e9199a31fb81361daf4102a65cb3418984fd61cb98bfb9136d9ee8d23a85d57e50051f9bb0059bd71fe0488a17f63c38ea5caa6004504
2 parents e060673 + 3b9bf0e commit 7d7b832

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)