diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 0ded034b7479a1..95b7f0fb38e05e 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -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); } }