Implement mining slow start with a linear ramp
This commit is contained in:
@@ -31,6 +31,7 @@ class CMainParams : public CChainParams {
|
|||||||
public:
|
public:
|
||||||
CMainParams() {
|
CMainParams() {
|
||||||
strNetworkID = "main";
|
strNetworkID = "main";
|
||||||
|
consensus.nSubsidySlowStartInterval = 5000;
|
||||||
consensus.nSubsidyHalvingInterval = 210000;
|
consensus.nSubsidyHalvingInterval = 210000;
|
||||||
consensus.nMajorityEnforceBlockUpgrade = 750;
|
consensus.nMajorityEnforceBlockUpgrade = 750;
|
||||||
consensus.nMajorityRejectBlockOutdated = 950;
|
consensus.nMajorityRejectBlockOutdated = 950;
|
||||||
|
|||||||
@@ -14,6 +14,20 @@ namespace Consensus {
|
|||||||
*/
|
*/
|
||||||
struct Params {
|
struct Params {
|
||||||
uint256 hashGenesisBlock;
|
uint256 hashGenesisBlock;
|
||||||
|
/** Needs to evenly divide MAX_SUBSIDY to avoid rounding errors. */
|
||||||
|
int nSubsidySlowStartInterval;
|
||||||
|
/**
|
||||||
|
* Shift based on a linear ramp for slow start:
|
||||||
|
*
|
||||||
|
* MAX_SUBSIDY*(t_s/2 + t/r) = MAX_SUBSIDY*t_h Coin balance
|
||||||
|
* t_s + t_r = t_h + t_c Block balance
|
||||||
|
*
|
||||||
|
* t_s = nSubsidySlowStartInterval
|
||||||
|
* t_r = number of blocks between end of slow start and first halving
|
||||||
|
* t_h = nSubsidyHalvingInterval
|
||||||
|
* t_c = SubsidySlowStartShift()
|
||||||
|
*/
|
||||||
|
int SubsidySlowStartShift() const { return nSubsidySlowStartInterval / 2; }
|
||||||
int nSubsidyHalvingInterval;
|
int nSubsidyHalvingInterval;
|
||||||
/** Used to check majorities for block version upgrade */
|
/** Used to check majorities for block version upgrade */
|
||||||
int nMajorityEnforceBlockUpgrade;
|
int nMajorityEnforceBlockUpgrade;
|
||||||
|
|||||||
19
src/main.cpp
19
src/main.cpp
@@ -1324,12 +1324,27 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex)
|
|||||||
|
|
||||||
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
|
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
|
||||||
{
|
{
|
||||||
int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;
|
CAmount nSubsidy = 50 * COIN;
|
||||||
|
|
||||||
|
// Mining slow start
|
||||||
|
// The subsidy is ramped up linearly, skipping the middle payout of
|
||||||
|
// MAX_SUBSIDY/2 to keep the monetary curve consistent with no slow start.
|
||||||
|
if (nHeight < consensusParams.nSubsidySlowStartInterval / 2) {
|
||||||
|
nSubsidy /= consensusParams.nSubsidySlowStartInterval;
|
||||||
|
nSubsidy *= nHeight;
|
||||||
|
return nSubsidy;
|
||||||
|
} else if (nHeight < consensusParams.nSubsidySlowStartInterval) {
|
||||||
|
nSubsidy /= consensusParams.nSubsidySlowStartInterval;
|
||||||
|
nSubsidy *= (nHeight+1);
|
||||||
|
return nSubsidy;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(nHeight > consensusParams.SubsidySlowStartShift());
|
||||||
|
int halvings = (nHeight - consensusParams.SubsidySlowStartShift()) / consensusParams.nSubsidyHalvingInterval;
|
||||||
// Force block reward to zero when right shift is undefined.
|
// Force block reward to zero when right shift is undefined.
|
||||||
if (halvings >= 64)
|
if (halvings >= 64)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
CAmount nSubsidy = 50 * COIN;
|
|
||||||
// Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
|
// Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
|
||||||
nSubsidy >>= halvings;
|
nSubsidy >>= halvings;
|
||||||
return nSubsidy;
|
return nSubsidy;
|
||||||
|
|||||||
Reference in New Issue
Block a user