Update adaptivepow to handle variable block times
This commit is contained in:
@@ -1416,6 +1416,29 @@ uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256
|
|||||||
return(addrhash.uints[0]);
|
return(addrhash.uints[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime)
|
||||||
|
{
|
||||||
|
arith_uint256 origtarget,easy; int32_t diff,mult; bool fNegative,fOverflow; CBlockIndex *tipindex;
|
||||||
|
if ( height > 10 && (tipindex= komodo_chainactive(height - 1)) != 0 )
|
||||||
|
{
|
||||||
|
diff = (nTime - tipindex->GetMedianTimePast());
|
||||||
|
if ( diff > 20 * ASSETCHAINS_BLOCKTIME )
|
||||||
|
{
|
||||||
|
mult = diff - 19 * ASSETCHAINS_BLOCKTIME;
|
||||||
|
mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 3;
|
||||||
|
origtarget = bnTarget;
|
||||||
|
bnTarget = bnTarget * arith_uint256(mult * mult);
|
||||||
|
easy.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
|
if ( bnTarget < origtarget || bnTarget > easy ) // deal with overflow
|
||||||
|
{
|
||||||
|
bnTarget = easy;
|
||||||
|
fprintf(stderr,"miner overflowed, set to mindiff\n");
|
||||||
|
} else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",diff,mult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(bnTarget);
|
||||||
|
}
|
||||||
|
|
||||||
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc)
|
arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t height,int32_t goalperc)
|
||||||
{
|
{
|
||||||
int32_t oldflag = 0,dispflag = 0;
|
int32_t oldflag = 0,dispflag = 0;
|
||||||
|
|||||||
@@ -337,6 +337,7 @@ int32_t komodo_priceget(int64_t *buf64,int32_t ind,int32_t height,int32_t numblo
|
|||||||
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
|
uint64_t komodo_accrued_interest(int32_t *txheightp,uint32_t *locktimep,uint256 hash,int32_t n,int32_t checkheight,uint64_t checkvalue,int32_t tipheight);
|
||||||
int32_t komodo_currentheight();
|
int32_t komodo_currentheight();
|
||||||
int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height);
|
int32_t komodo_notarized_bracket(struct notarized_checkpoint *nps[2],int32_t height);
|
||||||
|
arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,uint32_t nTime);
|
||||||
|
|
||||||
uint256 Parseuint256(const char *hexstr);
|
uint256 Parseuint256(const char *hexstr);
|
||||||
|
|
||||||
|
|||||||
@@ -1448,21 +1448,7 @@ void static BitcoinMiner_noeq()
|
|||||||
LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED);
|
LogPrintf("Block %d : PoS %d%% vs target %d%%\n", Mining_height, percPoS, (int32_t)ASSETCHAINS_STAKED);
|
||||||
}
|
}
|
||||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
||||||
{
|
HASHTarget_POW = komodo_adaptivepow_target(height,HASHTarget,pblock->nTime);
|
||||||
arith_uint256 origtarget; bool fNegative,fOverflow;
|
|
||||||
uint32_t elapsed = (pblock->nTime - komodo_heightstamp(Mining_height-1));
|
|
||||||
if ( elapsed > 777 )
|
|
||||||
{
|
|
||||||
elapsed -= 777;
|
|
||||||
origtarget = HASHTarget;
|
|
||||||
HASHTarget_POW = HASHTarget * arith_uint256(elapsed * elapsed);
|
|
||||||
if ( HASHTarget_POW < origtarget ) // deal with underflow
|
|
||||||
{
|
|
||||||
HASHTarget_POW.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
fprintf(stderr,"miner underflowed, set to mindiff\n");
|
|
||||||
} else fprintf(stderr,"miner elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|||||||
16
src/pow.cpp
16
src/pow.cpp
@@ -454,21 +454,7 @@ bool CheckProofOfWork(const CBlockHeader &blkHeader, uint8_t *pubkey33, int32_t
|
|||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
}
|
}
|
||||||
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
else if ( ASSETCHAINS_ADAPTIVEPOW != 0 && ASSETCHAINS_STAKED == 0 )
|
||||||
{
|
bnTarget = komodo_adaptivepow_target(height,bnTarget,blkHeader.nTime);
|
||||||
arith_uint256 origtarget;
|
|
||||||
uint32_t elapsed = (blkHeader.nTime - komodo_heightstamp(height-1));
|
|
||||||
if ( elapsed > 777 )
|
|
||||||
{
|
|
||||||
elapsed -= 777;
|
|
||||||
origtarget = bnTarget;
|
|
||||||
bnTarget = bnTarget * arith_uint256(elapsed * elapsed);
|
|
||||||
if ( bnTarget < origtarget ) // deal with underflow
|
|
||||||
{
|
|
||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
fprintf(stderr,"underflowed, set to mindiff\n");
|
|
||||||
} else fprintf(stderr,"elapsed %d, adjust by factor of %d\n",elapsed+777,elapsed*elapsed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() )
|
if ( UintToArith256(hash = blkHeader.GetHash()) > bnTarget && !blkHeader.IsVerusPOSBlock() )
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user