aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorPatrick Lodder <[email protected]>2021-08-04 00:07:58 +0200
committerPatrick Lodder <[email protected]>2021-08-04 00:15:33 +0200
commit0c3d683be4e6c0154b6666bdfd484aac3b4f2fe1 (patch)
tree0d01a3abce69f7768c292ac59a45d3c1635f5eb6 /src/validation.cpp
parenttests: mempool_packages.py (#2433) (diff)
downloaddiscoin-0c3d683be4e6c0154b6666bdfd484aac3b4f2fe1.tar.xz
discoin-0c3d683be4e6c0154b6666bdfd484aac3b4f2fe1.zip
bugfix: break ActivateBestChain() differently on shutdown
Moves the break in ActivateBestChain() when a node is being shut down from the beginning of the loop block to the end, allowing pindexNewTip to be populated with chainActive.Tip() rather than its initial NULL value. Solves issues when shutting down nodes while inside the ActivateBestChain loop.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index 46e586415..35778a2e7 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2504,9 +2504,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
CBlockIndex *pindexMostWork = NULL;
CBlockIndex *pindexNewTip = NULL;
do {
- boost::this_thread::interruption_point();
- if (ShutdownRequested())
- break;
const CBlockIndex *pindexFork;
ConnectTrace connectTrace;
@@ -2566,6 +2563,15 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
if (pindexFork != pindexNewTip) {
uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
}
+
+ // Perform the shutdown detection to the end of the loop to prevent
+ // pindexNewTip being nil
+ boost::this_thread::interruption_point();
+ if (ShutdownRequested()) {
+ LogPrintf("ActivateBestChain: shutdown requested, breaking loop\n");
+ break;
+ }
+
} while (pindexNewTip != pindexMostWork);
CheckBlockIndex(chainparams.GetConsensus(pindexNewTip->nHeight));