Change GetMasternodeScores and GetMasternodeRank/s to use CDeterministicMNCPtr
This leaves us with nMinProtocol unused, but this is ok as we will later remove that argument completely.
This commit is contained in:
parent
17c792cd3b
commit
37541ee00e
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -42,10 +42,10 @@ struct CompareLastPaidBlock
|
||||
|
||||
struct CompareScoreMN
|
||||
{
|
||||
bool operator()(const std::pair<arith_uint256, const CMasternode*>& t1,
|
||||
const std::pair<arith_uint256, const CMasternode*>& t2) const
|
||||
bool operator()(const std::pair<arith_uint256, const CDeterministicMNCPtr&>& t1,
|
||||
const std::pair<arith_uint256, const CDeterministicMNCPtr&>& 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<COutPoint, CMasternode> 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);
|
||||
vecMasternodeScoresRet.emplace_back(p.first, p.second);
|
||||
}
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
@ -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<arith_uint256, const CMasternode*> score_pair_t;
|
||||
typedef std::pair<arith_uint256, CDeterministicMNCPtr> score_pair_t;
|
||||
typedef std::vector<score_pair_t> score_pair_vec_t;
|
||||
typedef std::pair<int, const CMasternode> rank_pair_t;
|
||||
typedef std::pair<int, CDeterministicMNCPtr> rank_pair_t;
|
||||
typedef std::vector<rank_pair_t> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user