From 14aa6cc0e2269f0ff91d61af84fb7c4e537348ac Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:28:13 +0200 Subject: [PATCH 01/12] Initial --- src/komodo_bitcoind.h | 24 ++++++ src/komodo_gateway.h | 1 + src/main.cpp | 193 +++++------------------------------------- src/main.h | 3 +- src/miner.cpp | 24 +++--- 5 files changed, 61 insertions(+), 184 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 30a1a30fd..81e9c3918 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -804,3 +804,27 @@ 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) +{ + 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 -= 600; + if ( (int64_t)tx.nLockTime < cmptime-3600 ) + { + if ( tx.nLockTime != 1477258935 ) + { + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + } + return(-1); + } + } + fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(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 ef1937d0c..d19a3d6f6 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -629,6 +629,7 @@ const char *banned_txids[] = "2ef49d2d27946ad7c5d5e4ab5c089696762ff04e855f8ab48e83bdf0cc68726d", //235295 "c85dcffb16d5a45bd239021ad33443414d60224760f11d535ae2063e5709efee", //235296 // all vouts banned + "c4ea1462c207547cd6fb6a4155ca6d042b22170d29801a465db5c09fec55b19d", //246748 "305dc96d8bc23a69d3db955e03a6a87c1832673470c32fe25473a46cc473c7d1", //247204 }; diff --git a/src/main.cpp b/src/main.cpp index 7eabc07ff..a06d6ba92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -325,7 +325,18 @@ 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) { @@ -708,132 +719,11 @@ 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 txheight,uint32_t prevblocktime,int32_t strictflag) -{ - 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; - prevblocktime = pindex->nTime; - if ( (previndex= pindex->pprev) != 0 ) - prevblocktime = previndex->nTime; - } - } - if ( prevblocktime == 0 ) - { - if ( chainActive.Tip() != 0 ) - { - if ( strictflag == 0 || txheight == 0 || txheight == chainActive.Tip()->nHeight+1 ) - prevblocktime = chainActive.Tip()->nTime; - else - { - fprintf(stderr,"couldnt get prevblocktime for [%d] tiptime.%u\n",txheight,chainActive.Tip()->nTime); - return(-1); - } - } - } - if ( prevblocktime == 0 ) - return(-1); - cmptime = prevblocktime + 600; - /* 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 ) - { - 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 ( 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 ) - { - 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); - } - } - 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); - } - } - if ( strictflag != 0 ) - fprintf(stderr,"validateinterest strict.%d accept.%d [%d] tip.%d locktime %u cmp.%u\n",strictflag,(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,uint32_t prevblocktime) +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,nBlockHeight,prevblocktime < nBlockTime ? nBlockTime : prevblocktime,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 - } //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) @@ -879,7 +769,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); } /** @@ -984,11 +874,6 @@ bool CheckTransaction(const CTransaction& tx, CValidationState &state,libzcash:: static uint256 array[64]; static int32_t numbanned,indallvouts; int32_t j,k,n; if ( *(int32_t *)&array[0] == 0 ) 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"); - return(false); - }*/ n = tx.vin.size(); for (j=0; jnHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 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"); @@ -2407,27 +2292,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]; - uint32_t prevtime = 0; CBlockIndex *ptr; - if ( (ptr= pindex->pprev) != 0 ) - prevtime = ptr->nTime; - /*if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) - prevtime = chainActive.Tip()->nTime; - else if ( pindex != 0 ) - { - if ( (ptr= pindex->pprev) != 0 ) - prevtime = ptr->nTime; - } - if ( prevtime == 0 ) - { - if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) - prevtime = ptr->nTime; - }*/ - if ( komodo_validate_interest(0,tx,pindex->nHeight,prevtime,2) < 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 state.DoS(10, error("ConnectBlock(): validate interest failed"),REJECT_INVALID, "bad-apr-calc"); - } - nInputs += tx.vin.size(); nSigOps += GetLegacySigOpCount(tx); if (nSigOps > MAX_BLOCK_SIGOPS) @@ -3060,6 +2924,7 @@ 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. @@ -3361,24 +3226,8 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat // Check transactions BOOST_FOREACH(const CTransaction& tx, block.vtx) { - uint32_t prevtime = 0; CBlockIndex *ptr; - if ( chainActive.Tip() != 0 && height == chainActive.Tip()->nHeight+1 ) - prevtime = chainActive.Tip()->nTime; - else if ( pindex != 0 ) - { - if ( (ptr= pindex->pprev) != 0 ) - prevtime = ptr->nTime; - } - if ( prevtime == 0 ) - { - if ( height > 0 && (ptr= chainActive[height-1]) != 0 ) - prevtime = ptr->nTime; - } - if ( komodo_validate_interest(0,tx,height,prevtime,0) < 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 ( komodo_validate_interest(tx,komodo_block2height((CBlock *)&block),block.nTime) < 0 ) + return error("CheckBlock: komodo_validate_interest failed"); if (!CheckTransaction(tx, state, verifier)) return error("CheckBlock(): CheckTransaction failed"); } @@ -3458,7 +3307,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 71ec17ef1..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,uint32_t prevblocktime); +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 c0ab729d4..c0db1132a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -202,16 +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)) - { - 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 ( 0 && komodo_validate_interest(tx,pblock->nHeight,(uint32_t)pblock->nTime) < 0 ) + { + fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); + continue; + } COrphan* porphan = NULL; double dPriority = 0; CAmount nTotalIn = 0; @@ -438,8 +435,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); } } @@ -891,6 +887,12 @@ void static BitcoinMiner(CWallet *pwallet) // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } + CValidationState state; + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + { + fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); + break; + } } } } From 1691b50b8dfb8ca6dfa28b051e28d3a586c42217 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:35:34 +0200 Subject: [PATCH 02/12] Test --- src/main.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a06d6ba92..9b4e5633a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -326,15 +326,16 @@ void FinalizeNode(NodeId nodeid) { mapNodeState.erase(nodeid); } -void LimitMempoolSize(CTxMemPool& pool, size_t limit, unsigned long age) { - int expired = pool.Expire(GetTime() - age); +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); + pcoinsTip->Uncache(removed);*/ } // Requires cs_main. From ea5f02cb0a595303c9ff6e6d2b0ba0ee06bcf215 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:49:11 +0200 Subject: [PATCH 03/12] Test --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9b4e5633a..2b6ccae3a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2925,7 +2925,7 @@ bool InvalidateBlock(CValidationState& state, CBlockIndex *pindex) { return false; } } - LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60); + //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. From da3dcb034b5836efd8af39f4cfec9f2250c1c5ee Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:52:56 +0200 Subject: [PATCH 04/12] Test --- src/miner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c0db1132a..3ce396485 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -429,8 +429,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + CValidationState tmpstate; + if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) { static uint32_t counter; if ( counter++ < 100 ) From e70bdd48c5ad76fc8494b35be84d1525222fa41b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 22:53:41 +0200 Subject: [PATCH 05/12] Test --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3ce396485..fa553eea8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -204,7 +204,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - if ( 0 && komodo_validate_interest(tx,pblock->nHeight,(uint32_t)pblock->nTime) < 0 ) + if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; From c583e2a9ea145adfb74c00fe531ef4e41b354a96 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:02:13 +0200 Subject: [PATCH 06/12] Test --- src/miner.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index fa553eea8..77771965e 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); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -429,8 +430,8 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) pblock->nSolution.clear(); pblocktemplate->vTxSigOps[0] = GetLegacySigOpCount(pblock->vtx[0]); - CValidationState tmpstate; - if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) + CValidationState state; + if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) { static uint32_t counter; if ( counter++ < 100 ) @@ -887,8 +888,8 @@ void static BitcoinMiner(CWallet *pwallet) // Changing pblock->nTime can change work required on testnet: hashTarget.SetCompact(pblock->nBits); } - CValidationState state; - if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) + CValidationState tmpstate; + if ( !TestBlockValidity(tmpstate, *pblock, pindexPrev, false, false)) { fprintf(stderr,"formerly valid mining block became invalid, likely due to tx expiration\n"); break; From f42de68876d60427e015bead745676367b168863 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:07:39 +0200 Subject: [PATCH 07/12] 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 81e9c3918..a48908371 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -822,8 +822,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ } return(-1); } + fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } - fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); } return(0); } From d01c0463e79935a7de40c3b839858f98bb4b5d84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:27:24 +0200 Subject: [PATCH 08/12] Test --- src/komodo_bitcoind.h | 4 ++-- src/komodo_gateway.h | 4 ++-- src/main.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index a48908371..6d4278259 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -818,11 +818,11 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( tx.nLockTime != 1477258935 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp2.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); } return(-1); } - fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp2.%u\n",(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 d19a3d6f6..d3435d2e2 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1290,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])); } @@ -1300,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/main.cpp b/src/main.cpp index 2b6ccae3a..e35ef94e7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,7 +1111,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - if ( 0 && komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); From 3bc88f14513b15b49ac027e6cc110d847c1320af Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:46:52 +0200 Subject: [PATCH 09/12] Test --- src/komodo_bitcoind.h | 5 +++-- src/main.cpp | 4 ++-- src/miner.cpp | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 6d4278259..f80c0f47d 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -805,7 +805,7 @@ int32_t komodo_isrealtime(int32_t *kmdheightp) else return(0); } -int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime) +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 ) @@ -822,7 +822,8 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ } return(-1); } - fprintf(stderr,"validateinterest accept.%d [%d] locktime %u cmp2.%u\n",(int32_t)txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(int32_t)tx.nLockTime,cmptime); + if ( 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/main.cpp b/src/main.cpp index e35ef94e7..2e0ea8fff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,7 +1111,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777) < 0 ) + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,3) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -3227,7 +3227,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(tx,komodo_block2height((CBlock *)&block),block.nTime) < 0 ) + 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"); diff --git a/src/miner.cpp b/src/miner.cpp index 77771965e..233b972fe 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -114,7 +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 komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_t nTime,int32_t dispflag); CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) { @@ -205,7 +205,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime) < 0 ) + if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; From bbaa0f9df448b312bd91c2d636f58b0c1d0f455f Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 24 Mar 2017 23:51:12 +0200 Subject: [PATCH 10/12] Test --- src/komodo_bitcoind.h | 4 ++-- src/miner.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index f80c0f47d..56ebad946 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -810,13 +810,13 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748 ) + if ( txheight > 246748-24*3600*3600 ) { if ( txheight < 247205 ) cmptime -= 600; if ( (int64_t)tx.nLockTime < cmptime-3600 ) { - if ( tx.nLockTime != 1477258935 ) + if ( tx.nLockTime != 1477258935 || dispflag != 0 ) { fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp2.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); } diff --git a/src/miner.cpp b/src/miner.cpp index 233b972fe..3c9e79372 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -205,7 +205,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff)) continue; - if ( 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) + if ( komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,2) < 0 ) { fprintf(stderr,"CreateNewBlock: komodo_validate_interest failure\n"); continue; From 9f129494002fa31d43934cf6237264c4eaeffc38 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 00:06:04 +0200 Subject: [PATCH 11/12] Test --- src/komodo_bitcoind.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 56ebad946..583993481 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -810,7 +810,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748-24*3600*3600 ) + if ( txheight > 246748-1000 ) { if ( txheight < 247205 ) cmptime -= 600; @@ -818,7 +818,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ { if ( tx.nLockTime != 1477258935 || dispflag != 0 ) { - fprintf(stderr,"komodo_validate_interest reject.%d [%d] locktime %u cmp2.%u\n",txheight,(int32_t)(tx.nLockTime - (cmptime-3600)),(uint32_t)tx.nLockTime,cmptime); + 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); } From 3d02f57b4235eac7b9dd1e6bf38bcf84504626b5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 25 Mar 2017 01:10:50 +0200 Subject: [PATCH 12/12] Test --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 583993481..fd307a805 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -810,7 +810,7 @@ int32_t komodo_validate_interest(const CTransaction &tx,int32_t txheight,uint32_ uint32_t cmptime = nTime; if ( KOMODO_REWIND == 0 && ASSETCHAINS_SYMBOL[0] == 0 && (int64_t)tx.nLockTime >= LOCKTIME_THRESHOLD ) //1473793441 ) { - if ( txheight > 246748-1000 ) + if ( txheight > 246748 ) { if ( txheight < 247205 ) cmptime -= 600; diff --git a/src/main.cpp b/src/main.cpp index 2e0ea8fff..1599b2fe1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1111,7 +1111,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa if (pfMissingInputs) *pfMissingInputs = false; auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,3) < 0 ) + if ( komodo_validate_interest(tx,chainActive.Tip()->nHeight+1,chainActive.Tip()->GetMedianTimePast() + 777,0) < 0 ) { fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed");