Browse Source

Merge pull request #1678 from jl777/nSPV

NSPV
pull/37/head
jl777 5 years ago
committed by GitHub
parent
commit
3d15d269ad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 69
      src/pow.cpp

69
src/pow.cpp

@ -183,7 +183,7 @@ arith_uint256 RT_CST_RST_outer(int32_t height,uint32_t nTime,arith_uint256 bnTar
for (z=31; z>=0; z--)
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[z]);
}
fprintf(stderr," ht.%d initial outerK.%lld %d * %d * %d / %d\n",height,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator);
fprintf(stderr," ht.%d initial W.%d outerK.%lld %d * %d * %d / %d\n",height,W,(long long)outerK,(nTime-ts[0]),(ts[0]-ts[W]),denominator,numerator);
} //else fprintf(stderr,"ht.%d no outer trigger %d >= %d\n",height,(ts[0] - ts[W]),(T * numerator)/denominator);
return(bnTarget);
}
@ -322,7 +322,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],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget6,bnTarget12,bnTot {0};
arith_uint256 ct[64],ctinv[64],bnTmp,bnPrev,bnTarget,bnTarget2,bnTarget3,bnTarget6,bnTarget12,bnTot {0};
uint32_t nbits,blocktime,ts[sizeof(ct)/sizeof(*ct)]; int32_t zflags[sizeof(ct)/sizeof(*ct)],i,diff,height=0,mult = 0,tipdiff = 0;
memset(ts,0,sizeof(ts));
memset(ct,0,sizeof(ct));
@ -373,8 +373,8 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
mult = diff;
}
}
//if ( zflags[i] != 0 && zflags[0] != 0 )
// bnTmp = (ct[i] / arith_uint256(3));
if ( zflags[i] != 0 && zflags[0] == 0 ) // an RST block, but the most recent has no RST
bnTmp = (bnTmp / arith_uint256(8)) * arith_uint256(7);
}
bnTot += bnTmp;
pindexFirst = pindexFirst->pprev;
@ -384,7 +384,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if (pindexFirst == NULL)
return nProofOfWorkLimit;
bool fNegative,fOverflow; int32_t past,zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
bool fNegative,fOverflow; int32_t zawyflag = 0; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow};
nbits = CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
{
@ -395,43 +395,76 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if ( pblock != 0 )
{
origtarget = bnTarget;
past = 20;
if ( zflags[0] == 0 || zflags[0] == 3 )
{
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,2,3,past);
if ( ASSETCHAINS_BLOCKTIME >= 60 && ASSETCHAINS_BLOCKTIME < 100 )
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,60,1,10);
else if ( ASSETCHAINS_BLOCKTIME >= 100 )
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,1,100,1,10);
if ( bnTarget < origtarget )
zawyflag = 2;
else
{
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,7,3,6,past+10);
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,15,100,2,20);
if ( bnTarget < origtarget )
zawyflag = 2;
else
{
bnTarget = RT_CST_RST_outer(height,pblock->nTime,bnTarget,ts,ct,12,7,12,past+20);
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,1,2,3,30);
if ( bnTarget < origtarget )
zawyflag = 2;
else
{
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,7,3,6,40);
if ( bnTarget < origtarget )
zawyflag = 2;
else
{
bnTarget = RT_CST_RST_outer(height,pblock->nTime,origtarget,ts,ct,12,7,12,50);
if ( bnTarget < origtarget )
zawyflag = 2;
}
}
}
}
}
else
{
for (i=0; i<40; i++)
for (i=0; i<50; i++)
if ( zflags[i] == 2 )
break;
if ( i < 10 )
{
bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,1,i);
if ( bnTarget > origtarget )
bnTarget = origtarget;
}
if ( i < 20 )
{
bnTarget2 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,2,i);
if ( bnTarget2 < bnTarget )
bnTarget = bnTarget2;
}
if ( i < 30 )
{
bnTarget3 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i);
if ( bnTarget3 < bnTarget )
bnTarget = bnTarget3;
}
if ( i < 40 )
{
bnTarget = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,3,i);
bnTarget6 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,6,i);
if ( bnTarget6 < bnTarget )
bnTarget = bnTarget6;
}
if ( i < 50 )
{
bnTarget12 = RT_CST_RST_inner(height,pblock->nTime,bnTarget,ts,ct,12,i);
if ( bnTarget6 < bnTarget12 )
bnTmp = bnTarget6;
else bnTmp = bnTarget12;
if ( bnTmp < bnTarget )
bnTarget = bnTmp;
if ( bnTarget != origtarget )
zawyflag = 1;
if ( bnTarget12 < bnTarget)
bnTarget = bnTarget12;
}
if ( bnTarget != origtarget )
zawyflag = 1;
}
}
if ( mult > 1 ) // e^mult case, jl777: test of mult > 1 failed when it was int64_t???

Loading…
Cancel
Save