Skip to content

Commit

Permalink
[Budget] Validate proposal votes from deterministic masternodes
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed May 23, 2021
1 parent c5b9e6f commit f93bc0f
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "budget/budgetmanager.h"

#include "evo/deterministicmns.h"
#include "masternode-sync.h"
#include "masternodeman.h"
#include "net_processing.h"
Expand Down Expand Up @@ -533,7 +534,7 @@ void CBudgetManager::VoteOnFinalizedBudgets()
LogPrintf("%s: Error submitting vote - %s\n", __func__, strError);
continue;
}
LogPrint(BCLog::MNBUDGET,"%s: new finalized budget vote signed: %s\n", __func__, vote.GetHash().ToString());
LogPrint(BCLog::MNBUDGET, "%s: new finalized budget vote signed: %s\n", __func__, vote.GetHash().ToString());
AddSeenFinalizedBudgetVote(vote);
vote.Relay();
}
Expand Down Expand Up @@ -800,10 +801,18 @@ void CBudgetManager::RemoveStaleVotesOnProposal(CBudgetProposal* prop)

auto it = prop->mapVotes.begin();
while (it != prop->mapVotes.end()) {
CMasternode* pmn = mnodeman.Find(it->first);
(*it).second.SetValid(pmn && pmn->IsEnabled());
auto mnList = deterministicMNManager->GetListAtChainTip();
auto dmn = mnList.GetMNByCollateral(it->first);
if (dmn) {
(*it).second.SetValid(mnList.IsMNValid(dmn));
} else {
// -- Legacy System (!TODO: remove after enforcement) --
CMasternode* pmn = mnodeman.Find(it->first);
(*it).second.SetValid(pmn && pmn->IsEnabled());
}
++it;
}

LogPrint(BCLog::MNBUDGET, "Cleaned proposal votes for %s. After: YES=%d, NO=%d\n",
prop->GetName(), prop->GetYeas(), prop->GetNays());
}
Expand Down Expand Up @@ -967,6 +976,30 @@ int CBudgetManager::ProcessProposalVote(CBudgetVote& vote, CNode* pfrom)
}

const CTxIn& voteVin = vote.GetVin();

// See if this vote was signed with a deterministic masternode
auto mnList = deterministicMNManager->GetListAtChainTip();
auto dmn = mnList.GetMNByCollateral(voteVin.prevout);
if (dmn) {
if (!vote.CheckSignature(dmn->pdmnState->keyIDVoting)) {
LogPrint(BCLog::MNBUDGET, "mvote - signature invalid from dmn %s\n", dmn->proTxHash.ToString());
return 100;
}
AddSeenProposalVote(vote);
std::string strError = "masternode not valid or PoSe banned";
if (mnList.IsMNValid(dmn) && UpdateProposal(vote, pfrom, strError)) {
vote.Relay();
const uint256& voteID = vote.GetHash();
masternodeSync.AddedBudgetItem(voteID);
LogPrint(BCLog::MNBUDGET, "mvote - new vote (%s) for proposal %s from dmn %s\n",
voteID.ToString(), vote.GetProposalHash().ToString(), dmn->proTxHash.ToString());
} else {
LogPrint(BCLog::MNBUDGET, "mvote - error: %s", strError);
}
return 0;
}

// -- Legacy System (!TODO: remove after enforcement) --
CMasternode* pmn = mnodeman.Find(voteVin.prevout);
if (!pmn) {
LogPrint(BCLog::MNBUDGET, "mvote - unknown masternode - vin: %s\n", voteVin.ToString());
Expand All @@ -978,7 +1011,7 @@ int CBudgetManager::ProcessProposalVote(CBudgetVote& vote, CNode* pfrom)

if (!vote.CheckSignature(pmn->pubKeyMasternode.GetID())) {
if (masternodeSync.IsSynced()) {
LogPrintf("mvote - signature invalid\n");
LogPrint(BCLog::MNBUDGET, "mvote - signature invalid\n");
return 20;
}
// it could just be a non-synced masternode
Expand Down

0 comments on commit f93bc0f

Please sign in to comment.