Disable new connection handling and concentrated recovery for large LLMQs (#3548)

* Rename CollectSigSharesToSend to CollectSigSharesToSendConcentrated

* Allow to disable concentrated recovery and new connection handling for large LLMQs
This commit is contained in:
Alexander Block 2020-06-25 09:47:24 +02:00
parent c72bc354f8
commit 772b6bfe7c
6 changed files with 43 additions and 15 deletions

View File

@ -446,7 +446,7 @@ void CDKGSession::VerifyAndComplain(CDKGPendingMessages& pendingMessages)
void CDKGSession::VerifyConnectionAndMinProtoVersions() void CDKGSession::VerifyConnectionAndMinProtoVersions()
{ {
if (!sporkManager.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED)) { if (!CLLMQUtils::IsAllMembersConnectedEnabled(params.type)) {
return; return;
} }

View File

@ -530,7 +530,7 @@ void CDKGSessionHandler::HandleDKGRound()
}); });
CLLMQUtils::EnsureQuorumConnections(params.type, pindexQuorum, curSession->myProTxHash, gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS)); CLLMQUtils::EnsureQuorumConnections(params.type, pindexQuorum, curSession->myProTxHash, gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS));
if (curSession->AreWeMember() && sporkManager.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED)) { if (curSession->AreWeMember() && CLLMQUtils::IsAllMembersConnectedEnabled(params.type)) {
CLLMQUtils::AddQuorumProbeConnections(params.type, pindexQuorum, curSession->myProTxHash); CLLMQUtils::AddQuorumProbeConnections(params.type, pindexQuorum, curSession->myProTxHash);
} }

View File

