Skip to content

Commit

Permalink
Merge #893: [Wallet] Reduce shutdown delays when mining
Browse files Browse the repository at this point in the history
f71b152 [Wallet] Reduce shutdown delays when mining (Cave Spectre)

Pull request description:

  # Problem
  The wallet sometimes still takes a while before it actually shuts down when mining; this is most prevalent when the mining has been shutdown before the wallet is shut down.

  # Root cause
  The wallet will have to abort the mining generation loops when shutdown is active

  # Solution
  Add checks in the mining loops to abort when necessary

Tree-SHA512: 3d6314058a5eeeea29ec26ee96127c69cdf356a3a5a55658396c7351dc94278fd6b069c377a953764839ca2bc331d29d150d056600db8f53a4b8cd7f3afa217c
  • Loading branch information
codeofalltrades committed Jan 20, 2021
2 parents d64124f + f71b152 commit fc2233e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ void BitcoinMiner(std::shared_ptr<CReserveScript> coinbaseScript, bool fProofOfS
enablewallet = !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
#endif

while (GenerateActive() || (fProofOfStake && enablewallet))
while (!ShutdownRequested() && (GenerateActive() || (fProofOfStake && enablewallet)))
{
boost::this_thread::interruption_point();
#ifdef ENABLE_WALLET
Expand Down
6 changes: 3 additions & 3 deletions src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
uint256 mix_hash;
while (nMaxTries > 0 && pblock->nNonce64 < nInnerLoopCount &&
!CheckProofOfWork(ProgPowHash(*pblock, mix_hash), pblock->nBits,
Params().GetConsensus(), CBlockHeader::PROGPOW_BLOCK)) {
Params().GetConsensus(), CBlockHeader::PROGPOW_BLOCK) && !ShutdownRequested()) {
++pblock->nNonce64;
--nMaxTries;
}
Expand All @@ -246,7 +246,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen

bnTarget.SetCompact(pblock->nBits, &fNegative, &fOverflow);

while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount) {
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !ShutdownRequested()) {
// RandomX hash
uint256 hash_blob = pblock->GetRandomXHeaderHash();
randomx_calculate_hash(GetMyMachineValidating(), &hash_blob, sizeof uint256(), hash);
Expand All @@ -263,7 +263,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
} else if (pblock->IsSha256D() && pblock->nTime >= Params().PowUpdateTimestamp()) {
while (nMaxTries > 0 && pblock->nNonce64 < nInnerLoopCount &&
!CheckProofOfWork(pblock->GetSha256DPoWHash(), pblock->nBits,
Params().GetConsensus(), CBlockHeader::SHA256D_BLOCK)) {
Params().GetConsensus(), CBlockHeader::SHA256D_BLOCK) && !ShutdownRequested()) {
++pblock->nNonce64;
--nMaxTries;
}
Expand Down

0 comments on commit fc2233e

Please sign in to comment.