@@ -1136,45 +1136,26 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr)
|
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr)
|
||||||
{
|
{
|
||||||
CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 ratio,newhashval,hashval,origtarget,bnMaxPoSdiff; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
|
CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
|
||||||
origtarget = bnTarget;
|
|
||||||
txtime = komodo_txtime(&value,txid,vout,address);
|
txtime = komodo_txtime(&value,txid,vout,address);
|
||||||
|
txtime -= KOMODO_MAXMEMPOOLTIME;
|
||||||
if ( validateflag == 0 && blocktime < GetAdjustedTime() )
|
if ( validateflag == 0 && blocktime < GetAdjustedTime() )
|
||||||
blocktime = GetAdjustedTime();
|
blocktime = GetAdjustedTime();
|
||||||
if ( nHeight < 6000 ) // POSTEST64
|
if ( blocktime < prevtime+3 )
|
||||||
{
|
blocktime = prevtime+3;
|
||||||
if ( blocktime < prevtime+60 )
|
|
||||||
blocktime = prevtime+60;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( blocktime < prevtime+3 )
|
|
||||||
blocktime = prevtime+3;
|
|
||||||
}
|
|
||||||
if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 )
|
if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 )
|
||||||
{
|
{
|
||||||
//fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime);
|
//fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if ( nHeight < 4400 ) // POSTEST64 change newstake to stake and stake to oldstake and remove
|
if ( value < SATOSHIDEN )
|
||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
return(0);
|
||||||
else if ( nHeight >= 7250 )
|
mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
{
|
ratio = (mindiff / bnTarget);
|
||||||
bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
ratio = (bnMaxPoSdiff / bnTarget);
|
|
||||||
bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16));
|
|
||||||
if ( nHeight < 8000 && bnTarget < bnMaxPoSdiff )
|
|
||||||
bnTarget = bnMaxPoSdiff;
|
|
||||||
}
|
|
||||||
mfactor = 1024;
|
|
||||||
if ( (minage= nHeight*3) > 6000 ) // about 100 blocks
|
if ( (minage= nHeight*3) > 6000 ) // about 100 blocks
|
||||||
{
|
|
||||||
minage = 6000;
|
minage = 6000;
|
||||||
if ( nHeight >= 7500 )
|
|
||||||
txtime -= KOMODO_MAXMEMPOOLTIME;
|
|
||||||
}
|
|
||||||
pindex = 0;
|
pindex = 0;
|
||||||
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));
|
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));
|
||||||
segid = ((nHeight + addrhash.uints[0]) & 0x3f);
|
segid = ((nHeight + addrhash.uints[0]) & 0x3f);
|
||||||
@@ -1193,15 +1174,7 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe
|
|||||||
if ( blocktime+iter+segid*2 < txtime+minage )
|
if ( blocktime+iter+segid*2 < txtime+minage )
|
||||||
continue;
|
continue;
|
||||||
coinage = (value * diff) * ((diff >> 16) + 1);
|
coinage = (value * diff) * ((diff >> 16) + 1);
|
||||||
if ( nHeight < 7500 )
|
hashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1));
|
||||||
hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
newhashval = ratio * (UintToArith256(hash) / arith_uint256(coinage+1));
|
|
||||||
if ( hashval < 8000 )
|
|
||||||
hashval = (ratio * arith_uint256(supply) * UintToArith256(hash)) / arith_uint256(coinage+1);
|
|
||||||
else hashval = newhashval;
|
|
||||||
}
|
|
||||||
if ( hashval <= bnTarget )
|
if ( hashval <= bnTarget )
|
||||||
{
|
{
|
||||||
winner = 1;
|
winner = 1;
|
||||||
@@ -1241,100 +1214,15 @@ uint32_t komodo_newstake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHe
|
|||||||
return(blocktime * winner);
|
return(blocktime * winner);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 txid,int32_t vout,uint32_t blocktime,uint32_t prevtime,char *destaddr)
|
|
||||||
{
|
|
||||||
CBlockIndex *pindex; bool fNegative,fOverflow; uint8_t hashbuf[128]; char address[64]; bits256 addrhash; arith_uint256 hashval; uint256 hash,pasthash; int64_t diff=0; int32_t segid,minage,i,iter=0; uint32_t mfactor=64,txtime,winner = 0; arith_uint256 bnMaxPoSdiff; uint64_t value,coinage,supply = ASSETCHAINS_SUPPLY + nHeight*ASSETCHAINS_REWARD/SATOSHIDEN;
|
|
||||||
if ( nHeight >= 4000 ) // POSTEST64 remove when this is oldstake
|
|
||||||
return(komodo_newstake(validateflag,bnTarget,nHeight,txid,vout,blocktime,prevtime,destaddr));
|
|
||||||
txtime = komodo_txtime(&value,txid,vout,address);
|
|
||||||
if ( blocktime < prevtime+57 )
|
|
||||||
blocktime = prevtime+57;
|
|
||||||
if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 )
|
|
||||||
{
|
|
||||||
//fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
if ( ASSETCHAINS_STAKED != 100 || nHeight < 2000 )
|
|
||||||
{
|
|
||||||
bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(4));
|
|
||||||
if ( bnTarget < bnMaxPoSdiff )
|
|
||||||
bnTarget = bnMaxPoSdiff;
|
|
||||||
}
|
|
||||||
if ( (minage= nHeight*3) > 6000 ) // about 100 blocks
|
|
||||||
minage = 6000;
|
|
||||||
pindex = 0;
|
|
||||||
if ( (pindex= komodo_chainactive(nHeight>50?nHeight-50:1)) != 0 )
|
|
||||||
{
|
|
||||||
vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address));
|
|
||||||
segid = ((nHeight + addrhash.uints[0]) & 0x3f);
|
|
||||||
pasthash = pindex->GetBlockHash();
|
|
||||||
memcpy(hashbuf,&pasthash,sizeof(pasthash));
|
|
||||||
memcpy(&hashbuf[sizeof(pasthash)],&addrhash,sizeof(addrhash));
|
|
||||||
if ( nHeight >= 2000 )
|
|
||||||
{
|
|
||||||
memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)],&txid,sizeof(txid));
|
|
||||||
memcpy(&hashbuf[sizeof(pasthash)+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout));
|
|
||||||
vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*3 + sizeof(vout));
|
|
||||||
} else vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2);
|
|
||||||
vcalc_sha256(0,(uint8_t *)&hash,hashbuf,(int32_t)sizeof(uint256)*2);
|
|
||||||
//fprintf(stderr,"(%s) vs. (%s) %s %.8f txtime.%u\n",address,destaddr,hash.ToString().c_str(),dstr(value),txtime);
|
|
||||||
for (iter=0; iter<3600; iter++)
|
|
||||||
{
|
|
||||||
diff = (iter + blocktime - txtime - minage);
|
|
||||||
if ( diff > 3600*24*30 )
|
|
||||||
diff = 3600*24*30;
|
|
||||||
if ( iter > 0 )
|
|
||||||
diff += iter + segid*2;
|
|
||||||
if ( blocktime+iter+segid*2 < txtime+minage )
|
|
||||||
continue;
|
|
||||||
coinage = (value * diff) * ((diff >> 16) + 1);
|
|
||||||
hashval = arith_uint256(supply * mfactor) * (UintToArith256(hash) / arith_uint256(coinage+1));
|
|
||||||
if ( hashval <= bnTarget )
|
|
||||||
{
|
|
||||||
winner = 1;
|
|
||||||
if ( validateflag == 0 )
|
|
||||||
{
|
|
||||||
blocktime += iter;
|
|
||||||
blocktime += segid * 2;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ( validateflag != 0 )
|
|
||||||
{
|
|
||||||
/*for (i=31; i>=24; i--)
|
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);
|
|
||||||
fprintf(stderr," vs target ");
|
|
||||||
for (i=31; i>=24; i--)
|
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
|
|
||||||
fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d gap.%d %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,(int32_t)(blocktime - prevtime),dstr(value),(int32_t)diff);*/
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner);
|
|
||||||
if ( 0 )
|
|
||||||
{
|
|
||||||
for (i=31; i>=24; i--)
|
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]);
|
|
||||||
fprintf(stderr," vs ");
|
|
||||||
for (i=31; i>=24; i--)
|
|
||||||
fprintf(stderr,"%02x",((uint8_t *)&bnTarget)[i]);
|
|
||||||
fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u %.8f diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,dstr(value),(int32_t)diff);
|
|
||||||
}
|
|
||||||
} //else fprintf(stderr,"skip PoS scan: diff %d blocktime %u > %u txtime+minage %u pindex.%p\n",(int32_t)(blocktime - (txtime+minage)),blocktime,txtime,minage,pindex);
|
|
||||||
if ( nHeight < 10 )
|
|
||||||
return(blocktime);
|
|
||||||
return(blocktime * winner);
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
CBlockIndex *pindex; arith_uint256 bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val;
|
CBlockIndex *pindex; arith_uint256 easydiff,bnTarget,hashval,sum,ave; bool fNegative,fOverflow; int32_t i,n,ht,percPoS,diff,val;
|
||||||
*percPoSp = percPoS = 0;
|
*percPoSp = percPoS = 0;
|
||||||
if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) )
|
if ( height <= 10 || (ASSETCHAINS_STAKED == 100 && height <= 100) )
|
||||||
return(target);
|
return(target);
|
||||||
sum = arith_uint256(0);
|
sum = arith_uint256(0);
|
||||||
ave = sum;
|
ave = sum;
|
||||||
|
easydiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
for (i=n=0; i<100; i++)
|
for (i=n=0; i<100; i++)
|
||||||
{
|
{
|
||||||
ht = height - 100 + i;
|
ht = height - 100 + i;
|
||||||
@@ -1392,7 +1280,7 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
|
|||||||
}
|
}
|
||||||
else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget
|
else if ( percPoS > goalperc ) // decrease PoW diff -> raise bnTarget
|
||||||
{
|
{
|
||||||
bnTarget = ((ave * arith_uint256(goalperc)) + (target * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc);
|
bnTarget = ((ave * arith_uint256(goalperc)) + (easydiff * arith_uint256(percPoS))) / arith_uint256(percPoS + goalperc);
|
||||||
if ( 1 )
|
if ( 1 )
|
||||||
{
|
{
|
||||||
for (i=31; i>=24; i--)
|
for (i=31; i>=24; i--)
|
||||||
|
|||||||
@@ -117,11 +117,7 @@ uint32_t Mining_start,Mining_height;
|
|||||||
int32_t My_notaryid = -1;
|
int32_t My_notaryid = -1;
|
||||||
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
int32_t komodo_chosennotary(int32_t *notaryidp,int32_t height,uint8_t *pubkey33,uint32_t timestamp);
|
||||||
int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize);
|
int32_t komodo_pax_opreturn(int32_t height,uint8_t *opret,int32_t maxsize);
|
||||||
//uint64_t komodo_paxtotal();
|
|
||||||
int32_t komodo_baseid(char *origbase);
|
int32_t komodo_baseid(char *origbase);
|
||||||
//int32_t komodo_is_issuer();
|
|
||||||
//int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo);
|
|
||||||
//int32_t komodo_isrealtime(int32_t *kmdheightp);
|
|
||||||
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
|
int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag);
|
||||||
uint64_t komodo_commission(const CBlock *block);
|
uint64_t komodo_commission(const CBlock *block);
|
||||||
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig);
|
int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blocktimep,uint32_t *txtimep,uint256 *utxotxidp,int32_t *utxovoutp,uint64_t *utxovaluep,uint8_t *utxosig);
|
||||||
@@ -140,29 +136,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||||
/*if ( ASSETCHAINS_SYMBOL[0] != 0 && komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && chainActive.Tip()->nHeight >= ASSETCHAINS_MINHEIGHT )
|
// -regtest only: allow overriding block.nVersion with
|
||||||
{
|
|
||||||
isrealtime = komodo_isrealtime(&kmdheight);
|
|
||||||
deposits = komodo_paxtotal();
|
|
||||||
while ( KOMODO_ON_DEMAND == 0 && deposits == 0 && (int32_t)mempool.GetTotalTxSize() == 0 )
|
|
||||||
{
|
|
||||||
deposits = komodo_paxtotal();
|
|
||||||
if ( KOMODO_PASSPORT_INITDONE == 0 || KOMODO_INITDONE == 0 || (komodo_baseid(ASSETCHAINS_SYMBOL) >= 0 && (isrealtime= komodo_isrealtime(&kmdheight)) == 0) )
|
|
||||||
{
|
|
||||||
//fprintf(stderr,"INITDONE.%d RT.%d deposits %.8f ht.%d\n",KOMODO_INITDONE,isrealtime,(double)deposits/COIN,kmdheight);
|
|
||||||
}
|
|
||||||
else if ( komodo_isrealtime(&kmdheight) != 0 && (deposits != 0 || (int32_t)mempool.GetTotalTxSize() > 0) )
|
|
||||||
{
|
|
||||||
fprintf(stderr,"start CreateNewBlock %s initdone.%d deposit %.8f mempool.%d RT.%u KOMODO_ON_DEMAND.%d\n",ASSETCHAINS_SYMBOL,KOMODO_INITDONE,(double)komodo_paxtotal()/COIN,(int32_t)mempool.GetTotalTxSize(),isrealtime,KOMODO_ON_DEMAND);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sleep(10);
|
|
||||||
}
|
|
||||||
KOMODO_ON_DEMAND = 0;
|
|
||||||
if ( 0 && deposits != 0 )
|
|
||||||
printf("miner KOMODO_DEPOSIT %llu pblock->nHeight %d mempool.GetTotalTxSize(%d)\n",(long long)komodo_paxtotal(),(int32_t)chainActive.Tip()->nHeight,(int32_t)mempool.GetTotalTxSize());
|
|
||||||
}*/
|
|
||||||
// -regtest only: allow overriding block.nVersion with
|
|
||||||
// -blockversion=N to test forking scenarios
|
// -blockversion=N to test forking scenarios
|
||||||
if (Params().MineBlocksOnDemand())
|
if (Params().MineBlocksOnDemand())
|
||||||
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
|
pblock->nVersion = GetArg("-blockversion", pblock->nVersion);
|
||||||
@@ -915,13 +889,7 @@ void static BitcoinMiner()
|
|||||||
{
|
{
|
||||||
int32_t percPoS,z; bool fNegative,fOverflow;
|
int32_t percPoS,z; bool fNegative,fOverflow;
|
||||||
HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED);
|
HASHTarget_POW = komodo_PoWtarget(&percPoS,HASHTarget,Mining_height,ASSETCHAINS_STAKED);
|
||||||
if ( Mining_height >= 7250 )
|
HASHTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
{
|
|
||||||
bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16));
|
|
||||||
if ( HASHTarget < bnMaxPoSdiff )
|
|
||||||
HASHTarget = bnMaxPoSdiff;
|
|
||||||
}
|
|
||||||
if ( ASSETCHAINS_STAKED < 100 )
|
if ( ASSETCHAINS_STAKED < 100 )
|
||||||
{
|
{
|
||||||
for (z=31; z>=0; z--)
|
for (z=31; z>=0; z--)
|
||||||
|
|||||||
12
src/pow.cpp
12
src/pow.cpp
@@ -192,16 +192,8 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash,unsigned int
|
|||||||
return error("CheckProofOfWork(): nBits below minimum work");
|
return error("CheckProofOfWork(): nBits below minimum work");
|
||||||
if ( ASSETCHAINS_STAKED != 0 )
|
if ( ASSETCHAINS_STAKED != 0 )
|
||||||
{
|
{
|
||||||
if ( height >= 4200 && height < 4400 )
|
arith_uint256 bnMaxPoSdiff;
|
||||||
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
bnTarget.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
||||||
else if ( height >= 7250 )
|
|
||||||
{
|
|
||||||
arith_uint256 bnMaxPoSdiff;
|
|
||||||
bnMaxPoSdiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow);
|
|
||||||
bnMaxPoSdiff = (bnMaxPoSdiff / arith_uint256(16));
|
|
||||||
if ( bnTarget < bnMaxPoSdiff )
|
|
||||||
bnTarget = bnMaxPoSdiff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Check proof of work matches claimed amount
|
// Check proof of work matches claimed amount
|
||||||
if ( UintToArith256(hash) > bnTarget )
|
if ( UintToArith256(hash) > bnTarget )
|
||||||
|
|||||||
Reference in New Issue
Block a user