Skip to content

Commit fc2233e

Browse files
Merge #893: [Wallet] Reduce shutdown delays when mining
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
2 parents d64124f + f71b152 commit fc2233e

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/miner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ void BitcoinMiner(std::shared_ptr<CReserveScript> coinbaseScript, bool fProofOfS
869869
enablewallet = !gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET);
870870
#endif
871871

872-
while (GenerateActive() || (fProofOfStake && enablewallet))
872+
while (!ShutdownRequested() && (GenerateActive() || (fProofOfStake && enablewallet)))
873873
{
874874
boost::this_thread::interruption_point();
875875
#ifdef ENABLE_WALLET

src/rpc/mining.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
232232
uint256 mix_hash;
233233
while (nMaxTries > 0 && pblock->nNonce64 < nInnerLoopCount &&
234234
!CheckProofOfWork(ProgPowHash(*pblock, mix_hash), pblock->nBits,
235-
Params().GetConsensus(), CBlockHeader::PROGPOW_BLOCK)) {
235+
Params().GetConsensus(), CBlockHeader::PROGPOW_BLOCK) && !ShutdownRequested()) {
236236
++pblock->nNonce64;
237237
--nMaxTries;
238238
}
@@ -246,7 +246,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
246246

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

249-
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount) {
249+
while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !ShutdownRequested()) {
250250
// RandomX hash
251251
uint256 hash_blob = pblock->GetRandomXHeaderHash();
252252
randomx_calculate_hash(GetMyMachineValidating(), &hash_blob, sizeof uint256(), hash);
@@ -263,7 +263,7 @@ UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGen
263263
} else if (pblock->IsSha256D() && pblock->nTime >= Params().PowUpdateTimestamp()) {
264264
while (nMaxTries > 0 && pblock->nNonce64 < nInnerLoopCount &&
265265
!CheckProofOfWork(pblock->GetSha256DPoWHash(), pblock->nBits,
266-
Params().GetConsensus(), CBlockHeader::SHA256D_BLOCK)) {
266+
Params().GetConsensus(), CBlockHeader::SHA256D_BLOCK) && !ShutdownRequested()) {
267267
++pblock->nNonce64;
268268
--nMaxTries;
269269
}

0 commit comments

Comments
 (0)