Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,9 +1000,10 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
rank_pair_vec_t vecMasternodeRanks;
GetMasternodeRanks(vecMasternodeRanks, nCachedBlockHeight - 1, MIN_POSE_PROTO_VERSION);

LOCK(cs);
std::vector<CAddress> vAddr;

int nCount = 0;
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brace does not appear to get closed... What am I missing?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I tried to keep changes minimal here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think we should indent properly then. Personal preference I guess

LOCK(cs);

int nMyRank = -1;
int nRanksTotal = (int)vecMasternodeRanks.size();
Expand Down Expand Up @@ -1030,13 +1031,6 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
int nOffset = MAX_POSE_RANK + nMyRank - 1;
if(nOffset >= (int)vecMasternodeRanks.size()) return;

std::vector<const CMasternode*> vSortedByAddr;
for (const auto& mnpair : mapMasternodes) {
vSortedByAddr.push_back(&mnpair.second);
}

sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr());

auto it = vecMasternodeRanks.begin() + nOffset;
while(it != vecMasternodeRanks.end()) {
if(it->second.IsPoSeVerified() || it->second.IsPoSeBanned()) {
Expand All @@ -1052,16 +1046,22 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
}
LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Verifying masternode %s rank %d/%d address %s\n",
it->second.outpoint.ToStringShort(), it->first, nRanksTotal, it->second.addr.ToString());
if(SendVerifyRequest(CAddress(it->second.addr, NODE_NETWORK), vSortedByAddr, connman)) {
nCount++;
if(nCount >= MAX_POSE_CONNECTIONS) break;
CAddress addr = CAddress(it->second.addr, NODE_NETWORK);
if(CheckVerifyRequestAddr(addr, connman)) {
vAddr.push_back(addr);
if((int)vAddr.size() >= MAX_POSE_CONNECTIONS) break;
}
nOffset += MAX_POSE_CONNECTIONS;
if(nOffset >= (int)vecMasternodeRanks.size()) break;
it += MAX_POSE_CONNECTIONS;
}
} // cs

for (const auto& addr : vAddr) {
PrepareVerifyRequest(addr, connman);
}

LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Sent verification requests to %d masternodes\n", nCount);
LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Prepared verification requests for %d masternodes\n", vAddr.size());
}

// This function tries to find masternodes with the same addr,
Expand Down Expand Up @@ -1122,23 +1122,25 @@ void CMasternodeMan::CheckSameAddr()
}
}

bool CMasternodeMan::SendVerifyRequest(const CAddress& addr, const std::vector<const CMasternode*>& vSortedByAddr, CConnman& connman)
bool CMasternodeMan::CheckVerifyRequestAddr(const CAddress& addr, CConnman& connman)
{
if(netfulfilledman.HasFulfilledRequest(addr, strprintf("%s", NetMsgType::MNVERIFY)+"-request")) {
// we already asked for verification, not a good idea to do this too often, skip it
LogPrint("masternode", "CMasternodeMan::SendVerifyRequest -- too many requests, skipping... addr=%s\n", addr.ToString());
LogPrint("masternode", "CMasternodeMan::%s -- too many requests, skipping... addr=%s\n", __func__, addr.ToString());
return false;
}

if (connman.IsMasternodeOrDisconnectRequested(addr)) return false;
return !connman.IsMasternodeOrDisconnectRequested(addr);
}

void CMasternodeMan::PrepareVerifyRequest(const CAddress& addr, CConnman& connman)
{
connman.AddPendingMasternode(addr);
// use random nonce, store it and require node to reply with correct one later
CMasternodeVerification mnv(addr, GetRandInt(999999), nCachedBlockHeight - 1);
LOCK(cs_mapPendingMNV);
mapPendingMNV.insert(std::make_pair(addr, std::make_pair(GetTime(), mnv)));
LogPrintf("CMasternodeMan::SendVerifyRequest -- verifying node using nonce %d addr=%s\n", mnv.nonce, addr.ToString());
return true;
LogPrintf("CMasternodeMan::%s -- verifying node using nonce %d addr=%s\n", __func__, mnv.nonce, addr.ToString());
}

void CMasternodeMan::ProcessPendingMnvRequests(CConnman& connman)
Expand Down
3 changes: 2 additions & 1 deletion src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ class CMasternodeMan

void DoFullVerificationStep(CConnman& connman);
void CheckSameAddr();
bool SendVerifyRequest(const CAddress& addr, const std::vector<const CMasternode*>& vSortedByAddr, CConnman& connman);
bool CheckVerifyRequestAddr(const CAddress& addr, CConnman& connman);
void PrepareVerifyRequest(const CAddress& addr, CConnman& connman);
void ProcessPendingMnvRequests(CConnman& connman);
void SendVerifyReply(CNode* pnode, CMasternodeVerification& mnv, CConnman& connman);
void ProcessVerifyReply(CNode* pnode, CMasternodeVerification& mnv);
Expand Down