Skip to content

Commit 2159b89

Browse files
committed
Check coinbase validity for DMNs
1 parent 0c4d2df commit 2159b89

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/masternode-payments.cpp

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
#include "masternode-payments.h"
77

8+
#include "budget/budgetmanager.h"
89
#include "chainparams.h"
910
#include "evo/deterministicmns.h"
1011
#include "fs.h"
11-
#include "budget/budgetmanager.h"
1212
#include "masternodeman.h"
1313
#include "netmessagemaker.h"
14-
#include "tiertwo/netfulfilledman.h"
1514
#include "spork.h"
15+
#include "sporkid.h"
1616
#include "sync.h"
17+
#include "tiertwo/netfulfilledman.h"
1718
#include "tiertwo/tiertwo_sync_state.h"
1819
#include "util/system.h"
1920
#include "utilmoneystr.h"
@@ -228,16 +229,25 @@ bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev)
228229
{
229230
int nBlockHeight = pindexPrev->nHeight + 1;
230231
TrxValidationStatus transactionStatus = TrxValidationStatus::InValid;
232+
const bool isV6UpgradeEnforced = Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_V6_0);
233+
const bool isLegacyObsolete = deterministicMNManager->LegacyMNObsolete(nBlockHeight);
234+
235+
const bool fPayCoinstake = Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_POS) &&
236+
!isV6UpgradeEnforced;
237+
const CTransaction& txNew = *(fPayCoinstake ? block.vtx[1] : block.vtx[0]);
238+
239+
// If v6 is enforced and legacy mns are obsolete even not-synced nodes can check dmns reward
240+
if (!g_tiertwo_sync_state.IsSynced() && isV6UpgradeEnforced && isLegacyObsolete) {
241+
// This is a possible superblock cannot check anything: (TODO: update for single superblock payment)
242+
if (nBlockHeight % Params().GetConsensus().nBudgetCycleBlocks < 100) return true;
243+
return CheckMasternodePayee(txNew, pindexPrev);
244+
}
231245

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

237-
const bool fPayCoinstake = Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_POS) &&
238-
!Params().GetConsensus().NetworkUpgradeActive(nBlockHeight, Consensus::UPGRADE_V6_0);
239-
const CTransaction& txNew = *(fPayCoinstake ? block.vtx[1] : block.vtx[0]);
240-
241251
//check if it's a budget block
242252
if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)) {
243253
if (g_budgetman.IsBudgetPaymentBlock(nBlockHeight)) {
@@ -262,17 +272,21 @@ bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev)
262272
// In all cases a masternode will get the payment for this block
263273

264274
//check for masternode payee
275+
CheckMasternodePayee(txNew, pindexPrev);
276+
}
277+
278+
bool CheckMasternodePayee(const CTransaction& txNew, const CBlockIndex* pindexPrev)
279+
{
265280
if (masternodePayments.IsTransactionValid(txNew, pindexPrev))
266281
return true;
267-
LogPrint(BCLog::MASTERNODE,"Invalid mn payment detected %s\n", txNew.ToString().c_str());
282+
LogPrint(BCLog::MASTERNODE, "Invalid mn payment detected %s\n", txNew.ToString().c_str());
268283

269284
if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))
270285
return false;
271-
LogPrint(BCLog::MASTERNODE,"Masternode payment enforcement is disabled, accepting block\n");
286+
LogPrint(BCLog::MASTERNODE, "Masternode payment enforcement is disabled, accepting block\n");
272287
return true;
273288
}
274289

275-
276290
void FillBlockPayee(CMutableTransaction& txCoinbase, CMutableTransaction& txCoinstake, const CBlockIndex* pindexPrev, bool fProofOfStake)
277291
{
278292
if (!sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) || // if superblocks are not enabled

src/masternode-payments.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern CMasternodePayments masternodePayments;
2626
#define MNPAYMENTS_SIGNATURES_TOTAL 10
2727

2828
bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev);
29+
bool CheckMasternodePayee(const CTransaction& txNew, const CBlockIndex* pindexPrev);
2930
std::string GetRequiredPaymentsString(int nBlockHeight);
3031
bool IsBlockValueValid(int nHeight, CAmount& nExpectedValue, CAmount nMinted, CAmount& nBudgetAmt);
3132
void FillBlockPayee(CMutableTransaction& txCoinbase, CMutableTransaction& txCoinstake, const CBlockIndex* pindexPrev, bool fProofOfStake);

src/validation.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,12 +1661,9 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16611661
}
16621662

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

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

0 commit comments

Comments
 (0)