diff --git a/src/init.cpp b/src/init.cpp index 0f03aac21..f7a58fa50 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))) { diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 481ede104..213b9adde 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -594,6 +594,27 @@ int32_t komodo_blockload(CBlock& block,CBlockIndex *pindex) return(0); } +CBlockIndex *komodo_chainactive(int32_t height) +{ + if ( chainActive.Tip() != 0 ) + { + 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 null chainActive.Tip() height %d\n",height); + return(0); +} + +uint32_t komodo_heightstamp(int32_t height) +{ + CBlockIndex *ptr; + if ( height > 0 && (ptr= komodo_chainactive(height)) != 0 ) + return(ptr->nTime); + else fprintf(stderr,"komodo_heightstamp null ptr for block.%d\n",height); + return(0); +} + void komodo_index2pubkey33(uint8_t *pubkey33,CBlockIndex *pindex,int32_t height) { CBlock block; @@ -618,11 +639,6 @@ void komodo_connectpindex(CBlockIndex *pindex) komodo_connectblock(pindex,block); } -CBlockIndex *komodo_chainactive(int32_t height) -{ - return(chainActive[height]); -} - 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/komodo_gateway.h b/src/komodo_gateway.h index 3a09400a2..6bf946d6e 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -628,26 +628,32 @@ 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); @@ -714,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; i= LOCKTIME_THRESHOLD )//1473793441 ) + int32_t i; uint32_t cmptime=0,tiptime=0,locktime=0; uint64_t value=0; CBlockIndex *tip=0; + 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); + CTransaction gettx; uint256 hashBlock; CBlockIndex *pindex,*previndex; + if ( GetTransaction(tx.GetHash(),gettx,hashBlock,true) ) + { + if ( (pindex= mapBlockIndex[hashBlock]) != 0 ) + { + txheight = pindex->nHeight; + if ( (previndex= pindex->pprev) != 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); + if ( (txheight= txheightarg) == 0 ) + txheight = 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 ) @@ -733,6 +760,10 @@ 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 ( (prev= komodo_chainactive(txheight-1)) != 0 ) + cmptime = prev->nTime + 600; if ( cmptime >= 1490159171 - 24*3600 ) { if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) @@ -740,19 +771,44 @@ 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); } 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); + if ( (cmptime= prevblocktime) == 0 ) + { + if ( (cmptime= komodo_heightstamp(txheight-1)) == 0 ) + { + fprintf(stderr,"couldnt get prev.[%d] use tiptime.%u\n",txheight-1,cmptime); + return(-1); + } + }*/ + if ( cmptime > 0 && txheight > 246748 ) + { + 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",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 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); } -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,uint32_t prevblocktime) { int32_t i; if ( expiredp != 0 ) @@ -761,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,interesttime) < 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 @@ -914,9 +970,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"); @@ -925,13 +981,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); } } @@ -2829,27 +2885,22 @@ 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 ) { fprintf(stderr,"rewind ht.%d\n",chainActive.Tip()->nHeight); while ( chainActive.Tip()->nHeight > KOMODO_REWIND ) { 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; @@ -3279,9 +3330,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,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\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()); + 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)) diff --git a/src/main.h b/src/main.h index 1bea5030f..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,int32_t interesttime); +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 3caf774c0..91318d641 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,13 +202,13 @@ 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,chainActive.Tip()->nTime)) { 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); 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..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) { @@ -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);