Skip to content

Fix block reward #881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class CMainParams : public CChainParams {
CMainParams() {
strNetworkID = "main";
consensus.nSubsidyHalvingInterval = 210240; // Note: actual number of blocks per calendar year with DGW v3 is ~200700 (for example 449750 - 249050)
consensus.nMinimumSubsidyStartBlock = 600000;
consensus.nMasternodePaymentsStartBlock = 100000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
consensus.nMasternodePaymentsIncreaseBlock = 158000; // actual historical value
consensus.nMasternodePaymentsIncreasePeriod = 576*30; // 17280 - actual historical value
Expand Down Expand Up @@ -177,6 +178,7 @@ class CTestNetParams : public CChainParams {
CTestNetParams() {
strNetworkID = "test";
consensus.nSubsidyHalvingInterval = 210240;
consensus.nMinimumSubsidyStartBlock = 30000;
consensus.nMasternodePaymentsStartBlock = 10000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
consensus.nMasternodePaymentsIncreaseBlock = 46000;
consensus.nMasternodePaymentsIncreasePeriod = 576;
Expand Down Expand Up @@ -265,6 +267,7 @@ class CRegTestParams : public CChainParams {
CRegTestParams() {
strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 150;
consensus.nMinimumSubsidyStartBlock = 2000;
consensus.nMasternodePaymentsStartBlock = 240;
consensus.nMasternodePaymentsIncreaseBlock = 350;
consensus.nMasternodePaymentsIncreasePeriod = 10;
Expand Down
1 change: 1 addition & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Consensus {
struct Params {
uint256 hashGenesisBlock;
int nSubsidyHalvingInterval;
int nMinimumSubsidyStartBlock;
int nMasternodePaymentsStartBlock;
int nMasternodePaymentsIncreaseBlock;
int nMasternodePaymentsIncreasePeriod; // in blocks
Expand Down
75 changes: 38 additions & 37 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,29 +1473,31 @@ NOTE: unlike bitcoin we are using PREVIOUS block height here,
*/
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams)
{
double dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);

/* fixed bug caused diff to not be correctly calculated */
if(nPrevHeight > 4500 || Params().NetworkIDString() != CBaseChainParams::MAIN) dDiff = ConvertBitsToDouble(nPrevBits);

CAmount nSubsidy = 0;
if(nPrevHeight >= 5465) {
if((nPrevHeight >= 17000 && dDiff > 75) || nPrevHeight >= 24000) { // GPU/ASIC difficulty calc
// 2222222/(((x+2600)/9)^2)
nSubsidy = (2222222.0 / (pow((dDiff+2600.0)/9.0,2.0)));
if (nSubsidy > 25) nSubsidy = 25;
if (nSubsidy < 5) nSubsidy = 5;
} else { // CPU mining calc
nSubsidy = (11111.0 / (pow((dDiff+51.0)/6.0,2.0)));
CAmount nSubsidy = 5;
if(nPrevHeight < consensusParams.nMinimumSubsidyStartBlock - 1){
double dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);

/* fixed bug caused diff to not be correctly calculated */
if(nPrevHeight > 4500 || Params().NetworkIDString() != CBaseChainParams::MAIN) dDiff = ConvertBitsToDouble(nPrevBits);

nSubsidy = 0;
if(nPrevHeight >= 5465) {
if((nPrevHeight >= 17000 && dDiff > 75) || nPrevHeight >= 24000) { // GPU/ASIC difficulty calc
// 2222222/(((x+2600)/9)^2)
nSubsidy = (2222222.0 / (pow((dDiff+2600.0)/9.0,2.0)));
if (nSubsidy > 25) nSubsidy = 25;
if (nSubsidy < 5) nSubsidy = 5;
} else { // CPU mining calc
nSubsidy = (11111.0 / (pow((dDiff+51.0)/6.0,2.0)));
if (nSubsidy > 500) nSubsidy = 500;
if (nSubsidy < 25) nSubsidy = 25;
}
} else {
nSubsidy = (1111.0 / (pow((dDiff+1.0),2.0)));
if (nSubsidy > 500) nSubsidy = 500;
if (nSubsidy < 25) nSubsidy = 25;
if (nSubsidy < 1) nSubsidy = 1;
}
} else {
nSubsidy = (1111.0 / (pow((dDiff+1.0),2.0)));
if (nSubsidy > 500) nSubsidy = 500;
if (nSubsidy < 1) nSubsidy = 1;
}

// LogPrintf("height %u diff %4.2f reward %i \n", nPrevHeight, dDiff, nSubsidy);
nSubsidy *= COIN;

Expand All @@ -1508,24 +1510,23 @@ CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params&
return nSubsidy;
}

CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, const Consensus::Params& consensusParams)
{
CAmount ret = blockValue/5; // start at 20%

int nMNPIBlock = Params().GetConsensus().nMasternodePaymentsIncreaseBlock;
int nMNPIPeriod = Params().GetConsensus().nMasternodePaymentsIncreasePeriod;

// mainnet:
if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
if(nHeight > nMNPIBlock+(nMNPIPeriod* 1)) ret += blockValue / 20; // 175280 - 30.0% - 2014-11-25
if(nHeight > nMNPIBlock+(nMNPIPeriod* 2)) ret += blockValue / 20; // 192560 - 35.0% - 2014-12-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 3)) ret += blockValue / 40; // 209840 - 37.5% - 2015-01-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 4)) ret += blockValue / 40; // 227120 - 40.0% - 2015-02-27
if(nHeight > nMNPIBlock+(nMNPIPeriod* 5)) ret += blockValue / 40; // 244400 - 42.5% - 2015-03-30
if(nHeight > nMNPIBlock+(nMNPIPeriod* 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 9)) ret += blockValue / 40; // 313520 - 50.0% - 2015-08-03

CAmount ret = blockValue/2; // 50%
int nMNPIBlock = consensusParams.nMasternodePaymentsIncreaseBlock;
int nMNPIPeriod = consensusParams.nMasternodePaymentsIncreasePeriod;
if(nHeight <= nMNPIBlock+(nMNPIPeriod* 9))
ret = blockValue/5; // start at 20%
// mainnet:
if(nHeight > nMNPIBlock) ret += blockValue / 20; // 158000 - 25.0% - 2014-10-24
if(nHeight > nMNPIBlock+(nMNPIPeriod* 1)) ret += blockValue / 20; // 175280 - 30.0% - 2014-11-25
if(nHeight > nMNPIBlock+(nMNPIPeriod* 2)) ret += blockValue / 20; // 192560 - 35.0% - 2014-12-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 3)) ret += blockValue / 40; // 209840 - 37.5% - 2015-01-26
if(nHeight > nMNPIBlock+(nMNPIPeriod* 4)) ret += blockValue / 40; // 227120 - 40.0% - 2015-02-27
if(nHeight > nMNPIBlock+(nMNPIPeriod* 5)) ret += blockValue / 40; // 244400 - 42.5% - 2015-03-30
if(nHeight > nMNPIBlock+(nMNPIPeriod* 6)) ret += blockValue / 40; // 261680 - 45.0% - 2015-05-01
if(nHeight > nMNPIBlock+(nMNPIPeriod* 7)) ret += blockValue / 40; // 278960 - 47.5% - 2015-06-01
}
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params& consens

// ***TODO***
double ConvertBitsToDouble(unsigned int nBits);
CAmount GetMasternodePayment(int nHeight, CAmount blockValue);
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, const Consensus::Params& consensusParams);

/**
* Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a user-defined target.
Expand Down
4 changes: 2 additions & 2 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, CAmount nFe
}

CAmount blockValue = nFees + GetBlockSubsidy(chainActive.Tip()->nBits, chainActive.Tip()->nHeight, Params().GetConsensus());
CAmount masternodePayment = GetMasternodePayment(chainActive.Tip()->nHeight+1, blockValue);
CAmount masternodePayment = GetMasternodePayment(chainActive.Tip()->nHeight+1, blockValue, Params().GetConsensus());

txNew.vout[0].nValue = blockValue;

Expand Down Expand Up @@ -355,7 +355,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew)
int nMaxSignatures = 0;
std::string strPayeesPossible = "";

CAmount masternodePayment = GetMasternodePayment(nBlockHeight, txNew.GetValueOut());
CAmount masternodePayment = GetMasternodePayment(nBlockHeight, txNew.GetValueOut(), Params().GetConsensus());

//require at least MNPAYMENTS_SIGNATURES_REQUIRED signatures

Expand Down