diff options
| author | Ross Nicoll <[email protected]> | 2021-05-29 09:32:55 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2021-05-30 22:12:51 +0100 |
| commit | 4fea2ce46877fdf754dc9e22d1e8b3830f5919bd (patch) | |
| tree | c784707358fa06965cacf0ee90752fcbf82402ef /src/dogecoin.cpp | |
| parent | Merge pull request #1977 from rnicoll/1.21-difficulty (diff) | |
| download | archived-discoin-4fea2ce46877fdf754dc9e22d1e8b3830f5919bd.tar.xz archived-discoin-4fea2ce46877fdf754dc9e22d1e8b3830f5919bd.zip | |
Add Dogecoin block subsidies
Diffstat (limited to 'src/dogecoin.cpp')
| -rw-r--r-- | src/dogecoin.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index 7af47d5d4..31cd69bfc 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -2,10 +2,53 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include <boost/random/mersenne_twister.hpp> +#include <boost/random/uniform_int.hpp> + #include <arith_uint256.h> #include <dogecoin.h> #include <logging.h> +int static generateMTRandom(unsigned int s, int range) +{ + boost::mt19937 gen(s); + boost::uniform_int<> dist(1, range); + return dist(gen); +} + +CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash) +{ + int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; + + if (nHeight < 145000 && !consensusParams.fSimplifiedRewards) + { + // Old-style rewards derived from the previous block hash + + // This extracts 7*4 bits out of the middle of the previous block hash to use as a seed. + // It's longer than the 1.14 code, but avoids the locale-sensitive strtol() function. + const int bitsPerNibble = 4; + const int totalNibbles = 256 / bitsPerNibble; + const int nibblesToClear = 7; + const int nibblesToKeep = 7; + arith_uint256 upperBits = UintToArith256(prevHash) << (nibblesToClear * bitsPerNibble); + arith_uint256 cleanedBits = upperBits >> ((totalNibbles - nibblesToKeep) * bitsPerNibble); + uint64_t seed = ArithToUint256(cleanedBits).GetUint64(0); + + // Convert the seed into a subsidy value. + CAmount maxReward = (1000000 >> halvings) - 1; + int rand = generateMTRandom(seed, maxReward); + + return (1 + rand) * COIN; + } else if (nHeight < (6 * consensusParams.nSubsidyHalvingInterval)) { + // New-style constant rewards for each halving interval + return (500000 * COIN) >> halvings; + } else { + // Constant inflation + return 10000 * COIN; + } +} + + // Dogecoin: Normally minimum difficulty blocks can only occur in between // retarget blocks. However, once we introduce Digishield every block is // a retarget, so we need to handle minimum difficulty on all blocks. |