Skip to content

Commit f71b152

Browse files
committed
[Wallet] Reduce shutdown delays when mining
1 parent d64124f commit f71b152

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)