Skip to content

Commit

Permalink
Final block reward, Chain adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Krekeler committed Dec 20, 2018
1 parent 78dcab7 commit 24a1c63
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 67 deletions.
23 changes: 10 additions & 13 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ class CMainParams : public CChainParams {
public:
CMainParams() {
strNetworkID = "main";
consensus.nSubsidyHalvingInterval = 210000; // Bitcoin=210000, Dash=210240; // Note: actual number of blocks per calendar year with DGW v3 is ~200700 (for example 449750 - 249050)
consensus.nMasternodePaymentsStartBlock = 5000; // Dash=100000; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
consensus.nMasternodePaymentsIncreaseBlock = 158000; // actual historical value
//consensus.nSubsidyHalvingInterval = 210000; DMS does not use Halving, see validation.cpp GetBlockSubsidy
consensus.nMasternodePaymentsStartBlock = 5000; // Dash=100000;
consensus.nMasternodePaymentsIncreaseBlock = 158000; // Dash: actual historical value
consensus.nMasternodePaymentsIncreasePeriod = 576*30; // 17280 - actual historical value
consensus.nInstantSendConfirmationsRequired = 6;
consensus.nInstantSendKeepLock = 24;
consensus.nBudgetPaymentsStartBlock = 328008; // actual historical value
consensus.nBudgetPaymentsStartBlock = 100000000; // >1000 years: DMS does not use this yet
consensus.nBudgetPaymentsCycleBlocks = 7200; // DMS: (60*24*30)/6; Dash: ~(60*24*30)/2.6, actual number of blocks per month is 200700 / 12 = 16725
consensus.nBudgetPaymentsWindowBlocks = 100;
consensus.nSuperblockStartBlock = 614820; // TODO // The block at which 12.1 goes live (end of final 12.0 budget cycle)
consensus.nSuperblockStartHash = uint256S("0000000000020cb27c7ef164d21003d5d20cdca2f54dd9a9ca6d45f4d47f8aa3");
consensus.nSuperblockStartBlock = 100000000; // >1000 years: DMS does not use superblocks, but the code is not removed yet because it could be of interest for other purposes
consensus.nSuperblockStartHash = uint256S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); // - " -
consensus.nSuperblockCycle = 7200; // DMS: (60*24*30)/6; Dash: ~(60*24*30)/2.6, actual number of blocks per month is 200700 / 12 = 16725
consensus.nGovernanceMinQuorum = 10;
consensus.nGovernanceFilterElements = 20000;
Expand All @@ -150,10 +150,10 @@ class CMainParams : public CChainParams {
consensus.nPowTargetSpacing = 6 * 60; // DMS 6 minutes (initial 4 minutes); Bitcoin 10 minutes; Dash 2.5 minutes
consensus.fPowAllowMinDifficultyBlocks = false;
consensus.fPowNoRetargeting = false;
consensus.nPowKGWHeight = 0; // 15200; TODO
consensus.nPowDGWHeight = 0; // 34140; TODO
consensus.nPowKGWHeight = 0; // 15200;
consensus.nPowDGWHeight = 0; // 34140;
consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016
consensus.nMinerConfirmationWindow = 2016; // nPowTargetTimespan / nPowTargetSpacing
consensus.nMinerConfirmationWindow = 2016; // relevant to BIP 9 soft fork, see params.h
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit = 28;
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime = 1199145601; // Dash: January 1, 2008
consensus.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout = 1230767999; // Dash: December 31, 2008
Expand Down Expand Up @@ -279,7 +279,6 @@ class CTestNetParams : public CChainParams {
public:
CTestNetParams() {
strNetworkID = "test";
consensus.nSubsidyHalvingInterval = 210240;
consensus.nMasternodePaymentsStartBlock = 4010; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
consensus.nMasternodePaymentsIncreaseBlock = 4030;
consensus.nMasternodePaymentsIncreasePeriod = 10;
Expand All @@ -289,7 +288,7 @@ class CTestNetParams : public CChainParams {
consensus.nBudgetPaymentsCycleBlocks = 50;
consensus.nBudgetPaymentsWindowBlocks = 10;
consensus.nSuperblockStartBlock = 4200; // NOTE: Should satisfy nSuperblockStartBlock > nBudgetPeymentsStartBlock
consensus.nSuperblockStartHash = uint256S("00000000cffabc0f646867fba0550afd6e30e0f4b0fc54e34d3e101a1552df5d"); // TODO
consensus.nSuperblockStartHash = uint256S("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); // Hash of first Superblock
consensus.nSuperblockCycle = 24; // Superblocks can be issued hourly on testnet
consensus.nGovernanceMinQuorum = 1;
consensus.nGovernanceFilterElements = 500;
Expand Down Expand Up @@ -419,7 +418,6 @@ class CDevNetParams : public CChainParams {
public:
CDevNetParams() {
strNetworkID = "dev";
consensus.nSubsidyHalvingInterval = 210240;
consensus.nMasternodePaymentsStartBlock = 4010; // not true, but it's ok as long as it's less then nMasternodePaymentsIncreaseBlock
consensus.nMasternodePaymentsIncreaseBlock = 4030;
consensus.nMasternodePaymentsIncreasePeriod = 10;
Expand Down Expand Up @@ -549,7 +547,6 @@ class CRegTestParams : public CChainParams {
public:
CRegTestParams() {
strNetworkID = "regtest";
consensus.nSubsidyHalvingInterval = 150;
consensus.nMasternodePaymentsStartBlock = 240;
consensus.nMasternodePaymentsIncreaseBlock = 350;
consensus.nMasternodePaymentsIncreasePeriod = 10;
Expand Down
2 changes: 1 addition & 1 deletion src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct BIP9Deployment {
struct Params {
uint256 hashGenesisBlock;
uint256 hashDevnetGenesisBlock;
int nSubsidyHalvingInterval;
//int nSubsidyHalvingInterval; DMS does not use Halving, see validation.cpp GetBlockSubsidy
int nMasternodePaymentsStartBlock;
int nMasternodePaymentsIncreaseBlock;
int nMasternodePaymentsIncreasePeriod; // in blocks
Expand Down
81 changes: 28 additions & 53 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,58 +1291,33 @@ NOTE: unlike bitcoin we are using PREVIOUS block height here,
*/
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly)
{
double dDiff;
CAmount nSubsidyBase;

/*
if (nPrevHeight <= 4500 && Params().NetworkIDString() == CBaseChainParams::MAIN) {
// Dash: a bug which caused diff to not be correctly calculated
dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);
} else {
dDiff = ConvertBitsToDouble(nPrevBits);
}
*/
dDiff = ConvertBitsToDouble(nPrevBits);

/* Dash:
if (nPrevHeight < 5465) {
// Early ages...
// 1111/((x+1)^2)
nSubsidyBase = (1111.0 / (pow((dDiff+1.0),2.0)));
if(nSubsidyBase > 500) nSubsidyBase = 500;
else if(nSubsidyBase < 1) nSubsidyBase = 1;
} else if (nPrevHeight < 17000 || (dDiff <= 75 && nPrevHeight < 24000)) {
// CPU mining era
// 11111/(((x+51)/6)^2)
nSubsidyBase = (11111.0 / (pow((dDiff+51.0)/6.0,2.0)));
if(nSubsidyBase > 500) nSubsidyBase = 500;
else if(nSubsidyBase < 25) nSubsidyBase = 25;
} else {
// GPU/ASIC mining era
// 2222222/(((x+2600)/9)^2)
nSubsidyBase = (2222222.0 / (pow((dDiff+2600.0)/9.0,2.0)));
if(nSubsidyBase > 25) nSubsidyBase = 25;
else if(nSubsidyBase < 5) nSubsidyBase = 5;
}
*/
// DMS: CPU mining era, reward 25 - 50 DMS
// 11111/(((x+51)/6)^2)
nSubsidyBase = (11111.0 / (pow((dDiff+51.0)/6.0,2.0)));
if(nSubsidyBase > 50) nSubsidyBase = 50;
else if(nSubsidyBase < 25) nSubsidyBase = 25;

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

// yearly decline of production by ~7.1% per year, projected ~18M coins max by year 2050+.
for (int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) {
nSubsidy -= nSubsidy/14;
}

// Hard fork to reduce the block reward by 10 extra percent (allowing budget/superblocks)
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
else if (nHeight < 88001) { nReward = 40; } // 1 760 000 / 6 month
else if (nHeight < 132001) { nReward = 30; } // 1 320 000 / 6 month
else if (nHeight < 176001) { nReward = 20; } // 840 000 / 6 month
else if (nHeight < 350001) { nReward = 15; } // 2 610 000 / 2 years
else if (nHeight < 788001) { nReward = 10; } // 4 380 000 / 5 years
else if (nHeight < 1226001) { nReward = 5; } // 2 190 000 / 5 years
else if (nHeight < 2102001) { nReward = 3; } // 2 628 000 / 10 years
else if (nHeight < 2978001) { nReward = 2; } // 1 752 000 / 10 years
else if (nHeight < 4298001) { nReward = 1; } // 1 320 000 / 15 years
else { nReward = 0; }; // reward = fee only
// sum: 21 000 000 / 49 years

CAmount nSubsidy = nReward * COIN;
return nSubsidy;

// reduce the block reward by 10 extra percent (allowing budget/superblocks)
// DMS does not use superblocks (consensus.nSuperblockStartBlock is set to >1000 years ),
// but the code is not removed yet because it could be of interest for other purposes.
/* uncomment for budget/superblocks:
CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/10 : 0;

return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;
*/
}

CAmount GetMasternodePayment(int nHeight, CAmount blockValue)
Expand Down Expand Up @@ -2096,7 +2071,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
// This rule was originally applied to all blocks with a timestamp after March 15, 2012, 0:00 UTC.
// Now that the whole chain is irreversibly beyond that time it is applied to all blocks except the
// two in the chain that violate it. This prevents exploiting the issue against nodes during their
// initial block download.
// initial block download. DMS - TODO:
bool fEnforceBIP30 = (!pindex->phashBlock) || // Enforce on CreateNewBlock invocations which don't have a hash.
!((pindex->nHeight==91842 && pindex->GetBlockHash() == uint256S("0x00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")) ||
(pindex->nHeight==91880 && pindex->GetBlockHash() == uint256S("0x00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")));
Expand All @@ -2122,7 +2097,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
}
}

/// DMS: Check superblock start
/// Dash: Check superblock start

// make sure old budget is the real one
if (pindex->nHeight == chainparams.GetConsensus().nSuperblockStartBlock &&
Expand All @@ -2131,7 +2106,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
return state.DoS(100, error("ConnectBlock(): invalid superblock start"),
REJECT_INVALID, "bad-sb-start");

/// END DMS
/// END Dash

// BIP16 didn't become active until Apr 1 2012
int64_t nBIP16SwitchTime = 1333238400;
Expand Down

0 comments on commit 24a1c63

Please sign in to comment.