mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 13:59:06 +01:00
Streamline GetBlockSubsidy()
This commit is contained in:
parent
3b606b0c63
commit
2339409ac0
60
src/main.cpp
60
src/main.cpp
@ -1692,8 +1692,7 @@ double ConvertBitsToDouble(unsigned int nBits)
|
|||||||
{
|
{
|
||||||
int nShift = (nBits >> 24) & 0xff;
|
int nShift = (nBits >> 24) & 0xff;
|
||||||
|
|
||||||
double dDiff =
|
double dDiff = (double)0x0000ffff / (double)(nBits & 0x00ffffff);
|
||||||
(double)0x0000ffff / (double)(nBits & 0x00ffffff);
|
|
||||||
|
|
||||||
while (nShift < 29)
|
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)
|
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) {
|
||||||
if(nPrevHeight > 4500 || Params().NetworkIDString() != CBaseChainParams::MAIN) dDiff = ConvertBitsToDouble(nPrevBits);
|
/* a bug which caused diff to not be correctly calculated */
|
||||||
|
dDiff = (double)0x0000ffff / (double)(nPrevBits & 0x00ffffff);
|
||||||
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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
nSubsidy = (1111.0 / (pow((dDiff+1.0),2.0)));
|
dDiff = ConvertBitsToDouble(nPrevBits);
|
||||||
if (nSubsidy > 500) nSubsidy = 500;
|
|
||||||
if (nSubsidy < 1) nSubsidy = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogPrintf("height %u diff %4.2f reward %i \n", nPrevHeight, dDiff, nSubsidy);
|
if (nPrevHeight < 5465) {
|
||||||
nSubsidy *= COIN;
|
// 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.
|
// LogPrintf("height %u diff %4.2f reward %d\n", nPrevHeight, dDiff, nSubsidyBase);
|
||||||
for(int i = consensusParams.nSubsidyHalvingInterval; i <= nPrevHeight; i += consensusParams.nSubsidyHalvingInterval) nSubsidy -= nSubsidy/14;
|
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;
|
CAmount nSuperblockPart = (nPrevHeight > consensusParams.nBudgetPaymentsStartBlock) ? nSubsidy/10 : 0;
|
||||||
|
|
||||||
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;
|
return fSuperblockPartOnly ? nSuperblockPart : nSubsidy - nSuperblockPart;
|
||||||
|
Loading…
Reference in New Issue
Block a user