Skip to content

Commit e9e0f58

Browse files
committed
refactor: inline GetMNUsageBySnapshot to simplify code
1 parent 46383b1 commit e9e0f58

File tree

1 file changed

+18
-39
lines changed

1 file changed

+18
-39
lines changed

src/llmq/utils.cpp

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ static PreviousQuorumQuarters GetPreviousQuorumQuarterMembers(const Consensus::L
7676
static std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot(
7777
const Consensus::LLMQParams& llmqParams, CDeterministicMNManager& dmnman,
7878
const CBlockIndex* pCycleQuorumBaseBlockIndex, const llmq::CQuorumSnapshot& snapshot, int nHeight);
79-
static std::vector<CDeterministicMNCPtr> GetMNUsageBySnapshot(const Consensus::LLMQParams& llmqParams,
80-
const CDeterministicMNList& mn_list,
81-
const CBlockIndex* pCycleQuorumBaseBlockIndex,
82-
const llmq::CQuorumSnapshot& snapshot);
8379

8480
static void BuildQuorumSnapshot(const Consensus::LLMQParams& llmqParams, const CDeterministicMNList& allMns,
8581
const CDeterministicMNList& mnUsedAtH,
@@ -620,8 +616,25 @@ std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot
620616
const CBlockIndex* pWorkBlockIndex = pCycleQuorumBaseBlockIndex->GetAncestor(
621617
pCycleQuorumBaseBlockIndex->nHeight - 8);
622618
auto mn_list = dmnman.GetListForBlock(pWorkBlockIndex);
619+
const auto modifier = GetHashModifier(llmqParams, pCycleQuorumBaseBlockIndex);
620+
auto sortedAllMns = CalculateQuorum(mn_list, modifier);
621+
622+
std::vector<CDeterministicMNCPtr> usedMNs;
623+
size_t i{0};
624+
for (const auto& dmn : sortedAllMns) {
625+
if (snapshot.activeQuorumMembers[i]) {
626+
usedMNs.push_back(dmn);
627+
} else {
628+
if (!dmn->pdmnState->IsBanned()) {
629+
// the list begins with all the unused MNs
630+
sortedCombinedMns.push_back(dmn);
631+
}
632+
}
633+
i++;
634+
}
623635

624-
sortedCombinedMns = GetMNUsageBySnapshot(llmqParams, mn_list, pCycleQuorumBaseBlockIndex, snapshot);
636+
// Now add the already used MNs to the end of the list
637+
std::move(usedMNs.begin(), usedMNs.end(), std::back_inserter(sortedCombinedMns));
625638
}
626639

627640
if (LogAcceptDebug(BCLog::LLMQ)) {
@@ -697,40 +710,6 @@ std::vector<std::vector<CDeterministicMNCPtr>> GetQuorumQuarterMembersBySnapshot
697710
}
698711
}
699712

700-
static std::vector<CDeterministicMNCPtr> GetMNUsageBySnapshot(const Consensus::LLMQParams& llmqParams,
701-
const CDeterministicMNList& mn_list,
702-
const CBlockIndex* pCycleQuorumBaseBlockIndex,
703-
const llmq::CQuorumSnapshot& snapshot)
704-
{
705-
if (!llmqParams.useRotation || pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval != 0) {
706-
ASSERT_IF_DEBUG(false);
707-
return {};
708-
}
709-
710-
std::vector<CDeterministicMNCPtr> usedMNs;
711-
std::vector<CDeterministicMNCPtr> nonUsedMNs;
712-
713-
const auto modifier = GetHashModifier(llmqParams, pCycleQuorumBaseBlockIndex);
714-
auto sortedAllMns = CalculateQuorum(mn_list, modifier);
715-
716-
size_t i{0};
717-
for (const auto& dmn : sortedAllMns) {
718-
if (snapshot.activeQuorumMembers[i]) {
719-
usedMNs.push_back(dmn);
720-
} else {
721-
if (!dmn->pdmnState->IsBanned()) {
722-
nonUsedMNs.push_back(dmn);
723-
}
724-
}
725-
i++;
726-
}
727-
728-
// the list begins with all the unused MNs
729-
// Now add the already used MNs to the end of the list
730-
std::move(usedMNs.begin(), usedMNs.end(), std::back_inserter(nonUsedMNs));
731-
return nonUsedMNs;
732-
}
733-
734713
uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2)
735714
{
736715
// We need to deterministically select who is going to initiate the connection. The naive way would be to simply

0 commit comments

Comments
 (0)