diff --git a/src/governance-classes.cpp b/src/governance-classes.cpp index 4619037354731..9f3a6ed1a1971 100644 --- a/src/governance-classes.cpp +++ b/src/governance-classes.cpp @@ -552,7 +552,7 @@ CAmount CSuperblock::GetPaymentsLimit(int nBlockHeight) // min subsidy for high diff networks and vice versa int nBits = consensusParams.fPowAllowMinDifficultyBlocks ? UintToArith256(consensusParams.powLimit).GetCompact() : 1; // some part of all blocks issued during the cycle goes to superblock, see GetBlockSubsidy - CAmount nSuperblockPartOfSubsidy = GetBlockSubsidy(nBits, nBlockHeight - 1, consensusParams, true); + CAmount nSuperblockPartOfSubsidy = GetBlockSubsidy(nBits, nBlockHeight, consensusParams, true); CAmount nPaymentsLimit = nSuperblockPartOfSubsidy * consensusParams.nSuperblockCycle; LogPrint("gobject", "CSuperblock::GetPaymentsLimit -- Valid superblock height %d, payments max %lld\n", nBlockHeight, nPaymentsLimit); diff --git a/src/miner.cpp b/src/miner.cpp index df7589ec407fe..252402d020f57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -163,8 +163,8 @@ std::unique_ptr BlockAssembler::CreateNewBlock(const CScript& sc coinbaseTx.vout.resize(1); coinbaseTx.vout[0].scriptPubKey = scriptPubKeyIn; - // NOTE: unlike in bitcoin, we need to pass PREVIOUS block height here - CAmount blockReward = nFees + GetBlockSubsidy(pindexPrev->nBits, pindexPrev->nHeight, Params().GetConsensus()); + // NOTE: unlike in Dash, we need to pass CURRENT block height here (like Bitcoin) + CAmount blockReward = nFees + GetBlockSubsidy(pindexPrev->nBits, nHeight, Params().GetConsensus()); // Compute regular coinbase transaction. coinbaseTx.vout[0].nValue = blockReward; diff --git a/src/test/subsidy_tests.cpp b/src/test/subsidy_tests.cpp index 0a5bcb25cb067..e7e025d150979 100644 --- a/src/test/subsidy_tests.cpp +++ b/src/test/subsidy_tests.cpp @@ -24,43 +24,43 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test) // details for block 4249 (subsidy returned will be for block 4250) nPrevBits = 0x1c4a47c4; nPrevHeight = 4249; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 50000000000ULL); // details for block 4501 (subsidy returned will be for block 4502) nPrevBits = 0x1c4a47c4; nPrevHeight = 4501; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 5600000000ULL); // details for block 5464 (subsidy returned will be for block 5465) nPrevBits = 0x1c29ec00; nPrevHeight = 5464; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 2100000000ULL); // details for block 5465 (subsidy returned will be for block 5466) nPrevBits = 0x1c29ec00; nPrevHeight = 5465; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 12200000000ULL); // details for block 17588 (subsidy returned will be for block 17589) nPrevBits = 0x1c08ba34; nPrevHeight = 17588; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 6100000000ULL); // details for block 99999 (subsidy returned will be for block 100000) nPrevBits = 0x1b10cf42; nPrevHeight = 99999; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL); // details for block 210239 (subsidy returned will be for block 210240) nPrevBits = 0x1b11548e; nPrevHeight = 210239; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 500000000ULL); // 1st subsidy reduction happens here @@ -68,7 +68,7 @@ BOOST_AUTO_TEST_CASE(block_subsidy_test) // details for block 210240 (subsidy returned will be for block 210241) nPrevBits = 0x1b10d50b; nPrevHeight = 210240; - nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight, consensusParams, false); + nSubsidy = GetBlockSubsidy(nPrevBits, nPrevHeight + 1, consensusParams, false); BOOST_CHECK_EQUAL(nSubsidy, 464285715ULL); } diff --git a/src/validation.cpp b/src/validation.cpp index ce1366f98c3e5..293d95d3a1494 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1284,15 +1284,10 @@ double ConvertBitsToDouble(unsigned int nBits) return dDiff; } -/* -NOTE: unlike bitcoin we are using PREVIOUS block height here, - might be a good idea to change this to use prev bits - but current height to avoid confusion. -*/ -CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly) +// unlike Dash we are using current block height and previous nBits here, Dash uses previous height +// DMS uses only nHeight, but the params are not removed yet because they could be of interest for future purposes +CAmount GetBlockSubsidy(int nPrevBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly) { - int nHeight = nPrevHeight + 1; // TODO: use nHeight as param like bitcoin, remove unused params - // 10 blocks/hour, 240/day, 7200/month, 87600/year int nReward; if (nHeight < 44001) { nReward = 50; } // 2 200 000 / 6 month @@ -2292,15 +2287,15 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd int64_t nTime3 = GetTimeMicros(); nTimeConnect += nTime3 - nTime2; LogPrint("bench", " - Connect %u transactions: %.2fms (%.3fms/tx, %.3fms/txin) [%.2fs]\n", (unsigned)block.vtx.size(), 0.001 * (nTime3 - nTime2), 0.001 * (nTime3 - nTime2) / block.vtx.size(), nInputs <= 1 ? 0 : 0.001 * (nTime3 - nTime2) / (nInputs-1), nTimeConnect * 0.000001); - // DMS : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS - + // Dash : MODIFIED TO CHECK MASTERNODE PAYMENTS AND SUPERBLOCKS // It's possible that we simply don't have enough data and this could fail // (i.e. block itself could be a correct one and we need to store it), // that's why this is in ConnectBlock. Could be the other way around however - // the peer who sent us this block is missing some data and wasn't able // to recognize that block is actually invalid. // TODO: resync data (both ways?) and try to reprocess this block later. - CAmount blockReward = nFees + GetBlockSubsidy(pindex->pprev->nBits, pindex->pprev->nHeight, chainparams.GetConsensus()); + // DMS: GetBlockSubsidy uses previus nBits and current nHeight + CAmount blockReward = nFees + GetBlockSubsidy(pindex->pprev->nBits, pindex->nHeight, chainparams.GetConsensus()); std::string strError = ""; if (!IsBlockValueValid(block, pindex->nHeight, blockReward, strError)) { return state.DoS(0, error("ConnectBlock(DMS): %s", strError), REJECT_INVALID, "bad-cb-amount"); @@ -2311,7 +2306,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd return state.DoS(0, error("ConnectBlock(DMS): couldn't find masternode or superblock payments"), REJECT_INVALID, "bad-cb-payee"); } - // END DMS + // END Dash if (!control.Wait()) return state.DoS(100, false); diff --git a/src/validation.h b/src/validation.h index 71f15df3ca7c0..ebd5bf9d562e6 100644 --- a/src/validation.h +++ b/src/validation.h @@ -291,7 +291,7 @@ bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::P bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr pblock = std::shared_ptr()); double ConvertBitsToDouble(unsigned int nBits); -CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly = false); +CAmount GetBlockSubsidy(int nPrevBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly = false); CAmount GetMasternodePayment(int nHeight, CAmount blockValue); /** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */