diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index 903664a0fe..f1f649507e 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -922,7 +922,7 @@ void CDeterministicMNManager::HandleQuorumCommitment(const llmq::CFinalCommitmen { // The commitment has already been validated at this point, so it's safe to use members of it - auto members = llmq::CLLMQUtils::GetAllQuorumMembers(qc.llmqType, pQuorumBaseBlockIndex); + auto members = llmq::CLLMQUtils::GetAllQuorumMembers(llmq::GetLLMQParams(qc.llmqType), pQuorumBaseBlockIndex); for (size_t i = 0; i < members.size(); i++) { if (!mnList.HasMN(members[i]->proTxHash)) { diff --git a/src/llmq/blockprocessor.cpp b/src/llmq/blockprocessor.cpp index 98ab2e432c..2dc4aca3d8 100644 --- a/src/llmq/blockprocessor.cpp +++ b/src/llmq/blockprocessor.cpp @@ -141,15 +141,15 @@ bool CQuorumBlockProcessor::ProcessBlock(const CBlock& block, const CBlockIndex* // until the first non-null commitment has been mined. After the non-null commitment, no other commitments are // allowed, including null commitments. // Note: must only check quorums that were enabled at the _previous_ block height to match mining logic - for (const auto& type : CLLMQUtils::GetEnabledQuorumTypes(pindex->pprev)) { + for (const Consensus::LLMQParams& params : CLLMQUtils::GetEnabledQuorumParams(pindex->pprev)) { // skip these checks when replaying blocks after the crash if (!::ChainActive().Tip()) { break; } // does the currently processed block contain a (possibly null) commitment for the current session? - bool hasCommitmentInNewBlock = qcs.count(type) != 0; - bool isCommitmentRequired = IsCommitmentRequired(type, pindex->nHeight); + bool hasCommitmentInNewBlock = qcs.count(params.type) != 0; + bool isCommitmentRequired = IsCommitmentRequired(params, pindex->nHeight); if (hasCommitmentInNewBlock && !isCommitmentRequired) { // If we're either not in the mining phase or a non-null commitment was mined already, reject the block @@ -191,7 +191,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH const auto& llmq_params = GetLLMQParams(qc.llmqType); - uint256 quorumHash = GetQuorumBlockHash(qc.llmqType, nHeight); + uint256 quorumHash = GetQuorumBlockHash(llmq_params, nHeight); // skip `bad-qc-block` checks below when replaying blocks after the crash if (!::ChainActive().Tip()) { @@ -217,7 +217,7 @@ bool CQuorumBlockProcessor::ProcessCommitment(int nHeight, const uint256& blockH return state.DoS(100, false, REJECT_INVALID, "bad-qc-dup"); } - if (!IsMiningPhase(llmq_params.type, nHeight)) { + if (!IsMiningPhase(llmq_params, nHeight)) { // should not happen as it's already handled in ProcessBlock return state.DoS(100, false, REJECT_INVALID, "bad-qc-height"); } @@ -367,38 +367,37 @@ bool CQuorumBlockProcessor::GetCommitmentsFromBlock(const CBlock& block, const C return true; } -bool CQuorumBlockProcessor::IsMiningPhase(Consensus::LLMQType llmqType, int nHeight) +bool CQuorumBlockProcessor::IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight) { - const auto& llmq_params = GetLLMQParams(llmqType); - int phaseIndex = nHeight % llmq_params.dkgInterval; - if (phaseIndex >= llmq_params.dkgMiningWindowStart && phaseIndex <= llmq_params.dkgMiningWindowEnd) { + int phaseIndex = nHeight % llmqParams.dkgInterval; + if (phaseIndex >= llmqParams.dkgMiningWindowStart && phaseIndex <= llmqParams.dkgMiningWindowEnd) { return true; } return false; } -bool CQuorumBlockProcessor::IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight) const +bool CQuorumBlockProcessor::IsCommitmentRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const { AssertLockHeld(cs_main); - uint256 quorumHash = GetQuorumBlockHash(llmqType, nHeight); + uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight); // perform extra check for quorumHash.IsNull as the quorum hash is unknown for the first block of a session // this is because the currently processed block's hash will be the quorumHash of this session - bool isMiningPhase = !quorumHash.IsNull() && IsMiningPhase(llmqType, nHeight); + bool isMiningPhase = !quorumHash.IsNull() && IsMiningPhase(llmqParams, nHeight); // did we already mine a non-null commitment for this session? - bool hasMinedCommitment = !quorumHash.IsNull() && HasMinedCommitment(llmqType, quorumHash); + bool hasMinedCommitment = !quorumHash.IsNull() && HasMinedCommitment(llmqParams.type, quorumHash); return isMiningPhase && !hasMinedCommitment; } // WARNING: This method returns uint256() on the first block of the DKG interval (because the block hash is not known yet) -uint256 CQuorumBlockProcessor::GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight) +uint256 CQuorumBlockProcessor::GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight) { AssertLockHeld(cs_main); - int quorumStartHeight = nHeight - (nHeight % GetLLMQParams(llmqType).dkgInterval); + int quorumStartHeight = nHeight - (nHeight % llmqParams.dkgInterval); uint256 quorumBlockHash; if (!GetBlockHash(quorumBlockHash, quorumStartHeight)) { return {}; @@ -545,27 +544,27 @@ bool CQuorumBlockProcessor::GetMineableCommitmentByHash(const uint256& commitmen // Will return false if no commitment should be mined // Will return true and a null commitment if no mineable commitment is known and none was mined yet -bool CQuorumBlockProcessor::GetMineableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment& ret) const +bool CQuorumBlockProcessor::GetMineableCommitment(const Consensus::LLMQParams& llmqParams, int nHeight, CFinalCommitment& ret) const { AssertLockHeld(cs_main); - if (!IsCommitmentRequired(llmqType, nHeight)) { + if (!IsCommitmentRequired(llmqParams, nHeight)) { // no commitment required return false; } - uint256 quorumHash = GetQuorumBlockHash(llmqType, nHeight); + uint256 quorumHash = GetQuorumBlockHash(llmqParams, nHeight); if (quorumHash.IsNull()) { return false; } LOCK(minableCommitmentsCs); - auto k = std::make_pair(llmqType, quorumHash); + auto k = std::make_pair(llmqParams.type, quorumHash); auto it = minableCommitmentsByQuorum.find(k); if (it == minableCommitmentsByQuorum.end()) { // null commitment required - ret = CFinalCommitment(GetLLMQParams(llmqType), quorumHash); + ret = CFinalCommitment(llmqParams, quorumHash); return true; } @@ -574,12 +573,12 @@ bool CQuorumBlockProcessor::GetMineableCommitment(Consensus::LLMQType llmqType, return true; } -bool CQuorumBlockProcessor::GetMineableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef& ret) const +bool CQuorumBlockProcessor::GetMineableCommitmentTx(const Consensus::LLMQParams& llmqParams, int nHeight, CTransactionRef& ret) const { AssertLockHeld(cs_main); CFinalCommitmentTxPayload qc; - if (!GetMineableCommitment(llmqType, nHeight, qc.commitment)) { + if (!GetMineableCommitment(llmqParams, nHeight, qc.commitment)) { return false; } diff --git a/src/llmq/blockprocessor.h b/src/llmq/blockprocessor.h index cc2a05fb28..f6ba5409aa 100644 --- a/src/llmq/blockprocessor.h +++ b/src/llmq/blockprocessor.h @@ -54,8 +54,8 @@ public: void AddMineableCommitment(const CFinalCommitment& fqc); bool HasMineableCommitment(const uint256& hash) const; bool GetMineableCommitmentByHash(const uint256& commitmentHash, CFinalCommitment& ret) const; - bool GetMineableCommitment(Consensus::LLMQType llmqType, int nHeight, CFinalCommitment& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - bool GetMineableCommitmentTx(Consensus::LLMQType llmqType, int nHeight, CTransactionRef& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool GetMineableCommitment(const Consensus::LLMQParams& llmqParams, int nHeight, CFinalCommitment& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + bool GetMineableCommitmentTx(const Consensus::LLMQParams& llmqParams, int nHeight, CTransactionRef& ret) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool HasMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash) const; CFinalCommitmentPtr GetMinedCommitment(Consensus::LLMQType llmqType, const uint256& quorumHash, uint256& retMinedBlockHash) const; @@ -66,9 +66,9 @@ public: private: static bool GetCommitmentsFromBlock(const CBlock& block, const CBlockIndex* pindex, std::map& ret, CValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool ProcessCommitment(int nHeight, const uint256& blockHash, const CFinalCommitment& qc, CValidationState& state, bool fJustCheck) EXCLUSIVE_LOCKS_REQUIRED(cs_main); - static bool IsMiningPhase(Consensus::LLMQType llmqType, int nHeight); - bool IsCommitmentRequired(Consensus::LLMQType llmqType, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); - static uint256 GetQuorumBlockHash(Consensus::LLMQType llmqType, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main); + static bool IsMiningPhase(const Consensus::LLMQParams& llmqParams, int nHeight); + bool IsCommitmentRequired(const Consensus::LLMQParams& llmqParams, int nHeight) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); + static uint256 GetQuorumBlockHash(const Consensus::LLMQParams& llmqParams, int nHeight) EXCLUSIVE_LOCKS_REQUIRED(cs_main); }; extern CQuorumBlockProcessor* quorumBlockProcessor; diff --git a/src/llmq/commitment.cpp b/src/llmq/commitment.cpp index e1f8848b91..99fb872651 100644 --- a/src/llmq/commitment.cpp +++ b/src/llmq/commitment.cpp @@ -68,7 +68,7 @@ bool CFinalCommitment::Verify(const CBlockIndex* pQuorumBaseBlockIndex, bool che return false; } - auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + auto members = CLLMQUtils::GetAllQuorumMembers(llmq_params, pQuorumBaseBlockIndex); for (size_t i = members.size(); i < llmq_params.size; i++) { if (validMembers[i]) { LogPrintfFinalCommitment("invalid validMembers bitset. bit %d should not be set\n", i); diff --git a/src/llmq/debug.cpp b/src/llmq/debug.cpp index 4e79673338..7988e60c3e 100644 --- a/src/llmq/debug.cpp +++ b/src/llmq/debug.cpp @@ -27,7 +27,7 @@ UniValue CDKGDebugSessionStatus::ToJson(int detailLevel) const if (detailLevel == 2) { const CBlockIndex* pindex = WITH_LOCK(cs_main, return LookupBlockIndex(quorumHash)); if (pindex != nullptr) { - dmnMembers = CLLMQUtils::GetAllQuorumMembers( llmqType, pindex); + dmnMembers = CLLMQUtils::GetAllQuorumMembers(GetLLMQParams(llmqType), pindex); } } @@ -147,23 +147,23 @@ void CDKGDebugManager::ResetLocalSessionStatus(Consensus::LLMQType llmqType) localStatus.nTime = GetAdjustedTime(); } -void CDKGDebugManager::InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256& quorumHash, int quorumHeight) +void CDKGDebugManager::InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, const uint256& quorumHash, int quorumHeight) { LOCK(cs); - auto it = localStatus.sessions.find(llmqType); + auto it = localStatus.sessions.find(llmqParams.type); if (it == localStatus.sessions.end()) { - it = localStatus.sessions.emplace(llmqType, CDKGDebugSessionStatus()).first; + it = localStatus.sessions.emplace(llmqParams.type, CDKGDebugSessionStatus()).first; } auto& session = it->second; - session.llmqType = llmqType; + session.llmqType = llmqParams.type; session.quorumHash = quorumHash; session.quorumHeight = (uint32_t)quorumHeight; session.phase = 0; session.statusBitset = 0; session.members.clear(); - session.members.resize((size_t)GetLLMQParams(llmqType).size); + session.members.resize((size_t)llmqParams.size); } void CDKGDebugManager::UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function&& func) diff --git a/src/llmq/debug.h b/src/llmq/debug.h index 195a8b2782..d4cab07390 100644 --- a/src/llmq/debug.h +++ b/src/llmq/debug.h @@ -98,7 +98,7 @@ public: void GetLocalDebugStatus(CDKGDebugStatus& ret) const; void ResetLocalSessionStatus(Consensus::LLMQType llmqType); - void InitLocalSessionStatus(Consensus::LLMQType llmqType, const uint256& quorumHash, int quorumHeight); + void InitLocalSessionStatus(const Consensus::LLMQParams& llmqParams, const uint256& quorumHash, int quorumHeight); void UpdateLocalSessionStatus(Consensus::LLMQType llmqType, std::function&& func); void UpdateLocalMemberStatus(Consensus::LLMQType llmqType, size_t memberIdx, std::function&& func); diff --git a/src/llmq/dkgsession.cpp b/src/llmq/dkgsession.cpp index de66bcc29a..19c733d747 100644 --- a/src/llmq/dkgsession.cpp +++ b/src/llmq/dkgsession.cpp @@ -126,8 +126,8 @@ bool CDKGSession::Init(const CBlockIndex* _pQuorumBaseBlockIndex, const std::vec } if (!myProTxHash.IsNull()) { - quorumDKGDebugManager->InitLocalSessionStatus(params.type, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight); - relayMembers = CLLMQUtils::GetQuorumRelayMembers(params.type, m_quorum_base_block_index, myProTxHash, true); + quorumDKGDebugManager->InitLocalSessionStatus(params, m_quorum_base_block_index->GetBlockHash(), m_quorum_base_block_index->nHeight); + relayMembers = CLLMQUtils::GetQuorumRelayMembers(params, m_quorum_base_block_index, myProTxHash, true); } if (myProTxHash.IsNull()) { diff --git a/src/llmq/dkgsessionhandler.cpp b/src/llmq/dkgsessionhandler.cpp index 237405b8d0..e1bf0d06ac 100644 --- a/src/llmq/dkgsessionhandler.cpp +++ b/src/llmq/dkgsessionhandler.cpp @@ -164,7 +164,7 @@ bool CDKGSessionHandler::InitNewQuorum(const CBlockIndex* pQuorumBaseBlockIndex) return false; } - auto mns = CLLMQUtils::GetAllQuorumMembers(params.type, pQuorumBaseBlockIndex); + auto mns = CLLMQUtils::GetAllQuorumMembers(params, pQuorumBaseBlockIndex); if (!curSession->Init(pQuorumBaseBlockIndex, mns, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) { LogPrintf("CDKGSessionManager::%s -- quorum initialization failed for %s\n", __func__, curSession->params.name); @@ -518,9 +518,9 @@ void CDKGSessionHandler::HandleDKGRound() return changed; }); - CLLMQUtils::EnsureQuorumConnections(params.type, pQuorumBaseBlockIndex, curSession->myProTxHash); + CLLMQUtils::EnsureQuorumConnections(params, pQuorumBaseBlockIndex, curSession->myProTxHash); if (curSession->AreWeMember()) { - CLLMQUtils::AddQuorumProbeConnections(params.type, pQuorumBaseBlockIndex, curSession->myProTxHash); + CLLMQUtils::AddQuorumProbeConnections(params, pQuorumBaseBlockIndex, curSession->myProTxHash); } WaitForNextPhase(QuorumPhase_Initialized, QuorumPhase_Contribute, curQuorumHash, []{return false;}); diff --git a/src/llmq/dkgsessionmgr.cpp b/src/llmq/dkgsessionmgr.cpp index a5946f3543..1d38a207dc 100644 --- a/src/llmq/dkgsessionmgr.cpp +++ b/src/llmq/dkgsessionmgr.cpp @@ -310,7 +310,7 @@ void CDKGSessionManager::WriteEncryptedContributions(Consensus::LLMQType llmqTyp bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const std::vector& validMembers, std::vector& memberIndexesRet, std::vector& vvecsRet, BLSSecretKeyVector& skContributionsRet) const { LOCK(contributionsCacheCs); - auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + auto members = CLLMQUtils::GetAllQuorumMembers(GetLLMQParams(llmqType), pQuorumBaseBlockIndex); memberIndexesRet.clear(); vvecsRet.clear(); @@ -344,7 +344,7 @@ bool CDKGSessionManager::GetVerifiedContributions(Consensus::LLMQType llmqType, bool CDKGSessionManager::GetEncryptedContributions(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const std::vector& validMembers, const uint256& nProTxHash, std::vector>& vecRet) const { - auto members = CLLMQUtils::GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + auto members = CLLMQUtils::GetAllQuorumMembers(GetLLMQParams(llmqType), pQuorumBaseBlockIndex); vecRet.clear(); vecRet.reserve(members.size()); diff --git a/src/llmq/quorums.cpp b/src/llmq/quorums.cpp index 9101f65548..797155f883 100644 --- a/src/llmq/quorums.cpp +++ b/src/llmq/quorums.cpp @@ -257,7 +257,7 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial } for (auto& p : Params().GetConsensus().llmqs) { - EnsureQuorumConnections(p.first, pindexNew); + EnsureQuorumConnections(p.second, pindexNew); } { @@ -276,26 +276,24 @@ void CQuorumManager::UpdatedBlockTip(const CBlockIndex* pindexNew, bool fInitial TriggerQuorumDataRecoveryThreads(pindexNew); } -void CQuorumManager::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pindexNew) const +void CQuorumManager::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexNew) const { - const auto& llmq_params = GetLLMQParams(llmqType); + auto lastQuorums = ScanQuorums(llmqParams.type, pindexNew, (size_t)llmqParams.keepOldConnections); - auto lastQuorums = ScanQuorums(llmqType, pindexNew, (size_t)llmq_params.keepOldConnections); - - auto connmanQuorumsToDelete = g_connman->GetMasternodeQuorums(llmqType); + auto connmanQuorumsToDelete = g_connman->GetMasternodeQuorums(llmqParams.type); // don't remove connections for the currently in-progress DKG round - int curDkgHeight = pindexNew->nHeight - (pindexNew->nHeight % llmq_params.dkgInterval); + int curDkgHeight = pindexNew->nHeight - (pindexNew->nHeight % llmqParams.dkgInterval); auto curDkgBlock = pindexNew->GetAncestor(curDkgHeight)->GetBlockHash(); connmanQuorumsToDelete.erase(curDkgBlock); for (const auto& quorum : lastQuorums) { - if (CLLMQUtils::EnsureQuorumConnections(llmqType, quorum->m_quorum_base_block_index, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) { + if (CLLMQUtils::EnsureQuorumConnections(llmqParams, quorum->m_quorum_base_block_index, WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.proTxHash))) { continue; } if (connmanQuorumsToDelete.count(quorum->qc->quorumHash) > 0) { LogPrint(BCLog::LLMQ, "CQuorumManager::%s -- removing masternodes quorum connections for quorum %s:\n", __func__, quorum->qc->quorumHash.ToString()); - g_connman->RemoveMasternodeQuorumNodes(llmqType, quorum->qc->quorumHash); + g_connman->RemoveMasternodeQuorumNodes(llmqParams.type, quorum->qc->quorumHash); } } } @@ -313,8 +311,9 @@ CQuorumPtr CQuorumManager::BuildQuorumFromCommitment(const Consensus::LLMQType l } assert(qc->quorumHash == pQuorumBaseBlockIndex->GetBlockHash()); - auto quorum = std::make_shared(llmq::GetLLMQParams(llmqType), blsWorker); - auto members = CLLMQUtils::GetAllQuorumMembers((Consensus::LLMQType)qc->llmqType, pQuorumBaseBlockIndex); + const auto& llmqParams = llmq::GetLLMQParams(llmqType); + auto quorum = std::make_shared(llmqParams, blsWorker); + auto members = CLLMQUtils::GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex); quorum->Init(qc, pQuorumBaseBlockIndex, minedBlockHash, members); diff --git a/src/llmq/quorums.h b/src/llmq/quorums.h index 6860c75023..a6cf1113cf 100644 --- a/src/llmq/quorums.h +++ b/src/llmq/quorums.h @@ -235,7 +235,7 @@ public: private: // all private methods here are cs_main-free - void EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex *pindexNew) const; + void EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pindexNew) const; CQuorumPtr BuildQuorumFromCommitment(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex) const EXCLUSIVE_LOCKS_REQUIRED(quorumsCacheCs); bool BuildQuorumContributions(const CFinalCommitmentPtr& fqc, const std::shared_ptr& quorum) const; diff --git a/src/llmq/utils.cpp b/src/llmq/utils.cpp index 9b5d9e36ee..5592fc91c9 100644 --- a/src/llmq/utils.cpp +++ b/src/llmq/utils.cpp @@ -25,12 +25,12 @@ namespace llmq CCriticalSection cs_llmq_vbc; VersionBitsCache llmq_versionbitscache; -std::vector CLLMQUtils::GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex) +std::vector CLLMQUtils::GetAllQuorumMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex) { static CCriticalSection cs_members; static std::map, StaticSaltedHasher>> mapQuorumMembers; - if (!IsQuorumTypeEnabled(llmqType, pQuorumBaseBlockIndex->pprev)) { + if (!IsQuorumTypeEnabled(llmqParams.type, pQuorumBaseBlockIndex->pprev)) { return {}; } std::vector quorumMembers; @@ -39,16 +39,16 @@ std::vector CLLMQUtils::GetAllQuorumMembers(Consensus::LLM if (mapQuorumMembers.empty()) { InitQuorumsCache(mapQuorumMembers); } - if (mapQuorumMembers[llmqType].get(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers)) { + if (mapQuorumMembers[llmqParams.type].get(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers)) { return quorumMembers; } } auto allMns = deterministicMNManager->GetListForBlock(pQuorumBaseBlockIndex); - auto modifier = ::SerializeHash(std::make_pair(llmqType, pQuorumBaseBlockIndex->GetBlockHash())); - quorumMembers = allMns.CalculateQuorum(GetLLMQParams(llmqType).size, modifier); + auto modifier = ::SerializeHash(std::make_pair(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash())); + quorumMembers = allMns.CalculateQuorum(llmqParams.size, modifier); LOCK(cs_members); - mapQuorumMembers[llmqType].insert(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers); + mapQuorumMembers[llmqParams.type].insert(pQuorumBaseBlockIndex->GetBlockHash(), quorumMembers); return quorumMembers; } @@ -116,10 +116,10 @@ uint256 CLLMQUtils::DeterministicOutboundConnection(const uint256& proTxHash1, c return proTxHash2; } -std::set CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound) +std::set CLLMQUtils::GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound) { - if (IsAllMembersConnectedEnabled(llmqType)) { - auto mns = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + if (IsAllMembersConnectedEnabled(llmqParams.type)) { + auto mns = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex); std::set result; for (const auto& dmn : mns) { @@ -136,13 +136,13 @@ std::set CLLMQUtils::GetQuorumConnections(Consensus::LLMQType llmqType, } return result; } else { - return GetQuorumRelayMembers(llmqType, pQuorumBaseBlockIndex, forMember, onlyOutbound); + return GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, forMember, onlyOutbound); } } -std::set CLLMQUtils::GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &forMember, bool onlyOutbound) +std::set CLLMQUtils::GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &forMember, bool onlyOutbound) { - auto mns = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + auto mns = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex); std::set result; auto calcOutbound = [&](size_t i, const uint256& proTxHash) { @@ -202,9 +202,9 @@ std::set CLLMQUtils::CalcDeterministicWatchConnections(Consensus::LLMQTy return result; } -bool CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash) +bool CLLMQUtils::EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash) { - auto members = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + auto members = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex); bool isMember = std::find_if(members.begin(), members.end(), [&](const CDeterministicMNCPtr& dmn) { return dmn->proTxHash == myProTxHash; }) != members.end(); if (!isMember && !CLLMQUtils::IsWatchQuorumsEnabled()) { @@ -214,17 +214,17 @@ bool CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBl std::set connections; std::set relayMembers; if (isMember) { - connections = CLLMQUtils::GetQuorumConnections(llmqType, pQuorumBaseBlockIndex, myProTxHash, true); - relayMembers = CLLMQUtils::GetQuorumRelayMembers(llmqType, pQuorumBaseBlockIndex, myProTxHash, true); + connections = CLLMQUtils::GetQuorumConnections(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true); + relayMembers = CLLMQUtils::GetQuorumRelayMembers(llmqParams, pQuorumBaseBlockIndex, myProTxHash, true); } else { - auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqType, pQuorumBaseBlockIndex, members.size(), 1); + auto cindexes = CLLMQUtils::CalcDeterministicWatchConnections(llmqParams.type, pQuorumBaseBlockIndex, members.size(), 1); for (auto idx : cindexes) { connections.emplace(members[idx]->proTxHash); } relayMembers = connections; } if (!connections.empty()) { - if (!g_connman->HasMasternodeQuorumNodes(llmqType, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) { + if (!g_connman->HasMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash()) && LogAcceptCategory(BCLog::LLMQ)) { auto mnList = deterministicMNManager->GetListAtChainTip(); std::string debugMsg = strprintf("CLLMQUtils::%s -- adding masternodes quorum connections for quorum %s:\n", __func__, pQuorumBaseBlockIndex->GetBlockHash().ToString()); for (auto& c : connections) { @@ -237,21 +237,21 @@ bool CLLMQUtils::EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBl } LogPrint(BCLog::NET_NETCONN, debugMsg.c_str()); /* Continued */ } - g_connman->SetMasternodeQuorumNodes(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), connections); + g_connman->SetMasternodeQuorumNodes(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), connections); } if (!relayMembers.empty()) { - g_connman->SetMasternodeQuorumRelayMembers(llmqType, pQuorumBaseBlockIndex->GetBlockHash(), relayMembers); + g_connman->SetMasternodeQuorumRelayMembers(llmqParams.type, pQuorumBaseBlockIndex->GetBlockHash(), relayMembers); } return true; } -void CLLMQUtils::AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &myProTxHash) +void CLLMQUtils::AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex *pQuorumBaseBlockIndex, const uint256 &myProTxHash) { - if (!CLLMQUtils::IsQuorumPoseEnabled(llmqType)) { + if (!CLLMQUtils::IsQuorumPoseEnabled(llmqParams.type)) { return; } - auto members = GetAllQuorumMembers(llmqType, pQuorumBaseBlockIndex); + auto members = GetAllQuorumMembers(llmqParams, pQuorumBaseBlockIndex); auto curTime = GetAdjustedTime(); std::set probeConnections; @@ -331,9 +331,22 @@ bool CLLMQUtils::IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockI std::vector CLLMQUtils::GetEnabledQuorumTypes(const CBlockIndex* pindex) { std::vector ret; - for (const auto& p : Params().GetConsensus().llmqs) { - if (IsQuorumTypeEnabled(p.first, pindex)) { - ret.push_back(p.first); + ret.reserve(Params().GetConsensus().llmqs.size()); + for (const auto& [type, _] : Params().GetConsensus().llmqs) { + if (IsQuorumTypeEnabled(type, pindex)) { + ret.push_back(type); + } + } + return ret; +} + +std::vector> CLLMQUtils::GetEnabledQuorumParams(const CBlockIndex* pindex) +{ + std::vector> ret; + ret.reserve(Params().GetConsensus().llmqs.size()); + for (const auto& [type, params] : Params().GetConsensus().llmqs) { + if (IsQuorumTypeEnabled(type, pindex)) { + ret.emplace_back(params); } } return ret; diff --git a/src/llmq/utils.h b/src/llmq/utils.h index 0246cdc52d..1708ed7424 100644 --- a/src/llmq/utils.h +++ b/src/llmq/utils.h @@ -39,7 +39,7 @@ class CLLMQUtils { public: // includes members which failed DKG - static std::vector GetAllQuorumMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex); + static std::vector GetAllQuorumMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pindexQuorum); static uint256 BuildCommitmentHash(Consensus::LLMQType llmqType, const uint256& blockHash, const std::vector& validMembers, const CBLSPublicKey& pubKey, const uint256& vvecHash); static uint256 BuildSignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash); @@ -54,16 +54,17 @@ public: static bool IsAllMembersConnectedEnabled(Consensus::LLMQType llmqType); static bool IsQuorumPoseEnabled(Consensus::LLMQType llmqType); static uint256 DeterministicOutboundConnection(const uint256& proTxHash1, const uint256& proTxHash2); - static std::set GetQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); - static std::set GetQuorumRelayMembers(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); + static std::set GetQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); + static std::set GetQuorumRelayMembers(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& forMember, bool onlyOutbound); static std::set CalcDeterministicWatchConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, size_t memberCount, size_t connectionCount); - static bool EnsureQuorumConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash); - static void AddQuorumProbeConnections(Consensus::LLMQType llmqType, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash); + static bool EnsureQuorumConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash); + static void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex, const uint256& myProTxHash); static bool IsQuorumActive(Consensus::LLMQType llmqType, const uint256& quorumHash); static bool IsQuorumTypeEnabled(Consensus::LLMQType llmqType, const CBlockIndex* pindex); static std::vector GetEnabledQuorumTypes(const CBlockIndex* pindex); + static std::vector> GetEnabledQuorumParams(const CBlockIndex* pindex); /// Returns the state of `-llmq-data-recovery` static bool QuorumDataRecoveryEnabled(); @@ -115,7 +116,7 @@ public: static void InitQuorumsCache(CacheType& cache); }; -const Consensus::LLMQParams& GetLLMQParams(const Consensus::LLMQType llmqType); +const Consensus::LLMQParams& GetLLMQParams(Consensus::LLMQType llmqType); } // namespace llmq diff --git a/src/miner.cpp b/src/miner.cpp index 3a6d8c094e..893506c6df 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -148,9 +148,9 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc : pblock->GetBlockTime(); if (fDIP0003Active_context) { - for (const Consensus::LLMQType& type : llmq::CLLMQUtils::GetEnabledQuorumTypes(pindexPrev)) { + for (const Consensus::LLMQParams& params : llmq::CLLMQUtils::GetEnabledQuorumParams(pindexPrev)) { CTransactionRef qcTx; - if (llmq::quorumBlockProcessor->GetMineableCommitmentTx(type, + if (llmq::quorumBlockProcessor->GetMineableCommitmentTx(params, nHeight, qcTx)) { pblock->vtx.emplace_back(qcTx); diff --git a/src/rpc/rpcquorums.cpp b/src/rpc/rpcquorums.cpp index 56d1ba39fe..083aec82ee 100644 --- a/src/rpc/rpcquorums.cpp +++ b/src/rpc/rpcquorums.cpp @@ -196,8 +196,8 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request) if (fMasternodeMode) { const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return ::ChainActive()[tipHeight - (tipHeight % llmq_params.dkgInterval)]); - auto allConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params.type, pQuorumBaseBlockIndex, proTxHash, false); - auto outboundConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params.type, pQuorumBaseBlockIndex, proTxHash, true); + auto allConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params, pQuorumBaseBlockIndex, proTxHash, false); + auto outboundConnections = llmq::CLLMQUtils::GetQuorumConnections(llmq_params, pQuorumBaseBlockIndex, proTxHash, true); std::map foundConnections; g_connman->ForEachNode([&](const CNode* pnode) { auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash(); @@ -223,8 +223,7 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request) LOCK(cs_main); llmq::CFinalCommitment fqc; - if (llmq::quorumBlockProcessor->GetMineableCommitment(llmq_params.type, - tipHeight, fqc)) { + if (llmq::quorumBlockProcessor->GetMineableCommitment(llmq_params, tipHeight, fqc)) { UniValue obj(UniValue::VOBJ); fqc.ToJson(obj); minableCommitments.pushKV(std::string(llmq_params.name), obj);