From 252ee89c344205290f7801aedf4adca7bfc6ae05 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Tue, 19 Feb 2019 13:05:39 +0300 Subject: [PATCH] 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 --- src/chainparams.cpp | 8 -------- src/consensus/params.h | 8 -------- src/llmq/quorums_utils.cpp | 22 ++++++++-------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9da69c787..40a837afb 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -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, }; diff --git a/src/consensus/params.h b/src/consensus/params.h index 644a1a11e..083cbacfa 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -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; diff --git a/src/llmq/quorums_utils.cpp b/src/llmq/quorums_utils.cpp index 525606a5f..76583b960 100644 --- a/src/llmq/quorums_utils.cpp +++ b/src/llmq/quorums_utils.cpp @@ -50,26 +50,20 @@ std::set 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;