Skip to content

Commit b3a1c8b

Browse files
UdjinM6PastaPastaPasta
authored andcommitted
fix: ScanQuorums should not start cache population for outdated quorums (dashpay#5784)
## Issue being fixed or feature implemented Cache population for old quorums is a cpu heavy operation and should be avoided for inactive quorums _at least_ oin `ScanQuorums`. This issue is critical for testnet and other small network because every mn participate in almost every platform quorum and cache population for 2 months of quorums can easily block everything for 15+ minutes on a 4 cpu node. On mainnet quorum distribution is much better but it's still a small waste of cpu (or not so small for unlucky nodes). dashpay#5761 follow-up ## What was done? Do not start cache population for outdated quorums, improve logs in `StartCachePopulatorThread` to make it easier to see what's going on. ## How Has This Been Tested? run a mn on testnet ## Breaking Changes n/a ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_
1 parent 71e7658 commit b3a1c8b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/llmq/quorums.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void CQuorumManager::CheckQuorumConnections(const Consensus::LLMQParams& llmqPar
362362
}
363363
}
364364

365-
CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex) const
365+
CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool populate_cache) const
366366
{
367367
const uint256& quorumHash{pQuorumBaseBlockIndex->GetBlockHash()};
368368
uint256 minedBlockHash;
@@ -392,7 +392,7 @@ CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType l
392392
}
393393
}
394394

395-
if (hasValidVvec) {
395+
if (hasValidVvec && populate_cache) {
396396
// pre-populate caches in the background
397397
// recovering public key shares is quite expensive and would result in serious lags for the first few signing
398398
// sessions if the shares would be calculated on-demand
@@ -572,7 +572,9 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp
572572

573573
for (auto& pQuorumBaseBlockIndex : pQuorumBaseBlockIndexes) {
574574
assert(pQuorumBaseBlockIndex);
575-
auto quorum = GetQuorum(llmqType, pQuorumBaseBlockIndex);
575+
// populate cache for keepOldConnections most recent quorums only
576+
bool populate_cache = vecResultQuorums.size() < llmq_params_opt->keepOldConnections;
577+
auto quorum = GetQuorum(llmqType, pQuorumBaseBlockIndex, populate_cache);
576578
assert(quorum != nullptr);
577579
vecResultQuorums.emplace_back(quorum);
578580
}
@@ -602,7 +604,7 @@ CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, const uint25
602604
return GetQuorum(llmqType, pQuorumBaseBlockIndex);
603605
}
604606

605-
CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex) const
607+
CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool populate_cache) const
606608
{
607609
auto quorumHash = pQuorumBaseBlockIndex->GetBlockHash();
608610

@@ -617,7 +619,7 @@ CQuorumCPtr CQuorumManager::GetQuorum(Consensus::LLMQType llmqType, gsl::not_nul
617619
return pQuorum;
618620
}
619621

620-
return BuildQuorumFromCommitment(llmqType, pQuorumBaseBlockIndex);
622+
return BuildQuorumFromCommitment(llmqType, pQuorumBaseBlockIndex, populate_cache);
621623
}
622624

623625
size_t CQuorumManager::GetQuorumRecoveryStartOffset(const CQuorumCPtr pQuorum, const CBlockIndex* pIndex) const
@@ -850,7 +852,10 @@ void CQuorumManager::StartCachePopulatorThread(const CQuorumCPtr pQuorum) const
850852
}
851853

852854
cxxtimer::Timer t(true);
853-
LogPrint(BCLog::LLMQ, "CQuorumManager::StartCachePopulatorThread -- start\n");
855+
LogPrint(BCLog::LLMQ, "CQuorumManager::StartCachePopulatorThread -- type=%d height=%d hash=%s start\n",
856+
ToUnderlying(pQuorum->params.type),
857+
pQuorum->m_quorum_base_block_index->nHeight,
858+
pQuorum->m_quorum_base_block_index->GetBlockHash().ToString());
854859

855860
// when then later some other thread tries to get keys, it will be much faster
856861
workerPool.push([pQuorum, t, this](int threadId) {
@@ -862,7 +867,11 @@ void CQuorumManager::StartCachePopulatorThread(const CQuorumCPtr pQuorum) const
862867
pQuorum->GetPubKeyShare(i);
863868
}
864869
}
865-
LogPrint(BCLog::LLMQ, "CQuorumManager::StartCachePopulatorThread -- done. time=%d\n", t.count());
870+
LogPrint(BCLog::LLMQ, "CQuorumManager::StartCachePopulatorThread -- type=%d height=%d hash=%s done. time=%d\n",
871+
ToUnderlying(pQuorum->params.type),
872+
pQuorum->m_quorum_base_block_index->nHeight,
873+
pQuorum->m_quorum_base_block_index->GetBlockHash().ToString(),
874+
t.count());
866875
});
867876
}
868877

src/llmq/quorums.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ class CQuorumManager
267267
// all private methods here are cs_main-free
268268
void CheckQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pindexNew) const;
269269

270-
CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex) const;
270+
CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pQuorumBaseBlockIndex, bool populate_cache) const;
271271
bool BuildQuorumContributions(const CFinalCommitmentPtr& fqc, const std::shared_ptr<CQuorum>& quorum) const;
272272

273-
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindex) const;
273+
CQuorumCPtr GetQuorum(Consensus::LLMQType llmqType, gsl::not_null<const CBlockIndex*> pindex, bool populate_cache = true) const;
274274
/// Returns the start offset for the masternode with the given proTxHash. This offset is applied when picking data recovery members of a quorum's
275275
/// memberlist and is calculated based on a list of all member of all active quorums for the given llmqType in a way that each member
276276
/// should receive the same number of request if all active llmqType members requests data from one llmqType quorum.

0 commit comments

Comments
 (0)