Skip to content

Commit

Permalink
Fix deadlock in CSigSharesManager::SendMessages
Browse files Browse the repository at this point in the history
Locking "cs" at this location caused a (potential) deadlock due to changed
order of cs and cs_vNodes locking. This changes the method to not require
the session object anymore which removes the need for locking.
  • Loading branch information
codablock committed Mar 11, 2019
1 parent 64ae912 commit c75d534
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/llmq/quorums_signing_shares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ CSigSharesInv CBatchedSigShares::ToInv(Consensus::LLMQType llmqType) const
return inv;
}

std::string CBatchedSigShares::ToInvString() const
{
// we use LLMQ_400_60 here no matter what the real type is. The llmqType is only used to properly initialize the
// inv object's bitset. We don't really care about that size as we just want to call ToString()
return ToInv(Consensus::LLMQ_400_60).ToString();
}

template<typename T>
static void InitSession(CSigSharesNodeState::Session& s, const uint256& signHash, T& from)
{
Expand Down Expand Up @@ -443,7 +450,7 @@ bool CSigSharesManager::ProcessMessageBatchedSigShares(CNode* pfrom, const CBatc
}

LogPrint("llmq", "CSigSharesManager::%s -- signHash=%s, shares=%d, new=%d, inv={%s}, node=%d\n", __func__,
sessionInfo.signHash.ToString(), batchedSigShares.sigShares.size(), sigShares.size(), batchedSigShares.ToInv(sessionInfo.llmqType).ToString(), pfrom->id);
sessionInfo.signHash.ToString(), batchedSigShares.sigShares.size(), sigShares.size(), batchedSigShares.ToInvString(), pfrom->id);

if (sigShares.empty()) {
return true;
Expand Down Expand Up @@ -1101,14 +1108,8 @@ bool CSigSharesManager::SendMessages()
std::vector<CBatchedSigShares> msgs;
for (auto& p : jt->second) {
assert(!p.second.sigShares.empty());
if (LogAcceptCategory("llmq")) {
LOCK(cs);
auto session = nodeStates[pnode->id].GetSessionBySignHash(p.first);
assert(session);
LogPrint("llmq", "CSigSharesManager::SendMessages -- QBSIGSHARES signHash=%s, inv={%s}, node=%d\n",
p.first.ToString(), p.second.ToInv(session->llmqType).ToString(), pnode->id);
}

LogPrint("llmq", "CSigSharesManager::SendMessages -- QBSIGSHARES signHash=%s, inv={%s}, node=%d\n",
p.first.ToString(), p.second.ToInvString(), pnode->id);
if (totalSigsCount + p.second.sigShares.size() > MAX_MSGS_TOTAL_BATCHED_SIGS) {
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::QBSIGSHARES, msgs), false);
msgs.clear();
Expand Down
1 change: 1 addition & 0 deletions src/llmq/quorums_signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class CBatchedSigShares
}

CSigSharesInv ToInv(Consensus::LLMQType llmqType) const;
std::string ToInvString() const;
};

template<typename T>
Expand Down

0 comments on commit c75d534

Please sign in to comment.