aboutsummaryrefslogtreecommitdiff
path: root/src/pow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pow.cpp')
-rw-r--r--src/pow.cpp18
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)