From c5eb32a85beeec07dc4ebea3788a63da23df9dff Mon Sep 17 00:00:00 2001 From: Jannis Froese Date: Sat, 22 Mar 2014 07:33:44 +0100 Subject: [PATCH] updated to Dogecoin 1.6 protocol (cherry picked from commit d6dbaf412e2331426d5012d1c10b7749b6821b82) --- src/main.cpp | 34 ++++++++++++++++++++++++++++++---- src/main.h | 4 ++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f4159e269..2cfe9a6e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1184,9 +1184,12 @@ int64_t GetBlockValue(int nHeight, int64_t nFees, uint256 prevHash) } static const int64_t nTargetTimespan = 4 * 60 * 60; // DogeCoin: every 4 hours +static const int64_t nTargetTimespanNEW = 60 ; // DogeCoin: every 1 minute static const int64_t nTargetSpacing = 60; // DogeCoin: 1 minute static const int64_t nInterval = nTargetTimespan / nTargetSpacing; +static const int64_t nDiffChangeTarget = 145000; // Patch effective @ block 145000 + // // minimum amount of work that could possibly be required nTime after // minimum work required was nBase @@ -1217,6 +1220,18 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { unsigned int nProofOfWorkLimit = Params().ProofOfWorkLimit().GetCompact(); + int nHeight = pindexLast->nHeight + 1; + bool fNewDifficultyProtocol = (nHeight >= nDiffChangeTarget); + + int64_t retargetTimespan = nTargetTimespan; + int64_t retargetSpacing = nTargetSpacing; + int64_t retargetInterval = nInterval; + + if (fNewDifficultyProtocol) { + retargetInterval = nTargetTimespanNEW / nTargetSpacing; + retargetTimespan = nTargetTimespanNEW; + } + // Genesis block if (pindexLast == NULL) return nProofOfWorkLimit; @@ -1257,15 +1272,23 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Limit adjustment step int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime(); - //printf(" nActualTimespan = %"PRI64d" before bounds\n", nActualTimespan); - if(pindexLast->nHeight+1 > 10000) + LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan); + + 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) nActualTimespan = nTargetTimespan*4; } - else if(pindexLast->nHeight+1 > 5000) + else if (pindexLast->nHeight+1 > 5000) { if (nActualTimespan < nTargetTimespan/8) nActualTimespan = nTargetTimespan/8; @@ -1549,7 +1572,10 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, CCoinsViewCach // If prev is coinbase, check that it's matured if (coins.IsCoinBase()) { - if (nSpendHeight - coins.nHeight < COINBASE_MATURITY) + int minDepth = COINBASE_MATURITY; + if(coins.nHeight >= COINBASE_MATURITY_SWITCH) + minDepth = COINBASE_MATURITY_NEW; + if (nSpendHeight - coins.nHeight < minDepth) return state.Invalid( error("CheckInputs() : tried to spend coinbase at depth %d", nSpendHeight - coins.nHeight), REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); diff --git a/src/main.h b/src/main.h index 29015b2bc..96cd8733f 100644 --- a/src/main.h +++ b/src/main.h @@ -61,6 +61,10 @@ static const int64_t DUST_SOFT_LIMIT = 100000000; static const int64_t DUST_HARD_LIMIT = 1000000; /** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */ static const int COINBASE_MATURITY = 30; +/** Coinbase maturity after block 145000 **/ +static const int COINBASE_MATURITY_NEW = 60*4; +/** Block at which COINBASE_MATURITY_NEW comes into effect **/ +static const int COINBASE_MATURITY_SWITCH = 145000; /** Threshold for nLockTime: below this value it is interpreted as block number, otherwise as UNIX timestamp. */ static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC /** Maximum number of script-checking threads allowed */