From e6b699bc26a5b7aafe33f470a5fa950bbd3e45f6 Mon Sep 17 00:00:00 2001 From: Alexander Block Date: Sat, 3 Mar 2018 15:56:01 +0100 Subject: [PATCH] Enforce MN and superblock payments in same block 1. Enforce payment to masternodes in IsBlockPayeeValid even if superblocks are triggered. This new rule only gets activated when spork15 activates. 2. Always enforce masternode payments when spork15 is activated and ignore spork8 in that case. spork8 can be removed after spork15 activation and hardening of the spork15 height into consensus params. --- src/masternode-payments.cpp | 28 ++++++++++++++++++---------- src/rpc/mining.cpp | 3 ++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 2885ffb1d..bc1e08087 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -178,7 +178,10 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc if(CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) { if(CSuperblockManager::IsValid(txNew, nBlockHeight, blockReward)) { LogPrint("gobject", "%s -- Valid superblock at height %d: %s", __func__, nBlockHeight, txNew.ToString()); - return true; + // only allow superblock and masternode payments in the same block after spork15 activation + if (!deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) + return true; + // continue validation, should also pay MN } else { LogPrintf("%s -- ERROR: Invalid superblock detected at height %d: %s", __func__, nBlockHeight, txNew.ToString()); // should NOT allow such superblocks, when superblocks are enabled @@ -198,13 +201,18 @@ bool IsBlockPayeeValid(const CTransaction& txNew, int nBlockHeight, CAmount bloc return true; } - if(sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { - LogPrintf("%s -- ERROR: Invalid masternode payment detected at height %d: %s", __func__, nBlockHeight, txNew.ToString()); + if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + // always enforce masternode payments when spork15 is active return false; - } + } else { + if(sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { + LogPrintf("%s -- ERROR: Invalid masternode payment detected at height %d: %s", __func__, nBlockHeight, txNew.ToString()); + return false; + } - LogPrintf("%s -- WARNING: Masternode payment enforcement is disabled, accepting any payee\n", __func__); - return true; + LogPrintf("%s-- WARNING: Masternode payment enforcement is disabled, accepting any payee\n", __func__); + return true; + } } void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blockReward, std::vector& voutMasternodePaymentsRet, std::vector& voutSuperblockPaymentsRet) @@ -217,10 +225,7 @@ void FillBlockPayments(CMutableTransaction& txNew, int nBlockHeight, CAmount blo CSuperblockManager::GetSuperblockPayments(nBlockHeight, voutSuperblockPaymentsRet); } - // TODO this is a placeholder until DIP3 is merged, which will allow superblock payments and MN reward payments - // in the same block. We set this to false for now, which means that we'll always get into the next if statement - // when a superblock payment is present - bool allowSuperblockAndMNReward = false; + bool allowSuperblockAndMNReward = deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight); // don't allow payments to superblocks AND masternodes before spork15 activation if (!voutSuperblockPaymentsRet.empty() && !allowSuperblockAndMNReward) { @@ -253,6 +258,9 @@ std::string GetRequiredPaymentsString(int nBlockHeight) { // IF WE HAVE A ACTIVATED TRIGGER FOR THIS HEIGHT - IT IS A SUPERBLOCK, GET THE REQUIRED PAYEES if(CSuperblockManager::IsSuperblockTriggered(nBlockHeight)) { + if (deterministicMNManager->IsDeterministicMNsSporkActive(nBlockHeight)) { + return mnpayments.GetRequiredPaymentsString(nBlockHeight) + ", " + CSuperblockManager::GetRequiredPaymentsString(nBlockHeight); + } return CSuperblockManager::GetRequiredPaymentsString(nBlockHeight); } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 7a3a4bfb3..3ca55356b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -28,6 +28,7 @@ #include "masternode-payments.h" #include "masternode-sync.h" +#include "evo/deterministicmns.h" #include "evo/specialtx.h" #include "evo/cbtx.h" @@ -720,7 +721,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) result.push_back(Pair("masternode", masternodeObj)); result.push_back(Pair("masternode_payments_started", pindexPrev->nHeight + 1 > consensusParams.nMasternodePaymentsStartBlock)); - result.push_back(Pair("masternode_payments_enforced", sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))); + result.push_back(Pair("masternode_payments_enforced", deterministicMNManager->IsDeterministicMNsSporkActive() || sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT))); UniValue superblockObjArray(UniValue::VARR); if(pblocktemplate->voutSuperblockPayments.size()) {