mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Move and unify logic for quorum connection establishment into CLLMQUtils
This commit is contained in:
parent
c0bb06e766
commit
364d6c37f7
@ -187,37 +187,14 @@ void CQuorumManager::EnsureQuorumConnections(Consensus::LLMQType llmqType, const
|
||||
auto curDkgBlock = pindexNew->GetAncestor(curDkgHeight)->GetBlockHash();
|
||||
connmanQuorumsToDelete.erase(curDkgBlock);
|
||||
|
||||
bool allowWatch = gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS);
|
||||
for (auto& quorum : lastQuorums) {
|
||||
if (!quorum->IsMember(myProTxHash) && !gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS)) {
|
||||
if (!quorum->IsMember(myProTxHash) && !allowWatch) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!g_connman->HasMasternodeQuorumNodes(llmqType, quorum->qc.quorumHash)) {
|
||||
std::set<uint256> connections;
|
||||
if (quorum->IsMember(myProTxHash)) {
|
||||
connections = CLLMQUtils::GetQuorumConnections(llmqType, quorum->pindexQuorum, myProTxHash);
|
||||
} else {
|
||||
auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqType, quorum->pindexQuorum, quorum->members.size(), 1);
|
||||
for (auto idx : cindexes) {
|
||||
connections.emplace(quorum->members[idx]->proTxHash);
|
||||
}
|
||||
}
|
||||
if (!connections.empty()) {
|
||||
if (LogAcceptCategory(BCLog::LLMQ)) {
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
std::string debugMsg = strprintf("CQuorumManager::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, quorum->qc.quorumHash.ToString());
|
||||
for (auto& c : connections) {
|
||||
auto dmn = mnList.GetValidMN(c);
|
||||
if (!dmn) {
|
||||
debugMsg += strprintf(" %s (not in valid MN set anymore)\n", c.ToString());
|
||||
} else {
|
||||
debugMsg += strprintf(" %s (%s)\n", c.ToString(), dmn->pdmnState->addr.ToString(false));
|
||||
}
|
||||
}
|
||||
LogPrint(BCLog::LLMQ, debugMsg.c_str());
|
||||
}
|
||||
g_connman->AddMasternodeQuorumNodes(llmqType, quorum->qc.quorumHash, connections);
|
||||
}
|
||||
CLLMQUtils::EnsureQuorumConnections(llmqType, quorum->pindexQuorum, myProTxHash, allowWatch);
|
||||
}
|
||||
connmanQuorumsToDelete.erase(quorum->qc.quorumHash);
|
||||
}
|
||||
|
@ -500,33 +500,7 @@ void CDKGSessionHandler::HandleDKGRound()
|
||||
return changed;
|
||||
});
|
||||
|
||||
if (curSession->AreWeMember() || gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS)) {
|
||||
std::set<uint256> connections;
|
||||
if (curSession->AreWeMember()) {
|
||||
connections = CLLMQUtils::GetQuorumConnections(params.type, pindexQuorum, curSession->myProTxHash);
|
||||
} else {
|
||||
auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(params.type, pindexQuorum, curSession->members.size(), 1);
|
||||
for (auto idx : cindexes) {
|
||||
connections.emplace(curSession->members[idx]->dmn->proTxHash);
|
||||
}
|
||||
}
|
||||
if (!connections.empty()) {
|
||||
if (LogAcceptCategory(BCLog::LLMQ_DKG)) {
|
||||
std::string debugMsg = strprintf("CDKGSessionManager::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, curSession->pindexQuorum->GetBlockHash().ToString());
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
for (const auto& c : connections) {
|
||||
auto dmn = mnList.GetValidMN(c);
|
||||
if (!dmn) {
|
||||
debugMsg += strprintf(" %s (not in valid MN set anymore)\n", c.ToString());
|
||||
} else {
|
||||
debugMsg += strprintf(" %s (%s)\n", c.ToString(), dmn->pdmnState->addr.ToString(false));
|
||||
}
|
||||
}
|
||||
LogPrint(BCLog::LLMQ_DKG, debugMsg.c_str());
|
||||
}
|
||||
g_connman->AddMasternodeQuorumNodes(params.type, curQuorumHash, connections);
|
||||
}
|
||||
}
|
||||
CLLMQUtils::EnsureQuorumConnections(params.type, pindexQuorum, curSession->myProTxHash, gArgs.GetBoolArg("-watchquorums", DEFAULT_WATCH_QUORUMS));
|
||||
|
||||
WaitForNextPhase(QuorumPhase_Initialized, QuorumPhase_Contribute, curQuorumHash, []{return false;});
|
||||
|
||||
|
@ -95,6 +95,42 @@ std::set<size_t> CLLMQUtils::CalcDeterministicWatchConnections(Consensus::LLMQTy
|
||||
return result;
|
||||
}
|
||||
|
||||
void CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexQuorum, const uint256& myProTxHash, bool allowWatch)
|
||||
{
|
||||
auto members = GetAllQuorumMembers(llmqType, pindexQuorum);
|
||||
bool isMember = std::find_if(members.begin(), members.end(), [&](const CDeterministicMNCPtr& dmn) { return dmn->proTxHash == myProTxHash; }) != members.end();
|
||||
|
||||
if (!isMember && !allowWatch) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<uint256> connections;
|
||||
if (isMember) {
|
||||
connections = CLLMQUtils::GetQuorumConnections(llmqType, pindexQuorum, myProTxHash);
|
||||
} else {
|
||||
auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqType, pindexQuorum, members.size(), 1);
|
||||
for (auto idx : cindexes) {
|
||||
connections.emplace(members[idx]->proTxHash);
|
||||
}
|
||||
}
|
||||
if (!connections.empty()) {
|
||||
if (LogAcceptCategory(BCLog::LLMQ)) {
|
||||
auto mnList = deterministicMNManager->GetListAtChainTip();
|
||||
std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pindexQuorum->GetBlockHash().ToString());
|
||||
for (auto& c : connections) {
|
||||
auto dmn = mnList.GetValidMN(c);
|
||||
if (!dmn) {
|
||||
debugMsg += strprintf(" %s (not in valid MN set anymore)\n", c.ToString());
|
||||
} else {
|
||||
debugMsg += strprintf(" %s (%s)\n", c.ToString(), dmn->pdmnState->addr.ToString(false));
|
||||
}
|
||||
}
|
||||
LogPrint(BCLog::LLMQ, debugMsg.c_str());
|
||||
}
|
||||
g_connman->AddMasternodeQuorumNodes(llmqType, pindexQuorum->GetBlockHash(), connections);
|
||||
}
|
||||
}
|
||||
|
||||
bool CLLMQUtils::IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash)
|
||||
{
|
||||
auto& params = Params().GetConsensus().llmqs.at(llmqType);
|
||||
|
@ -34,6 +34,8 @@ public:
|
||||
static std::set<uint256> GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& forMember);
|
||||
static std::set<size_t> CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, size_t memberCount, size_t connectionCount);
|
||||
|
||||
static void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexQuorum, const uint256& myProTxHash, bool allowWatch);
|
||||
|
||||
static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash);
|
||||
|
||||
template<typename NodesContainer, typename Continue, typename Callback>
|
||||
|
Loading…
Reference in New Issue
Block a user