mirror of
https://git.hush.is/hush/hush3.git
synced 2025-09-27 00:03:21 -04:00
Speed up response to higher hash rate
This commit is contained in:
parent
527ee64eb3
commit
4e3e3a34e1
56
src/pow.cpp
56
src/pow.cpp
@ -74,8 +74,8 @@ 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 bnTarget,bnTot {0};
|
arith_uint256 bnTarget,bnTot {0};
|
||||||
uint32_t nbits; int32_t diff,mult = 0;
|
uint32_t nbits,blocktime,maxdiff=0,block4diff=0; int32_t diff,mult = 0;
|
||||||
if ( 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;
|
||||||
//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);
|
||||||
@ -85,14 +85,21 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
arith_uint256 bnTmp;
|
arith_uint256 bnTmp;
|
||||||
bnTmp.SetCompact(pindexFirst->nBits);
|
bnTmp.SetCompact(pindexFirst->nBits);
|
||||||
bnTot += bnTmp;
|
bnTot += bnTmp;
|
||||||
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && i < 12 && pblock != 0 )
|
if ( ASSETCHAINS_ADAPTIVEPOW > 0 && pblock != 0 )
|
||||||
{
|
{
|
||||||
diff = pblock->nTime - pindexFirst->nTime - (8+i)*ASSETCHAINS_BLOCKTIME;
|
blocktime = pindexFirst->nTime;
|
||||||
if ( diff > mult )
|
diff = (pblock->nTime - blocktime);
|
||||||
|
if ( i < 12 )
|
||||||
{
|
{
|
||||||
fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i));
|
if ( i == 3 )
|
||||||
mult = diff;
|
block4diff = diff;
|
||||||
}
|
diff -= (8+i)*ASSETCHAINS_BLOCKTIME;
|
||||||
|
if ( diff > mult )
|
||||||
|
{
|
||||||
|
fprintf(stderr,"i.%d diff.%d (%u - %u - %dx)\n",i,(int32_t)diff,pblock->nTime,pindexFirst->nTime,(8+i));
|
||||||
|
mult = diff;
|
||||||
|
}
|
||||||
|
} else maxdiff = diff;
|
||||||
}
|
}
|
||||||
pindexFirst = pindexFirst->pprev;
|
pindexFirst = pindexFirst->pprev;
|
||||||
}
|
}
|
||||||
@ -103,17 +110,34 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
|||||||
|
|
||||||
bool fNegative,fOverflow; 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 && mult > 1 ) // jl777: this test of mult > 1 failed when it was int64_t???
|
if ( ASSETCHAINS_ADAPTIVEPOW > 0 ) // jl777: test of mult > 1 failed when it was int64_t???
|
||||||
{
|
{
|
||||||
origtarget = bnTarget = arith_uint256().SetCompact(nbits);
|
origtarget = bnTarget = arith_uint256().SetCompact(nbits);
|
||||||
bnTarget = bnTarget * arith_uint256(mult * mult);
|
if ( mult > 1 )
|
||||||
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
if ( bnTarget < origtarget || bnTarget > easy )
|
|
||||||
{
|
{
|
||||||
bnTarget = easy;
|
bnTarget = bnTarget * arith_uint256(mult * mult);
|
||||||
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
|
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
return(KOMODO_MINDIFF_NBITS);
|
if ( bnTarget < origtarget || bnTarget > easy )
|
||||||
} else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
|
{
|
||||||
|
bnTarget = easy;
|
||||||
|
fprintf(stderr,"cmp.%d mult.%d ht.%d -> easy target\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
|
||||||
|
return(KOMODO_MINDIFF_NBITS);
|
||||||
|
} else fprintf(stderr,"cmp.%d mult.%d for ht.%d\n",mult>1,(int32_t)mult,(int32_t)pindexLast->GetHeight());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( block4diff < ASSETCHAINS_BLOCKTIME ) // for 10x and higher hashrate increases
|
||||||
|
{
|
||||||
|
block4diff += (2 * ASSETCHAINS_BLOCKTIME) / 3;
|
||||||
|
bnTarget = bnTarget * arith_uint256(block4diff) / arith_uint256(ASSETCHAINS_BLOCKTIME * 2);
|
||||||
|
fprintf(stderr,"4 blocks happened in %d adjust by %.4f\n",block4diff-((2 * ASSETCHAINS_BLOCKTIME) / 3),(double)block4diff/(ASSETCHAINS_BLOCKTIME*2));
|
||||||
|
}
|
||||||
|
if ( maxdiff < 13*ASSETCHAINS_BLOCKTIME ) // for miners trying to avoid the 10x trigger
|
||||||
|
{
|
||||||
|
bnTarget = bnTarget * arith_uint256(3) / arith_uint256(4);
|
||||||
|
fprintf(stderr,"17 blocks happened in %d < 13x %d\n",maxdiff,13*ASSETCHAINS_BLOCKTIME);
|
||||||
|
}
|
||||||
|
}
|
||||||
nbits = bnTarget.GetCompact();
|
nbits = bnTarget.GetCompact();
|
||||||
}
|
}
|
||||||
return(nbits);
|
return(nbits);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user