From efcbaca72c1a09b4b8eeb3db691bd83dfe5a5535 Mon Sep 17 00:00:00 2001 From: myriadcoin Date: Sun, 2 Nov 2014 13:14:13 +0200 Subject: [PATCH] 0.9.2.6 --- configure.ac | 2 +- src/clientversion.h | 2 +- src/main.cpp | 67 ++++++++++++++++++++++++++++++++++++++------- src/main.h | 1 + 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/configure.ac b/configure.ac index 0952b293..8dd93d44 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 0) define(_CLIENT_VERSION_MINOR, 9) define(_CLIENT_VERSION_REVISION, 2) -define(_CLIENT_VERSION_BUILD, 5) +define(_CLIENT_VERSION_BUILD, 6) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2014) AC_INIT([Myriadcoin Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[info@bitcoin.org],[myriadcoin]) diff --git a/src/clientversion.h b/src/clientversion.h index b917d0ff..3ef980a7 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -12,7 +12,7 @@ #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 9 #define CLIENT_VERSION_REVISION 2 -#define CLIENT_VERSION_BUILD 5 +#define CLIENT_VERSION_BUILD 6 // Set to true for release, false for prerelease or test build #define CLIENT_VERSION_IS_RELEASE true diff --git a/src/main.cpp b/src/main.cpp index 61d1f78b..32a980b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1317,25 +1317,72 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // find previous block with same algo const CBlockIndex* pindexPrev = GetLastBlockIndexForAlgo(pindexLast, algo); + if (pindexPrev == NULL) + return nProofOfWorkLimit; - // find first block in averaging interval - // Go back by what we want to be nAveragingInterval blocks - const CBlockIndex* pindexFirst = pindexPrev; - for (int i = 0; pindexFirst && i < nAveragingInterval - 1; i++) + const CBlockIndex* pindexFirst = NULL; + if (pindexLast->nHeight >= nBlockTimeWarpPreventStart) { - pindexFirst = pindexFirst->pprev; - pindexFirst = GetLastBlockIndexForAlgo(pindexFirst, algo); + // find first block in averaging interval + // Go back by what we want to be nAveragingInterval blocks + pindexFirst = pindexPrev; + for (int i = 0; pindexFirst && i < nAveragingInterval - 1; i++) + { + pindexFirst = pindexFirst->pprev; + pindexFirst = GetLastBlockIndexForAlgo(pindexFirst, algo); + } + if (pindexFirst == NULL) + return nProofOfWorkLimit; // not nAveragingInterval blocks of this algo available + + // check block before first block for time warp + const CBlockIndex* pindexFirstPrev = pindexFirst->pprev; + if (pindexFirstPrev == NULL) + return nProofOfWorkLimit; + pindexFirstPrev = GetLastBlockIndexForAlgo(pindexFirstPrev, algo); + if (pindexFirstPrev == NULL) + return nProofOfWorkLimit; + // take previous block if block times are out of order + if (pindexFirstPrev->GetBlockTime() > pindexFirst->GetBlockTime()) + { + LogPrintf(" First blocks out of order times, swapping: %d %d\n", pindexFirstPrev->GetBlockTime(), pindexFirst->GetBlockTime()); + pindexFirst = pindexFirstPrev; + } + } + else + { + // find first block in averaging interval + // Go back by what we want to be nAveragingInterval blocks + pindexFirst = pindexPrev; + for (int i = 0; pindexFirst && i < nAveragingInterval - 1; i++) + { + pindexFirst = pindexFirst->pprev; + pindexFirst = GetLastBlockIndexForAlgo(pindexFirst, algo); + } + if (pindexFirst == NULL) + return nProofOfWorkLimit; // not nAveragingInterval blocks of this algo available } - if (pindexFirst == NULL) - return nProofOfWorkLimit; // not nAveragingInterval blocks of this algo available // Limit adjustment step int64_t nActualTimespan = pindexPrev->GetBlockTime() - pindexFirst->GetBlockTime(); + LogPrintf(" nActualTimespan = %d before bounds %d %d\n", nActualTimespan, pindexPrev->GetBlockTime(), pindexFirst->GetBlockTime()); + + // Time warp mitigation: Don't adjust difficulty if time is negative + if (pindexLast->nHeight >= nBlockTimeWarpPreventStart) + { + if (nActualTimespan < 0) + { + LogPrintf(" nActualTimespan negative %d\n", nActualTimespan); + LogPrintf(" Keeping: %08x %s\n", pindexPrev->nBits, CBigNum().SetCompact(pindexPrev->nBits).getuint256().ToString()); + return pindexPrev->nBits; + } + } + if (nActualTimespan < nMinActualTimespan) nActualTimespan = nMinActualTimespan; if (nActualTimespan > nMaxActualTimespan) nActualTimespan = nMaxActualTimespan; + LogPrintf(" nActualTimespan = %d after bounds %d %d\n", nActualTimespan, nMinActualTimespan, nMaxActualTimespan); // Retarget CBigNum bnNew; @@ -1348,8 +1395,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead /// debug print LogPrintf("GetNextWorkRequired RETARGET\n"); - LogPrintf("nTargetTimespan = %d nActualTimespan = %d\n", nTargetTimespan, nActualTimespan); - LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexLast->nBits).getuint256().ToString()); + LogPrintf("nTargetTimespan = %d nActualTimespan = %d\n", nAveragingTargetTimespan, nActualTimespan); + LogPrintf("Before: %08x %s\n", pindexLast->nBits, CBigNum().SetCompact(pindexPrev->nBits).getuint256().ToString()); LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.getuint256().ToString()); return bnNew.GetCompact(); diff --git a/src/main.h b/src/main.h index f7975de6..45594150 100644 --- a/src/main.h +++ b/src/main.h @@ -691,6 +691,7 @@ const int64_t nBlockAlgoWorkWeightStart = 142000; // block where algo work weigh const int64_t nBlockAlgoNormalisedWorkStart = 740000; // block where algo combined weight starts const int64_t nBlockSequentialAlgoRuleStart = 740000; // block where sequential algo rule starts const int nBlockSequentialAlgoMaxCount = 6; // maximum sequential blocks of same algo +const int64_t nBlockTimeWarpPreventStart = 740500; // block where sequential algo rule starts /** The block chain is a tree shaped structure starting with the * genesis block at the root, with each block potentially having multiple