Skip to content

Commit

Permalink
Merge bitcoin#16262: rpc: Allow shutdown while in generateblocks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
laanwj authored and PastaPastaPasta committed Jun 28, 2021
1 parent e786675 commit 449b891
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ static UniValue getnetworkhashps(const JSONRPCRequest& request)
#if ENABLE_MINER
UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
{
static const int nInnerLoopCount = 0x10000;
int nHeightEnd = 0;
int nHeight = 0;

Expand All @@ -134,14 +133,14 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
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);
Expand Down

0 comments on commit 449b891

Please sign in to comment.