From bcb34c0802bbc1224a2c5b640b870fc028aaee62 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 19 Apr 2016 18:50:52 +1200 Subject: [PATCH] Implement mining slow start with a linear ramp --- src/chainparams.cpp | 1 + src/consensus/params.h | 14 ++++++++++++++ src/main.cpp | 19 +++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 9ff874cb..2a7837f1 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -31,6 +31,7 @@ class CMainParams : public CChainParams { public: CMainParams() { strNetworkID = "main"; + consensus.nSubsidySlowStartInterval = 5000; consensus.nSubsidyHalvingInterval = 210000; consensus.nMajorityEnforceBlockUpgrade = 750; consensus.nMajorityRejectBlockOutdated = 950; diff --git a/src/consensus/params.h b/src/consensus/params.h index c480a1cc..43f0fb43 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -14,6 +14,20 @@ namespace Consensus { */ struct Params { 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; /** Used to check majorities for block version upgrade */ int nMajorityEnforceBlockUpgrade; diff --git a/src/main.cpp b/src/main.cpp index 4860513b..80f14aa2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1324,12 +1324,27 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex) 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. if (halvings >= 64) return 0; - CAmount nSubsidy = 50 * COIN; // Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years. nSubsidy >>= halvings; return nSubsidy;