diff --git a/src/main.cpp b/src/main.cpp index 87a5e3135..aa9a63946 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin developers +// Copyright (c) 2011-2014 Litecoin Developers // Copyright (c) 2013-2014 Dogecoin Developers +// Contributions by /u/lleti, rog1121, and DigiByte (DigiShield Developers). // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -74,6 +76,7 @@ int64 nHPSTimerStart = 0; // Settings int64 nTransactionFee = 0; +int64 nMinimumInputValue = DUST_HARD_LIMIT; ////////////////////////////////////////////////////////////////////////////// @@ -1085,25 +1088,23 @@ int static generateMTRandom(unsigned int s, int range) return dist(gen); } +static const int64 nDiffChangeTarget = 145000; // Patch effective @ block 145000 + int64 static GetBlockValue(int nHeight, int64 nFees, uint256 prevHash) { - int64 nSubsidy = 10000 * COIN; + int64 nSubsidy = 500000 * COIN; std::string cseed_str = prevHash.ToString().substr(7,7); const char* cseed = cseed_str.c_str(); long seed = hex2long(cseed); int rand = generateMTRandom(seed, 999999); int rand1 = 0; - int rand2 = 0; - int rand3 = 0; - int rand4 = 0; - int rand5 = 0; if(nHeight < 100000) { nSubsidy = (1 + rand) * COIN; } - else if(nHeight < 200000) + else if(nHeight < 145000) { cseed_str = prevHash.ToString().substr(7,7); cseed = cseed_str.c_str(); @@ -1111,43 +1112,20 @@ int64 static GetBlockValue(int nHeight, int64 nFees, uint256 prevHash) rand1 = generateMTRandom(seed, 499999); nSubsidy = (1 + rand1) * COIN; } - else if(nHeight < 300000) - { - cseed_str = prevHash.ToString().substr(6,7); - cseed = cseed_str.c_str(); - seed = hex2long(cseed); - rand2 = generateMTRandom(seed, 249999); - nSubsidy = (1 + rand2) * COIN; - } - else if(nHeight < 400000) - { - cseed_str = prevHash.ToString().substr(7,7); - cseed = cseed_str.c_str(); - seed = hex2long(cseed); - rand3 = generateMTRandom(seed, 124999); - nSubsidy = (1 + rand3) * COIN; - } - else if(nHeight < 500000) - { - cseed_str = prevHash.ToString().substr(7,7); - cseed = cseed_str.c_str(); - seed = hex2long(cseed); - rand4 = generateMTRandom(seed, 62499); - nSubsidy = (1 + rand4) * COIN; - } else if(nHeight < 600000) { - cseed_str = prevHash.ToString().substr(6,7); - cseed = cseed_str.c_str(); - seed = hex2long(cseed); - rand5 = generateMTRandom(seed, 31249); - nSubsidy = (1 + rand5) * COIN; + nSubsidy >>= (nHeight / 100000); + } + else + { + nSubsidy = 10000 * COIN; } return nSubsidy + nFees; } -static const int64 nTargetTimespan = 4 * 60 * 60; // DogeCoin: every 4 hours +static const int64 nTargetTimespan = 4 * 60 * 60; // old retarget (4hrs) +static const int64 nTargetTimespanNEW = 60 ; // DogeCoin: every 1 minute static const int64 nTargetSpacing = 60; // DogeCoin: 1 minutes static const int64 nInterval = nTargetTimespan / nTargetSpacing; @@ -1164,12 +1142,20 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime) CBigNum bnResult; bnResult.SetCompact(nBase); + while (nTime > 0 && bnResult < bnProofOfWorkLimit) { - // Maximum 400% adjustment... - bnResult *= 4; - // ... in best-case exactly 4-times-normal target time - nTime -= nTargetTimespan*4; + if(nBestHeight+1 bnProofOfWorkLimit) bnResult = bnProofOfWorkLimit; @@ -1179,26 +1165,39 @@ unsigned int ComputeMinWork(unsigned int nBase, int64 nTime) unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock) { unsigned int nProofOfWorkLimit = bnProofOfWorkLimit.GetCompact(); - + int nHeight = pindexLast->nHeight + 1; + bool fNewDifficultyProtocol = (nHeight >= nDiffChangeTarget); + + + + int64 retargetTimespan = nTargetTimespan; + int64 retargetSpacing = nTargetSpacing; + int64 retargetInterval = nInterval; + + if (fNewDifficultyProtocol) { + retargetInterval = nTargetTimespanNEW / nTargetSpacing; + retargetTimespan = nTargetTimespanNEW; + } + // Genesis block if (pindexLast == NULL) return nProofOfWorkLimit; // Only change once per interval - if ((pindexLast->nHeight+1) % nInterval != 0) + if ((pindexLast->nHeight+1) % retargetInterval != 0) { // Special difficulty rule for testnet: if (fTestNet) { // If the new block's timestamp is more than 2* nTargetSpacing minutes // then allow mining of a min-difficulty block. - if (pblock->nTime > pindexLast->nTime + nTargetSpacing*2) + if (pblock->nTime > pindexLast->nTime + retargetSpacing*2) return nProofOfWorkLimit; else { // Return the last non-special-min-difficulty-rules-block const CBlockIndex* pindex = pindexLast; - while (pindex->pprev && pindex->nHeight % nInterval != 0 && pindex->nBits == nProofOfWorkLimit) + while (pindex->pprev && pindex->nHeight % retargetInterval != 0 && pindex->nBits == nProofOfWorkLimit) pindex = pindex->pprev; return pindex->nBits; } @@ -1209,9 +1208,9 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl // Dogecoin: This fixes an issue where a 51% attack can change difficulty at will. // Go back the full period unless it's the first retarget after genesis. Code courtesy of Art Forz - int blockstogoback = nInterval-1; - if ((pindexLast->nHeight+1) != nInterval) - blockstogoback = nInterval; + int blockstogoback = retargetInterval-1; + if ((pindexLast->nHeight+1) != retargetInterval) + blockstogoback = retargetInterval; // Go back by what we want to be 14 days worth of blocks const CBlockIndex* pindexFirst = pindexLast; @@ -1222,8 +1221,19 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl // Limit adjustment step int64 nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan); - if(pindexLast->nHeight+1 > 10000) + + CBigNum bnNew; + bnNew.SetCompact(pindexLast->nBits); + + if(fNewDifficultyProtocol) //DigiShield implementation - thanks to RealSolid & WDC for this code { + // amplitude filter - thanks to daft27 for this code + nActualTimespan = retargetTimespan + (nActualTimespan - retargetTimespan)/8; + printf("DIGISHIELD RETARGET\n"); + if (nActualTimespan < (retargetTimespan - (retargetTimespan/4)) ) nActualTimespan = (retargetTimespan - (retargetTimespan/4)); + if (nActualTimespan > (retargetTimespan + (retargetTimespan/2)) ) nActualTimespan = (retargetTimespan + (retargetTimespan/2)); + } + else if (pindexLast->nHeight+1 > 10000) { if (nActualTimespan < nTargetTimespan/4) nActualTimespan = nTargetTimespan/4; if (nActualTimespan > nTargetTimespan*4) @@ -1245,17 +1255,16 @@ unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBl } // Retarget - CBigNum bnNew; - bnNew.SetCompact(pindexLast->nBits); + bnNew *= nActualTimespan; - bnNew /= nTargetTimespan; + bnNew /= retargetTimespan; if (bnNew > bnProofOfWorkLimit) bnNew = bnProofOfWorkLimit; /// debug print printf("GetNextWorkRequired RETARGET\n"); - printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", nTargetTimespan, nActualTimespan); + printf("nTargetTimespan = %"PRI64d" nActualTimespan = %"PRI64d"\n", retargetTimespan, nActualTimespan); printf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString().c_str()); printf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString().c_str());