Test averaging
This commit is contained in:
12
src/pow.cpp
12
src/pow.cpp
@@ -214,7 +214,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
|
|
||||||
// Find the first block in the averaging interval
|
// Find the first block in the averaging interval
|
||||||
const CBlockIndex* pindexFirst = pindexLast;
|
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;
|
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(ts,0,sizeof(ts));
|
||||||
memset(ct,0,sizeof(ct));
|
memset(ct,0,sizeof(ct));
|
||||||
@@ -224,13 +224,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
{
|
{
|
||||||
tipdiff = (pblock->nTime - pindexFirst->nTime);
|
tipdiff = (pblock->nTime - pindexFirst->nTime);
|
||||||
mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME;
|
mult = tipdiff - 7 * ASSETCHAINS_BLOCKTIME;
|
||||||
|
bnPrev.SetCompact(pindexFirst->nBits);
|
||||||
for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++)
|
for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct)); i++)
|
||||||
{
|
{
|
||||||
ct[i].SetCompact(pindexFirst->nBits);
|
ct[i].SetCompact(pindexFirst->nBits);
|
||||||
ts[i] = pindexFirst->nTime;
|
ts[i] = pindexFirst->nTime;
|
||||||
pindexFirst = pindexFirst->pprev;
|
pindexFirst = pindexFirst->pprev;
|
||||||
}
|
}
|
||||||
//bnPrev.SetCompact(pindexFirst->nBits);
|
|
||||||
}
|
}
|
||||||
pindexFirst = pindexLast;
|
pindexFirst = pindexLast;
|
||||||
for (i = 0; pindexFirst && i < params.nPowAveragingWindow; i++)
|
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);
|
bnTarget = arith_uint256().SetCompact(nbits);
|
||||||
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
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???
|
if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???
|
||||||
{
|
{
|
||||||
origtarget = bnTarget;
|
|
||||||
bnTarget = zawy_exponential(bnTarget,mult);
|
bnTarget = zawy_exponential(bnTarget,mult);
|
||||||
if ( bnTarget < origtarget || bnTarget > easy )
|
if ( bnTarget < origtarget || bnTarget > easy )
|
||||||
{
|
{
|
||||||
@@ -293,6 +293,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
else bnTmp = bnTarget12;
|
else bnTmp = bnTarget12;
|
||||||
if ( 0 && bnTmp < bnTarget )
|
if ( 0 && bnTmp < bnTarget )
|
||||||
bnTarget = bnTmp;
|
bnTarget = bnTmp;
|
||||||
|
if ( pindexLast->GetHeight()+1 >= 230 )
|
||||||
|
{
|
||||||
|
if ( bnTarget < origtarget )
|
||||||
|
bnTarget = (origtarget + bnTarget + bnPrev) / arith_uint256(3);
|
||||||
|
else bnTarget = origtarget;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nbits = bnTarget.GetCompact();
|
nbits = bnTarget.GetCompact();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user