Implement new algo for quorum connections (#2710)

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
This commit is contained in:
UdjinM6 2019-02-19 13:05:39 +03:00 committed by GitHub
parent a79b928532
commit 252ee89c34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 30 deletions

View File

@ -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,
};
@ -142,8 +140,6 @@ static Consensus::LLMQParams llmq50_60 = {
.signingActiveQuorumCount = 24, // a full day worth of LLMQs
.neighborConnections = 2,
.diagonalConnections = 2,
.keepOldConnections = 24,
};
@ -162,8 +158,6 @@ static Consensus::LLMQParams llmq400_60 = {
.signingActiveQuorumCount = 4, // two days worth of LLMQs
.neighborConnections = 4,
.diagonalConnections = 4,
.keepOldConnections = 4,
};
@ -183,8 +177,6 @@ static Consensus::LLMQParams llmq400_85 = {
.signingActiveQuorumCount = 4, // two days worth of LLMQs
.neighborConnections = 4,
.diagonalConnections = 4,
.keepOldConnections = 4,
};

View File

@ -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;

View File

@ -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;