diff --git a/src/pow.cpp b/src/pow.cpp index ba7c1d91e..16db74f05 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -214,7 +214,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead // Find the first block in the averaging interval const CBlockIndex* pindexFirst = pindexLast; - arith_uint256 ct[64],bnTmp,bnTarget,bnTarget6,bnTarget12,bnTot {0}; + arith_uint256 ct[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0}; uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t i,diff,height=0,mult = 0,tipdiff = 0; memset(ts,0,sizeof(ts)); memset(ct,0,sizeof(ct)); @@ -224,13 +224,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { tipdiff = (pblock->nTime - pindexFirst->nTime); mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME; + bnPrev.SetCompact(pindexFirst->nBits); for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++) { ct[i].SetCompact(pindexFirst->nBits); ts[i] = pindexFirst->nTime; pindexFirst = pindexFirst->pprev; } - //bnPrev.SetCompact(pindexFirst->nBits); } pindexFirst = pindexLast; for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) @@ -265,9 +265,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead { bnTarget = arith_uint256().SetCompact(nbits); easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + origtarget = bnTarget; if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t??? { - origtarget = bnTarget; bnTarget = zawy_exponential(bnTarget,mult); if ( bnTarget < origtarget || bnTarget > easy ) { @@ -293,6 +293,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead else bnTmp = bnTarget12; if ( 0 && bnTmp < bnTarget ) bnTarget = bnTmp; + if ( pindexLast->GetHeight()+1 >= 230 ) + { + if ( bnTarget < origtarget ) + bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3); + else bnTarget = origtarget; + } } nbits = bnTarget.GetCompact(); }