From 832ca82122ea5ce196d0bf8b6e0ac261bb8120f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 08:53:46 -1100 Subject: [PATCH 01/72] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7199db0be..334b1dfe3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From c3ed86ad18cd337cfb0155d049bc001acde4a466 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:01:48 -1100 Subject: [PATCH 02/72] Test --- src/komodo_bitcoind.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d09503751..734c57f73 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1189,10 +1189,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh { bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; txtime = komodo_txtime2(&value,txid,vout,address); - if ( validateflag == 0 && blocktime < GetAdjustedTime() ) - blocktime = GetAdjustedTime(); - if ( blocktime < prevtime+3 ) - blocktime = prevtime+3; + if ( validateflag == 0 ) + { + fprintf(stderr,"blocktime.%u -> ",blocktime); + if ( blocktime < GetAdjustedTime() ) + blocktime = GetAdjustedTime(); + if ( blocktime < prevtime+3 ) + blocktime = prevtime+3; + fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { //fprintf(stderr,"komodo_stake null %.8f %u %u %u\n",dstr(value),txtime,blocktime,prevtime); @@ -1236,6 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } From e0a3ab0a32f12e972850b030e39e8d101a04f148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:24:58 -1100 Subject: [PATCH 03/72] Test --- src/komodo_bitcoind.h | 14 +++++++------- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 734c57f73..fa5266d38 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - fprintf(stderr,"blocktime.%u -> ",blocktime); - if ( blocktime < GetAdjustedTime() ) - blocktime = GetAdjustedTime(); + //fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; - fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + if ( blocktime < GetAdjustedTime()-60 ) + blocktime = GetAdjustedTime()-60; + //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1217,7 +1217,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); - for (iter=0; iter<120; iter++) + for (iter=0; iter<180; iter++) { diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } @@ -1401,7 +1401,7 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ if ( prevtime != 0 ) { if ( komodo_isPoS(pblock) != 0 ) - eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime,(char *)""); + eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 334b1dfe3..400dc9088 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4640,10 +4640,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { - if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime,(char *)CBitcoinAddress(address).ToString().c_str()) ) + if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); } From 8785f8cee0a64b1e7849c454d787764632b2b4e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:26:41 -1100 Subject: [PATCH 04/72] Fix --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fa5266d38..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1195,7 +1195,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) - blocktime = GetAdjustedTime()-60; + blocktime = GetAdjustedTime()+30; //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) @@ -1234,7 +1234,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh coinage = (value * diff); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); - if ( nHeight >= 900 ) + if ( nHeight >= 900 && nHeight < 916 ) hashval = (hashval / coinage256); if ( hashval <= bnTarget ) { From ed3d9247b42eb3797596457d1e6e3f51a1eb0e10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:28:34 -1100 Subject: [PATCH 05/72] New version --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index bc5bbe1f7..c6855cd57 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,7 +400,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-57 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); From 593d06a8c749d4a3aa11f76781b5f8c385726ec3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:29:20 -1100 Subject: [PATCH 06/72] -print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 400dc9088..85141aa6a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 668ff11a727af89f84dba5ffd22c5a0f471cc6b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:38:47 -1100 Subject: [PATCH 07/72] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 85141aa6a..400dc9088 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From c067f5148bc234ad863ccaa31f54994911f9c286 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:44:07 -1100 Subject: [PATCH 08/72] +print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..2916e4d56 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + //if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From e53395fccf810c66d567336fbe2fd1f09ae19d60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 09:50:00 -1100 Subject: [PATCH 09/72] Test --- src/komodo_bitcoind.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 2916e4d56..1a9377e85 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,9 +1257,15 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } + 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 v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( 0 && validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From cb595b48018eaa00c18631a1afb3597bf74c0f3a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:00:10 -1100 Subject: [PATCH 10/72] -print --- src/komodo_bitcoind.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 1a9377e85..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1257,12 +1257,6 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh fprintf(stderr," segid.%d iter.%d winner.%d coinage.%llu %d ht.%d t.%u v%d diff.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff);*/ break; } - 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 v%d diff.%d ht.%d\n",segid,iter,winner,(long long)coinage,(int32_t)(blocktime - txtime),nHeight,blocktime,(int32_t)value,(int32_t)diff,nHeight); } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); if ( 0 && validateflag != 0 ) From 2da6a5a5ad4d6813a9a7fed1b5416f29a475b11c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:05:05 -1100 Subject: [PATCH 11/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index c6855cd57..773762937 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,7 +400,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 )//&& GetAdjustedTime() < blocktime-157 ) return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); From eedbc1907eb46c12bae422c53014fba2531b3c66 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:09:48 -1100 Subject: [PATCH 12/72] Test --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..4e09b3592 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - //fprintf(stderr,"blocktime.%u -> ",blocktime); + fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) blocktime = GetAdjustedTime()+30; - //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } From 0debf37ff7cb7a0294eecc1f324a83050521b130 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:14:15 -1100 Subject: [PATCH 13/72] Test --- src/komodo_bitcoind.h | 6 +++--- src/miner.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4e09b3592..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1191,12 +1191,12 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh txtime = komodo_txtime2(&value,txid,vout,address); if ( validateflag == 0 ) { - fprintf(stderr,"blocktime.%u -> ",blocktime); + //fprintf(stderr,"blocktime.%u -> ",blocktime); if ( blocktime < prevtime+3 ) blocktime = prevtime+3; if ( blocktime < GetAdjustedTime()-60 ) blocktime = GetAdjustedTime()+30; - fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); + //fprintf(stderr,"blocktime.%u txtime.%u\n",blocktime,txtime); } if ( value == 0 || txtime == 0 || blocktime == 0 || prevtime == 0 ) { @@ -1241,7 +1241,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh winner = 1; if ( validateflag == 0 ) { - fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; } diff --git a/src/miner.cpp b/src/miner.cpp index 773762937..ca04343e4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -400,8 +400,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 )//&& GetAdjustedTime() < blocktime-157 ) - return(0); + //if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + // return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); From cdb34664622baacc337fc8a5d413bf64939dc486 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:18:16 -1100 Subject: [PATCH 14/72] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index ca04343e4..2b37590e1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -492,7 +492,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) return(0); } } - else + else if ( ASSETCHAINS_STAKED == 0 ) { CValidationState state; if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) From afa90f17b126d345fdae07b56479de45dc374a4d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:23:36 -1100 Subject: [PATCH 15/72] Detect new block while sleeping --- src/miner.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 2b37590e1..8a0c63f88 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -951,8 +951,8 @@ void static BitcoinMiner() fprintf(stderr," POW\n");*/ if ( h > hashTarget ) { - if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) - sleep(1); + //if ( ASSETCHAINS_STAKED != 0 && GetArg("-genproclimit", 0) == 0 ) + // sleep(1); return false; } if ( IS_KOMODO_NOTARY != 0 && B.nTime > GetAdjustedTime() ) @@ -980,12 +980,11 @@ void static BitcoinMiner() else { while ( B.nTime-57 > GetAdjustedTime() ) - sleep(1); - /*if ( Mining_height < 6000 ) { - while ( B.nTime > GetAdjustedTime() ) - sleep(1); - }*/ + sleep(1); + if ( chainActive.Tip()->nHeight >= Mining_height ) + return(false); + } uint256 tmp = B.GetHash(); int32_t z; for (z=31; z>=0; z--) fprintf(stderr,"%02x",((uint8_t *)&tmp)[z]); From b0910b9e2a17f93f908a47ac6170c46d49b3cb5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:33:01 -1100 Subject: [PATCH 16/72] +print --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 400dc9088..4c3a66c2a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4655,7 +4655,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From b30fdbd2378bbee5bb5801f83e5fc45d37ef5fc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:48:32 -1100 Subject: [PATCH 17/72] +segids print --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..8c4e2c537 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,13 +1174,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; i Date: Thu, 12 Jul 2018 10:49:26 -1100 Subject: [PATCH 18/72] -prints --- src/komodo_bitcoind.h | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8c4e2c537..e0c88065b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1174,13 +1174,13 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) for (i=0; iGetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + //fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 308ee0761c265b2c1af855d67a85b4e9014cc2dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 10:52:38 -1100 Subject: [PATCH 19/72] Guard error print --- src/komodo_bitcoind.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e0c88065b..0c714ba9c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1404,7 +1404,8 @@ int32_t komodo_is_PoSblock(int32_t slowflag,int32_t height,CBlock *pblock,arith_ eligible = komodo_stake(1,bnTarget,height,txid,vout,pblock->nTime,prevtime+27,(char *)""); if ( eligible == 0 || eligible > pblock->nTime ) { - fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); + if ( ASSETCHAINS_STAKED < 100 ) + fprintf(stderr,"komodo_is_PoSblock PoS failure ht.%d eligible.%u vs blocktime.%u, lag.%d -> check to see if it is PoW block\n",height,eligible,(uint32_t)pblock->nTime,(int32_t)(eligible - pblock->nTime)); } else isPoS = 1; } if ( slowflag == 0 ) // maybe previous block is not seen yet, do the best approx From 6d2faeb0b8ddcdf843198067740e8be7a7618e62 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 11:13:32 -1100 Subject: [PATCH 20/72] +print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c714ba9c..4b91f8230 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( 0 && validateflag != 0 ) + if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From d5614a7628dd72f744ed15cd878f2b32dea8ebeb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 11:43:32 -1100 Subject: [PATCH 21/72] Set nBits more often --- src/miner.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 8a0c63f88..dbe6dc41c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -832,8 +832,9 @@ void static BitcoinMiner() // Search // uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); savebits = pblock->nBits; - HASHTarget = arith_uint256().SetCompact(pblock->nBits); + HASHTarget = arith_uint256().SetCompact(savebits); roundrobin_delay = ROUNDROBIN_DELAY; if ( ASSETCHAINS_SYMBOL[0] == 0 && notaryid >= 0 ) { From 3dcc06d3acbd1cca46554f72589c15da41b49c26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 22:12:27 -1100 Subject: [PATCH 22/72] +print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 4b91f8230..74b9786f3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - if ( validateflag != 0 ) + //if ( validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 5162b553a0e0f91d5a976d533b810e72855fd2ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 12 Jul 2018 22:14:22 -1100 Subject: [PATCH 23/72] -print --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 74b9786f3..0c714ba9c 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1259,7 +1259,7 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } } //fprintf(stderr,"iterated until i.%d winner.%d\n",i,winner); - //if ( validateflag != 0 ) + if ( 0 && validateflag != 0 ) { for (i=31; i>=24; i--) fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); From 0401884fee36534c5508b794d89c559bfd0a66ea Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 04:45:32 -1100 Subject: [PATCH 24/72] Mitigation of very long block times, starting 2500 for PoW --- src/komodo_bitcoind.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 0c714ba9c..da244e079 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1219,6 +1219,8 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh vcalc_sha256(0,(uint8_t *)&hash,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); for (iter=0; iter<180; iter++) { + if ( blocktime+iter+segid*2 < txtime+minage ) + continue; diff = (iter + blocktime - txtime - minage); if ( diff < 0 ) diff = 60; @@ -1229,9 +1231,9 @@ uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeigh } if ( iter > 0 ) diff += segid*2; - if ( blocktime+iter+segid*2 < txtime+minage ) - continue; coinage = (value * diff); + if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); coinage256 = arith_uint256(coinage+1); hashval = ratio * (UintToArith256(hash) / coinage256); if ( nHeight >= 900 && nHeight < 916 ) From 485df724b988548f9204f0f59ef5841c51f32496 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 23:12:59 -1100 Subject: [PATCH 25/72] Fix invalid tx in mempool for PoS --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index da244e079..42318252f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) + if ( txheight > 246748 ) { - if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) + if ( txheight < 247205 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From 82fd97935b50eead75971b2d32e1180710237b6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 13 Jul 2018 23:15:43 -1100 Subject: [PATCH 26/72] Revert --- src/komodo_bitcoind.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 42318252f..e584b2c93 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,11 +1076,11 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { - if ( txheight < 247205 ) + if ( txheight < 247205 && ASSETCHAINS_STAKED == 0 ) cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-KOMODO_MAXMEMPOOLTIME ) { From b39b4d733efea2fb3140a737ec6f57ca86217043 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 00:11:29 -1100 Subject: [PATCH 27/72] ( --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index e584b2c93..da244e079 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1076,7 +1076,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t cmptime,int32_t dispflag) { - if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + if ( KOMODO_REWIND == 0 && (ASSETCHAINS_SYMBOL[0] == 0 || ASSETCHAINS_STAKED != 0) && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { if ( txheight > 246748 || ASSETCHAINS_STAKED != 0 ) { From 3cbc956e040778621e9ebd563485ac71635d2cc6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 03:08:05 -1100 Subject: [PATCH 28/72] Test fix for crash --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 10bf93598..df0cd9c2b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2112,7 +2112,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Don't rebroadcast if newer than nTime: if (wtx.nTimeReceived > nTime) continue; - if ( ASSETCHAINS_SYMBOL[0] == 0 ) + //if ( ASSETCHAINS_SYMBOL[0] == 0 ) { if ( wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-KOMODO_MAXMEMPOOLTIME ) { From 84eabd0d59a56b98e2bed897f8b8a6787750b386 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 05:43:18 -1100 Subject: [PATCH 29/72] Skip null privacy address --- src/komodo_bitcoind.h | 13 ++++++++++--- src/wallet/rpcwallet.cpp | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index da244e079..eb649be99 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1546,7 +1546,7 @@ int32_t komodo_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { - int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; + CTxDestination address; int32_t i,j,m,n,vout; uint8_t *script; uint256 txid,hashBlock; int64_t zfunds=0,vinsum=0,voutsum=0; n = pblock->vtx.size(); for (i=0; i 0 ) { for (j=0; j %s\n",dstr(),CBitcoinAddress(address).ToString().c_str()); + } script = (uint8_t *)tx.vout[j].scriptPubKey.data(); if ( script == 0 || script[0] != 0x6a ) - voutsum += tx.vout[j].nValue; + { + if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 ) + voutsum += tx.vout[j].nValue; + } } } *zfundsp = zfunds; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6831585c4..07bf91c89 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4643,11 +4643,17 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { - if ( eligible != komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + besttime = 0; + if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - //fprintf(stderr,"tip.%d validation of winning blocktime failed %u -> eligible.%u\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); - } - else if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime-300 ) + break; + fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } else continue; + eligible = besttime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; @@ -4655,7 +4661,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - //fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 27d76b740bb4b59e35335706c6d06b7f604de1d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:02:53 -1100 Subject: [PATCH 30/72] Syntax --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index eb649be99..f328853b3 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1574,7 +1574,7 @@ int64_t komodo_newcoins(int64_t *zfundsp,int32_t nHeight,CBlock *pblock) { if ( ExtractDestination(tx.vout[j].scriptPubKey,address) != 0 && strcmp("RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY",CBitcoinAddress(address).ToString().c_str()) != 0 ) voutsum += tx.vout[j].nValue; - else printf("skip %.8f -> %s\n",dstr(),CBitcoinAddress(address).ToString().c_str()); + else printf("skip %.8f -> %s\n",dstr(tx.vout[j].nValue),CBitcoinAddress(address).ToString().c_str()); } script = (uint8_t *)tx.vout[j].scriptPubKey.data(); if ( script == 0 || script[0] != 0x6a ) From b388a2914475cda3196eb45218f99f610283b9eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:22:25 -1100 Subject: [PATCH 31/72] Add loop --- src/wallet/rpcwallet.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 07bf91c89..542666755 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4646,11 +4646,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = 0; if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) { - besttime = eligible; - eligible--; - if ( eligible < (uint32_t)tipindex->nTime-300 ) - break; - fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + while ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + { + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime-300 ) + break; + fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + } } else continue; eligible = besttime; if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) From beb03773e4bd9c8550b3b48183ed2950ca7e1b02 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 06:37:07 -1100 Subject: [PATCH 32/72] Test --- src/wallet/rpcwallet.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 542666755..d5b01a495 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4640,6 +4640,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt CBlockIndex *tipindex; if ( (tipindex= chainActive.Tip()) != 0 ) { + m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { @@ -4652,7 +4653,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt eligible--; if ( eligible < (uint32_t)tipindex->nTime-300 ) break; - fprintf(stderr,"tip.%d validated winning blocktime %u -> eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,eligible); + m++; + //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); } } else continue; eligible = besttime; @@ -4664,7 +4666,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d] (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From 424aeca00d8ff14e541be3d84a3ee478c0171aa7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:04:10 -1100 Subject: [PATCH 33/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d5b01a495..be1be1b28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4651,7 +4651,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-300 ) + if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); From 17ec046d90b8966caea92d8c67cb62d1f5051721 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:15:26 -1100 Subject: [PATCH 34/72] Test --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index be1be1b28..765b718a1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4601,6 +4601,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) @@ -4702,6 +4703,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); + fprintf(stderr,"end scan of utxo for staking %u\n",(uint32_t)time(NULL)); return(siglen); } From 4fc4e200964a77efdb62eec30682642f8c98c704 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:22:28 -1100 Subject: [PATCH 35/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 765b718a1..51b9edb8e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4652,7 +4652,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + //if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); From 55dd662212f77be38ad94625d0019fa4fd3a671f Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 07:41:29 -1100 Subject: [PATCH 36/72] Optimize staking loop a bit --- src/wallet/rpcwallet.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 51b9edb8e..88759a6f4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4592,7 +4592,7 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) 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) { - set setAddress; int32_t i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; + set setAddress; int32_t counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *tipindex; CTxDestination address; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -4601,15 +4601,26 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt memset(utxovoutp,0,sizeof(*utxovoutp)); memset(utxosig,0,72); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); + if ( (tipindex= chainActive.Tip()) == 0 ) + return(0); fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); BOOST_FOREACH(const COutput& out, vecOutputs) { + counter++; + if ( chainActive.Tip() != tipindex ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) { //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } - if ( setAddress.size() ) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + /*if ( setAddress.size() ) { CTxDestination address; if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) @@ -4624,23 +4635,13 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } if ( IsMine(*pwalletMain, address) == 0 ) continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; + }*/ const CScript& pk = out.tx->vout[out.i].scriptPubKey; //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - CTxDestination address; - if (ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) - { - //entry.push_back(Pair("address", CBitcoinAddress(address).ToString())); - //if (pwalletMain->mapAddressBook.count(address)) - // entry.push_back(Pair("account", pwalletMain->mapAddressBook[address].name)); - } - //BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); - CBlockIndex *tipindex; - if ( (tipindex= chainActive.Tip()) != 0 ) + if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) != 0 ) { + if ( IsMine(*pwalletMain,address) == 0 ) + continue; m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) @@ -4703,7 +4704,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking %u\n",(uint32_t)time(NULL)); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d\n",(uint32_t)time(NULL),counter); return(siglen); } From aa2ef3abfcbaba8090f930a9358a92c178909c59 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 08:05:00 -1100 Subject: [PATCH 37/72] Test --- src/wallet/rpcwallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 88759a6f4..9b7e17d4e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4668,7 +4668,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); *utxovoutp = out.i; *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep,counter); + if ( counter > 1000 ) + break; } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); From d04efc6ff574bfdd826cdd137bd0aec0d4393f5b Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 08:30:38 -1100 Subject: [PATCH 38/72] Test --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 9b7e17d4e..5073ab845 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4642,6 +4642,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( IsMine(*pwalletMain,address) == 0 ) continue; +continue; m = 0; eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) From ac53109534eb6023a960ee2e01862ab2256dc623 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:29:29 -1100 Subject: [PATCH 39/72] Optimized staker --- src/komodo_bitcoind.h | 11 ++ src/wallet/rpcwallet.cpp | 212 +++++++++++++++++++++++++++------------ 2 files changed, 160 insertions(+), 63 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f328853b3..58fc643b7 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1185,6 +1185,17 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) } } +uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) +{ + bits256 addrhash; uint8_t hashbuf[256]; + vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); + memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); + memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); + memcpy(&hashbuf[100+sizeof(addrhash)+sizeof(txid)],&vout,sizeof(vout)); + vcalc_sha256(0,(uint8_t *)hashp,hashbuf,100 + (int32_t)sizeof(uint256)*2 + sizeof(vout)); + return(addrhash.uints[0]); +} + 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) { bool fNegative,fOverflow; uint8_t hashbuf[256]; char address[64]; bits256 addrhash; arith_uint256 hashval,mindiff,ratio,coinage256; uint256 hash,pasthash; int32_t diff=0,segid,minage,i,iter=0; uint32_t txtime,winner = 0 ; uint64_t value,coinage; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5073ab845..13ca693f5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4513,6 +4513,7 @@ UniValue z_listoperationids(const UniValue& params, bool fHelp) int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); +int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { @@ -4590,10 +4591,86 @@ int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) return(siglen); } +struct komodo_staking +{ + char address[64]; + uint256 txid; + arith_uint256 hashval; + uint64_t nValue; + uint32_t segid32; + int32_t vout; + const CScript scriptPubKey; +}; + +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,const CScript pk) +{ + uint256 hash; uint32_t segid32; struct komodo_staking *kp; + segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); + kp = &array[(*numlp)++]; + memset(*kp,0,sizeof(*kp)); + strcpy(kp->address,address); + kp->txid = txid; + kp->vout = vout; + kp->hashval = UintToArith256(hash); + kp->txtime = txtime; + kp->segid32 = segid32; + kp->nValue = nValue; + kp->scriptPubKey = pk; + return(array); +} + +arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uint32_t blocktime,int32_t iter,int32_t minage,int32_t segid,int32_t nHeight,uint32_t prevtime) +{ + int32_t diff; uint64_t coinage; arith_uint256 coinage256,hashval; + diff = (iter + blocktime - kp->txtime - minage); + if ( diff < 0 ) + diff = 60; + else if ( diff > 3600*24*30 ) + diff = 3600*24*30; + if ( iter > 0 ) + diff += segid*2; + coinage = ((uint64_t)kp->nValue/COIN * diff); + if ( nHeight >= 2500 && blocktime+iter+segid*2 > prevtime+180 ) + coinage *= ((blocktime+iter+segid*2) - (prevtime+60)); + coinage256 = arith_uint256(coinage+1); + hashval = ratio * (kp->hashval / coinage256); + if ( nHeight >= 900 && nHeight < 916 ) + hashval = (hashval / coinage256); + return(hashval); +} + +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage) +{ + int32_t maxiters = 180; + int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + segid = ((nHeight + kp->segid32) & 0x3f); + hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + for (iter=0; itertxtime+minage ) + continue; + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + if ( hashval <= bnTarget ) + { + //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + blocktime += iter; + blocktime += segid * 2; + return(blocktime); + } + } + } + return(0); +} + 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) { - set setAddress; int32_t counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; bool fNegative,fOverflow; CBlockIndex *tipindex; CTxDestination address; + static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 ratio,mindiff,hashBlock,ratio; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); + mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); + ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; @@ -4603,79 +4680,88 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); if ( (tipindex= chainActive.Tip()) == 0 ) return(0); - fprintf(stderr,"Start scan of utxo for staking %u\n",(uint32_t)time(NULL)); - BOOST_FOREACH(const COutput& out, vecOutputs) + nHeight = tipindex->nHeight + 1; + if ( (minage= nHeight*3) > 6000 ) // about 100 blocks + minage = 6000; + komodo_segids(hashbuf,nHeight-101,100); + fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); + if ( time(NULL) > lasttime+600 ) { - counter++; - if ( chainActive.Tip() != tipindex ) + if ( array != 0 ) { - fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); - return(0); + free(array); + array = 0; + maxkp = numkp = 0; } - if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + BOOST_FOREACH(const COutput& out, vecOutputs) { - //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); - continue; - } - CAmount nValue = out.tx->vout[out.i].nValue; - if ( nValue < COIN || !out.fSpendable ) - continue; - /*if ( setAddress.size() ) - { - CTxDestination address; - if (!ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) + if ( (tipindex= chainActive.Tip()) == 0 || tipindex->nHeight+1 > nHeight ) { - fprintf(stderr,"komodo_staked ExtractDestination error\n"); + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } + counter++; + if ( out.nDepth < nMinDepth || out.nDepth > nMaxDepth ) + { + //fprintf(stderr,"komodo_staked invalid depth %d\n",(int32_t)out.nDepth); continue; } - if (!setAddress.count(address)) + CAmount nValue = out.tx->vout[out.i].nValue; + if ( nValue < COIN || !out.fSpendable ) + continue; + const CScript& pk = out.tx->vout[out.i].scriptPubKey; + if ( ExtractDestination(pk,address) != 0 ) { - fprintf(stderr,"komodo_staked setAddress.count error\n"); - continue; - } - if ( IsMine(*pwalletMain, address) == 0 ) - continue; - }*/ - const CScript& pk = out.tx->vout[out.i].scriptPubKey; - //entry.push_back(Pair("generated", out.tx->IsCoinBase())); - if ( ExtractDestination(out.tx->vout[out.i].scriptPubKey, address) != 0 ) - { - if ( IsMine(*pwalletMain,address) == 0 ) - continue; -continue; - m = 0; - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); - if ( eligible > 0 ) - { - besttime = 0; - if ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) + if ( IsMine(*pwalletMain,address) == 0 ) + continue; + if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { - while ( eligible == komodo_stake(1,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,eligible,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()) ) - { - besttime = eligible; - eligible--; - //if ( eligible < (uint32_t)tipindex->nTime+3 ) - break; - m++; - //fprintf(stderr,"tip.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",(uint32_t)tipindex->nHeight,*blocktimep,(double)nValue/COIN,eligible); - } - } else continue; - eligible = besttime; - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) - { - earliest = eligible; - best_scriptPubKey = out.tx->vout[out.i].scriptPubKey; - *utxovaluep = (uint64_t)nValue; - decode_hex((uint8_t *)utxotxidp,32,(char *)out.tx->GetHash().GetHex().c_str()); - *utxovoutp = out.i; - *txtimep = (uint32_t)out.tx->nLockTime; - fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d\n",(uint32_t)tipindex->nHeight+1,earliest,(int32_t)(earliest- *blocktimep),m,CBitcoinAddress(address).ToString().c_str(),(double)nValue/COIN,*txtimep,counter); - if ( counter > 1000 ) - break; + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,pk); } - } //else fprintf(stderr,"utxo not eligible\n"); - } //else fprintf(stderr,"no tipindex\n"); + } + } + 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); } + for (i=0; inTime+27,minage); + //eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + if ( eligible > 0 ) + { + besttime = m = 0; + if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) + { + besttime = eligible; + eligible--; + if ( eligible < (uint32_t)tipindex->nTime+3 ) + break; + m++; + fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)nValue/COIN,eligible); + } + } + else + { + fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)nValue/COIN,eligible); + continue; + } + eligible = besttime; + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || 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\n",nHeight,earliest,(int32_t)(earliest- *blocktimep),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter); + } + } //else fprintf(stderr,"utxo not eligible\n"); + } //else fprintf(stderr,"no tipindex\n"); if ( earliest != 0 ) { bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; From 5649e3d39d0350598fa5bbeaf08c8a570fc7cb75 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:30:50 -1100 Subject: [PATCH 40/72] Test --- src/komodo_bitcoind.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 58fc643b7..fad483d3f 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) { - bits256 addrhash; uint8_t hashbuf[256]; + bits256 addrhash; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); From 1273624d3e440bd9578f246b45531dd4661dd7c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:38:45 -1100 Subject: [PATCH 41/72] Test --- src/komodo_bitcoind.h | 2 +- src/wallet/rpcwallet.cpp | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index fad483d3f..d624dc72a 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1187,7 +1187,7 @@ int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) uint32_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout) { - bits256 addrhash; + bits256 addrhash; vcalc_sha256(0,(uint8_t *)&addrhash,(uint8_t *)address,(int32_t)strlen(address)); memcpy(&hashbuf[100],&addrhash,sizeof(addrhash)); memcpy(&hashbuf[100+sizeof(addrhash)],&txid,sizeof(txid)); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 13ca693f5..d9de578d5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4514,6 +4514,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); +int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { @@ -4597,17 +4598,22 @@ struct komodo_staking uint256 txid; arith_uint256 hashval; uint64_t nValue; - uint32_t segid32; + uint32_t segid32,txtime; int32_t vout; - const CScript scriptPubKey; + CScript scriptPubKey; }; -struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,const CScript pk) +struct komodo_staking *komodo_addutxo(struct komodo_staking *array,int32_t *numkp,int32_t *maxkp,uint32_t txtime,uint64_t nValue,uint256 txid,int32_t vout,char *address,uint8_t *hashbuf,CScript pk) { uint256 hash; uint32_t segid32; struct komodo_staking *kp; segid32 = komodo_stakehash(&hash,address,hashbuf,txid,vout); - kp = &array[(*numlp)++]; - memset(*kp,0,sizeof(*kp)); + if ( *numkp >= *maxkp ) + { + *maxkp += 1000; + array = (struct komodo_staking *)realloc(array,sizeof(*array) * (*maxkp)); + } + kp = &array[(*numkp)++]; + memset(kp,0,sizeof(*kp)); strcpy(kp->address,address); kp->txid = txid; kp->vout = vout; @@ -4667,7 +4673,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 ratio,mindiff,hashBlock,ratio; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4716,7 +4722,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { - array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,pk); + array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); } } } From aecf58592c68a873893e4c8f476b6014d214f6d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:41:08 -1100 Subject: [PATCH 42/72] Fix --- src/wallet/rpcwallet.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d9de578d5..3633c56e4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4720,7 +4720,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { if ( IsMine(*pwalletMain,address) == 0 ) continue; - if ( GetTransaction(hash,tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) + if ( GetTransaction(out.tx->GetHash(),tx,hashBlock,true) != 0 && (pindex= mapBlockIndex[hashBlock]) != 0 ) { array = komodo_addutxo(array,&numkp,&maxkp,(uint32_t)pindex->nTime,(uint64_t)nValue,out.tx->GetHash(),out.i,(char *)CBitcoinAddress(address).ToString().c_str(),hashbuf,(CScript)pk); } @@ -4746,16 +4746,16 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; - fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)nValue/COIN,eligible); + fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else { - fprintf(stderr,"ht.%d error validating winning blocktime %u -> %.8f eligible.%u test prior\n",nHeight,*blocktimep,(double)nValue/COIN,eligible); + 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; - if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || nValue < *utxovaluep)) ) + if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; best_scriptPubKey = kp->scriptPubKey; //out.tx->vout[out.i].scriptPubKey; From 76df25be7a6f964272eb4383b698375c95351726 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:51:01 -1100 Subject: [PATCH 43/72] Test --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3633c56e4..c37e78889 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4732,8 +4732,9 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt for (i=0; inTime+27,minage); - //eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + continue; + eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); if ( eligible > 0 ) { besttime = m = 0; From ecae680bfa8f842849ca057233ea5973d7daec20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 10:52:42 -1100 Subject: [PATCH 44/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c37e78889..babeabe6e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4734,7 +4734,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt kp = &array[i]; if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; - eligible = komodo_stake(0,bnTarget,(uint32_t)tipindex->nHeight+1,out.tx->GetHash(),out.i,0,(uint32_t)tipindex->nTime+27,(char *)CBitcoinAddress(address).ToString().c_str()); + eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); if ( eligible > 0 ) { besttime = m = 0; From 011b0a24334378c2a71ef3a069efac111f3afeed Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:02:23 -1100 Subject: [PATCH 45/72] Test --- src/wallet/rpcwallet.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index babeabe6e..59516472b 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+600 ) + //if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) { @@ -4747,7 +4747,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; - fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); + //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); } } else @@ -4769,6 +4769,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); + if ( array != 0 ) + { + free(array); + array = 0; + maxkp = numkp = 0; + } if ( earliest != 0 ) { bool signSuccess; SignatureData sigdata; uint64_t txfee; uint8_t *ptr; uint256 revtxid,utxotxid; @@ -4800,7 +4806,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *blocktimep = earliest; } } //else fprintf(stderr,"no earliest utxo for staking\n"); - fprintf(stderr,"end scan of utxo for staking t.%u counter.%d\n",(uint32_t)time(NULL),counter); + fprintf(stderr,"end scan of utxo for staking t.%u counter.%d numkp.%d\n",(uint32_t)time(NULL),counter,numkp); return(siglen); } From 518e079e9172d69e211ed783bb7873f36b1e0333 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:14:53 -1100 Subject: [PATCH 46/72] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 59516472b..384c23001 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4740,11 +4740,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = m = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { + fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + if ( eligible < (uint32_t)tipindex->nTime-180 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 1d8f1b466afec494601820a696923f53ff68f6ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:18:36 -1100 Subject: [PATCH 47/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 384c23001..cc8f63040 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4740,7 +4740,6 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt besttime = m = 0; if ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { - fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); while ( eligible == komodo_stake(1,bnTarget,nHeight,kp->txid,kp->vout,eligible,(uint32_t)tipindex->nTime+27,kp->address) ) { besttime = eligible; @@ -4757,6 +4756,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } eligible = besttime; + fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); if ( earliest == 0 || eligible < earliest || (eligible == earliest && (*utxovaluep == 0 || kp->nValue < *utxovaluep)) ) { earliest = eligible; From 817aedba536f3573c715a90b49c24a2d240a68a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:53:42 -1100 Subject: [PATCH 48/72] Test --- src/wallet/rpcwallet.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cc8f63040..7c1b81af1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,13 +4691,14 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - //if ( time(NULL) > lasttime+600 ) + if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { free(array); array = 0; maxkp = numkp = 0; + lasttime = 0; } BOOST_FOREACH(const COutput& out, vecOutputs) { @@ -4731,6 +4732,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } for (i=0; inHeight+1 > nHeight ) + { + fprintf(stderr,"chain tip changed during staking loop t.%u counter.%d\n",(uint32_t)time(NULL),counter); + return(0); + } kp = &array[i]; if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; @@ -4770,11 +4776,12 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( array != 0 ) + if ( 0 && array != 0 ) { free(array); array = 0; maxkp = numkp = 0; + lasttime = 0; } if ( earliest != 0 ) { From a87b6f5f629a2d55c2db677155e5347f6dcad7e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 11:55:01 -1100 Subject: [PATCH 49/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7c1b81af1..8a0d83d1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4750,7 +4750,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-180 ) + if ( eligible < (uint32_t)tipindex->nTime-60 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 45c4bfef6434afc0f351566691257b49a126cebc Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:02:20 -1100 Subject: [PATCH 50/72] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 8a0d83d1f..d068ac18d 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+60 ) + //if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { @@ -4776,7 +4776,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } //else fprintf(stderr,"utxo not eligible\n"); } //else fprintf(stderr,"no tipindex\n"); - if ( 0 && array != 0 ) + if ( array != 0 ) { free(array); array = 0; From d5c81c59bbc70ea5067c316cf34a73960cc181a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:11:43 -1100 Subject: [PATCH 51/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d068ac18d..28166a6fa 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); From b8b06863603f0f0b284731d107cb4efc0de73447 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:21:33 -1100 Subject: [PATCH 52/72] Test --- src/wallet/rpcwallet.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 28166a6fa..d11300c96 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4660,7 +4660,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - //fprintf(stderr,"winner blocktime.%u iter.%d segid.%d\n",blocktime,iter,segid); + fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); @@ -4673,12 +4673,12 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); assert(pwalletMain != NULL); - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); *utxovaluep = 0; memset(utxotxidp,0,sizeof(*utxotxidp)); memset(utxovoutp,0,sizeof(*utxovoutp)); @@ -4691,7 +4691,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt minage = 6000; komodo_segids(hashbuf,nHeight-101,100); fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - //if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+60 ) { if ( array != 0 ) { @@ -4730,7 +4730,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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); } - for (i=0; inHeight+1 > nHeight ) { @@ -4738,9 +4738,10 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - if ( (eligible= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); + fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; From cfe64b2b487c991b8775a875949025bfb0ed0299 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:26:38 -1100 Subject: [PATCH 53/72] Test --- src/wallet/rpcwallet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index d11300c96..987e6db62 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4651,6 +4651,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); + fprintf(stderr,"b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter Date: Sat, 14 Jul 2018 12:35:26 -1100 Subject: [PATCH 54/72] Test --- src/wallet/rpcwallet.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 987e6db62..1977bb4df 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4645,20 +4645,24 @@ arith_uint256 _komodo_eligible(struct komodo_staking *kp,arith_uint256 ratio,uin return(hashval); } -uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage) +uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komodo_staking *kp,int32_t nHeight,uint32_t blocktime,uint32_t prevtime,int32_t minage,uint8_t *hashbuf) { - int32_t maxiters = 180; + int32_t maxiters = 180; uint256 hash; int32_t segid,iter,diff; uint64_t coinage; arith_uint256 hashval,coinage256; + komodo_stakehash(&hash,kp->address,hashbuf,kp->txid,kp->vout); + kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - fprintf(stderr,"b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + for (int i=32; i>=0; i--) + fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; itertxtime+minage ) continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime,hashbuf); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); @@ -4739,7 +4743,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt return(0); } kp = &array[i]; - if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage)) == 0 ) + if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); From 37d6294dbe692798fac29b536754a6cc8bf00425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:36:44 -1100 Subject: [PATCH 55/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1977bb4df..5612f5f79 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4662,7 +4662,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod { if ( blocktime+iter+segid*2 < kp->txtime+minage ) continue; - hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime,hashbuf); + hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); From d3ce166fb8b21972151ecb7673c8f9bbbd942194 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:41:30 -1100 Subject: [PATCH 56/72] Test --- src/wallet/rpcwallet.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 5612f5f79..824eb60b9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4653,9 +4653,9 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod kp->hashval = UintToArith256(hash); segid = ((nHeight + kp->segid32) & 0x3f); hashval = _komodo_eligible(kp,ratio,blocktime,maxiters,minage,segid,nHeight,prevtime); - for (int i=32; i>=0; i--) - fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); - fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); + //for (int i=32; i>=0; i--) + // fprintf(stderr,"%02x",((uint8_t *)&hashval)[i]); + //fprintf(stderr," b.%u minage.%d segid.%d ht.%d prev.%u\n",blocktime,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { for (iter=0; iter 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); + if ( blocktime > tipindex->nTime+60 ) + blocktime = tipindex->nTime+60; fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); - if ( time(NULL) > lasttime+60 ) + if ( time(NULL) > lasttime+100 ) { if ( array != 0 ) { @@ -4735,7 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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); } - for (i=0; inHeight+1 > nHeight ) { From 6e7dcf31067a4501dd6caf2643b58c1b5936ffe4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:42:51 -1100 Subject: [PATCH 57/72] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 824eb60b9..a8575497f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4695,8 +4695,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (minage= nHeight*3) > 6000 ) // about 100 blocks minage = 6000; komodo_segids(hashbuf,nHeight-101,100); - if ( blocktime > tipindex->nTime+60 ) - blocktime = tipindex->nTime+60; + if ( *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); if ( time(NULL) > lasttime+100 ) { From 1973dfa0505aa51cf471bc67aac2919a00615e82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 12:49:18 -1100 Subject: [PATCH 58/72] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a8575497f..330c5f253 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4665,7 +4665,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod hashval = _komodo_eligible(kp,ratio,blocktime,iter,minage,segid,nHeight,prevtime); if ( hashval <= bnTarget ) { - fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); + //fprintf(stderr,"winner %.8f blocktime.%u iter.%d segid.%d\n",(double)kp->nValue/COIN,blocktime,iter,segid); blocktime += iter; blocktime += segid * 2; return(blocktime); @@ -4698,7 +4698,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( *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); - if ( time(NULL) > lasttime+100 ) + if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) { @@ -4748,7 +4748,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt if ( (eligible2= komodo_eligible(bnTarget,ratio,kp,nHeight,*blocktimep,(uint32_t)tipindex->nTime+27,minage,hashbuf)) == 0 ) continue; eligible = komodo_stake(0,bnTarget,nHeight,kp->txid,kp->vout,0,(uint32_t)tipindex->nTime+27,kp->address); - fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); + //fprintf(stderr,"i.%d %u vs %u\n",i,eligible2,eligible); if ( eligible > 0 ) { besttime = m = 0; From 2d4811152640e6e4413f811af0b02cc8605022b6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:02:35 -1100 Subject: [PATCH 59/72] -prints --- src/wallet/rpcwallet.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 330c5f253..c55a306ed 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4697,7 +4697,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt komodo_segids(hashbuf,nHeight-101,100); if ( *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); + //fprintf(stderr,"Start scan of utxo for staking %u ht.%d\n",(uint32_t)time(NULL),nHeight); if ( time(NULL) > lasttime+600 ) { if ( array != 0 ) @@ -4737,7 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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); } - for (i=0; inHeight+1 > nHeight ) { @@ -4770,7 +4770,8 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt continue; } eligible = besttime; - fprintf(stderr,"ht.%d validated winning [%d] -> %.8f eligible.%u test prior\n",nHeight,(int32_t)(eligible - *blocktimep),(double)kp->nValue/COIN,eligible); + 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; @@ -4780,11 +4781,11 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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\n",nHeight,earliest,(int32_t)(earliest- *blocktimep),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter); + fprintf(stderr,"ht.%d earliest.%u [%d].%d (%s) nValue %.8f locktime.%u counter.%d winnders.%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"); } //else fprintf(stderr,"no tipindex\n"); - if ( 0 && array != 0 ) + if ( numkp < 10000 && array != 0 ) { free(array); array = 0; @@ -4822,7 +4823,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *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\n",(uint32_t)time(NULL),counter,numkp); + 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); } From 8cbf8d6a12fee8999c1a8b591e606b681e31b2f0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:12:08 -1100 Subject: [PATCH 60/72] Test --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c55a306ed..debec99b6 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4735,7 +4735,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt } } 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); } for (i=winners=0; inTime-60 ) + if ( eligible < (uint32_t)tipindex->nTime+30 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); @@ -4823,7 +4823,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt *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); + //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); } From 779b7b3a5b5a472bd0893807bbbf023fa4313360 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:16:18 -1100 Subject: [PATCH 61/72] Typo --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index debec99b6..23ba352dd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4781,7 +4781,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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 winnders.%d\n",nHeight,earliest,(int32_t)(earliest - tipindex->nTime),m,kp->address,(double)kp->nValue/COIN,*txtimep,counter,winners); + 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"); } //else fprintf(stderr,"no tipindex\n"); From 8afd5b3a0444e241dbcd885ffc300f580e60dcf3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:25:57 -1100 Subject: [PATCH 62/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 23ba352dd..383c84ef9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4758,7 +4758,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+30 ) + if ( eligible < (uint32_t)tipindex->nTime+3 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From a3b8c12830810f7d8b81bf7bfe5296675d2aa550 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 13:26:39 -1100 Subject: [PATCH 63/72] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 383c84ef9..c4374737f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4758,7 +4758,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime+3 ) + if ( eligible < (uint32_t)tipindex->nTime-63 ) break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 48c3fcbed30c10ef75297659012ab036bceaca30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 23:48:09 -1100 Subject: [PATCH 64/72] Snapshot() reverse iterator --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index a0f764962..ae15d37e1 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -402,7 +402,7 @@ int64_t CBlockTreeDB::Snapshot() { char chType; int64_t total = -1; std::string address; boost::scoped_ptr pcursor(NewIterator()); - pcursor->SeekToFirst(); + pcursor->SeekToLast(); fprintf(stderr,"pcursor iterate\n"); while (pcursor->Valid()) { @@ -428,7 +428,7 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Next(); + pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } From 6651944ae70065fa8f4a93c4fb81d2263d04f360 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 14 Jul 2018 23:59:08 -1100 Subject: [PATCH 65/72] Test --- src/txdb.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/txdb.cpp b/src/txdb.cpp index ae15d37e1..31af362ac 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -400,7 +400,7 @@ bool getAddressFromIndex(const int &type, const uint160 &hash, std::string &addr int64_t CBlockTreeDB::Snapshot() { - char chType; int64_t total = -1; std::string address; + char chType; int64_t total = 0; std::string address; boost::scoped_ptr pcursor(NewIterator()); pcursor->SeekToLast(); fprintf(stderr,"pcursor iterate\n"); @@ -428,7 +428,6 @@ int64_t CBlockTreeDB::Snapshot() total = (int64_t)nValue; else total += (int64_t)nValue; //addressIndex.push_back(make_pair(indexKey, nValue)); - pcursor->Prev(); } catch (const std::exception& e) { return error("failed to get address index value"); } @@ -436,6 +435,7 @@ int64_t CBlockTreeDB::Snapshot() } catch (const std::exception& e) { break; } + pcursor->Prev(); } return(total); } From 7246f7f31d21875d47ea815bf822bada3a88ad0c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 15 Jul 2018 22:01:35 -0700 Subject: [PATCH 66/72] WIP correctly calculate block progress for asset chains --- src/main.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b08d2e522..c17f4456f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3195,10 +3195,18 @@ void static UpdateTip(CBlockIndex *pindexNew) { nTimeBestReceived = GetTime(); mempool.AddTransactionsUpdated(1); KOMODO_NEWBLOCKS++; + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + } else { + progress = (KOMODO_LONGESTCHAIN > 0 ) ? chainActive.Height() / KOMODO_LONGESTCHAIN : 1.0; + } + LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); + chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), + log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, + pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); From 3bd2c3bd6a060f3408a22aff6debaa76865b0884 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 16 Jul 2018 07:57:56 +0000 Subject: [PATCH 67/72] Fix progress estimate for asset chains, mostly --- src/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index c17f4456f..2ef9eb519 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3199,7 +3199,8 @@ void static UpdateTip(CBlockIndex *pindexNew) { if ( ASSETCHAINS_SYMBOL[0] == 0 ) { progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); } else { - progress = (KOMODO_LONGESTCHAIN > 0 ) ? chainActive.Height() / KOMODO_LONGESTCHAIN : 1.0; + int32_t longestchain = komodo_longestchain(); + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, @@ -4858,11 +4859,21 @@ bool static LoadBlockIndexDB() it->second->hashAnchorEnd = pcoinsTip->GetBestAnchor(); PruneBlockIndexCandidates(); + + double progress; + if ( ASSETCHAINS_SYMBOL[0] == 0 ) { + progress = Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip()); + } else { + int32_t longestchain = komodo_longestchain(); + // TODO: komodo_longestchain does not have the data it needs at the time LoadBlockIndexDB + // runs, which makes it return 0, so we guess 50% for now + progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 0.5; + } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), - Checkpoints::GuessVerificationProgress(chainparams.Checkpoints(), chainActive.Tip())); + progress); EnforceNodeDeprecation(chainActive.Height(), true); From 8d487e52a7f01b137e3704315e0eedcf8e6b001c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Jul 2018 21:41:16 -1100 Subject: [PATCH 68/72] Change deprecation height for 1400000 --- src/deprecation.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/deprecation.h b/src/deprecation.h index 78ed8ebda..ec8b084d9 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -6,14 +6,14 @@ #define ZCASH_DEPRECATION_H // Deprecation policy: -// * Shut down 16 weeks' worth of blocks after the estimated release block height. -// * A warning is shown during the 2 weeks' worth of blocks prior to shut down. -static const int APPROX_RELEASE_HEIGHT = 800000; -static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 24); +// * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. +// * A warning is shown during the WEEKS_UNTIL_DEPRECATION worth of blocks prior to shut down. +//static const int APPROX_RELEASE_HEIGHT = 800000; +//static const int WEEKS_UNTIL_DEPRECATION = 52; +static const int DEPRECATION_HEIGHT = 1400000; //APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users -static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months +static const int WEEKS_UNTIL_DEPRECATION = 60 * 24 * 60; // 2 months /** * Checks whether the node is deprecated based on the current block height, and From 86131275722b856b80d3032d74f89d94ff6e0ea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 15 Jul 2018 22:47:16 -1100 Subject: [PATCH 69/72] LastTip() and tweak deprecation heights --- src/chain.cpp | 1 + src/chain.h | 6 ++++++ src/deprecation.h | 10 ++++----- src/komodo.h | 4 ++-- src/komodo_bitcoind.h | 16 +++++++------- src/komodo_gateway.h | 2 +- src/komodo_jumblr.h | 2 +- src/komodo_pax.h | 4 ++-- src/main.cpp | 44 +++++++++++++++++++-------------------- src/metrics.cpp | 2 +- src/miner.cpp | 34 +++++++++++++++--------------- src/rest.cpp | 6 +++--- src/rpcblockchain.cpp | 30 +++++++++++++------------- src/rpcmining.cpp | 24 ++++++++++----------- src/rpcmisc.cpp | 8 +++---- src/rpcrawtransaction.cpp | 2 +- src/txmempool.cpp | 2 +- src/wallet/rpcdump.cpp | 8 +++---- src/wallet/rpcwallet.cpp | 12 +++++------ src/wallet/wallet.cpp | 12 +++++------ 20 files changed, 118 insertions(+), 111 deletions(-) diff --git a/src/chain.cpp b/src/chain.cpp index 7bb72d5d3..d79a66f9a 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -11,6 +11,7 @@ using namespace std; * CChain implementation */ void CChain::SetTip(CBlockIndex *pindex) { + lastTip = pindex; if (pindex == NULL) { vChain.clear(); return; diff --git a/src/chain.h b/src/chain.h index 71d788531..d882083e6 100644 --- a/src/chain.h +++ b/src/chain.h @@ -416,6 +416,7 @@ public: class CChain { private: std::vector vChain; + CBlockIndex *lastTip; public: /** Returns the index entry for the genesis block of this chain, or NULL if none. */ @@ -427,6 +428,11 @@ public: CBlockIndex *Tip() const { return vChain.size() > 0 ? vChain[vChain.size() - 1] : NULL; } + + /** Returns the last tip of the chain, or NULL if none. */ + CBlockIndex *LastTip() const { + return vChain.size() > 0 ? lastTip : NULL; + } /** Returns the index entry at a particular height in this chain, or NULL if no such height exists. */ CBlockIndex *operator[](int nHeight) const { diff --git a/src/deprecation.h b/src/deprecation.h index ec8b084d9..11eb69ef4 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -7,13 +7,13 @@ // Deprecation policy: // * Shut down WEEKS_UNTIL_DEPRECATION weeks' worth of blocks after the estimated release block height. -// * A warning is shown during the WEEKS_UNTIL_DEPRECATION worth of blocks prior to shut down. -//static const int APPROX_RELEASE_HEIGHT = 800000; -//static const int WEEKS_UNTIL_DEPRECATION = 52; -static const int DEPRECATION_HEIGHT = 1400000; //APPROX_RELEASE_HEIGHT + (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); +// * A warning is shown during the DEPRECATION_WARN_LIMIT worth of blocks prior to shut down. +static const int WEEKS_UNTIL_DEPRECATION = 52; +static const int DEPRECATION_HEIGHT = 1400000; +static const int APPROX_RELEASE_HEIGHT = DEPRECATION_HEIGHT - (WEEKS_UNTIL_DEPRECATION * 7 * 24 * 60); // Number of blocks before deprecation to warn users -static const int WEEKS_UNTIL_DEPRECATION = 60 * 24 * 60; // 2 months +static const int DEPRECATION_WARN_LIMIT = 60 * 24 * 60; // 2 months /** * Checks whether the node is deprecated based on the current block height, and diff --git a/src/komodo.h b/src/komodo.h index ae0898ed3..e89dea2e4 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -823,7 +823,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) komodo_event_rewind(sp,symbol,pindex->nHeight); komodo_stateupdate(pindex->nHeight,0,0,0,zero,0,0,0,0,-pindex->nHeight,pindex->nTime,0,0,0,0,zero,0); } - komodo_currentheight_set(chainActive.Tip()->nHeight); + komodo_currentheight_set(chainActive.LastTip()->nHeight); if ( pindex != 0 ) { height = pindex->nHeight; @@ -907,7 +907,7 @@ void komodo_connectblock(CBlockIndex *pindex,CBlock& block) #else memcpy(scriptbuf,(uint8_t *)&block.vtx[i].vout[j].scriptPubKey[0],len); #endif - notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.Tip()->GetBlockTime()); + notaryid = komodo_voutupdate(&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( 0 && i > 0 ) { for (k=0; kGetBlockTime()); + if ( chainActive.LastTip() != 0 ) + return((uint32_t)chainActive.LastTip()->GetBlockTime()); else return(0); } @@ -760,11 +760,11 @@ CBlockIndex *komodo_chainactive(int32_t height) { if ( chainActive.Tip() != 0 ) { - if ( height <= chainActive.Tip()->nHeight ) + if ( height <= chainActive.LastTip()->nHeight ) return(chainActive[height]); - // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); + // else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.LastTip()->nHeight); } - //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); + //fprintf(stderr,"komodo_chainactive null chainActive.LastTip() height %d\n",height); return(0); } @@ -994,7 +994,7 @@ int32_t komodo_MoM(int32_t *notarized_heightp,uint256 *MoMp,uint256 *kmdtxidp,in int32_t komodo_checkpoint(int32_t *notarized_heightp,int32_t nHeight,uint256 hash) { int32_t notarized_height,MoMdepth; uint256 MoM,notarized_hash,notarized_desttxid; CBlockIndex *notary,*pindex; - if ( (pindex= chainActive.Tip()) == 0 ) + if ( (pindex= chainActive.LastTip()) == 0 ) return(-1); notarized_height = komodo_notarizeddata(pindex->nHeight,¬arized_hash,¬arized_desttxid); *notarized_heightp = notarized_height; @@ -1036,7 +1036,7 @@ uint32_t komodo_interest_args(uint32_t *txheighttimep,int32_t *txheightp,uint32_ *valuep = tx.vout[n].nValue; *txheightp = pindex->nHeight; *txheighttimep = pindex->nTime; - if ( *tiptimep == 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( *tiptimep == 0 && (tipindex= chainActive.LastTip()) != 0 ) *tiptimep = (uint32_t)tipindex->nTime; locktime = tx.nLockTime; //fprintf(stderr,"tx locktime.%u %.8f height.%d | tiptime.%u\n",locktime,(double)*valuep/COIN,*txheightp,*tiptimep); @@ -1069,7 +1069,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) if ( (sp= komodo_stateptrget((char *)"KMD")) != 0 ) *kmdheightp = sp->CURRENT_HEIGHT; else *kmdheightp = 0; - if ( (pindex= chainActive.Tip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() ) + if ( (pindex= chainActive.LastTip()) != 0 && pindex->nHeight >= (int32_t)komodo_longestchain() ) return(1); else return(0); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 9de6b4fc9..6a8ef310b 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1490,7 +1490,7 @@ void komodo_passport_iteration() komodo_statefname(fname,baseid<32?base:(char *)"",(char *)"realtime"); if ( (fp= fopen(fname,"wb")) != 0 ) { - buf[0] = (uint32_t)chainActive.Tip()->nHeight; + buf[0] = (uint32_t)chainActive.LastTip()->nHeight; buf[1] = (uint32_t)komodo_longestchain(); if ( buf[0] != 0 && buf[0] == buf[1] ) { diff --git a/src/komodo_jumblr.h b/src/komodo_jumblr.h index f36bb441a..fa44425fd 100755 --- a/src/komodo_jumblr.h +++ b/src/komodo_jumblr.h @@ -648,7 +648,7 @@ void jumblr_iteration() free(retstr); } } - height = (int32_t)chainActive.Tip()->nHeight; + height = (int32_t)chainActive.LastTip()->nHeight; if ( time(NULL) < lasttime+40 ) return; lasttime = (uint32_t)time(NULL); diff --git a/src/komodo_pax.h b/src/komodo_pax.h index d0bad0e14..35d226fc3 100644 --- a/src/komodo_pax.h +++ b/src/komodo_pax.h @@ -637,13 +637,13 @@ uint64_t komodo_paxpriceB(uint64_t seed,int32_t height,char *base,char *rel,uint uint64_t komodo_paxprice(uint64_t *seedp,int32_t height,char *base,char *rel,uint64_t basevolume) { int32_t i,nonz=0; int64_t diff; uint64_t price,seed,sum = 0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && height > chainActive.Tip()->nHeight ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && height > chainActive.LastTip()->nHeight ) { if ( height < 100000000 ) { static uint32_t counter; if ( counter++ < 3 ) - printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.Tip()->nHeight); + printf("komodo_paxprice height.%d vs tip.%d\n",height,chainActive.LastTip()->nHeight); } return(0); } diff --git a/src/main.cpp b/src/main.cpp index 2ef9eb519..330bf6ad1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1269,7 +1269,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) + if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) { //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -1399,7 +1399,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // Bring the best block into scope view.GetBestBlock(); - nValueIn = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime); + nValueIn = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime); if ( 0 && interest != 0 ) fprintf(stderr,"add interest %.8f\n",(double)interest/COIN); // we have all inputs cached now, so switch back to dummy, so we don't need to keep lock on mempool @@ -1891,7 +1891,7 @@ void CheckForkWarningConditions() if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 288) pindexBestForkTip = NULL; - if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6))) + if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.LastTip()->nChainWork + (GetBlockProof(*chainActive.LastTip()) * 6))) { if (!fLargeWorkForkFound && pindexBestForkBase) { @@ -1926,7 +1926,7 @@ void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) AssertLockHeld(cs_main); // If we are on a fork that is sufficiently large, set a warning flag CBlockIndex* pfork = pindexNewForkTip; - CBlockIndex* plonger = chainActive.Tip(); + CBlockIndex* plonger = chainActive.LastTip(); while (pfork && pfork != plonger) { while (plonger && plonger->nHeight > pfork->nHeight) @@ -1983,7 +1983,7 @@ void static InvalidChainFound(CBlockIndex* pindexNew) pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", pindexNew->GetBlockTime())); - CBlockIndex *tip = chainActive.Tip(); + CBlockIndex *tip = chainActive.LastTip(); assert (tip); LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", __func__, tip->GetBlockHash().ToString(), chainActive.Height(), log(tip->nChainWork.getdouble())/log(2.0), @@ -2111,14 +2111,14 @@ namespace Consensus { // Check for negative or overflow input values nValueIn += coins->vout[prevout.n].nValue; #ifdef KOMODO_ENABLE_INTEREST - if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && nSpendHeight > 60000 )//chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 ) { if ( coins->vout[prevout.n].nValue >= 10*COIN ) { int64_t interest; int32_t txheight; uint32_t locktime; if ( (interest= komodo_accrued_interest(&txheight,&locktime,prevout.hash,prevout.n,0,coins->vout[prevout.n].nValue,(int32_t)nSpendHeight-1)) != 0 ) { - //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.Tip()->nTime); + //fprintf(stderr,"checkResult %.8f += val %.8f interest %.8f ht.%d lock.%u tip.%u\n",(double)nValueIn/COIN,(double)coins->vout[prevout.n].nValue/COIN,(double)interest/COIN,txheight,locktime,chainActive.LastTip()->nTime); nValueIn += interest; } } @@ -2868,7 +2868,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (!tx.IsCoinBase()) { - nFees += view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime) - tx.GetValueOut(); + nFees += view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime) - tx.GetValueOut(); sum += interest; std::vector vChecks; @@ -3197,16 +3197,16 @@ void static UpdateTip(CBlockIndex *pindexNew) { KOMODO_NEWBLOCKS++; double progress; if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip()); + progress = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip()); } else { int32_t longestchain = komodo_longestchain(); progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.Tip()->nChainTx, - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), progress, + chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + log(chainActive.Tip()->nChainWork.getdouble())/log(2.0), (unsigned long)chainActive.LastTip()->nChainTx, + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress, pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize()); cvBlockChange.notify_all(); @@ -3455,7 +3455,7 @@ static void PruneBlockIndexCandidates() { // Note that we can't delete the current block itself, as we may need to return to it later in case a // reorganization to a better block fails. std::set::iterator it = setBlockIndexCandidates.begin(); - while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.Tip())) { + while (it != setBlockIndexCandidates.end() && setBlockIndexCandidates.value_comp()(*it, chainActive.LastTip())) { setBlockIndexCandidates.erase(it++); } // Either the current tip or a successor of it we're working towards is left in setBlockIndexCandidates. @@ -3507,8 +3507,8 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if ( KOMODO_REWIND != 0 ) { CBlockIndex *tipindex; - fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.Tip()->nHeight,KOMODO_REWIND); - while ( KOMODO_REWIND > 0 && (tipindex= chainActive.Tip()) != 0 && tipindex->nHeight > KOMODO_REWIND ) + fprintf(stderr,">>>>>>>>>>> rewind start ht.%d -> KOMODO_REWIND.%d\n",chainActive.LastTip()->nHeight,KOMODO_REWIND); + while ( KOMODO_REWIND > 0 && (tipindex= chainActive.LastTip()) != 0 && tipindex->nHeight > KOMODO_REWIND ) { fBlocksDisconnected = true; fprintf(stderr,"%d ",(int32_t)tipindex->nHeight); @@ -3922,9 +3922,9 @@ bool CheckBlockHeader(int32_t *futureblockp,int32_t height,CBlockIndex *pindex, for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- CheckBlockHeader\n"); - if ( chainActive.Tip() != 0 ) + if ( chainActive.LastTip() != 0 ) { - hash = chainActive.Tip()->GetBlockHash(); + hash = chainActive.LastTip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip\n"); @@ -4103,7 +4103,7 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta // Don't accept any forks from the main chain prior to last checkpoint CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(chainParams.Checkpoints()); int32_t notarized_height; - if ( nHeight == 1 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight > 1 ) + if ( nHeight == 1 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight > 1 ) { CBlockIndex *heightblock = chainActive[nHeight]; if ( heightblock != 0 && heightblock->GetBlockHash() == hash ) @@ -4440,8 +4440,8 @@ bool ProcessNewBlock(bool from_miner,int32_t height,CValidationState &state, CNo auto verifier = libzcash::ProofVerifier::Disabled(); hash = pblock->GetHash(); - if ( chainActive.Tip() != 0 ) - komodo_currentheight_set(chainActive.Tip()->nHeight); + if ( chainActive.LastTip() != 0 ) + komodo_currentheight_set(chainActive.LastTip()->nHeight); checked = CheckBlock(&futureblock,height!=0?height:komodo_block2height(pblock),0,*pblock, state, verifier,0); { LOCK(cs_main); @@ -4871,8 +4871,8 @@ bool static LoadBlockIndexDB() } LogPrintf("%s: hashBestChain=%s height=%d date=%s progress=%f\n", __func__, - chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), - DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime()), + chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.LastTip()->GetBlockTime()), progress); EnforceNodeDeprecation(chainActive.Height(), true); diff --git a/src/metrics.cpp b/src/metrics.cpp index 6c8f80fe5..cb9fe245c 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -211,7 +211,7 @@ int printStats(bool mining) { LOCK2(cs_main, cs_vNodes); height = chainActive.Height(); - tipmediantime = chainActive.Tip()->GetMedianTimePast(); + tipmediantime = chainActive.LastTip()->GetMedianTimePast(); connections = vNodes.size(); netsolps = GetNetworkHashPS(120, -1); } diff --git a/src/miner.cpp b/src/miner.cpp index dbe6dc41c..0c458a985 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -166,7 +166,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) { LOCK2(cs_main, mempool.cs); - CBlockIndex* pindexPrev = chainActive.Tip(); + CBlockIndex* pindexPrev = chainActive.LastTip(); const int nHeight = pindexPrev->nHeight + 1; uint32_t consensusBranchId = CurrentEpochBranchId(nHeight, chainparams.GetConsensus()); pblock->nTime = GetAdjustedTime(); @@ -334,7 +334,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"dont have inputs\n"); continue; } - CAmount nTxFees = view.GetValueIn(chainActive.Tip()->nHeight,&interest,tx,chainActive.Tip()->nTime)-tx.GetValueOut(); + CAmount nTxFees = view.GetValueIn(chainActive.LastTip()->nHeight,&interest,tx,chainActive.LastTip()->nTime)-tx.GetValueOut(); nTxSigOps += GetP2SHSigOpCount(tx, view); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) @@ -400,14 +400,14 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if ( (siglen= komodo_staked(txStaked,pblock->nBits,&blocktime,&txtime,&utxotxid,&utxovout,&utxovalue,utxosig)) > 0 ) { CAmount txfees = 0; - //if ( (int32_t)chainActive.Tip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) + //if ( (int32_t)chainActive.LastTip()->nHeight+1 > 100 && GetAdjustedTime() < blocktime-157 ) // return(0); pblock->vtx.push_back(txStaked); pblocktemplate->vTxFees.push_back(txfees); pblocktemplate->vTxSigOps.push_back(GetLegacySigOpCount(txStaked)); nFees += txfees; pblock->nTime = blocktime; - //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.Tip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); + //printf("staking PoS ht.%d t%u lag.%u\n",(int32_t)chainActive.LastTip()->nHeight+1,blocktime,(uint32_t)(GetAdjustedTime() - (blocktime-13))); } else return(0); //fprintf(stderr,"no utxos eligible for staking\n"); } @@ -640,19 +640,19 @@ static bool ProcessBlockFound(CBlock* pblock) #endif // ENABLE_WALLET { LogPrintf("%s\n", pblock->ToString()); - LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.Tip()->nHeight+1); + LogPrintf("generated %s height.%d\n", FormatMoney(pblock->vtx[0].vout[0].nValue),chainActive.LastTip()->nHeight+1); // Found a solution { LOCK(cs_main); - if (pblock->hashPrevBlock != chainActive.Tip()->GetBlockHash()) + if (pblock->hashPrevBlock != chainActive.LastTip()->GetBlockHash()) { uint256 hash; int32_t i; hash = pblock->hashPrevBlock; for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- prev (stale)\n"); - hash = chainActive.Tip()->GetBlockHash(); + hash = chainActive.LastTip()->GetBlockHash(); for (i=31; i>=0; i--) fprintf(stderr,"%02x",((uint8_t *)&hash)[i]); fprintf(stderr," <- chainTip (stale)\n"); @@ -680,7 +680,7 @@ static bool ProcessBlockFound(CBlock* pblock) // Process this block the same as if we had received it from another node CValidationState state; - if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) return error("KomodoMiner: ProcessNewBlock, block not accepted"); TrackMinedBlock(pblock->GetHash()); @@ -718,13 +718,13 @@ void static BitcoinMiner() unsigned int n = chainparams.EquihashN(); unsigned int k = chainparams.EquihashK(); uint8_t *script; uint64_t total,checktoshis; int32_t i,j,gpucount=KOMODO_MAXGPUCOUNT,notaryid = -1; - while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.Tip()->nHeight != 235300 && + while ( (ASSETCHAIN_INIT == 0 || KOMODO_INITDONE == 0) ) //chainActive.LastTip()->nHeight != 235300 && { sleep(1); if ( komodo_baseid(ASSETCHAINS_SYMBOL) < 0 ) break; } - komodo_chosennotary(¬aryid,chainActive.Tip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.Tip()->GetBlockTime()); + komodo_chosennotary(¬aryid,chainActive.LastTip()->nHeight,NOTARY_PUBKEY33,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( notaryid != My_notaryid ) My_notaryid = notaryid; std::string solver; @@ -750,9 +750,9 @@ void static BitcoinMiner() fprintf(stderr,"try %s Mining with %s\n",ASSETCHAINS_SYMBOL,solver.c_str()); while (true) { - if (chainparams.MiningRequiresPeers()) //chainActive.Tip()->nHeight != 235300 && + if (chainparams.MiningRequiresPeers()) //chainActive.LastTip()->nHeight != 235300 && { - //if ( ASSETCHAINS_SEED != 0 && chainActive.Tip()->nHeight < 100 ) + //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->nHeight < 100 ) // break; // Busy-wait for the network to come online so we don't waste time mining // on an obsolete chain. In regtest mode we expect to fly solo. @@ -776,7 +776,7 @@ void static BitcoinMiner() // Create new block // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrev = chainActive.Tip(); + CBlockIndex* pindexPrev = chainActive.LastTip(); if ( Mining_height != pindexPrev->nHeight+1 ) { Mining_height = pindexPrev->nHeight+1; @@ -962,7 +962,7 @@ void static BitcoinMiner() while ( GetAdjustedTime() < B.nTime-2 ) { sleep(1); - if ( chainActive.Tip()->nHeight >= Mining_height ) + if ( chainActive.LastTip()->nHeight >= Mining_height ) { fprintf(stderr,"new block arrived\n"); return(false); @@ -983,7 +983,7 @@ void static BitcoinMiner() while ( B.nTime-57 > GetAdjustedTime() ) { sleep(1); - if ( chainActive.Tip()->nHeight >= Mining_height ) + if ( chainActive.LastTip()->nHeight >= Mining_height ) return(false); } uint256 tmp = B.GetHash(); @@ -992,7 +992,7 @@ void static BitcoinMiner() fprintf(stderr," mined %s block %d!\n",ASSETCHAINS_SYMBOL,Mining_height); } CValidationState state; - if ( !TestBlockValidity(state,B, chainActive.Tip(), true, false)) + if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); for (z=31; z>=0; z--) @@ -1112,7 +1112,7 @@ void static BitcoinMiner() fprintf(stderr,"timeout, break\n"); break; } - if ( pindexPrev != chainActive.Tip() ) + if ( pindexPrev != chainActive.LastTip() ) { if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 ) fprintf(stderr,"Tip advanced, break\n"); diff --git a/src/rest.cpp b/src/rest.cpp index 8e2e4d1e6..38cc38466 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -530,7 +530,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // serialize data // use exact same output as mentioned in Bip64 CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; string ssGetUTXOResponseString = ssGetUTXOResponse.str(); req->WriteHeader("Content-Type", "application/octet-stream"); @@ -540,7 +540,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) case RF_HEX: { CDataStream ssGetUTXOResponse(SER_NETWORK, PROTOCOL_VERSION); - ssGetUTXOResponse << chainActive.Height() << chainActive.Tip()->GetBlockHash() << bitmap << outs; + ssGetUTXOResponse << chainActive.Height() << chainActive.LastTip()->GetBlockHash() << bitmap << outs; string strHex = HexStr(ssGetUTXOResponse.begin(), ssGetUTXOResponse.end()) + "\n"; req->WriteHeader("Content-Type", "text/plain"); @@ -554,7 +554,7 @@ static bool rest_getutxos(HTTPRequest* req, const std::string& strURIPart) // pack in some essentials // use more or less the same output as mentioned in Bip64 objGetUTXOResponse.push_back(Pair("chainHeight", chainActive.Height())); - objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.Tip()->GetBlockHash().GetHex())); + objGetUTXOResponse.push_back(Pair("chaintipHash", chainActive.LastTip()->GetBlockHash().GetHex())); objGetUTXOResponse.push_back(Pair("bitmap", bitmapStringRepresentation)); UniValue utxos(UniValue::VARR); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 42cf7f2b0..7f8984c63 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -38,10 +38,10 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul // minimum difficulty = 1.0. if (blockindex == NULL) { - if (chainActive.Tip() == NULL) + if (chainActive.LastTip() == NULL) return 1.0; else - blockindex = chainActive.Tip(); + blockindex = chainActive.LastTip(); } uint32_t bits; @@ -326,7 +326,7 @@ UniValue getbestblockhash(const UniValue& params, bool fHelp) ); LOCK(cs_main); - return chainActive.Tip()->GetBlockHash().GetHex(); + return chainActive.LastTip()->GetBlockHash().GetHex(); } UniValue getdifficulty(const UniValue& params, bool fHelp) @@ -803,13 +803,13 @@ UniValue kvsearch(const UniValue& params, bool fHelp) if ( (keylen= (int32_t)strlen(params[0].get_str().c_str())) > 0 ) { ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - ret.push_back(Pair("currentheight", (int64_t)chainActive.Tip()->nHeight)); + ret.push_back(Pair("currentheight", (int64_t)chainActive.LastTip()->nHeight)); ret.push_back(Pair("key",params[0].get_str())); ret.push_back(Pair("keylen",keylen)); if ( keylen < sizeof(key) ) { memcpy(key,params[0].get_str().c_str(),keylen); - if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) + if ( (valuesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&flags,&height,value,key,keylen)) >= 0 ) { std::string val; char *valuestr; val.resize(valuesize); @@ -837,7 +837,7 @@ UniValue minerids(const UniValue& params, bool fHelp) LOCK(cs_main); int32_t height = atoi(params[0].get_str().c_str()); if ( height <= 0 ) - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; else { CBlockIndex *pblockindex = chainActive[height]; @@ -899,8 +899,8 @@ UniValue notaries(const UniValue& params, bool fHelp) else timestamp = (uint32_t)time(NULL); if ( height < 0 ) { - height = chainActive.Tip()->nHeight; - timestamp = chainActive.Tip()->GetBlockTime(); + height = chainActive.LastTip()->nHeight; + timestamp = chainActive.LastTip()->GetBlockTime(); } else if ( params.size() < 2 ) { @@ -988,7 +988,7 @@ UniValue paxprice(const UniValue& params, bool fHelp) std::string rel = params[1].get_str(); int32_t height; if ( params.size() == 2 ) - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; else height = atoi(params[2].get_str().c_str()); //if ( params.size() == 3 || (basevolume= COIN * atof(params[3].get_str().c_str())) == 0 ) basevolume = 100000; @@ -1280,10 +1280,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("chain", Params().NetworkIDString())); obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); - obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); + obj.push_back(Pair("bestblockhash", chainActive.LastTip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetNetworkDifficulty())); - obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.Tip()))); - obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); + obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(Params().Checkpoints(), chainActive.LastTip()))); + obj.push_back(Pair("chainwork", chainActive.LastTip()->nChainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); ZCIncrementalMerkleTree tree; @@ -1294,7 +1294,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) obj.push_back(Pair("commitments", tree.size())); #endif - CBlockIndex* tip = chainActive.Tip(); + CBlockIndex* tip = chainActive.LastTip(); UniValue valuePools(UniValue::VARR); valuePools.push_back(ValuePoolDesc("sprout", tip->nChainSproutValue, boost::none)); obj.push_back(Pair("valuePools", valuePools)); @@ -1319,7 +1319,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) if (fPruneMode) { - CBlockIndex *block = chainActive.Tip(); + CBlockIndex *block = chainActive.LastTip(); while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) block = block->pprev; @@ -1394,7 +1394,7 @@ UniValue getchaintips(const UniValue& params, bool fHelp) } // Always report the currently active tip. - setTips.insert(chainActive.Tip()); + setTips.insert(chainActive.LastTip()); /* Construct the output array. */ UniValue res(UniValue::VARR); const CBlockIndex *forked; diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index afe4e5a33..47fbeec30 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -39,7 +39,7 @@ using namespace std; * If 'height' is nonnegative, compute the estimate at the time when a given block was found. */ int64_t GetNetworkHashPS(int lookup, int height) { - CBlockIndex *pb = chainActive.Tip(); + CBlockIndex *pb = chainActive.LastTip(); if (height >= 0 && height < chainActive.Height()) pb = chainActive[height]; @@ -224,7 +224,7 @@ UniValue generate(const UniValue& params, bool fHelp) CBlock *pblock = &pblocktemplate->block; { LOCK(cs_main); - IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce); + IncrementExtraNonce(pblock, chainActive.LastTip(), nExtraNonce); } // Hash state @@ -268,7 +268,7 @@ UniValue generate(const UniValue& params, bool fHelp) } endloop: CValidationState state; - if (!ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, pblock, true, NULL)) + if (!ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, pblock, true, NULL)) throw JSONRPCError(RPC_INTERNAL_ERROR, "ProcessNewBlock, block not accepted"); ++nHeight; blockHashes.push_back(pblock->GetHash().GetHex()); @@ -550,7 +550,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) return "duplicate-inconclusive"; } - CBlockIndex* const pindexPrev = chainActive.Tip(); + CBlockIndex* const pindexPrev = chainActive.LastTip(); // TestBlockValidity only supports blocks built on the current Tip if (block.hashPrevBlock != pindexPrev->GetBlockHash()) return "inconclusive-not-best-prevblk"; @@ -589,7 +589,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) else { // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier - hashWatchedChain = chainActive.Tip()->GetBlockHash(); + hashWatchedChain = chainActive.LastTip()->GetBlockHash(); nTransactionsUpdatedLastLP = nTransactionsUpdatedLast; } @@ -599,7 +599,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) checktxtime = boost::get_system_time() + boost::posix_time::minutes(1); boost::unique_lock lock(csBestBlock); - while (chainActive.Tip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) + while (chainActive.LastTip()->GetBlockHash() == hashWatchedChain && IsRPCRunning()) { if (!cvBlockChange.timed_wait(lock, checktxtime)) { @@ -621,7 +621,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) static CBlockIndex* pindexPrev; static int64_t nStart; static CBlockTemplate* pblocktemplate; - if (pindexPrev != chainActive.Tip() || + if (pindexPrev != chainActive.LastTip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { // Clear pindexPrev so future calls make a new block, despite any failures from here on @@ -629,7 +629,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Store the pindexBest used before CreateNewBlockWithKey, to avoid races nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); - CBlockIndex* pindexPrevNew = chainActive.Tip(); + CBlockIndex* pindexPrevNew = chainActive.LastTip(); nStart = GetTime(); // Create new block @@ -640,7 +640,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) } #ifdef ENABLE_WALLET CReserveKey reservekey(pwalletMain); - pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.Tip()->nHeight+1,KOMODO_MAXGPUCOUNT); + pblocktemplate = CreateNewBlockWithKey(reservekey,chainActive.LastTip()->nHeight+1,KOMODO_MAXGPUCOUNT); #else pblocktemplate = CreateNewBlockWithKey(); #endif @@ -693,7 +693,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) // Correct this if GetBlockTemplate changes the order // entry.push_back(Pair("foundersreward", (int64_t)tx.vout[1].nValue)); //} - CAmount nReward = GetBlockSubsidy(chainActive.Tip()->nHeight+1, Params().GetConsensus()); + CAmount nReward = GetBlockSubsidy(chainActive.LastTip()->nHeight+1, Params().GetConsensus()); entry.push_back(Pair("coinbasevalue", nReward)); entry.push_back(Pair("required", true)); txCoinbase = entry; @@ -726,7 +726,7 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("coinbaseaux", aux)); result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue)); } - result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); + result.push_back(Pair("longpollid", chainActive.LastTip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast))); result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); @@ -809,7 +809,7 @@ UniValue submitblock(const UniValue& params, bool fHelp) CValidationState state; submitblock_StateCatcher sc(block.GetHash()); RegisterValidationInterface(&sc); - bool fAccepted = ProcessNewBlock(1,chainActive.Tip()->nHeight+1,state, NULL, &block, true, NULL); + bool fAccepted = ProcessNewBlock(1,chainActive.LastTip()->nHeight+1,state, NULL, &block, true, NULL); UnregisterValidationInterface(&sc); if (fBlockPresent) { diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index bf7f345d5..4405a407d 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -133,8 +133,8 @@ UniValue getinfo(const UniValue& params, bool fHelp) //fprintf(stderr,"after longestchain %u\n",(uint32_t)time(NULL)); obj.push_back(Pair("longestchain", longestchain)); obj.push_back(Pair("timeoffset", GetTimeOffset())); - if ( chainActive.Tip() != 0 ) - obj.push_back(Pair("tiptime", (int)chainActive.Tip()->nTime)); + if ( chainActive.LastTip() != 0 ) + obj.push_back(Pair("tiptime", (int)chainActive.LastTip()->nTime)); obj.push_back(Pair("connections", (int)vNodes.size())); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("difficulty", (double)GetDifficulty())); @@ -152,7 +152,7 @@ UniValue getinfo(const UniValue& params, bool fHelp) obj.push_back(Pair("errors", GetWarnings("statusbar"))); { char pubkeystr[65]; int32_t notaryid; - if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.Tip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) + if ( (notaryid= komodo_whoami(pubkeystr,(int32_t)chainActive.LastTip()->nHeight,komodo_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); obj.push_back(Pair("pubkey", pubkeystr)); @@ -826,7 +826,7 @@ UniValue getaddressutxos(const UniValue& params, bool fHelp) result.push_back(Pair("utxos", utxos)); LOCK(cs_main); - result.push_back(Pair("hash", chainActive.Tip()->GetBlockHash().GetHex())); + result.push_back(Pair("hash", chainActive.LastTip()->GetBlockHash().GetHex())); result.push_back(Pair("height", (int)chainActive.Height())); return result; } else { diff --git a/src/rpcrawtransaction.cpp b/src/rpcrawtransaction.cpp index a9aff1b7f..525c35ca4 100644 --- a/src/rpcrawtransaction.cpp +++ b/src/rpcrawtransaction.cpp @@ -179,7 +179,7 @@ void TxToJSONExpanded(const CTransaction& tx, const uint256 hashBlock, UniValue& const CTxOut& txout = tx.vout[i]; UniValue out(UniValue::VOBJ); out.push_back(Pair("value", ValueFromAmount(txout.nValue))); - if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && tx.nLockTime >= 500000000 && (tipindex= chainActive.LastTip()) != 0 ) { int64_t interest; int32_t txheight; uint32_t locktime; interest = komodo_accrued_interest(&txheight,&locktime,tx.GetHash(),i,0,txout.nValue,(int32_t)tipindex->nHeight); diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 51ed1103e..e96f0d975 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -437,7 +437,7 @@ void CTxMemPool::removeExpired(unsigned int nBlockHeight) for (indexed_transaction_set::const_iterator it = mapTx.begin(); it != mapTx.end(); it++) { const CTransaction& tx = it->GetTx(); - tipindex = chainActive.Tip(); + tipindex = chainActive.LastTip(); if (IsExpiredTx(tx, nBlockHeight) || (ASSETCHAINS_SYMBOL[0] == 0 && tipindex != 0 && komodo_validate_interest(tx,tipindex->nHeight+1,tipindex->GetMedianTimePast() + 777,0)) < 0) { transactionsToRemove.push_back(tx); diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 15caad846..c8dc7aa5b 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -278,7 +278,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys if (!file.is_open()) throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot open wallet dump file"); - int64_t nTimeBegin = chainActive.Tip()->GetBlockTime(); + int64_t nTimeBegin = chainActive.LastTip()->GetBlockTime(); bool fGood = true; @@ -364,7 +364,7 @@ UniValue importwallet_impl(const UniValue& params, bool fHelp, bool fImportZKeys file.close(); pwalletMain->ShowProgress("", 100); // hide progress dialog in GUI - CBlockIndex *pindex = chainActive.Tip(); + CBlockIndex *pindex = chainActive.LastTip(); while (pindex && pindex->pprev && pindex->GetBlockTime() > nTimeBegin - 7200) pindex = pindex->pprev; @@ -509,8 +509,8 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys) // produce output file << strprintf("# Wallet dump created by Komodo %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); - file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); - file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); + file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.LastTip()->GetBlockHash().ToString()); + file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.LastTip()->GetBlockTime())); file << "\n"; for (std::vector >::const_iterator it = vKeyBirth.begin(); it != vKeyBirth.end(); it++) { const CKeyID &keyid = it->second; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c4374737f..084a4f752 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -574,7 +574,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) valuesize = (int32_t)strlen(params[1].get_str().c_str()); } memcpy(keyvalue,key,keylen); - if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.Tip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) + if ( (refvaluesize= komodo_kvsearch(&refpubkey,chainActive.LastTip()->nHeight,&tmpflags,&height,&keyvalue[keylen],key,keylen)) >= 0 ) { if ( (tmpflags & KOMODO_KVPROTECTED) != 0 ) { @@ -599,7 +599,7 @@ UniValue kvupdate(const UniValue& params, bool fHelp) // printf("%02x",((uint8_t *)&sig)[i]); //printf(" sig for keylen.%d + valuesize.%d\n",keylen,refvaluesize); ret.push_back(Pair("coin",(char *)(ASSETCHAINS_SYMBOL[0] == 0 ? "KMD" : ASSETCHAINS_SYMBOL))); - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; if ( memcmp(&zeroes,&refpubkey,sizeof(refpubkey)) != 0 ) ret.push_back(Pair("owner",refpubkey.GetHex())); ret.push_back(Pair("height", (int64_t)height)); @@ -671,7 +671,7 @@ UniValue paxdeposit(const UniValue& params, bool fHelp) int64_t fiatoshis = atof(params[1].get_str().c_str()) * COIN; std::string base = params[2].get_str(); std::string dest; - height = chainActive.Tip()->nHeight; + height = chainActive.LastTip()->nHeight; if ( pax_fiatstatus(&available,&deposited,&issued,&withdrawn,&approved,&redeemed,(char *)base.c_str()) != 0 || available < fiatoshis ) { fprintf(stderr,"available %llu vs fiatoshis %llu\n",(long long)available,(long long)fiatoshis); @@ -2713,13 +2713,13 @@ UniValue listunspent(const UniValue& params, bool fHelp) BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; uint64_t interest; uint32_t locktime; int32_t txheight; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); //interest = komodo_interest(txheight,nValue,out.tx->nLockTime,tipindex->nTime); entry.push_back(Pair("interest",ValueFromAmount(interest))); } - //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.Tip(),locktime,txheight,pindex->nHeight); + //fprintf(stderr,"nValue %.8f pindex.%p tipindex.%p locktime.%u txheight.%d pindexht.%d\n",(double)nValue/COIN,pindex,chainActive.LastTip(),locktime,txheight,pindex->nHeight); } entry.push_back(Pair("confirmations",out.nDepth)); entry.push_back(Pair("spendable", out.fSpendable)); @@ -2746,7 +2746,7 @@ uint64_t komodo_interestsum() { BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock()); CBlockIndex *tipindex,*pindex = it->second; - if ( pindex != 0 && (tipindex= chainActive.Tip()) != 0 ) + if ( pindex != 0 && (tipindex= chainActive.LastTip()) != 0 ) { interest = komodo_accrued_interest(&txheight,&locktime,out.tx->GetHash(),out.i,0,nValue,(int32_t)tipindex->nHeight); //interest = komodo_interest(pindex->nHeight,nValue,out.tx->nLockTime,tipindex->nTime); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index df0cd9c2b..ce5630fb6 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1819,7 +1819,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) ShowProgress(_("Rescanning..."), 0); // show rescan progress in GUI as dialog or on splashscreen, if -rescan on startup double dProgressStart = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), pindex, false); - double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.Tip(), false); + double dProgressTip = Checkpoints::GuessVerificationProgress(chainParams.Checkpoints(), chainActive.LastTip(), false); while (pindex) { if (pindex->nHeight % 100 == 0 && dProgressTip - dProgressStart > 0.0) @@ -2299,20 +2299,20 @@ void CWallet::AvailableCoins(vector& vCoins, bool fOnlyConfirmed, const if ( KOMODO_EXCHANGEWALLET == 0 ) { uint32_t locktime; int32_t txheight; CBlockIndex *tipindex; - if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.Tip() != 0 && chainActive.Tip()->nHeight >= 60000 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && chainActive.LastTip() != 0 && chainActive.LastTip()->nHeight >= 60000 ) { if ( pcoin->vout[i].nValue >= 10*COIN ) { - if ( (tipindex= chainActive.Tip()) != 0 ) + if ( (tipindex= chainActive.LastTip()) != 0 ) { komodo_accrued_interest(&txheight,&locktime,wtxid,i,0,pcoin->vout[i].nValue,(int32_t)tipindex->nHeight); interest = komodo_interestnew(txheight,pcoin->vout[i].nValue,locktime,tipindex->nTime); } else interest = 0; - //interest = komodo_interestnew(chainActive.Tip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.Tip()->nTime); + //interest = komodo_interestnew(chainActive.LastTip()->nHeight+1,pcoin->vout[i].nValue,pcoin->nLockTime,chainActive.LastTip()->nTime); if ( interest != 0 ) { //printf("wallet nValueRet %.8f += interest %.8f ht.%d lock.%u/%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,txheight,locktime,pcoin->nLockTime,tipindex->nTime); - //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.Tip()->nHeight+1,pcoin->nLockTime,chainActive.Tip()->nTime); + //fprintf(stderr,"wallet nValueRet %.8f += interest %.8f ht.%d lock.%u tip.%u\n",(double)pcoin->vout[i].nValue/COIN,(double)interest/COIN,chainActive.LastTip()->nHeight+1,pcoin->nLockTime,chainActive.LastTip()->nTime); //ptr = (uint64_t *)&pcoin->vout[i].nValue; //(*ptr) += interest; ptr = (uint64_t *)&pcoin->vout[i].interest; @@ -2687,7 +2687,7 @@ bool CWallet::CreateTransaction(const vector& vecSend, CWalletTx& wt int nextBlockHeight = chainActive.Height() + 1; CMutableTransaction txNew = CreateNewContextualCMutableTransaction( Params().GetConsensus(), nextBlockHeight); - txNew.nLockTime = (uint32_t)chainActive.Tip()->nTime + 1; // set to a time close to now + txNew.nLockTime = (uint32_t)chainActive.LastTip()->nTime + 1; // set to a time close to now // Activates after Overwinter network upgrade // Set nExpiryHeight to expiryDelta (default 20) blocks past current block height From 17839698a34ac122200fe4eaf82f709b3b1c94a8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 16 Jul 2018 00:55:48 -1100 Subject: [PATCH 70/72] block_from_future_rejecttime used in RAMstaker --- src/wallet/rpcwallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 084a4f752..02cea5bef 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4678,7 +4678,7 @@ uint32_t komodo_eligible(arith_uint256 bnTarget,arith_uint256 ratio,struct komod 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) { static struct komodo_staking *array; static int32_t numkp,maxkp; static uint32_t lasttime; - set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; + set setAddress; struct komodo_staking *kp; int32_t winners,segid,minage,nHeight,counter=0,i,m,siglen=0,nMinDepth = 1,nMaxDepth = 99999999; vector vecOutputs; uint32_t block_from_future_rejecttime,besttime,eligible,eligible2,earliest = 0; CScript best_scriptPubKey; arith_uint256 mindiff,ratio,bnTarget; CBlockIndex *tipindex,*pindex; CTxDestination address; bool fNegative,fOverflow; uint8_t hashbuf[256]; CTransaction tx; uint256 hashBlock; bnTarget.SetCompact(nBits, &fNegative, &fOverflow); mindiff.SetCompact(KOMODO_MINDIFF_NBITS,&fNegative,&fOverflow); ratio = (mindiff / bnTarget); @@ -4737,6 +4737,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt 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); } + block_from_future_rejecttime = (uint32_t)GetAdjustedTime() + 57; for (i=winners=0; inHeight+1 > nHeight ) @@ -4758,7 +4759,7 @@ int32_t komodo_staked(CMutableTransaction &txNew,uint32_t nBits,uint32_t *blockt { besttime = eligible; eligible--; - if ( eligible < (uint32_t)tipindex->nTime-63 ) + if ( eligible < block_from_future_rejecttime ) // nothing gained by going earlier break; m++; //fprintf(stderr,"m.%d ht.%d validated winning blocktime %u -> %.8f eligible.%u test prior\n",m,nHeight,*blocktimep,(double)kp->nValue/COIN,eligible); From 7000ef1af3ddfc99bde07c185c781ea198d5eea5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jul 2018 05:26:34 -1100 Subject: [PATCH 71/72] Possible workaround for crash --- src/wallet/wallet.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ce5630fb6..e62c6e60b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1885,6 +1885,11 @@ void CWallet::ReacceptWalletTransactions() bool CWalletTx::RelayWalletTransaction() { + if ( pwallet == 0 ) + { + fprintf(stderr,"unexpected null pwallet in RelayWalletTransaction\n"); + return(false); + } assert(pwallet->GetBroadcastTransactions()); if (!IsCoinBase()) { @@ -2124,9 +2129,13 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { - CWalletTx& wtx = *item.second; - if (wtx.RelayWalletTransaction()) - result.push_back(wtx.GetHash()); + CWalletTx& wtx; + if ( item.second != 0 ) + { + wtx = *item.second; + if (wtx.RelayWalletTransaction()) + result.push_back(wtx.GetHash()); + } } return result; } From 3872e9cb59b99fbffc23ea9fa3587afbb68a524c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 17 Jul 2018 05:29:01 -1100 Subject: [PATCH 72/72] Fix --- src/wallet/wallet.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e62c6e60b..5100a2470 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2129,10 +2129,9 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } BOOST_FOREACH(PAIRTYPE(const unsigned int, CWalletTx*)& item, mapSorted) { - CWalletTx& wtx; if ( item.second != 0 ) { - wtx = *item.second; + CWalletTx &wtx = *item.second; if (wtx.RelayWalletTransaction()) result.push_back(wtx.GetHash()); }