Skip to content

Commit 730b018

Browse files
Merge #6898: refactor: change GetMasternodeQuorumNodes return type from unordered_set to vector
f0b71d5 refactor: change GetMasternodeQuorumNodes return type from unordered_set to vector (pasta) Pull request description: ## Issue being fixed or feature implemented Updated the GetMasternodeQuorumNodes method to return a vector of NodeId instead of an unordered_set. This change simplifies the logic for filtering and transforming nodes, enhancing readability and maintainability. Additionally, adjusted related code in ProcessSigShare to accommodate the new return type. It's better to use a vector over a set, as all users are just iterating through this. They don't actually benefit from the O(1) lookup, so let's get the better benefits of cache locality. ## What was done? ## How Has This Been Tested? ## Breaking Changes ## Checklist: _Go over all the following points, and put an `x` in all the boxes that apply._ - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK f0b71d5 kwvg: utACK f0b71d5 knst: utACK f0b71d5 Tree-SHA512: e7817d947b6e3b1681301062d5585dd5df44ddd30cce8f7c4fdcb730a16b8fe51c34f9774a3fc713f11d7c3c4d43332c4c386b093db332308c79f0086a578d4a
2 parents 13a44ef + f0b71d5 commit 730b018

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

src/llmq/signing_shares.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,11 @@ void CSigSharesManager::ProcessSigShare(PeerManager& peerman, const CSigShare& s
717717
auto llmqType = quorum->params.type;
718718
bool canTryRecovery = false;
719719

720+
const bool isAllMembersConnectedEnabled = IsAllMembersConnectedEnabled(llmqType, m_sporkman);
721+
720722
// prepare node set for direct-push in case this is our sig share
721-
std::unordered_set<NodeId> quorumNodes;
722-
if (!IsAllMembersConnectedEnabled(llmqType, m_sporkman) && sigShare.getQuorumMember() == quorum->GetMemberIndex(m_mn_activeman->GetProTxHash())) {
723+
std::vector<NodeId> quorumNodes;
724+
if (!isAllMembersConnectedEnabled && sigShare.getQuorumMember() == quorum->GetMemberIndex(m_mn_activeman->GetProTxHash())) {
723725
quorumNodes = connman.GetMasternodeQuorumNodes(sigShare.getLlmqType(), sigShare.getQuorumHash());
724726
}
725727

@@ -733,7 +735,7 @@ void CSigSharesManager::ProcessSigShare(PeerManager& peerman, const CSigShare& s
733735
if (!sigShares.Add(sigShare.GetKey(), sigShare)) {
734736
return;
735737
}
736-
if (!IsAllMembersConnectedEnabled(llmqType, m_sporkman)) {
738+
if (!isAllMembersConnectedEnabled) {
737739
sigSharesQueuedToAnnounce.Add(sigShare.GetKey(), true);
738740
}
739741

src/net.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4348,7 +4348,7 @@ Uint256HashSet CConnman::GetMasternodeQuorums(Consensus::LLMQType llmqType) cons
43484348
return result;
43494349
}
43504350

4351-
std::unordered_set<NodeId> CConnman::GetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash) const
4351+
std::vector<NodeId> CConnman::GetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash) const
43524352
{
43534353
LOCK2(m_nodes_mutex, cs_vPendingMasternodes);
43544354
auto it = masternodeQuorumNodes.find(std::make_pair(llmqType, quorumHash));
@@ -4357,16 +4357,18 @@ std::unordered_set<NodeId> CConnman::GetMasternodeQuorumNodes(Consensus::LLMQTyp
43574357
}
43584358
const auto& proRegTxHashes = it->second;
43594359

4360-
std::unordered_set<NodeId> nodes;
4361-
for (const auto pnode : m_nodes) {
4362-
if (pnode->fDisconnect) {
4363-
continue;
4364-
}
4365-
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
4366-
if (!pnode->qwatch && (verifiedProRegTxHash.IsNull() || !proRegTxHashes.count(verifiedProRegTxHash))) {
4367-
continue;
4368-
}
4369-
nodes.emplace(pnode->GetId());
4360+
std::vector<NodeId> nodes;
4361+
4362+
auto IsMasternodeQuorumNode = [&](const CNode* n) {
4363+
if (n->fDisconnect) return false;
4364+
const auto h = n->GetVerifiedProRegTxHash();
4365+
return n->qwatch || (!h.IsNull() && proRegTxHashes.contains(h));
4366+
};
4367+
4368+
for (NodeId id : m_nodes
4369+
| std::views::filter(IsMasternodeQuorumNode)
4370+
| std::views::transform([](const CNode* n){ return n->GetId(); })) {
4371+
nodes.push_back(id);
43704372
}
43714373
return nodes;
43724374
}

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ friend class CNode;
14851485
bool HasMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash) const;
14861486
Uint256HashSet GetMasternodeQuorums(Consensus::LLMQType llmqType) const;
14871487
// also returns QWATCH nodes
1488-
std::unordered_set<NodeId> GetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash) const;
1488+
std::vector<NodeId> GetMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash) const;
14891489
void RemoveMasternodeQuorumNodes(Consensus::LLMQType llmqType, const uint256& quorumHash);
14901490
bool IsMasternodeQuorumNode(const CNode* pnode, const CDeterministicMNList& tip_mn_list) const;
14911491
bool IsMasternodeQuorumRelayMember(const uint256& protxHash);

0 commit comments

Comments
 (0)