Skip to content

Commit

Permalink
[Cleanup] Remove redundant checks in CMasternodePaymentWinner::IsValid
Browse files Browse the repository at this point in the history
we know that the masternode who signed the mnw message has positive
rank, thus it exists, it's enabled, and it has a valid active protocol.

Also change return value of CMasternodePayments::ProcessBlock to void.
  • Loading branch information
random-zebra committed May 23, 2021
1 parent 0db3f57 commit d616239
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
40 changes: 12 additions & 28 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,24 +165,9 @@ std::string CMasternodePaymentWinner::GetStrMessage() const

bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError)
{
CMasternode* pmn = mnodeman.Find(vinMasternode.prevout);

if (!pmn) {
strError = strprintf("Unknown Masternode %s", vinMasternode.prevout.hash.ToString());
LogPrint(BCLog::MASTERNODE,"CMasternodePaymentWinner::IsValid - %s\n", strError);
mnodeman.AskForMN(pnode, vinMasternode);
return false;
}

if (pmn->protocolVersion < ActiveProtocol()) {
strError = strprintf("Masternode protocol too old %d - req %d", pmn->protocolVersion, ActiveProtocol());
LogPrint(BCLog::MASTERNODE,"CMasternodePaymentWinner::IsValid - %s\n", strError);
return false;
}

int n = mnodeman.GetMasternodeRank(vinMasternode, nBlockHeight - 100);

if (n > MNPAYMENTS_SIGNATURES_TOTAL) {
if (n < 1 || n > MNPAYMENTS_SIGNATURES_TOTAL) {
//It's common to have masternodes mistakenly think they are in the top 10
// We don't want to print all of these messages, or punish them unless they're way off
if (n > MNPAYMENTS_SIGNATURES_TOTAL * 2) {
Expand Down Expand Up @@ -707,38 +692,38 @@ void CMasternodePayments::CleanPaymentList(int mnCount, int nHeight)
}
}

bool CMasternodePayments::ProcessBlock(int nBlockHeight)
void CMasternodePayments::ProcessBlock(int nBlockHeight)
{
// No more mnw messages after transition to DMN
if (deterministicMNManager->LegacyMNObsolete()) {
return false;
return;
}
if (!fMasterNode) return false;
if (!fMasterNode) return;

// Get the active masternode (operator) key
CKey mnKey; CKeyID mnKeyID; CTxIn mnVin;
if (!GetActiveMasternodeKeys(mnKey, mnKeyID, mnVin)) {
return false;
return;
}

//reference node - hybrid mode
int n = mnodeman.GetMasternodeRank(mnVin, nBlockHeight - 100);

if (n == -1) {
LogPrint(BCLog::MASTERNODE, "CMasternodePayments::ProcessBlock - Unknown Masternode\n");
return false;
return;
}

if (n > MNPAYMENTS_SIGNATURES_TOTAL) {
LogPrint(BCLog::MASTERNODE, "CMasternodePayments::ProcessBlock - Masternode not in the top %d (%d)\n", MNPAYMENTS_SIGNATURES_TOTAL, n);
return false;
return;
}

if (nBlockHeight <= nLastBlockHeight) return false;
if (nBlockHeight <= nLastBlockHeight) return;

if (g_budgetman.IsBudgetPaymentBlock(nBlockHeight)) {
//is budget payment block -- handled by the budgeting software
return false;
return;
}

// pay to the oldest MN that still had no payment but its input is old enough and it was active long enough
Expand All @@ -747,21 +732,20 @@ bool CMasternodePayments::ProcessBlock(int nBlockHeight)

if (pmn == nullptr) {
LogPrint(BCLog::MASTERNODE,"%s: Failed to find masternode to pay\n", __func__);
return false;
return;
}

CMasternodePaymentWinner newWinner(mnVin, nBlockHeight);
newWinner.AddPayee(pmn->GetPayeeScript());
if (!newWinner.Sign(mnKey, mnKeyID)) {
LogPrintf("%s: Failed to sign masternode winner\n", __func__);
return false;
return;
}
if (!AddWinningMasternode(newWinner)) {
return false;
return;
}
newWinner.Relay();
nLastBlockHeight = nBlockHeight;
return true;
}

void CMasternodePayments::Sync(CNode* node, int nCountNeeded)
Expand Down
2 changes: 1 addition & 1 deletion src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class CMasternodePayments
}

bool AddWinningMasternode(CMasternodePaymentWinner& winner);
bool ProcessBlock(int nBlockHeight);
void ProcessBlock(int nBlockHeight);

void Sync(CNode* node, int nCountNeeded);
void CleanPaymentList(int mnCount, int nHeight);
Expand Down

0 comments on commit d616239

Please sign in to comment.