@ -739,7 +739,7 @@ void CSigSharesManager::ProcessSigShare(NodeId nodeId, const CSigShare& sigShare
// prepare node set for direct-push in case this is our sig share // prepare node set for direct-push in case this is our sig share
std::set<NodeId> quorumNodes; std::set<NodeId> quorumNodes;
if (!sporkManager.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED)) { if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType)) {
if (sigShare.quorumMember == quorum->GetMemberIndex(activeMasternodeInfo.proTxHash)) { if (sigShare.quorumMember == quorum->GetMemberIndex(activeMasternodeInfo.proTxHash)) {
quorumNodes = connman.GetMasternodeQuorumNodes((Consensus::LLMQType) sigShare.llmqType, sigShare.quorumHash); quorumNodes = connman.GetMasternodeQuorumNodes((Consensus::LLMQType) sigShare.llmqType, sigShare.quorumHash);
} }
@ -755,7 +755,9 @@ void CSigSharesManager::ProcessSigShare(NodeId nodeId, const CSigShare& sigShare
if (!sigShares.Add(sigShare.GetKey(), sigShare)) { if (!sigShares.Add(sigShare.GetKey(), sigShare)) {
return; return;
} }
if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType)) {
sigSharesToAnnounce.Add(sigShare.GetKey(), true); sigSharesToAnnounce.Add(sigShare.GetKey(), true);
}
// Update the time we've seen the last sigShare // Update the time we've seen the last sigShare
timeSeenForSessions[sigShare.GetSignHash()] = GetAdjustedTime(); timeSeenForSessions[sigShare.GetSignHash()] = GetAdjustedTime();
@ -909,6 +911,10 @@ void CSigSharesManager::CollectSigSharesToRequest(std::unordered_map<NodeId, std
auto& signHash = p2.first; auto& signHash = p2.first;
auto& session = p2.second; auto& session = p2.second;
if (CLLMQUtils::IsAllMembersConnectedEnabled(session.llmqType)) {
continue;
}
if (quorumSigningManager->HasRecoveredSigForSession(signHash)) { if (quorumSigningManager->HasRecoveredSigForSession(signHash)) {
continue; continue;
} }
@ -982,6 +988,10 @@ void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::u
auto& signHash = p2.first; auto& signHash = p2.first;
auto& session = p2.second; auto& session = p2.second;
if (CLLMQUtils::IsAllMembersConnectedEnabled(session.llmqType)) {
continue;
}
if (quorumSigningManager->HasRecoveredSigForSession(signHash)) { if (quorumSigningManager->HasRecoveredSigForSession(signHash)) {
continue; continue;
} }
@ -1016,7 +1026,7 @@ void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::u
} }
} }
void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::vector<CSigShare>>& sigSharesToSend, const std::vector<CNode*>& vNodes) void CSigSharesManager::CollectSigSharesToSendConcentrated(std::unordered_map<NodeId, std::vector<CSigShare>>& sigSharesToSend, const std::vector<CNode*>& vNodes)
{ {
AssertLockHeld(cs); AssertLockHeld(cs);
@ -1031,6 +1041,10 @@ void CSigSharesManager::CollectSigSharesToSend(std::unordered_map<NodeId, std::v
auto curTime = GetTime<std::chrono::milliseconds>().count(); auto curTime = GetTime<std::chrono::milliseconds>().count();
for (auto& p : signedSessions) { for (auto& p : signedSessions) {
if (!CLLMQUtils::IsAllMembersConnectedEnabled(p.second.quorum->params.type)) {
continue;
}
if (p.second.attempt > p.second.quorum->params.recoveryMembers) { if (p.second.attempt > p.second.quorum->params.recoveryMembers) {
continue; continue;
} }
@ -1139,13 +1153,10 @@ bool CSigSharesManager::SendMessages()
{ {
LOCK(cs); LOCK(cs);
if (!sporkManager.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED)) {
CollectSigSharesToRequest(sigSharesToRequest); CollectSigSharesToRequest(sigSharesToRequest);
CollectSigSharesToSend(sigShareBatchesToSend); CollectSigSharesToSend(sigShareBatchesToSend);
CollectSigSharesToAnnounce(sigSharesToAnnounce); CollectSigSharesToAnnounce(sigSharesToAnnounce);
} else { CollectSigSharesToSendConcentrated(sigSharesToSend, vNodesCopy);
CollectSigSharesToSend(sigSharesToSend, vNodesCopy);
}
for (auto& p : sigSharesToRequest) { for (auto& p : sigSharesToRequest) {
for (auto& p2 : p.second) { for (auto& p2 : p.second) {
@ -1585,7 +1596,7 @@ void CSigSharesManager::Sign(const CQuorumCPtr& quorum, const uint256& id, const
signHash.ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), quorum->params.type, quorum->qc.quorumHash.ToString(), t.count()); signHash.ToString(), sigShare.id.ToString(), sigShare.msgHash.ToString(), quorum->params.type, quorum->qc.quorumHash.ToString(), t.count());
ProcessSigShare(-1, sigShare, *g_connman, quorum); ProcessSigShare(-1, sigShare, *g_connman, quorum);
if (sporkManager.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED)) { if (CLLMQUtils::IsAllMembersConnectedEnabled(quorum->params.type)) {
LOCK(cs); LOCK(cs);
auto& session = signedSessions[sigShare.GetSignHash()]; auto& session = signedSessions[sigShare.GetSignHash()];
session.sigShare = sigShare; session.sigShare = sigShare;
@ -1598,6 +1609,10 @@ void CSigSharesManager::Sign(const CQuorumCPtr& quorum, const uint256& id, const
// causes all known sigShares to be re-announced // causes all known sigShares to be re-announced
void CSigSharesManager::ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash) void CSigSharesManager::ForceReAnnouncement(const CQuorumCPtr& quorum, Consensus::LLMQType llmqType, const uint256& id, const uint256& msgHash)
{ {
if (!CLLMQUtils::IsAllMembersConnectedEnabled(llmqType)) {
return;
}
LOCK(cs); LOCK(cs);
auto signHash = CLLMQUtils::BuildSignHash(llmqType, quorum->qc.quorumHash, id, msgHash); auto signHash = CLLMQUtils::BuildSignHash(llmqType, quorum->qc.quorumHash, id, msgHash);
auto sigs = sigShares.GetAllForSignHash(signHash); auto sigs = sigShares.GetAllForSignHash(signHash);

View File

@ -450,7 +450,7 @@ private:
bool SendMessages(); bool SendMessages();
void CollectSigSharesToRequest(std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToRequest); void CollectSigSharesToRequest(std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToRequest);
void CollectSigSharesToSend(std::unordered_map<NodeId, std::unordered_map<uint256, CBatchedSigShares, StaticSaltedHasher>>& sigSharesToSend); void CollectSigSharesToSend(std::unordered_map<NodeId, std::unordered_map<uint256, CBatchedSigShares, StaticSaltedHasher>>& sigSharesToSend);
void CollectSigSharesToSend(std::unordered_map<NodeId, std::vector<CSigShare>>& sigSharesToSend, const std::vector<CNode*>& vNodes); void CollectSigSharesToSendConcentrated(std::unordered_map<NodeId, std::vector<CSigShare>>& sigSharesToSend, const std::vector<CNode*>& vNodes);
void CollectSigSharesToAnnounce(std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToAnnounce); void CollectSigSharesToAnnounce(std::unordered_map<NodeId, std::unordered_map<uint256, CSigSharesInv, StaticSaltedHasher>>& sigSharesToAnnounce);
bool SignPendingSigShares(); bool SignPendingSigShares();
void WorkThreadMain(); void WorkThreadMain();

View File

@ -44,6 +44,18 @@ uint256 CLLMQUtils::BuildSignHash(Consensus::LLMQType llmqType, const uint256& q
return h.GetHash(); return h.GetHash();
} }
bool CLLMQUtils::IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType)
{
auto spork21 = sporkManager.GetSporkValue(SPORK_21_QUORUM_ALL_CONNECTED);
if (spork21 == 0) {
return true;
}
if (spork21 == 1 && llmqType != Consensus::LLMQ_400_60 && llmqType != Consensus::LLMQ_400_85) {
return true;
}
return false;
}
uint256 CLLMQUtils::DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2) uint256 CLLMQUtils::DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2)
{ {
// We need to deterministically select who is going to initiate the connection. The naive way would be to simply // We need to deterministically select who is going to initiate the connection. The naive way would be to simply
@ -70,7 +82,7 @@ std::set<uint256> CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType,
{ {
auto& params = Params().GetConsensus().llmqs.at(llmqType); auto& params = Params().GetConsensus().llmqs.at(llmqType);
if (sporkManager.IsSporkActive(SPORK_21_QUORUM_ALL_CONNECTED)) { if (IsAllMembersConnectedEnabled(llmqType)) {
auto mns = GetAllQuorumMembers(llmqType, pindexQuorum); auto mns = GetAllQuorumMembers(llmqType, pindexQuorum);
std::set<uint256> result; std::set<uint256> result;

View File

@ -31,6 +31,7 @@ public:
return BuildSignHash((Consensus::LLMQType)s.llmqType, s.quorumHash, s.id, s.msgHash); return BuildSignHash((Consensus::LLMQType)s.llmqType, s.quorumHash, s.id, s.msgHash);
} }
static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType);
static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2); static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2);
static std::set<uint256> GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember, bool onlyOutbound); static std::set<uint256> GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember, bool onlyOutbound);
static std::set<uint256> GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember, bool onlyOutbound); static std::set<uint256> GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember, bool onlyOutbound);