Skip to content

Commit

Permalink
Rename inInvalidate->inEnforceBestChainLock and make it atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 28, 2019
1 parent 5033d5e commit 3237668
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/llmq/quorums_chainlocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down Expand Up @@ -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());
Expand All @@ -252,7 +252,7 @@ void CChainLocksHandler::EnforceBestChainLock()

pindex = pindex->pprev;
}
inInvalidate = false;
inEnforceBestChainLock = false;
}

CValidationState state;
Expand Down
4 changes: 3 additions & 1 deletion src/llmq/quorums_chainlocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "net.h"
#include "chainparams.h"

#include <atomic>

class CBlockIndex;
class CScheduler;

Expand Down Expand Up @@ -46,7 +48,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
private:
CScheduler* scheduler;
CCriticalSection cs;
bool inInvalidate{false};
std::atomic<bool> inEnforceBestChainLock{false};

uint256 bestChainLockHash;
CChainLockSig bestChainLock;
Expand Down

0 comments on commit 3237668

Please sign in to comment.