From 7c5710f64ba08799b8955b1b5df0bfecd8438a21 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 1 Feb 2021 18:21:52 +0300 Subject: [PATCH] chainlocks: Fix potential deadlock (#3972) Should fix this: ``` Previous lock order was: pnode->cs_sendProcessing net.cpp:2854 cs_main net_processing.cpp:3946 (TRY) mempool.cs net_processing.cpp:4183 (1) pto->cs_inventory net_processing.cpp:4183 pto->cs_filter net_processing.cpp:4233 (2) cs llmq/quorums_chainlocks.cpp:87 Current lock order is: cs_main llmq/quorums_chainlocks.cpp:138 (2) cs llmq/quorums_chainlocks.cpp:138 cs_vNodes net.cpp:3662 (1) cs_inventory ./net.h:1085 ``` --- src/llmq/quorums_chainlocks.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/llmq/quorums_chainlocks.cpp b/src/llmq/quorums_chainlocks.cpp index aaaab1422f..eb17bd5dd4 100644 --- a/src/llmq/quorums_chainlocks.cpp +++ b/src/llmq/quorums_chainlocks.cpp @@ -135,7 +135,7 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock } { - LOCK2(cs_main, cs); + LOCK(cs); if (InternalHasConflictingChainLock(clsig.nHeight, clsig.blockHash)) { // This should not happen. If it happens, it means that a malicious entity controls a large part of the MN @@ -144,13 +144,16 @@ void CChainLocksHandler::ProcessNewChainLock(NodeId from, const llmq::CChainLock __func__, clsig.ToString(), bestChainLock.ToString(), from); return; } + } + CInv inv(MSG_CLSIG, hash); + g_connman->RelayInv(inv, LLMQS_PROTO_VERSION); + + { + LOCK2(cs_main, cs); bestChainLockHash = hash; bestChainLock = clsig; - CInv inv(MSG_CLSIG, hash); - g_connman->RelayInv(inv, LLMQS_PROTO_VERSION); - const CBlockIndex* pindex = LookupBlockIndex(clsig.blockHash); if (!pindex) { // we don't know the block/header for this CLSIG yet, so bail out for now