Zawy12, reduce noise ave with bnPrev

This commit is contained in:
jl777
2019-08-03 06:24:09 -11:00
parent 62a57c1ebd
commit 4fa1f639e2

View File

@@ -100,11 +100,12 @@ 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 bnTmp,bnTarget,bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0}; arith_uint256 bnTmp,bnTarget,bnPrev {0},bnSum4 {0},bnSum7 {0},bnSum12 {0},bnTot {0};
uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0; uint32_t nbits,blocktime,block4diff=0,block7diff=0,block12diff=0; int32_t diff,mult = 0;
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 ) if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pindexFirst != 0 && pblock != 0 )
{ {
mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME; mult = pblock->nTime - pindexFirst->nTime - 7 * ASSETCHAINS_BLOCKTIME;
bnPrev.SetCompact(pindexFirst->nBits);
//fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime); //fprintf(stderr,"ht.%d mult.%d = (%u - %u - 7x)\n",pindexLast->GetHeight(),(int32_t)mult,pblock->nTime, pindexFirst->nTime);
} }
for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++) for (int i = 0; pindexFirst && i < params.nPowAveragingWindow; i++)
@@ -148,7 +149,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if (pindexFirst == NULL) if (pindexFirst == NULL)
return nProofOfWorkLimit; return nProofOfWorkLimit;
bool fNegative,fOverflow; int32_t flag; arith_uint256 easy,origtarget,bnAvg {bnTot / params.nPowAveragingWindow}; bool fNegative,fOverflow; 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 ) if ( ASSETCHAINS_ADAPTIVEPOW > 0 )
{ {
@@ -165,27 +166,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
} else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight()); } else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
} }
else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 ) else if ( block12diff != 0 && block7diff != 0 && block4diff != 0 )
{
flag = 0;
/*if ( block4diff >= 4 && block4diff < ASSETCHAINS_BLOCKTIME/3 )
{
bnTarget /= arith_uint256(4);
flag = 4;
fprintf(stderr,"ht.%d 4 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block4diff,0.25);
}
if ( block7diff >= 7 && block7diff < ASSETCHAINS_BLOCKTIME/2 )
{
bnTarget /= arith_uint256(7);
flag = 7;
fprintf(stderr,"ht.%d 7 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block7diff,1./7);
}
if ( block12diff >= 12 && block12diff < ASSETCHAINS_BLOCKTIME )
{
bnTarget /= arith_uint256(12);
flag = 12;
fprintf(stderr,"ht.%d 12 blocks happened in %d adjust by %.4f\n",(int32_t)pindexLast->GetHeight(),block12diff,1./12);
}
else if ( flag == 0 )*/
{ {
if ( block12diff < ASSETCHAINS_BLOCKTIME*11 ) if ( block12diff < ASSETCHAINS_BLOCKTIME*11 )
{ {
@@ -200,7 +180,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if ( bnTmp < bnTarget ) if ( bnTmp < bnTarget )
{ {
fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11); fprintf(stderr,"ht.%d block12diff %d < %d, make harder\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*11);
bnTarget = bnTmp; bnTarget = (bnTmp + bnPrev) / arith_uint256(2);
} //else fprintf(stderr,"nothing smaller\n"); } //else fprintf(stderr,"nothing smaller\n");
} }
else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 ) else if ( block12diff > ASSETCHAINS_BLOCKTIME*13 )
@@ -216,10 +196,9 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
if ( bnTmp > bnTarget ) if ( bnTmp > bnTarget )
{ {
fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13); fprintf(stderr,"ht.%d block12diff %d > %d, make easier\n",(int32_t)pindexLast->GetHeight()+1,block12diff,ASSETCHAINS_BLOCKTIME*13);
bnTarget = bnTmp; bnTarget = (bnTmp + bnPrev) / arith_uint256(2);
} //else fprintf(stderr,"nothing bigger\n"); } //else fprintf(stderr,"nothing bigger\n");
} }
}
} // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff); } // else fprintf(stderr,"null diff %d %d %d\n",block4diff,block7diff,block12diff);
nbits = bnTarget.GetCompact(); nbits = bnTarget.GetCompact();
} }