Skip to content

Commit

Permalink
fix: move CheckQuorumConnections to a separate thread
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Nov 27, 2023
1 parent e6d6e8a commit 153177c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
return;
}

for (const auto& params : Params().GetConsensus().llmqs) {
CheckQuorumConnections(params, pindexNew);
}
StartCheckQuorumConnectionsThreads(pindexNew);

{
// Cleanup expired data requests
Expand All @@ -299,8 +297,26 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial
CleanupOldQuorumData(pindexNew);
}

void CQuorumManager::StartCheckQuorumConnectionsThreads(const CBlockIndex* pindexNew) const
{
for (const auto& params : Params().GetConsensus().llmqs) {
// do not block the caller thread
workerPool.push([params, pindexNew, this](int threadId) {
CheckQuorumConnections(params, pindexNew);
});
}
}

void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const
{
cxxtimer::Timer t(/*start=*/ true);
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] start\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight);

if (quorumThreadInterrupt) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] aborted. time=%d\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, t.count());
return;
}

auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections);

auto connmanQuorumsToDelete = connman.GetMasternodeQuorums(llmqParams.type);
Expand Down Expand Up @@ -335,6 +351,10 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
});

for (const auto& quorum : lastQuorums) {
if (quorumThreadInterrupt) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] aborted. time=%d\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, t.count());
return;
}
if (utils::EnsureQuorumConnections(llmqParams, quorum->m_quorum_base_block_index, connman, myProTxHash)) {
if (connmanQuorumsToDelete.erase(quorum->qc->quorumHash) > 0) {
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] keeping mn quorum connections for quorum: [%d:%s]\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, quorum->m_quorum_base_block_index->nHeight, quorum->m_quorum_base_block_index->GetBlockHash().ToString());
Expand All @@ -361,6 +381,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- removing masternodes quorum connections for quorum %s:\n", __func__, quorumHash.ToString());
connman.RemoveMasternodeQuorumNodes(llmqParams.type, quorumHash);
}
LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- llmqType[%d] h[%d] done. time=%d\n", __func__, ToUnderlying(llmqParams.type), pindexNew->nHeight, t.count());
}

CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex) const
Expand Down
1 change: 1 addition & 0 deletions src/llmq/quorums.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class CQuorumManager

private:
// all private methods here are cs_main-free
void StartCheckQuorumConnectionsThreads(const CBlockIndex *pindexNew) const;
void CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pindexNew) const;

CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex) const;
Expand Down

0 comments on commit 153177c

Please sign in to comment.