From c95dba4f9c46bbc6a3755f5b2038853251cb67af Mon Sep 17 00:00:00 2001 From: khalahan Date: Sat, 1 Mar 2014 23:54:51 +0100 Subject: [PATCH 1/2] Testnet difficulty calculation changes, to take effect Mar 15 2014 Allow mining of min-difficulty blocks if 20 minutes have gone by without mining a regular-difficulty block. Normal rules apply every 2016 blocks, though, so there may be a very-slow-to-confirm block at the difficulty-adjustment blocks. --- src/main.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 26331adb5..1fe6ec39f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -746,19 +746,40 @@ int64 static GetBlockValue(int nHeight, int64 nFees) return nSubsidy + nFees; } -unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast) +unsigned int static GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlock *pblock) { const int64 nTargetTimespan = 14 * 24 * 60 * 60; // two weeks const int64 nTargetSpacing = 10 * 60; const int64 nInterval = nTargetTimespan / nTargetSpacing; + unsigned int nProofOfWorkLimit = bnProofOfWorkLimit.GetCompact(); + // Genesis block if (pindexLast == NULL) - return bnProofOfWorkLimit.GetCompact(); + return nProofOfWorkLimit; // Only change once per interval if ((pindexLast->nHeight+1) % nInterval != 0) + { + // Special rules for testnet after 15 Mar 2014: + if (fTestNet && pblock->nTime > 1394838000) + { + // If the new block's timestamp is more than 2* 10 minutes + // then allow mining of a min-difficulty block. + if (pblock->nTime - pindexLast->nTime > nTargetSpacing*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) + pindex = pindex->pprev; + return pindex->nBits; + } + } + return pindexLast->nBits; + } // Go back the full period unless it's the first retarget after genesis. Code courtesy of ArtForz @@ -1526,7 +1547,7 @@ bool CBlock::AcceptBlock() int nHeight = pindexPrev->nHeight+1; // Check proof of work - if (nBits != GetNextWorkRequired(pindexPrev)) + if (nBits != GetNextWorkRequired(pindexPrev, this)) return error("AcceptBlock() : incorrect proof of work"); // Check timestamp against prev @@ -3125,7 +3146,7 @@ CBlock* CreateNewBlock(CReserveKey& reservekey) pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashMerkleRoot = pblock->BuildMerkleTree(); pblock->nTime = max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); - pblock->nBits = GetNextWorkRequired(pindexPrev); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock.get()); pblock->nNonce = 0; return pblock.release(); From 8f64b47f58bc701ac0ae4aed53eaabc4c9337bf6 Mon Sep 17 00:00:00 2001 From: khalahan Date: Sun, 2 Mar 2014 00:15:12 +0100 Subject: [PATCH 2/2] Update version to 0.3.73 --- src/serialize.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serialize.h b/src/serialize.h index 2a8e0ff80..a6c80d23e 100644 --- a/src/serialize.h +++ b/src/serialize.h @@ -35,7 +35,7 @@ class CDataStream; class CAutoFile; static const unsigned int MAX_SIZE = 0x02000000; -static const int VERSION = 37200; +static const int VERSION = 37300; static const char* pszSubVer = ""; static const bool VERSION_IS_BETA = false;