Skip to content

Commit

Permalink
safe version of GetMasternodeByRank (#1595)
Browse files Browse the repository at this point in the history
* safe version of GetMasternodeByRank

* fix
  • Loading branch information
UdjinM6 committed Aug 31, 2017
1 parent 76181f5 commit 9028a22
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/darksend-relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ void CDarkSendRelay::Relay()

void CDarkSendRelay::RelayThroughNode(int nRank)
{
CMasternode* pmn = mnodeman.GetMasternodeByRank(nRank, nBlockHeight, MIN_PRIVATESEND_PEER_PROTO_VERSION);
masternode_info_t mnInfo;

if(pmn != NULL){
//printf("RelayThroughNode %s\n", pmn->addr.ToString().c_str());
if(mnodeman.GetMasternodeByRank(nRank, nBlockHeight, MIN_PRIVATESEND_PEER_PROTO_VERSION, false, mnInfo)){
//printf("RelayThroughNode %s\n", mnInfo.addr.ToString().c_str());
// 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) {
//printf("Connected\n");
pnode->PushMessage("dsr", (*this));
Expand Down
9 changes: 5 additions & 4 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ std::vector<std::pair<int, CMasternode> > CMasternodeMan::GetMasternodeRanks(int
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;

Expand All @@ -667,7 +667,7 @@ CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int nBlockHeight, in
uint256 blockHash;
if(!GetBlockHash(blockHash, nBlockHeight)) {
LogPrintf("CMasternode::GetMasternodeByRank -- ERROR: GetBlockHash() failed at nBlockHeight %d\n", nBlockHeight);
return NULL;
return false;
}

// Fill scores
Expand All @@ -687,11 +687,12 @@ CMasternode* CMasternodeMan::GetMasternodeByRank(int nRank, int nBlockHeight, in
BOOST_FOREACH (PAIRTYPE(int64_t, CMasternode*)& s, vecMasternodeScores){
rank++;
if(rank == nRank) {
return s.second;
mnInfoRet = *s.second;
return true;
}
}

return NULL;
return false;
}

void CMasternodeMan::ProcessMasternodeConnections()
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class CMasternodeMan

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);
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();
std::pair<CService, std::set<uint256> > PopScheduledMnbRequestConnection();
Expand Down

0 comments on commit 9028a22

Please sign in to comment.