From 48aa70ceccfd0ae9cef8ded086fdda84ea5c2ee7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 17:16:52 +0800 Subject: [PATCH 01/17] maybe this will works --- src/cc/dice.cpp | 46 +++++++++++++++++++++------------------------- src/cc/eval.cpp | 7 +++---- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 86483d008..b1e369344 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -445,7 +445,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; - CBlockIndex block; int skipped = 0; + CBlockIndex block; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -553,8 +553,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { char str[65],str2[65],str3[65]; fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); - skipped = 1; + return eval->Invalid("always should find looking vin.0, but didnt for wlt"); } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -578,30 +577,27 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - if ( skipped == 0) + //vout.0: funding CC change to entropy owner + //vout.2: normal output to bettor's address + //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + odds = vinTx.vout[2].nValue - txfee; + if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); + else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) + return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); + else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) + return eval->Invalid("vout[2] payut mismatch for win/timeout"); + else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) { - //vout.0: funding CC change to entropy owner - //vout.2: normal output to bettor's address - //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - odds = vinTx.vout[2].nValue - txfee; - if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) - return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); - else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) - return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); - else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) - return eval->Invalid("vout[2] payut mismatch for win/timeout"); - else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) - { - fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); - return eval->Invalid("CC funds mismatch for win/timeout"); - } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } - iswin = (funcid == 'W'); + fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); + return eval->Invalid("CC funds mismatch for win/timeout"); } + else if ( tx.vout[3].scriptPubKey != fundingPubKey ) + { + if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) + return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); + } + iswin = (funcid == 'W'); } if ( iswin != 0 ) { diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 113c4a6e8..9ae6d4626 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -98,10 +98,9 @@ bool Eval::GetSpendsConfirmed(uint256 hash, std::vector &spends) c bool Eval::GetTxUnconfirmed(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) const { - // there is a LOCK(cs_main) in the normal GetTransaction(), which leads to deadlocks - //bool fAllowSlow = false; // Don't allow slow - //return GetTransaction(hash, txOut, hashBlock, fAllowSlow); - return myGetTransaction(hash, txOut,hashBlock); + if (!myGetTransaction(hash, txOut,hashBlock)) { + return(GetTransaction(hash, txOut,hashBlock)); + } else return(true); } From 20441562c3a70f0989832c8eadeda155908f4dc3 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 17:05:31 +0800 Subject: [PATCH 02/17] fix --- src/cc/dice.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a7c412e1c..c5bebeba0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,17 +551,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); -<<<<<<< HEAD - else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - char str[65],str2[65],str3[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - return eval->Invalid("always should find looking vin.0, but didnt for wlt"); - } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); -======= else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) - return eval->Invalid("always should find looking vin.0, but didnt for wlt"); ->>>>>>> 19d614c8344b70a0d4a7da8620a2dd1168016abc + return eval->Invalid("always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) @@ -597,21 +588,12 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); return eval->Invalid("CC funds mismatch for win/timeout"); -<<<<<<< HEAD } else if ( tx.vout[3].scriptPubKey != fundingPubKey ) { if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); } -======= - } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } ->>>>>>> 19d614c8344b70a0d4a7da8620a2dd1168016abc iswin = (funcid == 'W'); } if ( iswin != 0 ) From ada693f7d3912f8bc50bb7682530ae658e88a346 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 19:09:26 +0800 Subject: [PATCH 03/17] add prints back --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 938cfdfe0..957060373 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - //fprintf(stderr, "added mempool tx to temp mempool\n"); + fprintf(stderr, "added mempool tx to temp mempool\n"); } // clear the mempool before importing all block txs to mempool. mempool.clear(); @@ -4320,7 +4320,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C CValidationState state; bool fMissingInputs,fOverrideFees = false; if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; - //else fprintf(stderr, "added mempool tx back to mempool\n"); + else fprintf(stderr, "added mempool tx back to mempool\n"); } if ( 0 && invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); From bc2c46ebd74f5988ba8740db23cc27f1fc09ebe9 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 21:23:15 +0800 Subject: [PATCH 04/17] true != false :) --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 957060373..5817525d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if (fNullifiers == false) + if ( fNullifiers == true ) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { From 39837a7c8c73689b8cf8e7d1a1f106672cb9a29a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 21:36:37 +0800 Subject: [PATCH 05/17] false is the default --- src/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5817525d2..57f4a3ebc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if ( fNullifiers == true ) + if ( fNullifiers == false ) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { @@ -1454,7 +1454,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } // are the joinsplit's requirements met? - if ( fNullifiers == true ) + if ( fNullifiers == false ) { if (!view.HaveJoinSplitRequirements(tx)) { From 0e9c871b74b1864f95a5f5de1b1ee17ac72f6cf1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 21:59:05 +0800 Subject: [PATCH 06/17] mmm --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 57f4a3ebc..1c9a860f1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1404,7 +1404,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } } - } + } else fprintf(stderr, "bool = true"); } { @@ -4318,6 +4318,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); CValidationState state; bool fMissingInputs,fOverrideFees = false; + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); From 993ada0a73574268826ab54ab55b7e4a8abd8d14 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:29:36 +0800 Subject: [PATCH 07/17] try to get vjoinsplit size --- src/main.cpp | 41 +++++++++++++++++++---------------------- src/main.h | 2 +- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1c9a860f1..a5e02cb30 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1310,7 +1310,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF } -bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, bool fNullifiers) +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee) { AssertLockHeld(cs_main); if (pfMissingInputs) @@ -1391,20 +1391,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if ( fNullifiers == false ) + BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { - BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) + BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) + if (pool.mapNullifiers.count(nf)) { - if (pool.mapNullifiers.count(nf)) - { - fprintf(stderr,"pool.mapNullifiers.count\n"); - return false; - } + fprintf(stderr,"pool.mapNullifiers.count\n"); + return false; } } - } else fprintf(stderr, "bool = true"); + } } { @@ -1454,13 +1451,11 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } // are the joinsplit's requirements met? - if ( fNullifiers == false ) + if (!view.HaveJoinSplitRequirements(tx)) { - if (!view.HaveJoinSplitRequirements(tx)) - { - //fprintf(stderr,"accept failure.2\n"); - return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); - } + //fprintf(stderr,"accept failure.2\n"); + return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); + } } // Bring the best block into scope view.GetBestBlock(); @@ -4258,11 +4253,13 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - fprintf(stderr, "added mempool tx to temp mempool\n"); + int vjoinsplit_size = tx.vjoinsplit.size(); + + //tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); + fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); } // clear the mempool before importing all block txs to mempool. - mempool.clear(); + //mempool.clear(); // add all the txs in the block to the empty mempool. while ( 1 ) { @@ -4312,14 +4309,14 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + /*if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); CValidationState state; bool fMissingInputs,fOverrideFees = false; - if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees) == false ) invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); } @@ -4327,7 +4324,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); - } + } */ return true; } diff --git a/src/main.h b/src/main.h index 244817a61..76e0f73ae 100644 --- a/src/main.h +++ b/src/main.h @@ -267,7 +267,7 @@ void PruneAndFlush(); /** (try to) add transaction to memory pool **/ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree, - bool* pfMissingInputs, bool fRejectAbsurdFee=false, bool fNullifiers=false); + bool* pfMissingInputs, bool fRejectAbsurdFee=false); struct CNodeStateStats { From 536ba8f5dc9da035c3bffc92051d3d8b9e1018cc Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:32:45 +0800 Subject: [PATCH 08/17] } --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a5e02cb30..7597eee95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1456,7 +1456,6 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //fprintf(stderr,"accept failure.2\n"); return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); } - } // Bring the best block into scope view.GetBestBlock(); From a8b0ae0d111b45a882b054232958f8a6a148a5c2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:44:53 +0800 Subject: [PATCH 09/17] try this to stop ztx beig removed from mempool --- src/main.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7597eee95..3c5acd464 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4249,16 +4249,20 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C //fprintf(stderr,"put block's tx into mempool\n"); // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); + BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - int vjoinsplit_size = tx.vjoinsplit.size(); - - //tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); + int vjoinsplit_size = ; + if ( tx.vjoinsplit.size() == 0 ) { + tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); + list removed; + mempool.remove(tx, removed, false); + } else { + // is a z-tx so leave it alone! + fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); + } } - // clear the mempool before importing all block txs to mempool. - //mempool.clear(); // add all the txs in the block to the empty mempool. while ( 1 ) { @@ -4308,7 +4312,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - /*if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { @@ -4319,11 +4323,11 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); } - if ( 0 && invalidtxs > 0 ) + if ( invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear(); - } */ + } return true; } From b5a999bc46ae3b7d80f37770ee6c42a51e962ce1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:46:49 +0800 Subject: [PATCH 10/17] fix --- src/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3c5acd464..271d8e2cc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4253,7 +4253,6 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - int vjoinsplit_size = ; if ( tx.vjoinsplit.size() == 0 ) { tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); list removed; From b3ab073a7a1ad1a8d9a4116ca08f9fe5147f91be Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:48:19 +0800 Subject: [PATCH 11/17] oops --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 271d8e2cc..2c28b3914 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",vjoinsplit_size); + fprintf(stderr, "tx vjoinsplit size: %d\n",tx.vjoinsplit.size()); } } // add all the txs in the block to the empty mempool. From fac4fbdee443ea6aa8c9b78fa9fa0a54fd74b68e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:49:40 +0800 Subject: [PATCH 12/17] ld --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2c28b3914..3561130bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4259,7 +4259,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",tx.vjoinsplit.size()); + fprintf(stderr, "tx vjoinsplit size: %ld\n",tx.vjoinsplit.size()); } } // add all the txs in the block to the empty mempool. From 8370c8d5bbdd6d4fda059e01e9dae185743652f0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:53:10 +0800 Subject: [PATCH 13/17] seg fault fix --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3561130bc..a28629528 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4253,13 +4253,14 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); + int txsize = tx.vjoinsplit.size(); if ( tx.vjoinsplit.size() == 0 ) { tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); list removed; mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %ld\n",tx.vjoinsplit.size()); + fprintf(stderr, "tx vjoinsplit size: %d\n",txsize; } } // add all the txs in the block to the empty mempool. From 3e3ce74e966ea15d54d7b13ee9d82051a25ed4a8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 22:54:35 +0800 Subject: [PATCH 14/17] ) --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a28629528..73cf8a7df 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4260,7 +4260,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",txsize; + fprintf(stderr, "tx vjoinsplit size: %d\n",txsize); } } // add all the txs in the block to the empty mempool. From 5d5ec3d25f0ca0cab7d7e115ac4171ebaeb3686b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 23:03:35 +0800 Subject: [PATCH 15/17] try again --- src/main.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 73cf8a7df..2b33ddef5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4249,20 +4249,23 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C //fprintf(stderr,"put block's tx into mempool\n"); // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); - + list transactionsToRemove; BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); int txsize = tx.vjoinsplit.size(); if ( tx.vjoinsplit.size() == 0 ) { + transactionsToRemove.push_back(tx); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - list removed; - mempool.remove(tx, removed, false); } else { // is a z-tx so leave it alone! fprintf(stderr, "tx vjoinsplit size: %d\n",txsize); } } + BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { + list removed; + remove(tx, removed, false); + } // add all the txs in the block to the empty mempool. while ( 1 ) { From 6c7f8711d4cf8ecac4be0faf15883ba88c089963 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 23:05:19 +0800 Subject: [PATCH 16/17] oops --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 2b33ddef5..560bd55ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4264,7 +4264,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C } BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { list removed; - remove(tx, removed, false); + mempool.remove(tx, removed, false); } // add all the txs in the block to the empty mempool. while ( 1 ) From 134db2dad7eeedc2a40e1b0ab61426b5f3629417 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Thu, 1 Nov 2018 23:17:16 +0800 Subject: [PATCH 17/17] and we are done here --- src/main.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 560bd55ef..f6c8520d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4247,19 +4247,15 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { CValidationState stateDummy; int32_t i,j,rejects=0,lastrejects=0; //fprintf(stderr,"put block's tx into mempool\n"); - // Copy the mempool to temporary mempool because there can be tx in local mempool that make the block invalid. + // Copy all non Z-txs in mempool to temporary mempool because there can be tx in local mempool that make the block invalid. LOCK(mempool.cs); list transactionsToRemove; BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx) { const CTransaction &tx = e.GetTx(); const uint256 &hash = tx.GetHash(); - int txsize = tx.vjoinsplit.size(); if ( tx.vjoinsplit.size() == 0 ) { transactionsToRemove.push_back(tx); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); - } else { - // is a z-tx so leave it alone! - fprintf(stderr, "tx vjoinsplit size: %d\n",txsize); } } BOOST_FOREACH(const CTransaction& tx, transactionsToRemove) { @@ -4315,8 +4311,10 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - if ( ASSETCHAINS_CC != 0 ) // CC contracts might refer to transactions in the current block, from a CC spend within the same block and out of order + if ( ASSETCHAINS_CC != 0 ) { + // here we add back all txs from the temp mempool to the main mempool. + // which removes any tx locally that were invalid after the block arrives. int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); @@ -4326,7 +4324,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n"); } - if ( invalidtxs > 0 ) + if ( 0 && invalidtxs > 0 ) fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. tmpmempool.clear();