Skip to content

Commit

Permalink
fix: avoid lock order inversion between cs_main and cs_quorumBaseBloc…
Browse files Browse the repository at this point in the history
…kIndexCache
  • Loading branch information
PastaPastaPasta committed Nov 21, 2024
1 parent 9f5903c commit e6a28c4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,13 @@ CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, const uint25
{
const CBlockIndex* pQuorumBaseBlockIndex = [&]() {
// Lock contention may still be high here; consider using a shared lock
LOCK(cs_quorumBaseBlockIndexCache);
// We cannot hold cs_quorumBaseBlockIndexCache the whole time as that creates lock-order inversion with cs_main;
// We cannot aquire cs_main if we have cs_quorumBaseBlockIndexCache held
const CBlockIndex* pindex;
if (!quorumBaseBlockIndexCache.get(quorumHash, pindex)) {
if (!WITH_LOCK(cs_quorumBaseBlockIndexCache, return quorumBaseBlockIndexCache.get(quorumHash, pindex))) {
pindex = WITH_LOCK(cs_main, return m_chainstate.m_blockman.LookupBlockIndex(quorumHash));
if (pindex) {
LOCK(cs_quorumBaseBlockIndexCache);
quorumBaseBlockIndexCache.insert(quorumHash, pindex);
}
}
Expand Down

0 comments on commit e6a28c4

Please sign in to comment.