diff options
| author | Patrick Lodder <[email protected]> | 2015-07-20 15:03:02 +0200 |
|---|---|---|
| committer | Patrick Lodder <[email protected]> | 2015-07-20 15:03:02 +0200 |
| commit | 8cd835cddba565594f5cde2d91ee92e32bcbf2fd (patch) | |
| tree | 049698b334daf7e65af268b0da64134fd9dbbfdc /src/pow.cpp | |
| parent | Merge pull request #1200 from rnicoll/1.10-auxpow-clean (diff) | |
| parent | Update Python test address and key values to match Dogecoin format. (diff) | |
| download | discoin-8cd835cddba565594f5cde2d91ee92e32bcbf2fd.tar.xz discoin-8cd835cddba565594f5cde2d91ee92e32bcbf2fd.zip | |
Merge pull request #1201 from rnicoll/1.10-sync
Consensus fixes
Diffstat (limited to 'src/pow.cpp')
| -rw-r--r-- | src/pow.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/pow.cpp b/src/pow.cpp index 44eee9c35..1dac0b81c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -20,6 +20,15 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexLast == NULL) return nProofOfWorkLimit; + // Dogecoin: Special rules for minimum difficulty blocks with Digishield + if (AllowDigishieldMinDifficultyForBlock(pindexLast, pblock, params)) + { + // Special difficulty rule for testnet: + // If the new block's timestamp is more than 2* nTargetSpacing minutes + // then allow mining of a min-difficulty block. + return nProofOfWorkLimit; + } + // Only change once per difficulty adjustment interval if ((pindexLast->nHeight+1) % params.DifficultyAdjustmentInterval() != 0) { @@ -42,8 +51,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead return pindexLast->nBits; } + // Litecoin: 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 = params.DifficultyAdjustmentInterval()-1; + if ((pindexLast->nHeight+1) != params.DifficultyAdjustmentInterval()) + blockstogoback = params.DifficultyAdjustmentInterval(); + // Go back by what we want to be 14 days worth of blocks - int nHeightFirst = pindexLast->nHeight - (params.DifficultyAdjustmentInterval()-1); + int nHeightFirst = pindexLast->nHeight - blockstogoback; assert(nHeightFirst >= 0); const CBlockIndex* pindexFirst = pindexLast->GetAncestor(nHeightFirst); assert(pindexFirst); @@ -55,7 +70,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF { // Limit adjustment step int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime; - LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan); if (nActualTimespan < params.nPowTargetTimespan/4) nActualTimespan = params.nPowTargetTimespan/4; if (nActualTimespan > params.nPowTargetTimespan*4) |