From 9f4d431b52a08a23acc6df5c0caef3ed44af8cc8 Mon Sep 17 00:00:00 2001 From: PastaPastaPasta <6443210+PastaPastaPasta@users.noreply.github.com> Date: Mon, 20 Feb 2023 04:12:49 -0600 Subject: [PATCH] refactor: minimize GetLLMQParams calls (#5211) ## Issue being fixed or feature implemented Avoid redundant calls to GetLLMQParams ## What was done? ## How Has This Been Tested? ## Breaking Changes ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation **For repository code-owners and collaborators only** - [x] I have assigned this pull request to a milestone --- src/llmq/signing_shares.cpp | 2 +- src/llmq/utils.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/llmq/signing_shares.cpp b/src/llmq/signing_shares.cpp index 42ec9aa327..59a1411278 100644 --- a/src/llmq/signing_shares.cpp +++ b/src/llmq/signing_shares.cpp @@ -97,7 +97,7 @@ std::string CBatchedSigShares::ToInvString() const static void InitSession(CSigSharesNodeState::Session& s, const uint256& signHash, CSigBase from) { - const auto& llmq_params = GetLLMQParams((Consensus::LLMQType)from.getLlmqType()); + const auto& llmq_params = GetLLMQParams(from.getLlmqType()); s.llmqType = from.getLlmqType(); s.quorumHash = from.getQuorumHash(); diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 36b03d18f8..552d2abb70 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -35,7 +35,7 @@ namespace utils { // Forward declarations static std::vector ComputeQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex); -static std::vector> ComputeQuorumMembersByQuarterRotation(Consensus::LLMQType llmqType, const CBlockIndex* pCycleQuorumBaseBlockIndex); +static std::vector> ComputeQuorumMembersByQuarterRotation(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex); static std::vector> BuildNewQuorumQuarterMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const PreviousQuorumQuarters& quarters); @@ -112,7 +112,7 @@ std::vector GetAllQuorumMembers(Consensus::LLMQType llmqTy return quorumMembers; } - auto q = ComputeQuorumMembersByQuarterRotation(llmqType, pCycleQuorumBaseBlockIndex); + auto q = ComputeQuorumMembersByQuarterRotation(llmqParams, pCycleQuorumBaseBlockIndex); LOCK(cs_indexed_members); for (const size_t i : irange::range(q.size())) { mapIndexedQuorumMembers[llmqType].insert(std::make_pair(pCycleQuorumBaseBlockIndex->GetBlockHash(), i), q[i]); @@ -136,9 +136,9 @@ std::vector ComputeQuorumMembers(Consensus::LLMQType llmqT return allMns.CalculateQuorum(GetLLMQParams(llmqType).size, modifier, HPMNOnly); } -std::vector> ComputeQuorumMembersByQuarterRotation(Consensus::LLMQType llmqType, const CBlockIndex* pCycleQuorumBaseBlockIndex) +std::vector> ComputeQuorumMembersByQuarterRotation(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex) { - const Consensus::LLMQParams& llmqParams = GetLLMQParams(llmqType); + const Consensus::LLMQType llmqType = llmqParams.type; const int cycleLength = llmqParams.dkgInterval; assert(pCycleQuorumBaseBlockIndex->nHeight % cycleLength == 0); @@ -610,12 +610,14 @@ bool IsQuorumRotationEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pi { assert(pindex); - if (!GetLLMQParams(llmqType).useRotation) { + const auto& llmqParams = GetLLMQParams(llmqType); + + if (!llmqParams.useRotation) { return false; } LOCK(cs_llmq_vbc); - int cycleQuorumBaseHeight = pindex->nHeight - (pindex->nHeight % GetLLMQParams(llmqType).dkgInterval); + int cycleQuorumBaseHeight = pindex->nHeight - (pindex->nHeight % llmqParams.dkgInterval); if (cycleQuorumBaseHeight < 1) { return false; }