Skip to content

Commit

Permalink
refactor: add and use max_cycles() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 committed Dec 17, 2023
1 parent d241a65 commit 947c626
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/llmq/quorums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,11 @@ std::vector<CQuorumCPtr> 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];
Expand Down
8 changes: 6 additions & 2 deletions src/llmq/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,15 @@ void IterateNodesRandom(NodesContainer& nodeStates, Continue&& cont, Callback&&
template <typename CacheType>
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
Expand Down

0 comments on commit 947c626

Please sign in to comment.