Skip to content

Commit

Permalink
Check coinbase validity for DMNs
Browse files Browse the repository at this point in the history
  • Loading branch information
panleone committed Jul 28, 2023
1 parent 0c4d2df commit 06cc5fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
32 changes: 23 additions & 9 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

#include "masternode-payments.h"

#include "budget/budgetmanager.h"
#include "chainparams.h"
#include "evo/deterministicmns.h"
#include "fs.h"
#include "budget/budgetmanager.h"
#include "masternodeman.h"
#include "netmessagemaker.h"
#include "tiertwo/netfulfilledman.h"
#include "spork.h"
#include "sporkid.h"
#include "sync.h"
#include "tiertwo/netfulfilledman.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "util/system.h"
#include "utilmoneystr.h"
Expand Down Expand Up @@ -228,16 +229,25 @@ bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev)
{
int nBlockHeight = pindexPrev->nHeight + 1;
TrxValidationStatus transactionStatus = TrxValidationStatus::InValid;
const bool isV6UpgradeEnforced = Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_V6_0);
const bool isLegacyObsolete = deterministicMNManager->LegacyMNObsolete(nBlockHeight);

const bool fPayCoinstake = Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_POS) &&
!isV6UpgradeEnforced;
const CTransaction& txNew = *(fPayCoinstake ? block.vtx[1] : block.vtx[0]);

// If v6 is enforced and legacy mns are obsolete even not-synced nodes can check dmns reward
if (!g_tiertwo_sync_state.IsSynced() && isV6UpgradeEnforced && isLegacyObsolete) {
// This is a possible superblock cannot check anything: (TODO: update for single superblock payment)
if (nBlockHeight % Params().GetConsensus().nBudgetCycleBlocks < 100) return true;
return CheckMasternodePayee(txNew, pindexPrev);
}

if (!g_tiertwo_sync_state.IsSynced()) { //there is no budget data to use to check anything -- find the longest chain
LogPrint(BCLog::MASTERNODE, "Client not synced, skipping block payee checks\n");
return true;
}

const bool fPayCoinstake = Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_POS) &&
!Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_V6_0);
const CTransaction& txNew = *(fPayCoinstake ? block.vtx[1] : block.vtx[0]);

//check if it's a budget block
if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)) {
if (g_budgetman.IsBudgetPaymentBlock(nBlockHeight)) {
Expand All @@ -262,17 +272,21 @@ bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev)
// In all cases a masternode will get the payment for this block

//check for masternode payee
return CheckMasternodePayee(txNew, pindexPrev);
}

bool CheckMasternodePayee(const CTransaction& txNew, const CBlockIndex* pindexPrev)
{
if (masternodePayments.IsTransactionValid(txNew, pindexPrev))
return true;
LogPrint(BCLog::MASTERNODE,"Invalid mn payment detected %s\n", txNew.ToString().c_str());
LogPrint(BCLog::MASTERNODE, "Invalid mn payment detected %s\n", txNew.ToString().c_str());

if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))
return false;
LogPrint(BCLog::MASTERNODE,"Masternode payment enforcement is disabled, accepting block\n");
LogPrint(BCLog::MASTERNODE, "Masternode payment enforcement is disabled, accepting block\n");
return true;
}


void FillBlockPayee(CMutableTransaction& txCoinbase, CMutableTransaction& txCoinstake, const CBlockIndex* pindexPrev, bool fProofOfStake)
{
if (!sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) || // if superblocks are not enabled
Expand Down
1 change: 1 addition & 0 deletions src/masternode-payments.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern CMasternodePayments masternodePayments;
#define MNPAYMENTS_SIGNATURES_TOTAL 10

bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev);
bool CheckMasternodePayee(const CTransaction& txNew, const CBlockIndex* pindexPrev);
std::string GetRequiredPaymentsString(int nBlockHeight);
bool IsBlockValueValid(int nHeight, CAmount& nExpectedValue, CAmount nMinted, CAmount& nBudgetAmt);
void FillBlockPayee(CMutableTransaction& txCoinbase, CMutableTransaction& txCoinstake, const CBlockIndex* pindexPrev, bool fProofOfStake);
Expand Down
9 changes: 3 additions & 6 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,12 +1661,9 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
}

// Masternode/Budget payments
// !TODO: after transition to DMN is complete, check this also during IBD
if (!fInitialBlockDownload) {
if (!IsBlockPayeeValid(block, pindex->pprev)) {
mapRejectedBlocks.emplace(block.GetHash(), GetTime());
return state.DoS(0, false, REJECT_INVALID, "bad-cb-payee", false, "Couldn't find masternode/budget payment");
}
if (!IsBlockPayeeValid(block, pindex->pprev)) {
mapRejectedBlocks.emplace(block.GetHash(), GetTime());
return state.DoS(0, false, REJECT_INVALID, "bad-cb-payee", false, "Couldn't find masternode/budget payment");
}

// After v6 enforcement: Check that the coinbase pays the exact amount
Expand Down

0 comments on commit 06cc5fc

Please sign in to comment.