diff --git a/src/instantx.cpp b/src/instantx.cpp index b598bc871..2afb982dd 100644 --- a/src/instantx.cpp +++ b/src/instantx.cpp @@ -245,8 +245,7 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman) int nRank; uint256 quorumModifierHash; - int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto()); - if (!mnodeman.GetMasternodeRank(activeMasternodeInfo.outpoint, nRank, quorumModifierHash, nLockInputHeight, nMinRequiredProtocol)) { + if (!mnodeman.GetMasternodeRank(activeMasternodeInfo.outpoint, nRank, quorumModifierHash, nLockInputHeight)) { LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternodeInfo.outpoint.ToStringShort()); continue; } @@ -1061,8 +1060,7 @@ bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const int nRank; uint256 expectedQuorumModifierHash; - int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto()); - if (!mnodeman.GetMasternodeRank(outpointMasternode, nRank, expectedQuorumModifierHash, nLockInputHeight, nMinRequiredProtocol)) { + if (!mnodeman.GetMasternodeRank(outpointMasternode, nRank, expectedQuorumModifierHash, nLockInputHeight)) { //can be caused by past versions trying to vote with an invalid protocol LogPrint("instantsend", "CTxLockVote::IsValid -- Can't calculate rank for masternode %s\n", outpointMasternode.ToStringShort()); return false; diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 99a647178..87ff0dcf8 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -1046,7 +1046,7 @@ void CMasternodePayments::CheckBlockVotes(int nBlockHeight) voteHash.ToString()); continue; } - if (itVote->second.masternodeOutpoint == mn.second.outpoint) { + if (itVote->second.masternodeOutpoint == mn.second->collateralOutpoint) { payee = itVote->second.payee; found = true; break; @@ -1061,12 +1061,12 @@ void CMasternodePayments::CheckBlockVotes(int nBlockHeight) CBitcoinAddress address2(address1); debugStr += strprintf(" - %s - voted for %s\n", - mn.second.outpoint.ToStringShort(), address2.ToString()); + mn.second->collateralOutpoint.ToStringShort(), address2.ToString()); } else { - mapMasternodesDidNotVote.emplace(mn.second.outpoint, 0).first->second++; + mapMasternodesDidNotVote.emplace(mn.second->collateralOutpoint, 0).first->second++; debugStr += strprintf(" - %s - no vote received\n", - mn.second.outpoint.ToStringShort()); + mn.second->collateralOutpoint.ToStringShort()); } if (++i >= MNPAYMENTS_SIGNATURES_TOTAL) break; diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 71980c9ad..aa696e840 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -42,10 +42,10 @@ struct CompareLastPaidBlock struct CompareScoreMN { - bool operator()(const std::pair& t1, - const std::pair& t2) const + bool operator()(const std::pair& t1, + const std::pair& t2) const { - return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->outpoint < t2.second->outpoint); + return (t1.first != t2.first) ? (t1.first < t2.first) : (t1.second->collateralOutpoint < t2.second->collateralOutpoint); } }; @@ -257,9 +257,9 @@ void CMasternodeMan::CheckAndRemove(CConnman& connman) // ask first MNB_RECOVERY_QUORUM_TOTAL masternodes we can connect to and we haven't asked recently for(int i = 0; setRequested.size() < MNB_RECOVERY_QUORUM_TOTAL && i < (int)vecMasternodeRanks.size(); i++) { // avoid banning - if(mWeAskedForMasternodeListEntry.count(it->first) && mWeAskedForMasternodeListEntry[it->first].count(vecMasternodeRanks[i].second.addr)) continue; + if(mWeAskedForMasternodeListEntry.count(it->first) && mWeAskedForMasternodeListEntry[it->first].count(vecMasternodeRanks[i].second->pdmnState->addr)) continue; // didn't ask recently, ok to ask now - CService addr = vecMasternodeRanks[i].second.addr; + CService addr = vecMasternodeRanks[i].second->pdmnState->addr; setRequested.insert(addr); listScheduledMnbRequestConnections.push_back(std::make_pair(addr, hash)); fAskedForMnbRecovery = true; @@ -766,33 +766,18 @@ std::map CMasternodeMan::GetFullMasternodeMap() } } -bool CMasternodeMan::GetMasternodeScores(const uint256& nBlockHash, CMasternodeMan::score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol) +bool CMasternodeMan::GetMasternodeScores(const uint256& nBlockHash, CMasternodeMan::score_pair_vec_t& vecMasternodeScoresRet) { AssertLockHeld(cs); vecMasternodeScoresRet.clear(); - if (deterministicMNManager->IsDIP3Active()) { - auto mnList = deterministicMNManager->GetListAtChainTip(); - auto scores = mnList.CalculateScores(nBlockHash); - for (const auto& p : scores) { - auto* mn = Find(p.second->collateralOutpoint); - vecMasternodeScoresRet.emplace_back(p.first, mn); - } - } else { - if (!masternodeSync.IsMasternodeListSynced()) - return false; - - if (mapMasternodes.empty()) - return false; - - // calculate scores - for (const auto& mnpair : mapMasternodes) { - if (mnpair.second.nProtocolVersion >= nMinProtocol) { - vecMasternodeScoresRet.push_back(std::make_pair(mnpair.second.CalculateScore(nBlockHash), &mnpair.second)); - } - } + auto mnList = deterministicMNManager->GetListAtChainTip(); + auto scores = mnList.CalculateScores(nBlockHash); + for (const auto& p : scores) { + vecMasternodeScoresRet.emplace_back(p.first, p.second); } + sort(vecMasternodeScoresRet.rbegin(), vecMasternodeScoresRet.rend(), CompareScoreMN()); return !vecMasternodeScoresRet.empty(); } @@ -820,13 +805,13 @@ bool CMasternodeMan::GetMasternodeRank(const COutPoint& outpoint, int& nRankRet, LOCK(cs); score_pair_vec_t vecMasternodeScores; - if (!GetMasternodeScores(blockHashRet, vecMasternodeScores, nMinProtocol)) + if (!GetMasternodeScores(blockHashRet, vecMasternodeScores)) return false; int nRank = 0; for (const auto& scorePair : vecMasternodeScores) { nRank++; - if(scorePair.second->outpoint == outpoint) { + if(scorePair.second->collateralOutpoint == outpoint) { nRankRet = nRank; return true; } @@ -852,13 +837,13 @@ bool CMasternodeMan::GetMasternodeRanks(CMasternodeMan::rank_pair_vec_t& vecMast LOCK(cs); score_pair_vec_t vecMasternodeScores; - if (!GetMasternodeScores(nBlockHash, vecMasternodeScores, nMinProtocol)) + if (!GetMasternodeScores(nBlockHash, vecMasternodeScores)) return false; int nRank = 0; for (const auto& scorePair : vecMasternodeScores) { nRank++; - vecMasternodeRanksRet.push_back(std::make_pair(nRank, *scorePair.second)); + vecMasternodeRanksRet.push_back(std::make_pair(nRank, scorePair.second)); } return true; @@ -1188,7 +1173,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) (int)MAX_POSE_RANK); return; } - if(rankPair.second.outpoint == activeMasternodeInfo.outpoint) { + if(rankPair.second->collateralOutpoint == activeMasternodeInfo.outpoint) { nMyRank = rankPair.first; LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n", nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS); @@ -1218,8 +1203,8 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman) continue; } LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Verifying masternode %s rank %d/%d address %s\n", - it->second.outpoint.ToStringShort(), it->first, nRanksTotal, it->second.addr.ToString()); - CAddress addr = CAddress(it->second.addr, NODE_NETWORK); + it->second->collateralOutpoint.ToStringShort(), it->first, nRanksTotal, it->second->pdmnState->addr.ToString()); + CAddress addr = CAddress(it->second->pdmnState->addr, NODE_NETWORK); if(CheckVerifyRequestAddr(addr, connman)) { vAddr.push_back(addr); if((int)vAddr.size() >= MAX_POSE_CONNECTIONS) break; diff --git a/src/masternodeman.h b/src/masternodeman.h index 695229a96..aa30b2e4f 100644 --- a/src/masternodeman.h +++ b/src/masternodeman.h @@ -8,6 +8,8 @@ #include "masternode.h" #include "sync.h" +#include "evo/deterministicmns.h" + class CMasternodeMan; class CConnman; @@ -16,9 +18,9 @@ extern CMasternodeMan mnodeman; class CMasternodeMan { public: - typedef std::pair score_pair_t; + typedef std::pair score_pair_t; typedef std::vector score_pair_vec_t; - typedef std::pair rank_pair_t; + typedef std::pair rank_pair_t; typedef std::vector rank_pair_vec_t; private: @@ -80,7 +82,7 @@ private: /// Find an entry CMasternode* Find(const COutPoint& outpoint); - bool GetMasternodeScores(const uint256& nBlockHash, score_pair_vec_t& vecMasternodeScoresRet, int nMinProtocol = 0); + bool GetMasternodeScores(const uint256& nBlockHash, score_pair_vec_t& vecMasternodeScoresRet); void SyncSingle(CNode* pnode, const COutPoint& outpoint, CConnman& connman); void SyncAll(CNode* pnode, CConnman& connman);