chainlocks: fix atomicity in chainlock signing scheduler (#4589)

Signed-off-by: pasta <pasta@dashboost.org>
This commit is contained in:
PastaPastaPasta 2021-11-29 00:06:50 -05:00 committed by GitHub
parent fec2d25094
commit 850806e6e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
tryLockChainTipScheduled = true;
// 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);
}
}
void CChainLocksHandler::CheckActiveState()