Skip to content

Commit 02db066

Browse files
authored
Fix loop in CLLMQUtils::GetQuorumConnections to add at least 2 connections (#2796)
* Fix warning about size_t to int conversion * Fix loop in CLLMQUtils::GetQuorumConnections to add at least 2 connections When reaching very small quorum sizes, the current algorithm results in only a single connection to be added. This would be fine usually, but is an issue when this connection fails. We should always have at least one backup connection. This fixes simple PoSe test failures where the quorum size gets down to 4 with one of the 4 members being down. If other nodes are unlucky to connect to this node, they fail as well even though 3 members in a quorum should work fine. * Update src/llmq/quorums_utils.cpp Co-Authored-By: codablock <ablock84@gmail.com>
1 parent 071b60d commit 02db066

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/llmq/quorums_utils.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,21 @@ std::set<CService> CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType
5050
for (size_t i = 0; i < mns.size(); i++) {
5151
auto& dmn = mns[i];
5252
if (dmn->proTxHash == forMember) {
53-
// Connect to nodes at indexes (i+2^k)%n, k: 0..floor(log2(n-1))-1, n: size of the quorum/ring
53+
// Connect to nodes at indexes (i+2^k)%n, where
54+
// k: 0..max(1, floor(log2(n-1))-1)
55+
// n: size of the quorum/ring
5456
int gap = 1;
55-
int gap_max = mns.size() - 1;
56-
while (gap_max >>= 1) {
57+
int gap_max = (int)mns.size() - 1;
58+
int k = 0;
59+
while ((gap_max >>= 1) || k <= 1) {
5760
size_t idx = (i + gap) % mns.size();
5861
auto& otherDmn = mns[idx];
5962
if (otherDmn == dmn) {
6063
continue;
6164
}
6265
result.emplace(otherDmn->pdmnState->addr);
6366
gap <<= 1;
67+
k++;
6468
}
6569
// there can be no two members with the same proTxHash, so return early
6670
break;

0 commit comments

Comments
 (0)