Test averaging

This commit is contained in:
jl777
2019-08-05 08:40:21 -11:00
parent 4dbac8fea0
commit 4d7f11ccf8

View File

@@ -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();
}