diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index f55f20434ce6c..3a5fffb097e31 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -535,12 +535,11 @@ std::vector CQuorumManager::ScanQuorums(Consensus::LLMQType llmqTyp 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 MAX_CYCLES of the most recent quorums + // And we only do this for max_cycles() 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; scanQuorumsCache.emplace(std::piecewise_construct, std::forward_as_tuple(llmq.type), - std::forward_as_tuple(MAX_CYCLES * (llmq.dkgMiningWindowEnd - llmq.dkgMiningWindowStart))); + std::forward_as_tuple(utils::max_cycles(llmq, llmq.keepOldConnections) * (llmq.dkgMiningWindowEnd - llmq.dkgMiningWindowStart))); } } auto& cache = scanQuorumsCache[llmqType]; diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 6f69e3c6155c4..188b917336f89 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -119,11 +119,15 @@ void IterateNodesRandom(NodesContainer& nodeStates, Continue&& cont, Callback&& template void InitQuorumsCache(CacheType& cache, bool limit_by_connections = true); +[[ nodiscard ]] static constexpr int max_cycles(const Consensus::LLMQParams& llmqParams, int quorums_count) +{ + return llmqParams.useRotation ? quorums_count / llmqParams.signingActiveQuorumCount : quorums_count; +} + [[ nodiscard ]] static constexpr int max_store_depth(const Consensus::LLMQParams& llmqParams) { // For how many blocks recent DKG info should be kept - const int MAX_CYCLES = llmqParams.useRotation ? llmqParams.keepOldKeys / llmqParams.signingActiveQuorumCount : llmqParams.keepOldKeys; - return MAX_CYCLES * llmqParams.dkgInterval; + return max_cycles(llmqParams, llmqParams.keepOldKeys) * llmqParams.dkgInterval; } } // namespace utils