Streamline GetBlockSubsidy()

This commit is contained in:
UdjinM6 2016-08-20 20:27:03 +03:00
parent 3b606b0c63
commit 2339409ac0

View File

@ -1692,8 +1692,7 @@ double ConvertBitsToDouble(unsigned int nBits)
{
int nShift = (nBits >> 24) & 0xff;
double dDiff =
(double)0x0000ffff / (double)(nBits & 0x00ffffff);
double dDiff = (double)0x0000ffff / (double)(nBits & 0x00ffffff);
while (nShift < 29)
{
@ -1741,36 +1740,45 @@ NOTE: unlike bitcoin we are using PREVIOUS block height here,
*/
CAmount GetBlockSubsidy(int nPrevBits, int nPrevHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly)
{
double dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);
double dDiff;
CAmount nSubsidyBase;
/* 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)));
if (nSubsidy > 500) nSubsidy = 500;
if (nSubsidy < 25) nSubsidy = 25;
}
if (nPrevHeight <= 4500 && Params().NetworkIDString() == CBaseChainParams::MAIN) {
/* a bug which caused diff to not be correctly calculated */
dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);
} else {
nSubsidy = (1111.0 / (pow((dDiff+1.0),2.0)));
if (nSubsidy > 500) nSubsidy = 500;
if (nSubsidy < 1) nSubsidy = 1;
dDiff = ConvertBitsToDouble(nPrevBits);
}
// LogPrintf("height %u diff %4.2f reward %i \n", nPrevHeight, dDiff, nSubsidy);
nSubsidy *= COIN;
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;
}
// yearly decline of production by 7.1% per year, projected 21.3M coins max by year 2050.
for(int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14;
// LogPrintf("height %u diff %4.2f reward %d\n", nPrevHeight, dDiff, nSubsidyBase);
CAmount nSubsidy = nSubsidyBase * COIN;
// Hard fork to reduce the block reward by 10 extra percent (allowing budget super-blocks)
// 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)
CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/10 : 0;
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;