From 949b1ccd88ff13c74a3c1a7b9faa7f36c1085904 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Thu, 9 Jul 2015 22:06:41 +0100 Subject: Modify chain consensus parameters to be height aware --- src/pow.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 44eee9c35..772e11f2f 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -12,6 +12,22 @@ #include "uint256.h" #include "util.h" +// Determine if the for the given block, a min difficulty setting applies +bool AllowMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) +{ + // check if the chain allows minimum difficulty blocks + if (!params.fPowAllowMinDifficultyBlocks) + return false; + + // Dogecoin: Magic number at which reset protocol switches + // check if we allow minimum difficulty at this block-height + if (pindexLast->nHeight < 157500) + return false; + + // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing + return (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2); +} + unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); @@ -20,6 +36,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) { @@ -55,7 +80,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) -- cgit v1.2.3 From 8d5284422914164f73bfbdf3b275879da355af30 Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Mon, 6 Jul 2015 00:07:37 +0100 Subject: Minor Dogecoin consensus fixes Updated maximum coins to match Dogecoin. Updated protocol version to disable connections to pre-AuxPoW clients. Disable version 2 block requirement Update coinbase maturity to match Dogecoin --- src/pow.cpp | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index 772e11f2f..a0fac9219 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -12,22 +12,6 @@ #include "uint256.h" #include "util.h" -// Determine if the for the given block, a min difficulty setting applies -bool AllowMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) -{ - // check if the chain allows minimum difficulty blocks - if (!params.fPowAllowMinDifficultyBlocks) - return false; - - // Dogecoin: Magic number at which reset protocol switches - // check if we allow minimum difficulty at this block-height - if (pindexLast->nHeight < 157500) - return false; - - // Allow for a minimum block time if the elapsed time > 2*nTargetSpacing - return (pblock->GetBlockTime() > pindexLast->GetBlockTime() + params.nPowTargetSpacing*2); -} - unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); -- cgit v1.2.3 From 106ecab0e0c8c33a2a601afd8c42cac2e6b80e0c Mon Sep 17 00:00:00 2001 From: coblee Date: Sun, 9 Oct 2011 20:46:21 -1000 Subject: Litecoin: Fix zeitgeist2 attack thanks to Lolcust and ArtForz. 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. --- src/pow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/pow.cpp') diff --git a/src/pow.cpp b/src/pow.cpp index a0fac9219..1dac0b81c 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -51,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); -- cgit v1.2.3