diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 9379a3a503a2aa..c1d7faa31783a3 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -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" @@ -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)) { @@ -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 + 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 diff --git a/src/masternode-payments.h b/src/masternode-payments.h index 17be8863b7152e..68d4c5da370a37 100644 --- a/src/masternode-payments.h +++ b/src/masternode-payments.h @@ -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); diff --git a/src/validation.cpp b/src/validation.cpp index 5961d7f0afec1b..1d9a2eeb896be1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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