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
```
This commit is contained in:
UdjinM6 2021-02-01 18:21:52 +03:00 committed by GitHub
parent 7099dea2e4
commit 7c5710f64b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}
bestChainLockHash = hash;
bestChainLock = clsig;
}
CInv inv(MSG_CLSIG, hash);
g_connman->RelayInv(inv, LLMQS_PROTO_VERSION);
{
LOCK2(cs_main, cs);
bestChainLockHash = hash;
bestChainLock = clsig;
const CBlockIndex* pindex = LookupBlockIndex(clsig.blockHash);
if (!pindex) {
// we don't know the block/header for this CLSIG yet, so bail out for now