From 3237668b1da43d15e257f181d856ac191e6d0289 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Mon, 28 Jan 2019 12:23:03 +0100 Subject: [PATCH] Rename inInvalidate->inEnforceBestChainLock and make it atomic --- src/llmq/quorums_chainlocks.cpp | 6 +++--- src/llmq/quorums_chainlocks.h | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/llmq/quorums_chainlocks.cpp b/src/llmq/quorums_chainlocks.cpp index 593c683bb3..2cf46ad008 100644 --- a/src/llmq/quorums_chainlocks.cpp +++ b/src/llmq/quorums_chainlocks.cpp @@ -192,7 +192,7 @@ void CChainLocksHandler::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBl LOCK(cs); if (InternalHasConflictingChainLock(pindexNew->nHeight, pindexNew->GetBlockHash())) { - if (!inInvalidate) { + if (!inEnforceBestChainLock) { // we accepted this block when there was no lock yet, but now a conflicting lock appeared. Invalidate it. LogPrintf("CChainLocksHandler::%s -- conflicting lock after block was accepted, invalidating now\n", __func__); @@ -237,7 +237,7 @@ void CChainLocksHandler::EnforceBestChainLock() // Go backwards through the chain referenced by clsig until we find a block that is part of the main chain. // For each of these blocks, check if there are children that are NOT part of the chain referenced by clsig // and invalidate each of them. - inInvalidate = true; // avoid unnecessary ScheduleInvalidateBlock calls inside UpdatedBlockTip + inEnforceBestChainLock = true; // avoid unnecessary ScheduleInvalidateBlock calls inside UpdatedBlockTip while (pindex && !chainActive.Contains(pindex)) { // Invalidate all blocks that have the same prevBlockHash but are not equal to blockHash auto itp = mapPrevBlockIndex.equal_range(pindex->pprev->GetBlockHash()); @@ -252,7 +252,7 @@ void CChainLocksHandler::EnforceBestChainLock() pindex = pindex->pprev; } - inInvalidate = false; + inEnforceBestChainLock = false; } CValidationState state; diff --git a/src/llmq/quorums_chainlocks.h b/src/llmq/quorums_chainlocks.h index f38fb4eb4c..064d6bd417 100644 --- a/src/llmq/quorums_chainlocks.h +++ b/src/llmq/quorums_chainlocks.h @@ -11,6 +11,8 @@ #include "net.h" #include "chainparams.h" +#include + class CBlockIndex; class CScheduler; @@ -46,7 +48,7 @@ class CChainLocksHandler : public CRecoveredSigsListener private: CScheduler* scheduler; CCriticalSection cs; - bool inInvalidate{false}; + std::atomic inEnforceBestChainLock{false}; uint256 bestChainLockHash; CChainLockSig bestChainLock;