Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve quorum caching (again) #5761

Merged
merged 10 commits into from
Dec 20, 2023
14 changes: 12 additions & 2 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ CQuorumManager::CQuorumManager(CBLSWorker& _blsWorker, CChainState& chainstate,
m_peerman(peerman)
{
utils::InitQuorumsCache(mapQuorumsCache, false);
utils::InitQuorumsCache(scanQuorumsCache, false);

quorumThreadInterrupt.reset();
}

Expand Down Expand Up @@ -533,6 +531,18 @@ std::vector<CQuorumCPtr> CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp

{
LOCK(cs_scan_quorums);
if (scanQuorumsCache.empty()) {
for (const auto& llmq : Params().GetConsensus().llmqs) {
// NOTE: We store it for each block hash in the DKG mining phase here
// and not for a single quorum hash per quorum like we do for other caches.
// And we only do this for GetMaxCacheCycles() of the most recent quorums
// because signing by old quorums requires the exact quorum hash to be specified
// and quorum scanning isn't needed there.
const int MAX_CYCLES = llmq.useRotation ? llmq.keepOldConnections / llmq.signingActiveQuorumCount : llmq.keepOldConnections;
knst marked this conversation as resolved.
Show resolved Hide resolved
scanQuorumsCache.emplace(std::piecewise_construct, std::forward_as_tuple(llmq.type),
PastaPastaPasta marked this conversation as resolved.
Show resolved Hide resolved
std::forward_as_tuple(MAX_CYCLES * (llmq.dkgMiningWindowEnd - llmq.dkgMiningWindowStart)));
}
}
auto& cache = scanQuorumsCache[llmqType];
bool fCacheExists = cache.get(pindexStore->GetBlockHash(), vecResultQuorums);
if (fCacheExists) {
Expand Down