Skip to content

Commit f91161f

Browse files
committed
[Validation] Reject under-minting blocks
1 parent 6c5884c commit f91161f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/masternode-payments.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,11 @@ void DumpMasternodePayments()
198198

199199
bool IsBlockValueValid(int nHeight, CAmount& nExpectedValue, CAmount nMinted, CAmount& nBudgetAmt)
200200
{
201+
const Consensus::Params& consensus = Params().GetConsensus();
201202
if (!masternodeSync.IsSynced()) {
202203
//there is no budget data to use to check anything
203204
//super blocks will always be on these blocks, max 100 per budgeting
204-
if (nHeight % Params().GetConsensus().nBudgetCycleBlocks < 100) {
205+
if (nHeight % consensus.nBudgetCycleBlocks < 100) {
205206
if (Params().IsTestnet()) {
206207
return true;
207208
}
@@ -218,7 +219,9 @@ bool IsBlockValueValid(int nHeight, CAmount& nExpectedValue, CAmount nMinted, CA
218219
}
219220
}
220221

221-
return nMinted <= nExpectedValue;
222+
// !todo: remove after V6 enforcement and default it to true
223+
const bool isV6UpgradeEnforced = consensus.NetworkUpgradeActive(nHeight, Consensus::UPGRADE_V6_0);
224+
return (!isV6UpgradeEnforced || nMinted >= 0) && nMinted <= nExpectedValue;
222225
}
223226

224227
bool IsBlockPayeeValid(const CBlock& block, const CBlockIndex* pindexPrev)

src/test/budget_tests.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,13 @@ BOOST_AUTO_TEST_CASE(budget_value)
5656
BOOST_FIXTURE_TEST_CASE(block_value, TestnetSetup)
5757
{
5858
enableMnSyncAndSuperblocksPayment();
59-
// regular block
6059
int nHeight = 100; std::string strError;
6160
const CAmount nBlockReward = GetBlockValue(nHeight);
6261
CAmount nExpectedRet = nBlockReward;
6362
CAmount nBudgetAmtRet = 0;
63+
64+
// regular block
65+
BOOST_CHECK(IsBlockValueValid(nHeight, nExpectedRet, 0, nBudgetAmtRet));
6466
BOOST_CHECK(IsBlockValueValid(nHeight, nExpectedRet, nBlockReward-1, nBudgetAmtRet));
6567
BOOST_CHECK_EQUAL(nExpectedRet, nBlockReward);
6668
BOOST_CHECK_EQUAL(nBudgetAmtRet, 0);
@@ -127,6 +129,16 @@ BOOST_FIXTURE_TEST_CASE(block_value, TestnetSetup)
127129
BOOST_CHECK_EQUAL(nBudgetAmtRet, 0);
128130
}
129131

132+
BOOST_FIXTURE_TEST_CASE(block_value_undermint, RegTestingSetup)
133+
{
134+
int nHeight = 100;
135+
CAmount nExpectedRet = GetBlockValue(nHeight);
136+
CAmount nBudgetAmtRet = 0;
137+
// under-minting blocks are invalid after v6
138+
BOOST_CHECK(IsBlockValueValid(nHeight, nExpectedRet, -1, nBudgetAmtRet));
139+
UpdateNetworkUpgradeParameters(Consensus::UPGRADE_V6_0, Consensus::NetworkUpgrade::ALWAYS_ACTIVE);
140+
BOOST_CHECK(!IsBlockValueValid(nHeight, nExpectedRet, -1, nBudgetAmtRet));
141+
}
130142

131143
/**
132144
* 1) Create two proposals and two budget finalizations with a different proposal payment order:

0 commit comments

Comments
 (0)