diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index 2e6136357..a1865b649 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -109,6 +109,11 @@ base_uint& base_uint::operator/=(const base_uint& b) template int base_uint::CompareTo(const base_uint& b) const { + if ( (uint64_t)pn < 0x1000 || (uint64_t)b.pn <= 0x1000 ) + { + fprintf(stderr,"CompareTo null %p or %p\n",pn,b.pn); + return(0); + } for (int i = WIDTH - 1; i >= 0; i--) { if (pn[i] < b.pn[i]) return -1; 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..05893328f 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); @@ -788,3 +804,28 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) return(1); else return(0); } + +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag) +{ + uint32_t cmptime = nTime; + if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) + { + if ( txheight > 246748 ) + { + if ( txheight < 247205 ) + cmptime -= 16000; + if ( (int64_t)tx.nLockTime < cmptime-3600 ) + { + if ( tx.nLockTime != 1477258935 || dispflag != 0 ) + { + fprintf(stderr,"komodo_validate_interest.%d reject.%d [%d] locktime %u cmp2.%u\n",dispflag,txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + } + return(-1); + } + if ( 0 && dispflag != 0 ) + fprintf(stderr,"validateinterest.%d accept.%d [%d] locktime %u cmp2.%u\n",dispflag,(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + } + } + return(0); +} + diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 185145bdd..a79537ee3 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -628,26 +628,33 @@ const char *banned_txids[] = "a01671c8775328a41304e31a6693bbd35e9acbab28ab117f729eaba9cb769461", //235265 "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 + // all vouts banned + "c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748 + "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 +721,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 %.8f (%.8f %.8f %.8f)\n",CURRENCIES[baseids[i-1]],height,i,dstr(srcvalues[i-1]),dstr(values[i-1]),dstr(pax->komodoshis),dstr(pax->fiatoshis),dstr(block.vtx[0].vout[i].nValue)); } - else + else if ( strcmp(ASSETCHAINS_SYMBOL,CURRENCIES[baseids[i-1]]) == 0 ) { for (j=0; j<32; j++) printf("%02x",((uint8_t *)&txids[i-1])[j]); @@ -1283,7 +1290,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { basesp->approved += values[i]; didstats = 1; - printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); + //printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); } //printf(" i.%d (%s) <- %.8f ADDFLAG APPROVED\n",i,coinaddr,dstr(values[i])); } @@ -1293,7 +1300,7 @@ const char *komodo_opreturn(int32_t height,uint64_t value,uint8_t *opretbuf,int3 { basesp->approved += values[i]; didstats = 1; - printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); + //printf("pax.%p ########### %p approved %s += %.8f -> %.8f/%.8f kht.%d %d\n",pax,basesp,CURRENCIES[baseids[i]],dstr(values[i]),dstr(srcvalues[i]),dstr(checktoshis),kmdheights[i],otherheights[i]); } } //else printf(" i.%d of n.%d pax.%p baseids[] %d\n",i,n,pax,baseids[i]); if ( (pax= komodo_paxfind(txids[i],vouts[i],'A')) != 0 ) 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 7396530ce..1599b2fe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -325,7 +325,19 @@ void FinalizeNode(NodeId nodeid) { mapNodeState.erase(nodeid); } - + +void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) +{ +/* int expired = pool.Expire(GetTime() - age); + if (expired != 0) + LogPrint("mempool", "Expired %i transactions from the memory pool\n", expired); + + std::vector vNoSpendsRemaining; + pool.TrimToSize(limit, &vNoSpendsRemaining); + BOOST_FOREACH(const uint256& removed, vNoSpendsRemaining) + pcoinsTip->Uncache(removed);*/ +} + // Requires cs_main. // Returns a bool indicating whether we requested this block. bool MarkBlockAsReceived(const uint256& hash) { @@ -367,7 +379,8 @@ void ProcessBlockAvailability(NodeId nodeid) { if (!state->hashLastUnknownBlock.IsNull()) { BlockMap::iterator itOld = mapBlockIndex.find(state->hashLastUnknownBlock); - if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) { + if (itOld != mapBlockIndex.end() && itOld->second->nChainWork > 0) + { if (state->pindexBestKnownBlock == NULL || itOld->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = itOld->second; state->hashLastUnknownBlock.SetNull(); @@ -380,14 +393,15 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { CNodeState *state = State(nodeid); assert(state != NULL); - ProcessBlockAvailability(nodeid); + /*ProcessBlockAvailability(nodeid); BlockMap::iterator it = mapBlockIndex.find(hash); if (it != mapBlockIndex.end() && it->second->nChainWork > 0) { // An actually better block was announced. if (state->pindexBestKnownBlock == NULL || it->second->nChainWork >= state->pindexBestKnownBlock->nChainWork) state->pindexBestKnownBlock = it->second; - } else { + } else*/ + { // An unknown block was announced; just assume that the latest one is the best one. state->hashLastUnknownBlock = hash; } @@ -706,65 +720,11 @@ 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 i,txheight=0; uint32_t cmptime,txheighttime,tiptime=0,locktime; uint64_t value=0; - if ( ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD )//1473793441 ) - { - locktime = komodo_interest_args(&txheighttime,&txheight,&tiptime,&value,tx.GetHash(),0); - if ( tiptime == 0 ) - tiptime = (int32_t)chainActive.Tip()->nTime; - if ( txheighttime == 0 ) - { - static uint32_t counter0; - txheighttime = chainActive.Tip()->nTime; - if ( counter0++ < 3 ) - fprintf(stderr,"error getting txheighttime, set to tiptime.%u\n",txheighttime); - } - if ( txheighttime != 0 && txblocktime != 0 ) - { - cmptime = txheighttime; - if ( txblocktime < cmptime ) - cmptime = txblocktime; - } - else if ( (cmptime= txheighttime) == 0 ) - cmptime = txblocktime; - if ( tiptime != 0 && tiptime < cmptime ) - cmptime = tiptime; - if ( cmptime >= 1490159171 - 24*3600 ) - { - if ( cmptime != 0 && (int64_t)tx.nLockTime < cmptime-3600 ) - { - if ( txheighttime > 1490159171 || (locktime == 0 && txheighttime >= 1490159171) ) // 246748 - { - if ( tx.nLockTime != 1477258935 ) - fprintf(stderr,"komodo_validate_interest reject.%d locktime %u/%u vs nBlockTime %u txheighttime.%u tiptime.%u txb.%u cmp.%u\n",txheight,(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); - } - return(0); -} - -bool IsFinalTx(uint32_t *expiredp,const CTransaction &tx, int nBlockHeight, int64_t nBlockTime,int flags,int32_t interesttime) +bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime) { int32_t i; - if ( expiredp != 0 ) - *expiredp = 0; if (tx.nLockTime == 0) 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 - { - 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 - } else fprintf(stderr,"IsFinalTx accept.%d locktime %u vs nBlockTime %u\n",(int32_t)nBlockHeight,tx.nLockTime,(uint32_t)nBlockTime); - } if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime)) return true; BOOST_FOREACH(const CTxIn& txin, tx.vin) @@ -810,7 +770,7 @@ bool CheckFinalTx(const CTransaction &tx, int flags) ? chainActive.Tip()->GetMedianTimePast() : GetAdjustedTime(); - return IsFinalTx(0,tx, nBlockHeight, nBlockTime,flags,chainActive.Tip()->nTime); + return IsFinalTx(tx, nBlockHeight, nBlockTime); } /** @@ -912,24 +872,19 @@ 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))); - /*if ( komodo_validate_interest(tx) < 0 ) - { - fprintf(stderr,"CheckTransaction komodo_validate_interest error\n"); - return(false); - }*/ + numbanned = komodo_bannedset(&indallvouts,array,(int32_t)(sizeof(array)/sizeof(*array))); 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); } } @@ -1156,11 +1111,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - /*if ( komodo_validate_interest(tx) < 0 ) // called from CheckFinalTx() below + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) { - fprintf(stderr,"komodo_validate_interest failure\n"); + fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); - }*/ + } if (!CheckTransaction(tx, state, verifier)) { fprintf(stderr,"accept failure.0\n"); @@ -1184,7 +1139,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa // be mined yet. if (!CheckFinalTx(tx, STANDARD_LOCKTIME_VERIFY_FLAGS)) { - fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); + //fprintf(stderr,"AcceptToMemoryPool reject non-final\n"); return state.DoS(0, false, REJECT_NONSTANDARD, "non-final"); } // is it already in the memory pool? @@ -2338,7 +2293,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin for (unsigned int i = 0; i < block.vtx.size(); i++) { const CTransaction &tx = block.vtx[i]; - nInputs += tx.vin.size(); nSigOps += GetLegacySigOpCount(tx); if (nSigOps > MAX_BLOCK_SIGOPS) @@ -2827,27 +2781,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 ) + fprintf(stderr,"rewind start ht.%d\n",chainActive.Tip()->nHeight); + while ( KOMODO_REWIND > 0 && chainActive.Tip()->nHeight > KOMODO_REWIND ) { if ( !DisconnectTip(state) ) { - //InvalidateBlock(state,chainActive.Tip()); - return false; + InvalidateBlock(state,chainActive.Tip()); + break; } } - 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; @@ -2976,11 +2925,12 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { return false; } } + //LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); // The resulting new best tip may not be in setBlockIndexCandidates anymore, so // add it again. BlockMap::iterator it = mapBlockIndex.begin(); - while (it != mapBlockIndex.end()) { + while (it != mapBlockIndex.end() && it->second != 0 ) { if (it->second->IsValid(BLOCK_VALID_TRANSACTIONS) && it->second->nChainTx && !setBlockIndexCandidates.value_comp()(it->second, chainActive.Tip())) { setBlockIndexCandidates.insert(it->second); } @@ -3277,11 +3227,8 @@ 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 ) - { - //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"); - } + if ( komodo_validate_interest(tx,komodo_block2height((CBlock *)&block),block.nTime,1) < 0 ) + return error("CheckBlock: komodo_validate_interest failed"); if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock(): CheckTransaction failed"); } @@ -3361,7 +3308,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(tx, nHeight, nLockTimeCutoff)) { 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..3ba8ce7f2 100644 --- a/src/main.h +++ b/src/main.h @@ -46,6 +46,7 @@ class CValidationInterface; class CValidationState; struct CNodeStateStats; +#define DEFAULT_MEMPOOL_EXPIRY 1 /** Default for -blockmaxsize and -blockminsize, which control the range of sizes the mining code will create **/ static const unsigned int DEFAULT_BLOCK_MAX_SIZE = MAX_BLOCK_SIZE; @@ -351,7 +352,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(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime); /** * Check if transaction will be final in the next block to be created. diff --git a/src/miner.cpp b/src/miner.cpp index 91318d641..82d177cda 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -114,6 +114,7 @@ int32_t komodo_baseid(char *origbase); int32_t komodo_is_issuer(); int32_t komodo_gateway_deposits(CMutableTransaction *txNew,char *symbol,int32_t tokomodo); int32_t komodo_isrealtime(int32_t *kmdheightp); +int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -202,16 +203,13 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) ? nMedianTimePast : pblock->GetBlockTime(); - 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); - } + if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - } //else fprintf(stderr,"coinbase or is finaltx (%d %u)\n",(int32_t)nHeight,(uint32_t)tx.nLockTime); + if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) + { + fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); + continue; + } COrphan* porphan = NULL; double dPriority = 0; CAmount nTotalIn = 0; @@ -427,7 +425,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) // Fill in header pblock->hashPrevBlock = pindexPrev->GetBlockHash(); pblock->hashReserved = uint256(); - UpdateTime(pblock, Params().GetConsensus(), pindexPrev); + //UpdateTime(pblock, Params().GetConsensus(), pindexPrev); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); @@ -438,8 +436,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) static uint32_t counter; if ( counter++ < 100 ) fprintf(stderr,"warning: testblockvalidity failed\n"); - //return(0); - throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); + return(0); } } @@ -885,12 +882,18 @@ void static BitcoinMiner(CWallet *pwallet) // Update nNonce and nTime pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); pblock->nBits = savebits; - UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); + //UpdateTime(pblock, chainparams.GetConsensus(), pindexPrev); if (chainparams.GetConsensus().fPowAllowMinDifficultyBlocks) { // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } + /*CValidationState tmpstate; + if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) + { + fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); + break; + }*/ } } } 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);