Skip to content

Commit 41ab95d

Browse files
committed
feat: skip governance checks for blocks below the best chainlock
1 parent cfc4086 commit 41ab95d

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/masternode/payments.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ CAmount PlatformShare(const CAmount reward)
181181
* - Other blocks are 10% lower in outgoing value, so in total, no extra coins are created
182182
* - When non-superblocks are detected, the normal schedule should be maintained
183183
*/
184-
bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlockHeight, const CAmount blockReward, std::string& strErrorRet)
184+
bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlockHeight, const CAmount blockReward, std::string& strErrorRet, const bool check_superblock)
185185
{
186186
bool isBlockRewardValueMet = (block.vtx[0]->GetValueOut() <= blockReward);
187187

@@ -242,6 +242,8 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo
242242
return isBlockRewardValueMet;
243243
}
244244

245+
if (!check_superblock) return true;
246+
245247
const auto tip_mn_list = m_dmnman.GetListAtChainTip();
246248

247249
if (!CSuperblockManager::IsSuperblockTriggered(m_govman, tip_mn_list, nBlockHeight)) {
@@ -267,7 +269,7 @@ bool CMNPaymentsProcessor::IsBlockValueValid(const CBlock& block, const int nBlo
267269
return true;
268270
}
269271

270-
bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CBlockIndex* pindexPrev, const CAmount blockSubsidy, const CAmount feeReward)
272+
bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CBlockIndex* pindexPrev, const CAmount blockSubsidy, const CAmount feeReward, const bool check_superblock)
271273
{
272274
const int nBlockHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1;
273275

@@ -298,6 +300,7 @@ bool CMNPaymentsProcessor::IsBlockPayeeValid(const CTransaction& txNew, const CB
298300
// superblocks started
299301

300302
if (AreSuperblocksEnabled(m_sporkman)) {
303+
if (!check_superblock) return true;
301304
const auto tip_mn_list = m_dmnman.GetListAtChainTip();
302305
if (CSuperblockManager::IsSuperblockTriggered(m_govman, tip_mn_list, nBlockHeight)) {
303306
if (CSuperblockManager::IsValid(m_govman, tip_mn_list, txNew, nBlockHeight, blockSubsidy + feeReward)) {

src/masternode/payments.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class CMNPaymentsProcessor
5252
const CMasternodeSync& mn_sync, const CSporkManager& sporkman) :
5353
m_dmnman{dmnman}, m_govman{govman}, m_consensus_params{consensus_params}, m_mn_sync{mn_sync}, m_sporkman{sporkman} {}
5454

55-
bool IsBlockValueValid(const CBlock& block, const int nBlockHeight, const CAmount blockReward, std::string& strErrorRet);
56-
bool IsBlockPayeeValid(const CTransaction& txNew, const CBlockIndex* pindexPrev, const CAmount blockSubsidy, const CAmount feeReward);
55+
bool IsBlockValueValid(const CBlock& block, const int nBlockHeight, const CAmount blockReward, std::string& strErrorRet, const bool check_superblock);
56+
bool IsBlockPayeeValid(const CTransaction& txNew, const CBlockIndex* pindexPrev, const CAmount blockSubsidy, const CAmount feeReward, const bool check_superblock);
5757
void FillBlockPayments(CMutableTransaction& txNew, const CBlockIndex* pindexPrev, const CAmount blockSubsidy, const CAmount feeReward,
5858
std::vector<CTxOut>& voutMasternodePaymentsRet, std::vector<CTxOut>& voutSuperblockPaymentsRet);
5959
};

src/validation.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,9 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
24452445
int64_t nTime5_3 = GetTimeMicros(); nTimeCreditPool += nTime5_3 - nTime5_2;
24462446
LogPrint(BCLog::BENCHMARK, " - CheckCreditPoolDiffForBlock: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime5_3 - nTime5_2), nTimeCreditPool * MICRO, nTimeCreditPool * MILLI / nBlocksTotal);
24472447

2448-
if (!m_chain_helper->mn_payments->IsBlockValueValid(block, pindex->nHeight, blockSubsidy + feeReward, strError)) {
2448+
bool check_superblock = m_clhandler->GetBestChainLock().getHeight() < pindex->nHeight;
2449+
2450+
if (!m_chain_helper->mn_payments->IsBlockValueValid(block, pindex->nHeight, blockSubsidy + feeReward, strError, check_superblock)) {
24492451
// NOTE: Do not punish, the node might be missing governance data
24502452
LogPrintf("ERROR: ConnectBlock(DASH): %s\n", strError);
24512453
return state.Invalid(BlockValidationResult::BLOCK_RESULT_UNSET, "bad-cb-amount");
@@ -2454,7 +2456,7 @@ bool CChainState::ConnectBlock(const CBlock& block, BlockValidationState& state,
24542456
int64_t nTime5_4 = GetTimeMicros(); nTimeValueValid += nTime5_4 - nTime5_3;
24552457
LogPrint(BCLog::BENCHMARK, " - IsBlockValueValid: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime5_4 - nTime5_3), nTimeValueValid * MICRO, nTimeValueValid * MILLI / nBlocksTotal);
24562458

2457-
if (!m_chain_helper->mn_payments->IsBlockPayeeValid(*block.vtx[0], pindex->pprev, blockSubsidy, feeReward)) {
2459+
if (!m_chain_helper->mn_payments->IsBlockPayeeValid(*block.vtx[0], pindex->pprev, blockSubsidy, feeReward, check_superblock)) {
24582460
// NOTE: Do not punish, the node might be missing governance data
24592461
LogPrintf("ERROR: ConnectBlock(DASH): couldn't find masternode or superblock payments\n");
24602462
return state.Invalid(BlockValidationResult::BLOCK_RESULT_UNSET, "bad-cb-payee");

0 commit comments

Comments
 (0)