Merge pull request #86 from KMDLabs/master

staker fixes
This commit is contained in:
blackjok3rtt
2019-05-21 13:55:36 +08:00
committed by GitHub
3 changed files with 23 additions and 48 deletions

View File

@@ -7,6 +7,8 @@ make -f Makefile_rogue
rm ../libcc.so rm ../libcc.so
cp librogue.so ../libcc.so cp librogue.so ../libcc.so
exit 0
echo sudoku/musig/dilithium echo sudoku/musig/dilithium
gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp gcc -O3 -std=c++11 -I../secp256k1/include -I../univalue/include -I../cryptoconditions/include -I../cryptoconditions/src -I../cryptoconditions/src/asn -I.. -I. -fPIC -shared -c -o sudokucc.so cclib.cpp

View File

@@ -1422,10 +1422,6 @@ arith_uint256 komodo_PoWtarget(int32_t *percPoSp,arith_uint256 target,int32_t he
if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 ) if ( ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASH || ASSETCHAINS_ALGO == ASSETCHAINS_VERUSHASHV1_1 )
percPoS = (percPoS*100) / (m+n); percPoS = (percPoS*100) / (m+n);
else else
// This seems to be inverse. The actual PoS % is backwards in the first 100 blocks.
// I dont't understand the math here, or why its backwards, so I am just disabling it for VerusHash.
// No doubt this is probably wrong for equihash aswell, we may need to test an equihash chain with the rule above.
// Need to ask james what the deal is here! Seems to be causeing ALL the problems.
percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100; percPoS = ((percPoS * n) + (goalperc * (100-n))) / 100;
} }
if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 ) if ( dispflag != 0 && ASSETCHAINS_STAKED < 100 )
@@ -2524,7 +2520,6 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
komodo_segids(hashbuf,nHeight-101,100); komodo_segids(hashbuf,nHeight-101,100);
if ( *blocktimep < tipindex->nTime+60) if ( *blocktimep < tipindex->nTime+60)
*blocktimep = tipindex->nTime+60; *blocktimep = tipindex->nTime+60;
//fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight);
bool resetstaker = false; bool resetstaker = false;
if ( array != 0 ) if ( array != 0 )
@@ -2609,9 +2604,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
} }
} }
lasttime = (uint32_t)time(NULL); lasttime = (uint32_t)time(NULL);
//fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp); //fprintf(stderr,"finished kp data of utxo for staking %u ht.%d numkp.%d maxkp.%d\n",(uint32_t)time(NULL),nHeight,numkp,maxkp);
} }
//fprintf(stderr,"numkp.%d blocktime.%u\n",numkp,*blocktimep);
block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57;
for (i=winners=0; i<numkp; i++) for (i=winners=0; i<numkp; i++)
{ {
@@ -2624,44 +2618,28 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
} }
kp = &array[i]; kp = &array[i];
eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address,PoSperc); eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address,PoSperc);
//fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible);
if ( eligible > 0 ) if ( eligible > 0 )
{ {
besttime = m = 0; besttime = 0;
if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) ) if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) )
{ {
while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address,PoSperc) ) // have elegible utxo to stake with.
if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) )
{ {
besttime = eligible; // is better than the previous best, so use it instead.
eligible--; earliest = eligible;
if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier best_scriptPubKey = kp->scriptPubKey;
break; *utxovaluep = (uint64_t)kp->nValue;
m++; decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str());
//fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); *utxovoutp = kp->vout;
*txtimep = kp->txtime;
} }
} if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier
else break;
{ } else continue;
//fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); }
continue;
}
eligible = besttime;
winners++;
//fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - tipindex->nTime),(double)kp->nValue/COIN,eligible);
if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) )
{
earliest = eligible;
best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey;
*utxovaluep = (uint64_t)kp->nValue;
//decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str());
decode_hex((uint8_t *)utxotxidp,32,(char *)kp->txid.GetHex().c_str());
*utxovoutp = kp->vout;
*txtimep = kp->txtime;//(uint32_t)out.tx->nLockTime;
//fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winners.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners);
}
} //else fprintf(stderr,"utxo not eligible\n");
} }
if ( numkp < 1000 && array != 0 ) if ( numkp < 500 && array != 0 )
{ {
free(array); free(array);
array = 0; array = 0;
@@ -2680,7 +2658,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i]; ((uint8_t *)&revtxid)[i] = ((uint8_t *)utxotxidp)[31 - i];
txNew.vin[0].prevout.hash = revtxid; txNew.vin[0].prevout.hash = revtxid;
txNew.vin[0].prevout.n = *utxovoutp; txNew.vin[0].prevout.n = *utxovoutp;
txNew.vout[0].scriptPubKey = best_scriptPubKey;// CScript() << ParseHex(NOTARY_PUBKEY) << OP_CHECKSIG; txNew.vout[0].scriptPubKey = best_scriptPubKey;
txNew.vout[0].nValue = *utxovaluep - txfee; txNew.vout[0].nValue = *utxovaluep - txfee;
txNew.nLockTime = earliest; txNew.nLockTime = earliest;
CTransaction txNewConst(txNew); CTransaction txNewConst(txNew);
@@ -2691,7 +2669,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
ptr = (uint8_t *)&sigdata.scriptSig[0]; ptr = (uint8_t *)&sigdata.scriptSig[0];
siglen = sigdata.scriptSig.size(); siglen = sigdata.scriptSig.size();
for (i=0; i<siglen; i++) for (i=0; i<siglen; i++)
utxosig[i] = ptr[i];//, fprintf(stderr,"%02x",ptr[i]); utxosig[i] = ptr[i];
} }
else else
{ {
@@ -2703,12 +2681,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt
if (!signSuccess) if (!signSuccess)
fprintf(stderr,"failed to create signature\n"); fprintf(stderr,"failed to create signature\n");
else else
{
//fprintf(stderr," siglen.%d\n",siglen);
//fprintf(stderr,"best %u from %u, gap %d lag.%d\n",earliest,*blocktimep,(int32_t)(earliest - *blocktimep),(int32_t)(time(NULL) - *blocktimep));
*blocktimep = earliest; *blocktimep = earliest;
} }
} //else fprintf(stderr,"no earliest utxo for staking\n");
//fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d winners.%d\n",(uint32_t)time(NULL),counter,numkp,winners);
return(siglen); return(siglen);
} }

View File

@@ -34,8 +34,8 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
// If CCLIB fails to compile with this, use the one below. // If CCLIB fails to compile with this, use the one below.
#include <db_cxx.h> //include <db_cxx.h>
//#include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h" #include "../depends/x86_64-unknown-linux-gnu/include/db_cxx.h"
extern unsigned int nWalletDBUpdated; extern unsigned int nWalletDBUpdated;