mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
chainlocks: fix atomicity in chainlock signing scheduler (#4589)
Signed-off-by: pasta <pasta@dashboost.org>
This commit is contained in:
parent
fec2d25094
commit
850806e6e7
@ -207,16 +207,15 @@ void CChainLocksHandler::UpdatedBlockTip(const CBlockIndex* pindexNew)
|
||||
// don't call TrySignChainTip directly but instead let the scheduler call it. This way we ensure that cs_main is
|
||||
// never locked and TrySignChainTip is not called twice in parallel. Also avoids recursive calls due to
|
||||
// EnforceBestChainLock switching chains.
|
||||
if (tryLockChainTipScheduled) {
|
||||
return;
|
||||
// atomic[If tryLockChainTipScheduled is false, do (set it to true] and schedule signing).
|
||||
if (bool expected = false; tryLockChainTipScheduled.compare_exchange_strong(expected, true)) {
|
||||
scheduler->scheduleFromNow([&]() {
|
||||
CheckActiveState();
|
||||
EnforceBestChainLock();
|
||||
TrySignChainTip();
|
||||
tryLockChainTipScheduled = false;
|
||||
}, 0);
|
||||
}
|
||||
tryLockChainTipScheduled = true;
|
||||
scheduler->scheduleFromNow([&]() {
|
||||
CheckActiveState();
|
||||
EnforceBestChainLock();
|
||||
TrySignChainTip();
|
||||
tryLockChainTipScheduled = false;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
void CChainLocksHandler::CheckActiveState()
|
||||
|
Loading…
Reference in New Issue
Block a user