From 10c862f271f1efb60e5b6489d2308edd5fe8aab5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 22:32:48 +0200 Subject: [PATCH 01/51] Test --- src/main.cpp | 2 +- src/miner.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 99800a600..ba8944a24 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -747,7 +747,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } } - //fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); } return(0); } diff --git a/src/miner.cpp b/src/miner.cpp index 3caf774c0..301a1037a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -206,9 +206,9 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { if ( expired != 0 ) { - //fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); - //list removed; - //mempool.remove(tx, removed, true); + fprintf(stderr,"expire from mempool tx. need to verify this works\n");//(%d %d) %.8f\n",tx.vins.size(),tx.vouts.size(),(double)tx.vouts[0].nValue/COIN); + list removed; + mempool.remove(tx, removed, true); } continue; } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); From b2d09a90d469c62c9cbbad5ca3855c404648b5aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 22:46:42 +0200 Subject: [PATCH 02/51] Test --- src/komodo_bitcoind.h | 5 ++++- src/main.cpp | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 481ede104..8a5bcfec1 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -620,7 +620,10 @@ void komodo_connectpindex(CBlockIndex *pindex) CBlockIndex *komodo_chainactive(int32_t height) { - return(chainActive[height]); + if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) + { + return(chainActive[height]); + } else return(0); } int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); diff --git a/src/main.cpp b/src/main.cpp index ba8944a24..cf7da0e44 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,10 +710,15 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint32_t txblocktime) { - int32_t i,txheight=0; uint32_t cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; + int32_t i,txheight=0; uint32_t prevblocktime,cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); + prevblocktime = 0; + if ( (locktime= komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0)) != 0 && txheight > 0 ) + { + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + prevblocktime = prev->nTime; + } if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) @@ -733,6 +738,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 cmptime = txblocktime; if ( tiptime != 0 && tiptime < cmptime ) cmptime = tiptime; + if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) + cmptime = prevblocktime; if ( cmptime >= 1490159171 - 24*3600 ) { if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) @@ -740,7 +747,9 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748 { if ( tx.nLockTime != 1477258935 ) + { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)chainActive.Tip()->nTime,txheighttime,tiptime,txblocktime,cmptime); + } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); From b9551735cf54eb1f56488e15e291cdfab572954c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:07:51 +0200 Subject: [PATCH 03/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index cf7da0e44..890482c30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -756,7 +756,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } } - fprintf(stderr,"validateinterest accept.%d tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); } return(0); } From 9a9b36ca7ee9af11b3957b2d72616cbbecb47727 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:20:31 +0200 Subject: [PATCH 04/51] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 890482c30..7797376f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -719,6 +719,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( (prev= komodo_chainactive(txheight-1)) != 0 ) prevblocktime = prev->nTime; } + if ( txheight == 0 ) + txheight = (int32_t)chainActive.Tip()->nHeight + 1; if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) From 3fd98f8ff6fa0b9edf6cc520fbf42f0f22a470b9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:21:02 +0200 Subject: [PATCH 05/51] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7797376f0..305dbc4ba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -716,11 +716,11 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 prevblocktime = 0; if ( (locktime= komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0)) != 0 && txheight > 0 ) { + if ( txheight == 0 ) + txheight = (int32_t)chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) prevblocktime = prev->nTime; } - if ( txheight == 0 ) - txheight = (int32_t)chainActive.Tip()->nHeight + 1; if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) From 52e5ebfdc2d8712e4ba2beedc8a0e6dbedd25540 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:22:08 +0200 Subject: [PATCH 06/51] Test --- src/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 305dbc4ba..d502b7e1e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -714,13 +714,11 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { prevblocktime = 0; - if ( (locktime= komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0)) != 0 && txheight > 0 ) - { - if ( txheight == 0 ) - txheight = (int32_t)chainActive.Tip()->nHeight + 1; - if ( (prev= komodo_chainactive(txheight-1)) != 0 ) - prevblocktime = prev->nTime; - } + locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); + if ( txheight == 0 ) + txheight = (int32_t)chainActive.Tip()->nHeight + 1; + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + prevblocktime = prev->nTime; if ( tiptime == 0 ) tiptime = (int32_t)chainActive.Tip()->nTime; if ( txheighttime == 0 ) From c2123afed997868470ec5187ada76fc3a1656a56 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 23 Mar 2017 23:58:39 +0200 Subject: [PATCH 07/51] Test --- src/komodo_gateway.h | 19 ++++++++++++++----- src/komodo_globals.h | 2 +- src/main.cpp | 26 +++++++++++++------------- src/main.h | 2 +- src/miner.cpp | 2 +- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 3a09400a2..a0a64231d 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -628,26 +628,35 @@ const char *banned_txids[] = "a01671c8775328a41304e31a6693bbd35e9acbab28ab117f729eaba9cb769461", //235265 "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 + // all vouts banned + "305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204 }; -void komodo_bannedset(uint256 *array,int32_t max) +int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) { int32_t i; + if ( sizeof(banned_txids)/sizeof(*banned_txids) > max ) + { + fprintf(stderr,"komodo_bannedset: buffer too small %ld vs %d\n",sizeof(banned_txids)/sizeof(*banned_txids),max); + exit(-1); + } for (i=0; i= indallvouts) ) { printf("banned tx.%d being used at ht.%d txi.%d vini.%d\n",k,height,i,j); return(-1); diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 905b4fb4b..6d8d6c325 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -24,7 +24,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp); uint64_t komodo_paxtotal(); int32_t komodo_longestchain(); uint64_t komodo_maxallowed(int32_t baseid); -void komodo_bannedset(uint256 *array,int32_t max); +int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max); pthread_mutex_t komodo_mutex; diff --git a/src/main.cpp b/src/main.cpp index d502b7e1e..25532182c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -708,15 +708,15 @@ bool IsStandardTx(const CTransaction& tx, string& reason) return true; } -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint32_t txblocktime) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { int32_t i,txheight=0; uint32_t prevblocktime,cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - if ( txheight == 0 ) - txheight = (int32_t)chainActive.Tip()->nHeight + 1; + if ( (txheight= txheightarg) == 0 ) + txheight = chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) prevblocktime = prev->nTime; if ( tiptime == 0 ) @@ -761,7 +761,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,uint3 return(0); } -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,int32_t interesttime) +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags) { int32_t i; if ( expiredp != 0 ) @@ -770,7 +770,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,interesttime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -821,7 +821,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime); + return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags); } /** @@ -923,9 +923,9 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash::ProofVerifier& verifier) { - static uint256 array[15]; int32_t j,k,n; + static uint256 array[64]; static int32_t numbanned,indallvouts; int32_t j,k,n; if ( *(int32_t *)&array[0] == 0 ) - komodo_bannedset(array,(int32_t)(sizeof(array)/sizeof(*array))); + numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); /*if ( komodo_validate_interest(tx) < 0 ) { fprintf(stderr,"CheckTransaction komodo_validate_interest error\n"); @@ -934,13 +934,13 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash:: n = tx.vin.size(); for (j=0; j= indallvouts) ) { static uint32_t counter; if ( counter++ < 100 ) - printf("MEMPOOL: banned tx.%d being used at ht.%d vini.%d\n",k,(int32_t)chainActive.Tip()->nHeight,j); + printf("MEMPOOL: banned tx.%d being used at ht.%d vout.%d\n",k,(int32_t)chainActive.Tip()->nHeight,j); return(false); } } @@ -3288,7 +3288,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,block.nTime) < 0 ) + if ( komodo_validate_interest(0,tx,height != 0 ? height : komodo_block2height((CBlock *)&block)) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); return error("CheckBlock: komodo_validate_interest failed"); @@ -3372,7 +3372,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST) ? pindexPrev->GetMedianTimePast() : block.GetBlockTime(); - if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev->nTime)) { + if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS)) { return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } } diff --git a/src/main.h b/src/main.h index 1bea5030f..dcbd23632 100644 --- a/src/main.h +++ b/src/main.h @@ -351,7 +351,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason); * Check if transaction is final and can be included in a block with the * specified height and time. Consensus critical. */ -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags,int32_t interesttime); +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags); /** * Check if transaction will be final in the next block to be created. diff --git a/src/miner.cpp b/src/miner.cpp index 301a1037a..ff6f0bcf1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,7 +202,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime+600)) + if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS)) { if ( expired != 0 ) { From b575c4fb7b5ff63170885b3f32de0e5bdb220484 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:08:11 +0200 Subject: [PATCH 08/51] Test --- src/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 25532182c..9daea90da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,11 +710,11 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i,txheight=0; uint32_t prevblocktime,cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; CBlockIndex *prev; + int32_t i,txheight=0; uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); + /*prevblocktime = 0; if ( (txheight= txheightarg) == 0 ) txheight = chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) @@ -739,7 +739,9 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( tiptime != 0 && tiptime < cmptime ) cmptime = tiptime; if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) - cmptime = prevblocktime; + cmptime = prevblocktime;*/ + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + cmptime = prev->nTime + 600; if ( cmptime >= 1490159171 - 24*3600 ) { if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) From 9f539d8804000902a539efcc05bea1092a99e7d2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:13:52 +0200 Subject: [PATCH 09/51] Test --- src/main.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9daea90da..b1d061427 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,11 +710,12 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i,txheight=0; uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *prev; + int32_t i; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { + /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; + prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - /*prevblocktime = 0; if ( (txheight= txheightarg) == 0 ) txheight = chainActive.Tip()->nHeight + 1; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) @@ -739,7 +740,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( tiptime != 0 && tiptime < cmptime ) cmptime = tiptime; if ( locktime != 0 && prevblocktime != 0 && prevblocktime < cmptime ) - cmptime = prevblocktime;*/ + cmptime = prevblocktime; if ( (prev= komodo_chainactive(txheight-1)) != 0 ) cmptime = prev->nTime + 600; if ( cmptime >= 1490159171 - 24*3600 ) @@ -757,8 +758,23 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } + }*/ + if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + cmptime = prev->nTime + 600; + if ( cmptime > 0 && txheightarg > 246748 ) + { + if ( (int64_t)tx.nLockTime < cmptime-3600 ) + { + if ( tx.nLockTime != 1477258935 ) + { + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u vs nBlockTime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); + } + if ( expiredp != 0 ) + *expiredp = cmptime-3600; + return(-1); + } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u/%u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,locktime,txheighttime,tiptime,txblocktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,cmptime); } return(0); } From 1a85595b5a5ddc4c39dda16faf602df4bcbe22da Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:14:38 +0200 Subject: [PATCH 10/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index b1d061427..cae353b38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i; uint64_t value=0; CBlockIndex *prev; + int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *prev; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; From 48b72e17251e06482d996bd0ed5a11bcbe52a564 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:16:18 +0200 Subject: [PATCH 11/51] Test --- src/komodo_gateway.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index a0a64231d..16be739e4 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -645,7 +645,7 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) if ( i != max ) printf("banned txid array error i.%d != max.%d\n",i,max); //else printf("set %d banned txids\n",max); - *allvoutsp = i-1; + *indallvoutsp = i-1; return(0); } diff --git a/src/main.cpp b/src/main.cpp index cae353b38..ab08b5a82 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -759,7 +759,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ - if ( (prev= komodo_chainactive(txheight-1)) != 0 ) + if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) { From 8795f3397f866c8c882bb981404966f98da86e78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:23:47 +0200 Subject: [PATCH 12/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ab08b5a82..2a2189a2d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -767,7 +767,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u vs nBlockTime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; From 28c39e54b63108f82adf84a0b81fdfeed8ff539e Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:28:42 +0200 Subject: [PATCH 13/51] Test --- src/komodo_gateway.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 16be739e4..2b1b8ef57 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -642,9 +642,6 @@ int32_t komodo_bannedset(int32_t *indallvoutsp,uint256 *array,int32_t max) } for (i=0; i Date: Fri, 24 Mar 2017 00:36:23 +0200 Subject: [PATCH 14/51] Test --- src/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 2a2189a2d..466f1d139 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -763,6 +763,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) { + if ( txheightarg < 247205 ) + cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) From ad0b9d62375ce58f4a9ab355ca57fcd49f905343 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:47:51 +0200 Subject: [PATCH 15/51] Test --- src/init.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 0f03aac21..b9881cf1e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,6 +1246,19 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n", MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } + uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); + //uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); + CValidationState state; + { + LOCK(cs_main); + if ( mapBlockIndex.count(hash) != 0 ) + { + CBlockIndex* pblockindex; + if ( (pblockindex= mapBlockIndex[hash]) != 0 ) + InvalidateBlock(state, pblockindex); + } + } + if ( KOMODO_REWIND >= 0 ) { if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), From a710762818470e2fcaf865de4459ba3362c75888 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:51:12 +0200 Subject: [PATCH 16/51] Test --- src/init.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index b9881cf1e..ad7559fcd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1247,7 +1247,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); - //uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); + uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); CValidationState state; { LOCK(cs_main); @@ -1257,6 +1257,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if ( (pblockindex= mapBlockIndex[hash]) != 0 ) InvalidateBlock(state, pblockindex); } + if ( mapBlockIndex.count(hash2) != 0 ) + { + CBlockIndex* pblockindex; + if ( (pblockindex= mapBlockIndex[hash2]) != 0 ) + InvalidateBlock(state, pblockindex); + } } if ( KOMODO_REWIND >= 0 ) From 5ead8b4e858d4831fe80cc83c9c62c5549b704d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 00:55:19 +0200 Subject: [PATCH 17/51] Test --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index ad7559fcd..0f89ae6ed 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1249,6 +1249,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); CValidationState state; + if ( 0 ) { LOCK(cs_main); if ( mapBlockIndex.count(hash) != 0 ) From e20babf1dffb8d577175d99bbc51528705352a98 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:01:49 +0200 Subject: [PATCH 18/51] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 466f1d139..91de3b315 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -790,7 +790,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight-1) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -3308,7 +3308,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,height != 0 ? height : komodo_block2height((CBlock *)&block)) < 0 ) + if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block)) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); return error("CheckBlock: komodo_validate_interest failed"); From 88416f2bc93c5588621da3d14fc6a60b6519c9f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:04:18 +0200 Subject: [PATCH 19/51] Test --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 91de3b315..11af67f81 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -761,6 +761,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 }*/ if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) cmptime = prev->nTime + 600; + else fprintf(stderr,"couldnt get prev.[%d]\n",txheightarg-1); if ( cmptime > 0 && txheightarg > 246748 ) { if ( txheightarg < 247205 ) @@ -790,7 +791,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight-1) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx From 7d44d3dddda83699e2c7d1c722938a4b5a7708de Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:19:53 +0200 Subject: [PATCH 20/51] Test --- src/komodo_bitcoind.h | 27 +++++++++++++++++++-------- src/main.cpp | 12 +++++++++--- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 8a5bcfec1..9c615c329 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -594,6 +594,25 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) return(0); } +CBlockIndex *komodo_chainactive(int32_t height) +{ + if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) + { + return(chainActive[height]); + } else return(0); +} + +uint32_t komodo_heightstamp(int32_t height) +{ + CBlock block; CBlockIndex *ptr; + if ( (ptr= komodo_chainactive(height)) != 0 ) + { + if ( komodo_blockload(block,ptr) == 0 && komodo_block2height(&block) == height ) + return(block.nTime); + } + return(0); +} + void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; @@ -618,14 +637,6 @@ void komodo_connectpindex(CBlockIndex *pindex) komodo_connectblock(pindex,block); } -CBlockIndex *komodo_chainactive(int32_t height) -{ - if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) - { - return(chainActive[height]); - } else return(0); -} - int32_t komodo_notaries(uint8_t pubkeys[64][33],int32_t height); int32_t komodo_electednotary(uint8_t *pubkey33,int32_t height); diff --git a/src/main.cpp b/src/main.cpp index 11af67f81..4c37892bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -708,6 +708,8 @@ bool IsStandardTx(const CTransaction& tx, string& reason) return true; } +uint32_t komodo_heightstamp(int32_t height); + int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *prev; @@ -759,9 +761,13 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ - if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) - cmptime = prev->nTime + 600; - else fprintf(stderr,"couldnt get prev.[%d]\n",txheightarg-1); + if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) + { + cmptime = chainActive.Tip()->nTime; + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); + } + //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) + // cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) { if ( txheightarg < 247205 ) From 58bec1f9b51b98cc7a49a9780eca0719f67b0930 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:27:03 +0200 Subject: [PATCH 21/51] Test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9c615c329..bfd138287 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -605,7 +605,7 @@ CBlockIndex *komodo_chainactive(int32_t height) uint32_t komodo_heightstamp(int32_t height) { CBlock block; CBlockIndex *ptr; - if ( (ptr= komodo_chainactive(height)) != 0 ) + if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) { if ( komodo_blockload(block,ptr) == 0 && komodo_block2height(&block) == height ) return(block.nTime); diff --git a/src/main.cpp b/src/main.cpp index 4c37892bd..de593507f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -761,6 +761,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ + if ( txheightarg == 0 ) + txheightarg = chainActive.Tip()->nHeight + 1; if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { cmptime = chainActive.Tip()->nTime; From fa0a031c09648c905e69297c4b1e3d4fcc238825 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:33:47 +0200 Subject: [PATCH 22/51] Test --- src/main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index de593507f..78af52e15 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -762,11 +762,12 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } }*/ if ( txheightarg == 0 ) - txheightarg = chainActive.Tip()->nHeight + 1; + txheightarg = chainActive.Tip()->nHeight; + else txheightarg--; if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { - cmptime = chainActive.Tip()->nTime; fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); + return(-1); } //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) // cmptime = prev->nTime + 600; From d54aa57df49d7de997fdaf422528b045a882349b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:41:11 +0200 Subject: [PATCH 23/51] 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 bfd138287..be70286f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -599,7 +599,9 @@ CBlockIndex *komodo_chainactive(int32_t height) if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) { return(chainActive[height]); - } else return(0); + } + fprintf(stderr,"komodo_chainactive height %d > %d active.%d\n",height,chainActive.Tip()->nHeight); + return(0); } uint32_t komodo_heightstamp(int32_t height) @@ -607,9 +609,13 @@ uint32_t komodo_heightstamp(int32_t height) CBlock block; CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) { - if ( komodo_blockload(block,ptr) == 0 && komodo_block2height(&block) == height ) - return(block.nTime); - } + if ( komodo_blockload(block,ptr) == 0 ) + { + if ( komodo_block2height(&block) == height ) + return(block.nTime); + else fprintf(stderr,"komodo_heightstamp block2height %d != %d\n",komodo_block2height(&block),height); + } else fprintf(stderr,"komodo_heightstamp cant load block.%d\n",height); + } else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } From 89b6584b23447374f28eaef6dd5124157fc94170 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:45:07 +0200 Subject: [PATCH 24/51] 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 be70286f2..9b5d4e898 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -600,7 +600,7 @@ CBlockIndex *komodo_chainactive(int32_t height) { return(chainActive[height]); } - fprintf(stderr,"komodo_chainactive height %d > %d active.%d\n",height,chainActive.Tip()->nHeight); + fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); return(0); } From 5150cb47a92688f51dfcbc08d92ab241ba9c65e3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:53:24 +0200 Subject: [PATCH 25/51] Test --- src/komodo_bitcoind.h | 8 +++++--- src/main.cpp | 18 +++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 9b5d4e898..65b1b4e8b 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -596,11 +596,13 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) CBlockIndex *komodo_chainactive(int32_t height) { - if ( chainActive.Tip() != 0 && height <= chainActive.Tip()->nHeight ) + if ( chainActive.Tip() != 0 ) { - return(chainActive[height]); + if ( height <= chainActive.Tip()->nHeight ) + return(chainActive[height]); + else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); } - fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); + fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); return(0); } diff --git a/src/main.cpp b/src/main.cpp index 78af52e15..40d9ee355 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -712,7 +712,7 @@ uint32_t komodo_heightstamp(int32_t height); int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) { - int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *prev; + int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; @@ -761,9 +761,17 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ + tip = chainActive.Tip(); if ( txheightarg == 0 ) - txheightarg = chainActive.Tip()->nHeight; - else txheightarg--; + { + if ( tip != 0 ) + txheightarg = tip->nHeight + 1; + else + { + fprintf(stderr,"couldnt get chaintip for [%d]\n",txheightarg); + return(-1); + } + } if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); @@ -779,14 +787,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)chainActive.Tip()->nTime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)tip != 0 ? tip->nTime : 0,cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)chainActive.Tip()->nHeight,(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tip != 0 ? tip->nHeight : 0,(int32_t)tx.nLockTime,cmptime); } return(0); } From 4b470a580170be53b2418252c3a448c0f51f1c4b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:54:48 +0200 Subject: [PATCH 26/51] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 40d9ee355..fcef4808f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -787,14 +787,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)tip != 0 ? tip->nTime : 0,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tip != 0 ? tip->nHeight : 0,(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); } return(0); } From 8c8a07ce2448e1a67734f09344d93a692c9a62ce Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 01:57:33 +0200 Subject: [PATCH 27/51] 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 65b1b4e8b..29a4f35c0 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -602,7 +602,7 @@ CBlockIndex *komodo_chainactive(int32_t height) return(chainActive[height]); else fprintf(stderr,"komodo_chainactive height %d > active.%d\n",height,chainActive.Tip()->nHeight); } - fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); + //fprintf(stderr,"komodo_chainactive null chainActive.Tip() height %d\n",height); return(0); } From 0cb1d2da0db2f700ca78643fad8c51749a48f3d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:09:32 +0200 Subject: [PATCH 28/51] Test --- src/komodo_bitcoind.h | 12 +++--------- src/main.cpp | 26 +++++++++----------------- src/main.h | 2 +- src/miner.cpp | 2 +- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 29a4f35c0..a80e0b1ed 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -608,16 +608,10 @@ CBlockIndex *komodo_chainactive(int32_t height) uint32_t komodo_heightstamp(int32_t height) { - CBlock block; CBlockIndex *ptr; + CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) - { - if ( komodo_blockload(block,ptr) == 0 ) - { - if ( komodo_block2height(&block) == height ) - return(block.nTime); - else fprintf(stderr,"komodo_heightstamp block2height %d != %d\n",komodo_block2height(&block),height); - } else fprintf(stderr,"komodo_heightstamp cant load block.%d\n",height); - } else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); + reeturn(ptr->nTime); + else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } diff --git a/src/main.cpp b/src/main.cpp index fcef4808f..f5965813c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) uint32_t komodo_heightstamp(int32_t height); -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg,uint32_t prevblocktime) { int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) @@ -761,22 +761,14 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } }*/ - tip = chainActive.Tip(); - if ( txheightarg == 0 ) + if ( (cmptime= prevblocktime) == 0 ) { - if ( tip != 0 ) - txheightarg = tip->nHeight + 1; - else + if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) { - fprintf(stderr,"couldnt get chaintip for [%d]\n",txheightarg); + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); return(-1); } } - if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) - { - fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); - return(-1); - } //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) // cmptime = prev->nTime + 600; if ( cmptime > 0 && txheightarg > 246748 ) @@ -799,7 +791,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(0); } -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags) +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,uint32_t prevblocktime) { int32_t i; if ( expiredp != 0 ) @@ -808,7 +800,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -859,7 +851,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags); + return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime); } /** @@ -3326,7 +3318,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block)) < 0 ) + if ( komodo_validate_interest(0,tx,0,chainActive.Tip()->nTime) < 0 ) { //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); return error("CheckBlock: komodo_validate_interest failed"); @@ -3410,7 +3402,7 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, CBlockIn int64_t nLockTimeCutoff = (nLockTimeFlags & LOCKTIME_MEDIAN_TIME_PAST) ? pindexPrev->GetMedianTimePast() : block.GetBlockTime(); - if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS)) { + if (!IsFinalTx(0,tx, nHeight, nLockTimeCutoff,0*STANDARD_LOCKTIME_VERIFY_FLAGS,pindexPrev->nTime)) { return state.DoS(10, error("%s: contains a non-final transaction", __func__), REJECT_INVALID, "bad-txns-nonfinal"); } } diff --git a/src/main.h b/src/main.h index dcbd23632..71ec17ef1 100644 --- a/src/main.h +++ b/src/main.h @@ -351,7 +351,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason); * Check if transaction is final and can be included in a block with the * specified height and time. Consensus critical. */ -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags); +bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime, int flags,uint32_t prevblocktime); /** * Check if transaction will be final in the next block to be created. diff --git a/src/miner.cpp b/src/miner.cpp index ff6f0bcf1..91318d641 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,7 +202,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS)) + if (tx.IsCoinBase() || !IsFinalTx(&expired,tx, nHeight, nLockTimeCutoff,STANDARD_LOCKTIME_VERIFY_FLAGS,chainActive.Tip()->nTime)) { if ( expired != 0 ) { From f21afd942018132a59df0745717e33d6d5a1b1ab Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:11:26 +0200 Subject: [PATCH 29/51] 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 a80e0b1ed..213b9adde 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -610,7 +610,7 @@ uint32_t komodo_heightstamp(int32_t height) { CBlockIndex *ptr; if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) - reeturn(ptr->nTime); + return(ptr->nTime); else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); return(0); } From c1004caa427af7934d6fd9f012b2bbd3258a5a84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:21:23 +0200 Subject: [PATCH 30/51] Test --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5965813c..888a502a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -712,9 +712,11 @@ uint32_t komodo_heightstamp(int32_t height); int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg,uint32_t prevblocktime) { - int32_t i; uint32_t cmptime; uint64_t value=0; CBlockIndex *tip=0; + int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { + if ( txheightarg == 0 ) + locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); From ccd177d94f40deb2557d14d0d45dcf4bc3ddaae5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:23:12 +0200 Subject: [PATCH 31/51] Test --- src/main.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 888a502a1..2d36ef88b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -710,7 +710,7 @@ bool IsStandardTx(const CTransaction& tx, string& reason) uint32_t komodo_heightstamp(int32_t height); -int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheightarg,uint32_t prevblocktime) +int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime) { int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) @@ -765,30 +765,30 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 }*/ if ( (cmptime= prevblocktime) == 0 ) { - if ( (cmptime= komodo_heightstamp(txheightarg-1)) == 0 ) + if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 ) { - fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheightarg-1,cmptime); + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime); return(-1); } } //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) // cmptime = prev->nTime + 600; - if ( cmptime > 0 && txheightarg > 246748 ) + if ( cmptime > 0 && txheight > 246748 ) { - if ( txheightarg < 247205 ) + if ( txheight < 247205 ) cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u:%u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheightarg,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheighta,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); } return(0); } From 2af7fbc524fbf6b23f138ed2f4300f42c7b80d8a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:24:55 +0200 Subject: [PATCH 32/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2d36ef88b..299f547b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -715,7 +715,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - if ( txheightarg == 0 ) + if ( txheight == 0 ) locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; From 03be8eb889ed9a72ced9c2b6de6fad1b6ca0b724 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:26:05 +0200 Subject: [PATCH 33/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 299f547b5..92aa8f526 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -788,7 +788,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheighta,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); } return(0); } From 3345b002032f6b345a7e5d197ed898285df9f8f8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:30:22 +0200 Subject: [PATCH 34/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 92aa8f526..b50bb8da1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -776,7 +776,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( cmptime > 0 && txheight > 246748 ) { if ( txheight < 247205 ) - cmptime -= 600; + cmptime -= 16000; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) From 044a7b96ebe6afae2236186e27ff02786e5fce65 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:42:27 +0200 Subject: [PATCH 35/51] Test --- src/main.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b50bb8da1..36dd3a02e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -715,8 +715,25 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { - if ( txheight == 0 ) - locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); + //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); + LOCK(cs_main); + CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + if ( GetTransaction(hash,tx,hashBlock,true) ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) + { + txheight = pindex->nHeight; + if ( (previndex= mapBlockIndex[pindex->hashPrevBlock]) != 0 ) + prevblocktime = previndex->nTime; + } + } + if ( prevblocktime != 0 ) + cmptime = prevblocktime + 600; + else + { + fprintf(stderr,"couldnt get cmptime for [%d] t%u\n",txheight,prevblocktime); + return(-1); + } /* uint32_t prevblocktime=0,cmptime=0,txheighttime=0,tiptime=0,locktime=0; prevblocktime = 0; locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); @@ -762,7 +779,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 return(-1); } else fprintf(stderr,"validateinterest grandfather.%d locktime %u vs txheighttime.%u tiptime.%u txb.%u cmp.%u\n",(int32_t)txheight,tx.nLockTime,txheighttime,tiptime,txblocktime,cmptime); } - }*/ + } if ( (cmptime= prevblocktime) == 0 ) { if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 ) @@ -770,25 +787,23 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime); return(-1); } - } - //if ( (prev= komodo_chainactive(txheightarg-1)) != 0 ) - // cmptime = prev->nTime + 600; + }*/ if ( cmptime > 0 && txheight > 246748 ) { if ( txheight < 247205 ) - cmptime -= 16000; + cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u:%u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,locktime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } if ( expiredp != 0 ) *expiredp = cmptime-3600; return(-1); } } - fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u:%u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,locktime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] tip.%d locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)(tip != 0 ? tip->nHeight : 0),(int32_t)tx.nLockTime,cmptime); } return(0); } From 4ba649d62dac475d1df2a0dcf88e0c8dd21bb724 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:44:30 +0200 Subject: [PATCH 36/51] test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 36dd3a02e..c92b3bfaf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -723,7 +723,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { txheight = pindex->nHeight; - if ( (previndex= mapBlockIndex[pindex->hashPrevBlock]) != 0 ) + if ( (previndex= pindex->pprev) != 0 ) prevblocktime = previndex->nTime; } } From f25914ebf547ad01682f477b22753f0783204536 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:45:32 +0200 Subject: [PATCH 37/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index c92b3bfaf..68b4728c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -718,7 +718,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*previndex; - if ( GetTransaction(hash,tx,hashBlock,true) ) + if ( GetTransaction(tx.GetHash(),tx,hashBlock,true) ) { if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { From 01efddaecf0f16fd7f72d93f82daa3599d200eb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:52:45 +0200 Subject: [PATCH 38/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 68b4728c7..f2f077b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -717,7 +717,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); - CTransaction tx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + uint256 hashBlock; CBlockIndex *pindex,*previndex; if ( GetTransaction(tx.GetHash(),tx,hashBlock,true) ) { if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) From e8950acaa745149c53b2466a17f0a08f068b517a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:54:30 +0200 Subject: [PATCH 39/51] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f2f077b68..375096199 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -717,8 +717,8 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 { //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); - uint256 hashBlock; CBlockIndex *pindex,*previndex; - if ( GetTransaction(tx.GetHash(),tx,hashBlock,true) ) + CTransaction gettx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + if ( GetTransaction(tx.GetHash(),gettx,hashBlock,true) ) { if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) { From aa8eaec46fe45170702176595ea7b507919af567 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:05:51 +0200 Subject: [PATCH 40/51] Test --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 375096199..ac0d8501d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -817,7 +817,7 @@ bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int6 return true; if ( ASSETCHAINS_SYMBOL[0] == 0 && flags == STANDARD_LOCKTIME_VERIFY_FLAGS && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//&& nBlockTime >= 1473793441 ) //&& (int64_t)tx.nLockTime < nBlockTime-3600 { - if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 + if ( komodo_validate_interest(expiredp,tx,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime) < 0 ) //if ( nBlockTime >= 1490159171 ) // 246748 { fprintf(stderr,"[%d] IsFinalTx reject.%d locktime %u vs nBlockTime %u\n",(int32_t)(tx.nLockTime-nBlockTime),(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); return(false); // need to prevent pastdating tx @@ -3335,9 +3335,9 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,0,chainActive.Tip()->nTime) < 0 ) + if ( komodo_validate_interest(0,tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->nTime) < 0 ) { - //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size()); + fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From d8be8b2ef749d74a2dc9381c91509f0775a50a7a Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:22:43 +0200 Subject: [PATCH 41/51] Test --- src/init.cpp | 20 -------------------- src/komodo_gateway.h | 4 ++-- src/main.cpp | 24 ++++++++++-------------- src/pow.cpp | 6 +++--- src/wallet/wallet.cpp | 2 +- 5 files changed, 16 insertions(+), 40 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 0f89ae6ed..0f03aac21 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,26 +1246,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n", MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } - uint256 hash(uint256S("0000005213c9cea80d42aae6e917487485d0b197a83ffbc0bcd0aef6e38c6ded")); - uint256 hash2(uint256S("05a8cd56e2118713ed5931300868fbcd96f573c5051b3568f053658b2a5a1115")); - CValidationState state; - if ( 0 ) - { - LOCK(cs_main); - if ( mapBlockIndex.count(hash) != 0 ) - { - CBlockIndex* pblockindex; - if ( (pblockindex= mapBlockIndex[hash]) != 0 ) - InvalidateBlock(state, pblockindex); - } - if ( mapBlockIndex.count(hash2) != 0 ) - { - CBlockIndex* pblockindex; - if ( (pblockindex= mapBlockIndex[hash2]) != 0 ) - InvalidateBlock(state, pblockindex); - } - } - if ( KOMODO_REWIND >= 0 ) { if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 2b1b8ef57..6bf946d6e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -720,13 +720,13 @@ int32_t komodo_check_deposit(int32_t height,const CBlock& block) // verify above offset += komodo_scriptitemlen(&opretlen,&script[offset]); if ( ASSETCHAINS_SYMBOL[0] == 0 ) { - extern int32_t KOMODO_REWIND; + /*extern int32_t KOMODO_REWIND; if ( KOMODO_REWIND < 0 ) { fprintf(stderr,">>>>>>> rewind.%d will pause here for a minute. issue command and stop\n",KOMODO_REWIND); sleep(60); KOMODO_REWIND = 0; - } + }*/ // 6a35506c65617365206d616b6520796f75722047697420636f6d6d6974206d65737361676573206d6f726520696e74657265737469 height.241778 checkdeposit n.4 [6a] [P] 80 vs 88 //for (i=0; inHeight >= KOMODO_REWIND ) + if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight >= KOMODO_REWIND ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) { - if ( !DisconnectTip(state) ) + InvalidateBlock(state,chainActive.Tip()); + /*if ( !DisconnectTip(state) ) { - //InvalidateBlock(state,chainActive.Tip()); + InvalidateBlock(state,chainActive.Tip()); return false; - } + }*/ } - fprintf(stderr,"end rewind ht.%d\n",chainActive.Tip()->nHeight); - if ( chainActive.Tip()->nHeight == KOMODO_REWIND ) - { - fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); - sleep(3); - return(true); - } - pindexOldTip = chainActive.Tip(); - pindexFork = chainActive.FindFork(pindexMostWork); - }*/ + fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); + sleep(60); + KOMODO_REWIND = 0; + return(true); + } // Build list of new blocks to connect. std::vector vpindexToConnect; bool fContinue = true; diff --git a/src/pow.cpp b/src/pow.cpp index ce959254c..c6cfe9fab 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -119,7 +119,7 @@ extern std::string NOTARY_PUBKEY; bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned int nBits, const Consensus::Params& params) { - //extern int32_t KOMODO_REWIND; + extern int32_t KOMODO_REWIND; bool fNegative,fOverflow; int32_t i,nonzpkeys=0,nonz=0,special=0,special2=0,notaryid=-1,duplicate,flag = 0, mids[66]; arith_uint256 bnTarget; CBlockIndex *pindex; uint8_t pubkeys[66][33]; @@ -156,7 +156,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in if ( UintToArith256(hash) > bnTarget ) { if ( (height < 235300 || height >= 236000) && KOMODO_LOADINGBLOCKS == 0 && height > 188000 ) - //&& KOMODO_REWIND == 0 )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0 + //&& )//186269, 182507&& komodo_chainactive(height) != 0 && nonzpkeys > 0 { int32_t i; for (i=31; i>=0; i--) @@ -171,7 +171,7 @@ bool CheckProofOfWork(int32_t height,uint8_t *pubkey33,uint256 hash, unsigned in for (i=0; i<66; i++) printf("%d ",mids[i]); printf(" minerids from ht.%d\n",height); - if ( notaryid >= 0 || height > 225000 ) + if ( KOMODO_REWIND == 0 && (notaryid >= 0 || height > 225000) ) return error("CheckProofOfWork(): hash doesn't match nBits"); } } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ac7f1f9f5..030f6cc8a 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -806,7 +806,7 @@ void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) extern char ASSETCHAINS_SYMBOL[16]; fprintf(stderr,"%s nWitnessCacheSize.%d\n",ASSETCHAINS_SYMBOL,(int32_t)nWitnessCacheSize); } - //if ( KOMODO_REWIND == 0 ) + if ( KOMODO_REWIND == 0 ) assert(nWitnessCacheSize > 0); //if (fFileBacked) { // CWalletDB walletdb(strWalletFile); From 8ba454139033186ca375b1169b954432e97179a0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:26:30 +0200 Subject: [PATCH 42/51] Test --- 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 030f6cc8a..091fb5e22 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -757,7 +757,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex, void CWallet::DecrementNoteWitnesses(const CBlockIndex* pindex) { - //extern int32_t KOMODO_REWIND; + extern int32_t KOMODO_REWIND; { LOCK(cs_wallet); for (std::pair& wtxItem : mapWallet) { From a43b1a183841c16cea68cc82422ca850754e21cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:31:24 +0200 Subject: [PATCH 43/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f5a955975..08e9fdbfd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3331,7 +3331,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->nTime) < 0 ) + if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nTime:0) < 0 ) { fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime); return error("CheckBlock: komodo_validate_interest failed"); From a63e5f12561a3a40351b2c2a4e9620e2aa2690e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:32:04 +0200 Subject: [PATCH 44/51] Test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 0f03aac21..d9fb2cd04 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1461,7 +1461,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (mapArgs.count("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); - if ( KOMODO_REWIND >= 0 ) + if ( KOMODO_REWIND == 0 ) { uiInterface.InitMessage(_("Activating best chain...")); // scan for better chains in the block chain database, that are not yet connected in the active best chain From b3df07a000fb341c5803cf29857879d905575cc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:36:37 +0200 Subject: [PATCH 45/51] Test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index d9fb2cd04..cffdb7a9b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1246,7 +1246,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Prune: pruned datadir may not have more than %d blocks; -checkblocks=%d may fail\n", MIN_BLOCKS_TO_KEEP, GetArg("-checkblocks", 288)); } - if ( KOMODO_REWIND >= 0 ) + if ( KOMODO_REWIND == 0 ) { if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), GetArg("-checkblocks", 288))) { From afc067b72801fdbe22f41fc8b23880b623c24dc7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:42:17 +0200 Subject: [PATCH 46/51] Test --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 08e9fdbfd..1ffbc295b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3331,9 +3331,9 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nTime:0) < 0 ) + if ( komodo_validate_interest(0,tx,height,block.nTime) < 0 ) { - fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime); + fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,block.nTime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From 045850921ef707db62924e9f22d3ee2e9cd8972c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:51:56 +0200 Subject: [PATCH 47/51] Test --- src/main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1ffbc295b..e619f2a67 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -794,7 +794,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - if ( tx.nLockTime != 1477258935 ) + //if ( tx.nLockTime != 1477258935 ) { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } @@ -3331,9 +3331,22 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - if ( komodo_validate_interest(0,tx,height,block.nTime) < 0 ) + uint32_t prevtime = 0; CBlockIndex *ptr; + if ( height == chainActive.Tip()->nHeight+1 ) + prevtime = chainActive.Tip()->nTime; + else if ( pindex != 0 ) { - fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,block.nTime); + if ( (ptr= pindex->pprev) != 0 ) + prevtime = ptr->nTime; + } + if ( prevtime == 0 ) + { + if ( height > 0 && (ptr= chainActive[height-1]) ) + prevtime = ptr->nTime; + } + if ( komodo_validate_interest(0,tx,height,prevtime) < 0 ) + { + fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From e0446653ba231e8c122d870740cb8e4a0cb4d7d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 03:58:47 +0200 Subject: [PATCH 48/51] Test --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index cffdb7a9b..f7a58fa50 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1461,7 +1461,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (mapArgs.count("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); - if ( KOMODO_REWIND == 0 ) + if ( KOMODO_REWIND >= 0 ) { uiInterface.InitMessage(_("Activating best chain...")); // scan for better chains in the block chain database, that are not yet connected in the active best chain From 4f7a54254fe4102c57b1556169debab4e9a06069 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:12:06 +0200 Subject: [PATCH 49/51] Test --- src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e619f2a67..6e18120c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -713,7 +713,7 @@ uint32_t komodo_heightstamp(int32_t height); int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32_t txheight,uint32_t prevblocktime) { int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) { //locktime = komodo_interest_args(&prevblocktime,&txheight,&tiptime,&value,tx.GetHash(),0); LOCK(cs_main); @@ -794,7 +794,7 @@ int32_t komodo_validate_interest(uint32_t *expiredp,const CTransaction& tx,int32 cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - //if ( tx.nLockTime != 1477258935 ) + if ( tx.nLockTime != 1477258935 ) { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u tiptime.%u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,(uint32_t)(tip != 0 ? tip->nTime : 0),cmptime); } @@ -2885,7 +2885,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if (!DisconnectTip(state)) return false; } - if ( KOMODO_REWIND != 0 && chainActive.Tip()->nHeight >= KOMODO_REWIND ) + if ( KOMODO_REWIND != 0 && (KOMODO_REWIND < 0 || chainActive.Tip()->nHeight >= KOMODO_REWIND) ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) @@ -3346,7 +3346,7 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat } if ( komodo_validate_interest(0,tx,height,prevtime) < 0 ) { - fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); + //fprintf(stderr,"CheckBlock(%d:%d) %d, %u: komodo_validate_interest failure blocksize.%d tiptime.%u %u\n",height,komodo_block2height((CBlock *)&block),pindex!=0?(int32_t)pindex->nHeight:0,pindex!=0?(int32_t)pindex->nTime:0,(int32_t)block.vtx.size(),chainActive.Tip()->nTime,prevtime); return error("CheckBlock: komodo_validate_interest failed"); } if (!CheckTransaction(tx, state, verifier)) From 8abcd8195e58b453fa613634afb7ea3beb294489 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:20:04 +0200 Subject: [PATCH 50/51] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 6e18120c9..bd80a4eae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2885,7 +2885,7 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo if (!DisconnectTip(state)) return false; } - if ( KOMODO_REWIND != 0 && (KOMODO_REWIND < 0 || chainActive.Tip()->nHeight >= KOMODO_REWIND) ) + if ( KOMODO_REWIND != 0 ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) From 310bb0a1b932db69a065d16d0558991589975c50 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 04:20:21 +0200 Subject: [PATCH 51/51] Test --- src/main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bd80a4eae..261694762 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2890,12 +2890,11 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) { - InvalidateBlock(state,chainActive.Tip()); - /*if ( !DisconnectTip(state) ) + if ( !DisconnectTip(state) ) { InvalidateBlock(state,chainActive.Tip()); return false; - }*/ + } } fprintf(stderr,"reached rewind.%d, best to do: ./komodo-cli stop\n",KOMODO_REWIND); sleep(60);