Skip to content

Commit

Permalink
Implement new algo for quorum connections (#2710)
Browse files Browse the repository at this point in the history
Instead of trying to manually figure out params for different quorum/ring sizes, connect to nodes at indexes (i+2^k)%n where k: 0..floor(log2(n-1))-1, n: size of the quorum/ring
  • Loading branch information
UdjinM6 committed Feb 19, 2019
1 parent a79b928 commit 252ee89
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 30 deletions.
8 changes: 0 additions & 8 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ static Consensus::LLMQParams llmq10_60 = {

.signingActiveQuorumCount = 2, // just a few ones to allow easier testing

.neighborConnections = 2,
.diagonalConnections = 2,
.keepOldConnections = 24,
};

Expand All @@ -142,8 +140,6 @@ static Consensus::LLMQParams llmq50_60 = {

.signingActiveQuorumCount = 24, // a full day worth of LLMQs

.neighborConnections = 2,
.diagonalConnections = 2,
.keepOldConnections = 24,
};

Expand All @@ -162,8 +158,6 @@ static Consensus::LLMQParams llmq400_60 = {

.signingActiveQuorumCount = 4, // two days worth of LLMQs

.neighborConnections = 4,
.diagonalConnections = 4,
.keepOldConnections = 4,
};

Expand All @@ -183,8 +177,6 @@ static Consensus::LLMQParams llmq400_85 = {

.signingActiveQuorumCount = 4, // two days worth of LLMQs

.neighborConnections = 4,
.diagonalConnections = 4,
.keepOldConnections = 4,
};

Expand Down
8 changes: 0 additions & 8 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ struct LLMQParams {
// Number of quorums to consider "active" for signing sessions
int signingActiveQuorumCount;

// Used for inter-quorum communication. This is the number of deterministic connections built to the clockwise
// neighbors on the circle shaped nodes topography
int neighborConnections;

// Used for inter-quorum communication. This is the number of deterministic connections built diagonally to the
// member on the circle shaped nodes topography.
int diagonalConnections;

// Used for inter-quorum communication. This is the number of quorums for which we should keep old connections. This
// should be at least as much as the active quorums set.
int keepOldConnections;
Expand Down
22 changes: 8 additions & 14 deletions src/llmq/quorums_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,20 @@ 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) {
for (int n = 0; n < params.neighborConnections; n++) {
size_t idx = (i + 1 + n) % mns.size();
auto& otherDmn = mns[idx];
if (otherDmn == dmn) {
continue;
}
result.emplace(otherDmn->pdmnState->addr);
}
size_t startIdx = i + mns.size() / 2;
startIdx -= (params.diagonalConnections / 2) * params.neighborConnections;
startIdx %= mns.size();
for (int n = 0; n < params.diagonalConnections; n++) {
size_t idx = startIdx + n * params.neighborConnections;
idx %= mns.size();
// Connect to nodes at indexes (i+2^k)%n, k: 0..floor(log2(n-1))-1, n: size of the quorum/ring
int gap = 1;
int gap_max = mns.size() - 1;
while (gap_max >>= 1) {
size_t idx = (i + gap) % mns.size();
auto& otherDmn = mns[idx];
if (otherDmn == dmn) {
continue;
}
result.emplace(otherDmn->pdmnState->addr);
gap <<= 1;
}
// there can be no two members with the same proTxHash, so return early
break;
}
}
return result;
Expand Down

0 comments on commit 252ee89

Please sign in to comment.