safe version of GetMasternodeByRank (#1595)

* safe version of GetMasternodeByRank

* fix
This commit is contained in:
UdjinM6 2017-08-31 18:58:23 +03:00 committed by GitHub
parent 76181f5757
commit 9028a22b88
3 changed files with 10 additions and 9 deletions

View File

@ -99,12 +99,12 @@ void CDarkSendRelay::Relay()
void CDarkSendRelay::RelayThroughNode(int nRank) void CDarkSendRelay::RelayThroughNode(int nRank)
{ {
CMasternode* pmn = mnodeman.GetMasternodeByRank(nRank, nBlockHeight, MIN_PRIVATESEND_PEER_PROTO_VERSION); masternode_info_t mnInfo;
if(pmn != NULL){ if(mnodeman.GetMasternodeByRank(nRank, nBlockHeight, MIN_PRIVATESEND_PEER_PROTO_VERSION, false, mnInfo)){
//printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str()); //printf("RelayThroughNode %s\n", mnInfo.addr.ToString().c_str());
// TODO: Pass CConnman instance somehow and don't use global variable. // TODO: Pass CConnman instance somehow and don't use global variable.
CNode* pnode = g_connman->ConnectNode((CAddress)pmn->addr, NULL); CNode* pnode = g_connman->ConnectNode((CAddress)mnInfo.addr, NULL);
if(pnode) { if(pnode) {
//printf("Connected\n"); //printf("Connected\n");
pnode->PushMessage("dsr", (*this)); pnode->PushMessage("dsr", (*this));

View File

@ -658,7 +658,7 @@ std::vector<std::pair<int, CMasternode> > CMasternodeMan::GetMasternodeRanks(int
return vecMasternodeRanks; return vecMasternodeRanks;
} }
CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int nBlockHeight, int nMinProtocol, bool fOnlyActive) bool CMasternodeMan::GetMasternodeByRank(int nRank, int nBlockHeight, int nMinProtocol, bool fOnlyActive, masternode_info_t& mnInfoRet)
{ {
std::vector<std::pair<int64_t, CMasternode*> > vecMasternodeScores; std::vector<std::pair<int64_t, CMasternode*> > vecMasternodeScores;
@ -667,7 +667,7 @@ CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int nBlockHeight, in
uint256 blockHash; uint256 blockHash;
if(!GetBlockHash(blockHash, nBlockHeight)) { if(!GetBlockHash(blockHash, nBlockHeight)) {
LogPrintf("CMasternode::GetMasternodeByRank -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", nBlockHeight); LogPrintf("CMasternode::GetMasternodeByRank -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", nBlockHeight);
return NULL; return false;
} }
// Fill scores // Fill scores
@ -687,11 +687,12 @@ CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int nBlockHeight, in
BOOST_FOREACH (PAIRTYPE(int64_t, CMasternode*)& s, vecMasternodeScores){ BOOST_FOREACH (PAIRTYPE(int64_t, CMasternode*)& s, vecMasternodeScores){
rank++; rank++;
if(rank == nRank) { if(rank == nRank) {
return s.second; mnInfoRet = *s.second;
return true;
} }
} }
return NULL; return false;
} }
void CMasternodeMan::ProcessMasternodeConnections() void CMasternodeMan::ProcessMasternodeConnections()

View File

@ -168,7 +168,7 @@ public:
std::vector<std::pair<int, CMasternode> > GetMasternodeRanks(int nBlockHeight = -1, int nMinProtocol=0); std::vector<std::pair<int, CMasternode> > GetMasternodeRanks(int nBlockHeight = -1, int nMinProtocol=0);
int GetMasternodeRank(const CTxIn &vin, int nBlockHeight, int nMinProtocol=0, bool fOnlyActive=true); int GetMasternodeRank(const CTxIn &vin, int nBlockHeight, int nMinProtocol=0, bool fOnlyActive=true);
CMasternode* GetMasternodeByRank(int nRank, int nBlockHeight, int nMinProtocol=0, bool fOnlyActive=true); bool GetMasternodeByRank(int nRank, int nBlockHeight, int nMinProtocol, bool fOnlyActive, masternode_info_t& mnInfoRet);
void ProcessMasternodeConnections(); void ProcessMasternodeConnections();
std::pair<CService, std::set<uint256> > PopScheduledMnbRequestConnection(); std::pair<CService, std::set<uint256> > PopScheduledMnbRequestConnection();