Always set nBits
This commit is contained in:
116
src/pow.cpp
116
src/pow.cpp
@@ -107,7 +107,7 @@ arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTar
|
|||||||
bnTarget = ct[0] / arith_uint256(K);
|
bnTarget = ct[0] / arith_uint256(K);
|
||||||
bnTarget *= arith_uint256(outerK);
|
bnTarget *= arith_uint256(outerK);
|
||||||
}
|
}
|
||||||
}
|
} else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator);
|
||||||
return(bnTarget);
|
return(bnTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,6 +127,7 @@ arith_uint256 RT_CST_RST_target(int32_t height,uint32_t nTime,arith_uint256 bnTa
|
|||||||
arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri)
|
arith_uint256 RT_CST_RST_inner(int32_t height,uint32_t nTime,arith_uint256 bnTarget,uint32_t *ts,arith_uint256 *ct,int32_t numerator,int32_t denominator,int32_t W,int32_t past,int32_t outeri)
|
||||||
{
|
{
|
||||||
arith_uint256 bnTargetW,bnTargetwidth,bnTmp; int32_t width = outeri+W;
|
arith_uint256 bnTargetW,bnTargetwidth,bnTmp; int32_t width = outeri+W;
|
||||||
|
fprintf(stderr,"check inner outeri.%d, width.%d %d vs %d\n",outeri,width,(ts[0] - ts[width]),width*T);
|
||||||
if ( (ts[0] - ts[width]) < width*T )
|
if ( (ts[0] - ts[width]) < width*T )
|
||||||
{
|
{
|
||||||
bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W);
|
bnTargetW = RT_CST_RST_target(height,nTime,bnTarget,ts,ct,W);
|
||||||
@@ -293,20 +294,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
bnPrev.SetCompact(pindexFirst->nBits);
|
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++)
|
||||||
{
|
{
|
||||||
if ( height-i-1 >= (int32_t)(sizeof(ct)/sizeof(*ct)) )
|
zflags[i] = (pindexFirst->nBits & 3);
|
||||||
zflags[i] = (pindexFirst->nBits & 3);
|
ct[i].SetCompact(pindexFirst->nBits);
|
||||||
/*if ( (pindexFirst->nBits&3) != 0 )
|
|
||||||
{
|
|
||||||
ct[i] = UintToArith256(pindexFirst->GetBlockHash());
|
|
||||||
ct[i] /= arith_uint256((pindexFirst->nBits&3) + 1);
|
|
||||||
} else*/
|
|
||||||
ct[i].SetCompact(pindexFirst->nBits);
|
|
||||||
ts[i] = pindexFirst->nTime;
|
ts[i] = pindexFirst->nTime;
|
||||||
pindexFirst = pindexFirst->pprev;
|
pindexFirst = pindexFirst->pprev;
|
||||||
}
|
}
|
||||||
for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++)
|
for (i=0; pindexFirst != 0 && i<(int32_t)(sizeof(ct)/sizeof(*ct))-1; i++)
|
||||||
{
|
{
|
||||||
if ( zflags[i] != 0 )
|
if ( zflags[i] != 0 && height-1-i >= (int32_t)(sizeof(ct)/sizeof(*ct)) )
|
||||||
ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]);
|
ct[i] = zawy_ctB(ct[i],ts[i] - ts[i+1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,64 +336,67 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
|
|
||||||
bool fNegative,fOverflow; int32_t past,zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
|
bool fNegative,fOverflow; int32_t past,zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
|
||||||
nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && height >= (int32_t)(sizeof(ct)/sizeof(*ct)) )
|
if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
|
||||||
{
|
{
|
||||||
bnTarget = arith_uint256().SetCompact(nbits);
|
bnTarget = arith_uint256().SetCompact(nbits);
|
||||||
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
if ( height >= (int32_t)(sizeof(ct)/sizeof(*ct)) )
|
||||||
if ( pblock != 0 )
|
|
||||||
{
|
{
|
||||||
origtarget = bnTarget;
|
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
past = 20;
|
if ( pblock != 0 )
|
||||||
if ( zflags[0] == 0 )
|
|
||||||
{
|
{
|
||||||
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past);
|
origtarget = bnTarget;
|
||||||
if ( bnTarget < origtarget )
|
past = 20;
|
||||||
zawyflag = 2;
|
if ( zflags[0] == 0 )
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (i=1; i<past; i++)
|
|
||||||
if ( (zflags[i] & 2) != 0 )
|
|
||||||
break;
|
|
||||||
if ( i < past )
|
|
||||||
{
|
{
|
||||||
bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past,i);
|
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past);
|
||||||
if ( bnTarget != origtarget )
|
if ( bnTarget < origtarget )
|
||||||
zawyflag = 1;
|
zawyflag = 2;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i=1; i<past; i++)
|
||||||
|
if ( (zflags[i] & 2) != 0 )
|
||||||
|
break;
|
||||||
|
if ( i < past )
|
||||||
|
{
|
||||||
|
bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past,i);
|
||||||
|
if ( bnTarget != origtarget )
|
||||||
|
zawyflag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past);
|
||||||
|
bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20);
|
||||||
|
if ( 0 )
|
||||||
|
{
|
||||||
|
bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50);
|
||||||
|
bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50);
|
||||||
|
if ( bnTarget6 < bnTarget12 )
|
||||||
|
bnTmp = bnTarget6;
|
||||||
|
else bnTmp = bnTarget12;
|
||||||
|
if ( bnTmp < bnTarget )
|
||||||
|
bnTarget = bnTmp;
|
||||||
|
}*/
|
||||||
|
if ( bnTarget > origtarget )
|
||||||
|
bnTarget = origtarget;
|
||||||
}
|
}
|
||||||
/*
|
if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???
|
||||||
// bnTarget = RT_CST_RST (height,nTime,bnTarget, ts, cw, numerator, denominator, W, T, past);
|
|
||||||
bnTarget = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,1,2,3,20);
|
|
||||||
if ( 0 )
|
|
||||||
{
|
{
|
||||||
bnTarget6 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,7,3,6,50);
|
origtarget = bnTarget;
|
||||||
bnTarget12 = RT_CST_RST(height,pblock->nTime,bnTarget,ts,ct,12,7,12,50);
|
bnTarget = zawy_exponential(bnTarget,mult);
|
||||||
if ( bnTarget6 < bnTarget12 )
|
if ( bnTarget < origtarget || bnTarget > easy )
|
||||||
bnTmp = bnTarget6;
|
{
|
||||||
else bnTmp = bnTarget12;
|
bnTarget = easy;
|
||||||
if ( bnTmp < bnTarget )
|
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height);
|
||||||
bnTarget = bnTmp;
|
return(KOMODO_MINDIFF_NBITS);
|
||||||
}*/
|
}
|
||||||
if ( bnTarget > origtarget )
|
{
|
||||||
bnTarget = origtarget;
|
int32_t z;
|
||||||
}
|
for (z=31; z>=0; z--)
|
||||||
if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???
|
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
||||||
{
|
}
|
||||||
origtarget = bnTarget;
|
fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height);
|
||||||
bnTarget = zawy_exponential(bnTarget,mult);
|
|
||||||
if ( bnTarget < origtarget || bnTarget > easy )
|
|
||||||
{
|
|
||||||
bnTarget = easy;
|
|
||||||
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,height);
|
|
||||||
return(KOMODO_MINDIFF_NBITS);
|
|
||||||
}
|
}
|
||||||
{
|
|
||||||
int32_t z;
|
|
||||||
for (z=31; z>=0; z--)
|
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
|
|
||||||
}
|
|
||||||
fprintf(stderr," cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,height);
|
|
||||||
}
|
}
|
||||||
nbits = bnTarget.GetCompact();
|
nbits = bnTarget.GetCompact();
|
||||||
nbits = (nbits & 0xfffffffc) | zawyflag;
|
nbits = (nbits & 0xfffffffc) | zawyflag;
|
||||||
|
|||||||
Reference in New Issue
Block a user