Skip to content

Commit

Permalink
Add more logging for MN votes and MNs missing votes (#1683)
Browse files Browse the repository at this point in the history
* Add logging for MNs which did not vote

* Implement review suggestions
  • Loading branch information
codablock authored and UdjinM6 committed Oct 17, 2017
1 parent 4cac044 commit 1df889e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
67 changes: 66 additions & 1 deletion src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,68 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight, CConnman& connman)
return false;
}

void CMasternodePayments::CheckPreviousBlockVotes(int nPrevBlockHeight)
{
if (!masternodeSync.IsWinnersListSynced()) return;

std::string debugStr;

debugStr += strprintf("CMasternodePayments::CheckPreviousBlockVotes -- nPrevBlockHeight=%d, expected voting MNs:\n", nPrevBlockHeight);

CMasternodeMan::rank_pair_vec_t mns;
if (!mnodeman.GetMasternodeRanks(mns, nPrevBlockHeight - 101, GetMinMasternodePaymentsProto())) {
debugStr += "CMasternodePayments::CheckPreviousBlockVotes -- GetMasternodeRanks failed\n";
LogPrint("mnpayments", "%s", debugStr);
return;
}

LOCK2(cs_mapMasternodeBlocks, cs_mapMasternodePaymentVotes);

for (int i = 0; i < MNPAYMENTS_SIGNATURES_TOTAL && i < (int)mns.size(); i++) {
auto mn = mns[i];
CScript payee;
bool found = false;

if (mapMasternodeBlocks.count(nPrevBlockHeight)) {
for (auto &p : mapMasternodeBlocks[nPrevBlockHeight].vecPayees) {
for (auto &voteHash : p.GetVoteHashes()) {
if (!mapMasternodePaymentVotes.count(voteHash)) {
debugStr += strprintf("CMasternodePayments::CheckPreviousBlockVotes -- could not find vote %s\n",
voteHash.ToString());
continue;
}
auto vote = mapMasternodePaymentVotes[voteHash];
if (vote.vinMasternode.prevout == mn.second.vin.prevout) {
payee = vote.payee;
found = true;
break;
}
}
}
}

if (!found) {
debugStr += strprintf("CMasternodePayments::CheckPreviousBlockVotes -- %s - no vote received\n",
mn.second.vin.prevout.ToStringShort());
mapMasternodesDidNotVote[mn.second.vin.prevout]++;
continue;
}

CTxDestination address1;
ExtractDestination(payee, address1);
CBitcoinAddress address2(address1);

debugStr += strprintf("CMasternodePayments::CheckPreviousBlockVotes -- %s - voted for %s\n",
mn.second.vin.prevout.ToStringShort(), address2.ToString());
}
debugStr += "CMasternodePayments::CheckPreviousBlockVotes -- Masternodes which missed a vote in the past:\n";
for (auto it : mapMasternodesDidNotVote) {
debugStr += strprintf("CMasternodePayments::CheckPreviousBlockVotes -- %s: %d\n", it.first.ToStringShort(), it.second);
}

LogPrint("mnpayments", "%s", debugStr);
}

void CMasternodePaymentVote::Relay(CConnman& connman)
{
// do not relay until synced
Expand Down Expand Up @@ -956,5 +1018,8 @@ void CMasternodePayments::UpdatedBlockTip(const CBlockIndex *pindex, CConnman& c
nCachedBlockHeight = pindex->nHeight;
LogPrint("mnpayments", "CMasternodePayments::UpdatedBlockTip -- nCachedBlockHeight=%d\n", nCachedBlockHeight);

ProcessBlock(nCachedBlockHeight + 10, connman);
int nFutureBlock = nCachedBlockHeight + 10;

CheckPreviousBlockVotes(nFutureBlock - 1);
ProcessBlock(nFutureBlock, connman);
}
2 changes: 2 additions & 0 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class CMasternodePayments
std::map<uint256, CMasternodePaymentVote> mapMasternodePaymentVotes;
std::map<int, CMasternodeBlockPayees> mapMasternodeBlocks;
std::map<COutPoint, int> mapMasternodesLastVote;
std::map<COutPoint, int> mapMasternodesDidNotVote;

CMasternodePayments() : nStorageCoeff(1.25), nMinBlocksToStore(5000) {}

Expand All @@ -195,6 +196,7 @@ class CMasternodePayments
bool AddPaymentVote(const CMasternodePaymentVote& vote);
bool HasVerifiedPaymentVote(uint256 hashIn);
bool ProcessBlock(int nBlockHeight, CConnman& connman);
void CheckPreviousBlockVotes(int nPrevBlockHeight);

void Sync(CNode* node, CConnman& connman);
void RequestLowDataPaymentBlocks(CNode* pnode, CConnman& connman);
Expand Down

0 comments on commit 1df889e

Please sign in to comment.