Skip to content

Commit

Permalink
Fix loop in CLLMQUtils::GetQuorumConnections to add at least 2 connec…
Browse files Browse the repository at this point in the history
…tions (#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>
  • Loading branch information
codablock committed Mar 22, 2019
1 parent 071b60d commit 02db066
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/llmq/quorums_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ std::set<CService> CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType
for (size_t i = 0; i < mns.size(); i++) {
auto& dmn = mns[i];
if (dmn->proTxHash == forMember) {
// Connect to nodes at indexes (i+2^k)%n, k: 0..floor(log2(n-1))-1, n: size of the quorum/ring
// Connect to nodes at indexes (i+2^k)%n, where
// k: 0..max(1, floor(log2(n-1))-1)
// n: size of the quorum/ring
int gap = 1;
int gap_max = mns.size() - 1;
while (gap_max >>= 1) {
int gap_max = (int)mns.size() - 1;
int k = 0;
while ((gap_max >>= 1) || k <= 1) {
size_t idx = (i + gap) % mns.size();
auto& otherDmn = mns[idx];
if (otherDmn == dmn) {
continue;
}
result.emplace(otherDmn->pdmnState->addr);
gap <<= 1;
k++;
}
// there can be no two members with the same proTxHash, so return early
break;
Expand Down

0 comments on commit 02db066

Please sign in to comment.