From 0cb1d2da0db2f700ca78643fad8c51749a48f3d9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 02:09:32 +0200 Subject: [PATCH] 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 ) {