|
11 | 11 | #include "validation.h"
|
12 | 12 |
|
13 | 13 | #include "addrman.h"
|
| 14 | +#include "amount.h" |
14 | 15 | #include "blocksignature.h"
|
15 | 16 | #include "budget/budgetmanager.h"
|
16 | 17 | #include "chainparams.h"
|
|
21 | 22 | #include "consensus/tx_verify.h"
|
22 | 23 | #include "consensus/validation.h"
|
23 | 24 | #include "consensus/zerocoin_verify.h"
|
| 25 | +#include "evo/deterministicmns.h" |
24 | 26 | #include "evo/evodb.h"
|
25 | 27 | #include "evo/specialtx_validation.h"
|
26 | 28 | #include "flatfile.h"
|
@@ -1567,6 +1569,28 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
|
1567 | 1569 | CAmount txValueOut = tx.GetValueOut();
|
1568 | 1570 | if (!tx.IsCoinBase()) {
|
1569 | 1571 | CAmount txValueIn = view.GetValueIn(tx);
|
| 1572 | + // Once v6 is enforced and legacy mns are obsolete check that CoinStake does not overmint |
| 1573 | + if (tx.IsCoinStake() && isV6UpgradeEnforced && deterministicMNManager->LegacyMNObsolete(pindex->nHeight)) { |
| 1574 | + CAmount stakeMint = txValueOut - txValueIn; |
| 1575 | + // This is a possible superblock: coinstake cannot pay more than the blockvalue (TODO: update for single superblock payment) |
| 1576 | + if (pindex->nHeight % consensus.nBudgetCycleBlocks < 100) { |
| 1577 | + CAmount maxStakeMint = GetBlockValue(pindex->nHeight); |
| 1578 | + if (stakeMint > maxStakeMint) { |
| 1579 | + return state.DoS(100, error("%s: coinstake pays too much (actual=%s vs limit=%s)", __func__, FormatMoney(stakeMint), FormatMoney(maxStakeMint)), |
| 1580 | + REJECT_INVALID, "bad-blk-stake-amount"); |
| 1581 | + } |
| 1582 | + } else { |
| 1583 | + // Masternode found, subtract its reward from the expected stake reward |
| 1584 | + CAmount nExpectedStakeMint = GetBlockValue(pindex->nHeight); |
| 1585 | + if (deterministicMNManager->GetListForBlock(pindex->pprev).GetMNPayee()) { |
| 1586 | + nExpectedStakeMint -= GetMasternodePayment(pindex->nHeight); |
| 1587 | + } |
| 1588 | + if (stakeMint != nExpectedStakeMint) { |
| 1589 | + return state.DoS(100, error("%s: coinstake pays too much (actual=%s vs limit=%s)", __func__, FormatMoney(stakeMint), FormatMoney(nExpectedStakeMint)), |
| 1590 | + REJECT_INVALID, "bad-blk-stake-amount"); |
| 1591 | + } |
| 1592 | + } |
| 1593 | + } |
1570 | 1594 | if (!tx.IsCoinStake())
|
1571 | 1595 | nFees += txValueIn - txValueOut;
|
1572 | 1596 | nValueIn += txValueIn;
|
|
0 commit comments