mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
Rename inInvalidate->inEnforceBestChainLock and make it atomic
This commit is contained in:
parent
5033d5ef4a
commit
3237668b1d
@ -192,7 +192,7 @@ void CChainLocksHandler::UpdatedBlockTip(const CBlockIndex* pindexNew, const CBl
|
|||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
|
||||||
if (InternalHasConflictingChainLock(pindexNew->nHeight, pindexNew->GetBlockHash())) {
|
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.
|
// 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",
|
LogPrintf("CChainLocksHandler::%s -- conflicting lock after block was accepted, invalidating now\n",
|
||||||
__func__);
|
__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.
|
// 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
|
// 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.
|
// 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)) {
|
while (pindex && !chainActive.Contains(pindex)) {
|
||||||
// Invalidate all blocks that have the same prevBlockHash but are not equal to blockHash
|
// Invalidate all blocks that have the same prevBlockHash but are not equal to blockHash
|
||||||
auto itp = mapPrevBlockIndex.equal_range(pindex->pprev->GetBlockHash());
|
auto itp = mapPrevBlockIndex.equal_range(pindex->pprev->GetBlockHash());
|
||||||
@ -252,7 +252,7 @@ void CChainLocksHandler::EnforceBestChainLock()
|
|||||||
|
|
||||||
pindex = pindex->pprev;
|
pindex = pindex->pprev;
|
||||||
}
|
}
|
||||||
inInvalidate = false;
|
inEnforceBestChainLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CValidationState state;
|
CValidationState state;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "chainparams.h"
|
#include "chainparams.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
class CBlockIndex;
|
class CBlockIndex;
|
||||||
class CScheduler;
|
class CScheduler;
|
||||||
|
|
||||||
@ -46,7 +48,7 @@ class CChainLocksHandler : public CRecoveredSigsListener
|
|||||||
private:
|
private:
|
||||||
CScheduler* scheduler;
|
CScheduler* scheduler;
|
||||||
CCriticalSection cs;
|
CCriticalSection cs;
|
||||||
bool inInvalidate{false};
|
std::atomic<bool> inEnforceBestChainLock{false};
|
||||||
|
|
||||||
uint256 bestChainLockHash;
|
uint256 bestChainLockHash;
|
||||||
CChainLockSig bestChainLock;
|
CChainLockSig bestChainLock;
|
||||||
|
Loading…
Reference in New Issue
Block a user