diff options
| author | Ross Nicoll <[email protected]> | 2015-06-28 21:27:28 +0100 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2015-06-28 22:10:58 +0100 |
| commit | 8da45ed40ba5ce2bc5e52f125dbc0a146c0e2a79 (patch) | |
| tree | 0e77c38c34b0f8af5ad0a2afa18729aeadfab9da /src/dogecoin.cpp | |
| parent | Merge pull request #1188 from rnicoll/1.10-reward (diff) | |
| download | discoin-8da45ed40ba5ce2bc5e52f125dbc0a146c0e2a79.tar.xz discoin-8da45ed40ba5ce2bc5e52f125dbc0a146c0e2a79.zip | |
Added Digishield support and unit tests
Diffstat (limited to 'src/dogecoin.cpp')
| -rw-r--r-- | src/dogecoin.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp index 72a9f3cc5..e946acad6 100644 --- a/src/dogecoin.cpp +++ b/src/dogecoin.cpp @@ -5,7 +5,9 @@ #include <boost/random/uniform_int.hpp> #include <boost/random/mersenne_twister.hpp> +#include "arith_uint256.h" #include "dogecoin.h" +#include "util.h" int static generateMTRandom(unsigned int s, int range) { @@ -14,6 +16,65 @@ int static generateMTRandom(unsigned int s, int range) return dist(gen); } +unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) +{ + int nHeight = pindexLast->nHeight + 1; + bool fNewDifficultyProtocol = (nHeight >= 145000); + // bool fNewDifficultyProtocol = (nHeight >= params.GetDigiShieldForkBlock()); + const int64_t retargetTimespan = fNewDifficultyProtocol + ? 60 // params.DigiShieldTargetTimespan() + : params.nPowTargetTimespan; + + const int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime; + int64_t nModulatedTimespan = nActualTimespan; + int64_t nMaxTimespan; + int64_t nMinTimespan; + + if (fNewDifficultyProtocol) //DigiShield implementation - thanks to RealSolid & WDC for this code + { + // amplitude filter - thanks to daft27 for this code + nModulatedTimespan = retargetTimespan + (nModulatedTimespan - retargetTimespan) / 8; + + nMinTimespan = retargetTimespan - (retargetTimespan / 4); + nMaxTimespan = retargetTimespan + (retargetTimespan / 2); + } else if (nHeight > 10000) { + nMinTimespan = retargetTimespan / 4; + nMaxTimespan = retargetTimespan * 4; + } else if (nHeight > 5000) { + nMinTimespan = retargetTimespan / 8; + nMaxTimespan = retargetTimespan * 4; + } else { + nMinTimespan = retargetTimespan / 16; + nMaxTimespan = retargetTimespan * 4; + } + + // Limit adjustment step + if (nModulatedTimespan < nMinTimespan) + nModulatedTimespan = nMinTimespan; + else if (nModulatedTimespan > nMaxTimespan) + nModulatedTimespan = nMaxTimespan; + + // Retarget + const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); + arith_uint256 bnNew; + arith_uint256 bnOld; + bnNew.SetCompact(pindexLast->nBits); + bnOld = bnNew; + bnNew *= nModulatedTimespan; + bnNew /= retargetTimespan; + + if (bnNew > bnPowLimit) + bnNew = bnPowLimit; + + /// debug print + LogPrintf("GetNextWorkRequired RETARGET\n"); + LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan); + LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString()); + LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString()); + + return bnNew.GetCompact(); +} + CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash) { int halvings = nHeight / consensusParams.nSubsidyHalvingInterval; |