From 16e69092d98ff90aa360cac66515d8cfd548c114 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:17:09 +0800 Subject: [PATCH 01/26] first try --- src/main.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 11df78609..676c77cdc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,6 +92,7 @@ unsigned int expiryDelta = DEFAULT_TX_EXPIRY_DELTA; CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE); CTxMemPool mempool(::minRelayTxFee); +CTxMemPool tmpmempool(::minRelayTxFee); struct COrphanTx { CTransaction tx; @@ -1697,7 +1698,7 @@ bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlo } } //fprintf(stderr,"check disk\n"); - + if (fTxIndex) { CDiskTxPos postx; //fprintf(stderr,"ReadTxIndex\n"); @@ -4247,6 +4248,17 @@ 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. + LOCK(mempool.cs); + 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"); + } + // 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 ) { for (i=0; i Date: Mon, 29 Oct 2018 21:19:15 +0800 Subject: [PATCH 02/26] more --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 676c77cdc..cb07c181b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4310,7 +4310,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { const CTransaction &tx = e.GetTx(); - if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival. + if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } From 7a0832ebb09153978d96c36eec3533ecb67aa6d6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:31:31 +0800 Subject: [PATCH 03/26] fix --- src/main.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cb07c181b..1b160097b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4307,16 +4307,19 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C LogPrintf("CheckBlockHeader komodo_check_deposit error"); return(false); } - int invalidtxs = 0; - BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - const CTransaction &tx = e.GetTx(); - if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. - invalidtxs++; - fprintf(stderr, "added mempool tx back to mempool\n"); + 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) { + const CTransaction &tx = e.GetTx(); + if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. + invalidtxs++; + fprintf(stderr, "added mempool tx back to mempool\n"); + } + fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); + // empty the temp mempool for next time. + tmpmempool.clear(); } - fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); - // empty the temp mempool for next time. - tmpmempool.clear(); return true; } From eae3058c515ac9b3675838e71a504ae7a6d9ef80 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:34:45 +0800 Subject: [PATCH 04/26] try --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1b160097b..ac22d7dd5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4251,8 +4251,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // 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(); + CTransaction &tx = e.GetTx(); + uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); fprintf(stderr, "added mempool tx to temp mempool\n"); } @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - const CTransaction &tx = e.GetTx(); + CTransaction &tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From 22bbf1477c258b75efc930172df2d73f4ca87fd0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:40:12 +0800 Subject: [PATCH 05/26] try --- src/main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ac22d7dd5..db2e9a3f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4251,8 +4251,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C // 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) { - CTransaction &tx = e.GetTx(); - uint256 &hash = tx.GetHash(); + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); tmpmempool.addUnchecked(hash,e,!IsInitialBlockDownload()); fprintf(stderr, "added mempool tx to temp mempool\n"); } @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction &tx = e.GetTx(); + CTransaction &tx = e->GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From bb2a48ab545d10b23853d68cc77e0d995fee1456 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:43:13 +0800 Subject: [PATCH 06/26] try --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index db2e9a3f4..3ec949b21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction &tx = e->GetTx(); + CTransaction &tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From 441240215fc3365499a3493ccbf2cd2a559a2903 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:43:37 +0800 Subject: [PATCH 07/26] this --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 3ec949b21..0ed53e0c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction &tx = e.GetTx(); + CTransaction tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From 624d0e81cbc06ea573031b15ccaf5088a260a756 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:43:58 +0800 Subject: [PATCH 08/26] a --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 0ed53e0c7..801432a71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction tx = e.GetTx(); + CTransaction& tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From b64c592e07dc6ad1fb07852de5a8fd521af73db1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:46:24 +0800 Subject: [PATCH 09/26] try --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 801432a71..0ed53e0c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4311,7 +4311,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C { int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { - CTransaction& tx = e.GetTx(); + CTransaction tx = e.GetTx(); if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); From f8074b70496e72cacdd2fabc3b50e1f8dce987d4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 21:57:48 +0800 Subject: [PATCH 10/26] remove hack --- src/cc/dice.cpp | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 67d251bcc..c5f289487 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -443,7 +443,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; @@ -551,8 +551,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' ) @@ -576,30 +575,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 ) { From 98eeeff0014ec84a2d705bcbda18700d92b830ef Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 22:14:55 +0800 Subject: [PATCH 11/26] temp disable random entropy to try and brake mempool --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c5f289487..39a433efb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,9 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } - int32_t entropytxs=0,emptyvar=0; + int32_t entropytxs=0; //,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + //DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 916986cd544bd6dfc2edfcd12690e4c238a63fac Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 22:55:43 +0800 Subject: [PATCH 12/26] enabled utxo selection. --- src/cc/CCtx.cpp | 5 +++++ src/cc/dice.cpp | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 71669a0a6..60b52fba0 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -276,6 +276,11 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * abovei = belowi = -1; for (above=below=i=0; i 500 ) { + // if ( (rand() % 100) < 80 ) + // continue; + //} if ( (atx_value= utxos[i].nValue) <= 0 ) continue; if ( atx_value == value ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 39a433efb..c5f289487 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,9 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = strprintf("Dice plan %s illegal bet %.8f: minbet %.8f maxbet %.8f or odds %d vs max.%d\n",planstr,(double)bet/COIN,(double)minbet/COIN,(double)maxbet/COIN,(int32_t)odds,(int32_t)maxodds); return(""); } - int32_t entropytxs=0; //,emptyvar=0; + int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - //DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 07cfded72b2305f8e70d2a8014a512ff552fe302 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 22:58:41 +0800 Subject: [PATCH 13/26] remoce getblock, redundant --- src/cc/dice.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c5f289487..ef0b7675b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -548,12 +548,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"); - 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)); + 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"); - } 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' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) From b88f5e1484d113f0631563ae8d69ae9503dedfd2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:00:38 +0800 Subject: [PATCH 14/26] missed --- src/cc/dice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef0b7675b..29e36e968 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -542,7 +542,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vin.3+: funding CC vout.0 from 'F', 'E', 'W', 'L' or 'T' //vout.1: tag to owner address for entropy funds preventCCvouts = 1; - CBlockIndex block; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); From b655a5ff0e13639060c964c41c3ac34ec07355c7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:03:18 +0800 Subject: [PATCH 15/26] more --- src/cc/dice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 29e36e968..7e013ffe2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -443,7 +443,6 @@ 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; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; From 6ba8c494e6925db53e8bbebf0e80866bd7206b86 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:26:41 +0800 Subject: [PATCH 16/26] try optional to disable nullifiers check --- src/main.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 0ed53e0c7..2f90f161d 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 AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) { AssertLockHeld(cs_main); if (pfMissingInputs) @@ -1391,14 +1391,17 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) + if (!bool_nullifiers) { - BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) + BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { - if (pool.mapNullifiers.count(nf)) + BOOST_FOREACH(const uint256 &nf, joinsplit.nullifiers) { - fprintf(stderr,"pool.mapNullifiers.count\n"); - return false; + if (pool.mapNullifiers.count(nf)) + { + fprintf(stderr,"pool.mapNullifiers.count\n"); + return false; + } } } } @@ -1678,11 +1681,15 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx) +bool myAddtomempool(CTransaction &tx,boost:optional bool_nullifiers) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; - if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); + if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { + if (bool_nullifiers) + return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,bool_nullifiers)); + else + return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); + } else return(true); } @@ -4312,7 +4319,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); - if ( myAddtomempool(tx) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. + if ( myAddtomempool(tx,1) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } From 5010217b996a86edddd5b1603cc0473e7772235f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:29:35 +0800 Subject: [PATCH 17/26] bootst include --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 2f90f161d..31becb7d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,6 +42,7 @@ #include #include #include +#include using namespace std; From 2c98a4f5fea89b776b7fe20fc262cbd1f45436ed Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:40:05 +0800 Subject: [PATCH 18/26] try --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.cpp b/src/main.cpp index 31becb7d2..ea5255928 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1310,6 +1310,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF return nMinFee; } +using boost::optional; bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) { From 30d0a58a1ad8dce1b82b032ee7d91311d7d9b57d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:41:54 +0800 Subject: [PATCH 19/26] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ea5255928..2ccc9aa17 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1683,7 +1683,7 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx,boost:optional bool_nullifiers) +bool myAddtomempool(CTransaction &tx,boost::optional bool_nullifiers) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { From 06bdc769992bb6f94b33390f7ab19ce346bf9d02 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:52:17 +0800 Subject: [PATCH 20/26] try --- src/main.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2ccc9aa17..5415705c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,7 +42,6 @@ #include #include #include -#include using namespace std; @@ -1310,7 +1309,6 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF return nMinFee; } -using boost::optional; bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, boost::optional bool_nullifiers) { @@ -1683,15 +1681,11 @@ bool GetAddressUnspent(uint160 addressHash, int type, else return(coins.vout[n].nValue); }*/ -bool myAddtomempool(CTransaction &tx,boost::optional bool_nullifiers) +bool myAddtomempool(CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; - if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { - if (bool_nullifiers) - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,bool_nullifiers)); - else - return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); - } + if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) + return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); else return(true); } @@ -4321,7 +4315,8 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C int invalidtxs = 0; BOOST_FOREACH(const CTxMemPoolEntry& e, tmpmempool.mapTx) { CTransaction tx = e.GetTx(); - if ( myAddtomempool(tx,1) == false ) // this happens if there were invalid txs in the local mempool, on block arrival, used to make the block invalid. + CValidationState state; bool fMissingInputs,fOverrideFees = false; + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,1) == false ); invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } From 71c57902668e87ff3fa88a9ebcacc09205961435 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 23:56:53 +0800 Subject: [PATCH 21/26] maybe --- src/main.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main.h b/src/main.h index fd418502a..7e2c0fe9f 100644 --- a/src/main.h +++ b/src/main.h @@ -180,11 +180,11 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals); /** Unregister a network node */ void UnregisterNodeSignals(CNodeSignals& nodeSignals); -/** +/** * Process an incoming block. This only returns after the best known valid * block is made active. Note that it does not, however, guarantee that the * specific block passed to it has been checked for validity! - * + * * @param[out] state This may be set to an Error state if any error occurred processing it, including during validation/connection/etc of otherwise unrelated blocks during reorganisation; or it may be set to an Invalid state if pblock is itself invalid (but this is not guaranteed even when the block is checked). If you want to *possibly* get feedback on whether pblock is valid, you must also install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever *any* block completes validation. * @param[in] pfrom The node which we are receiving the block from; it is added to mapBlockSource and may be penalised if the block is invalid. * @param[in] pblock The block we want to process. @@ -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* pfMissingInputs, bool fRejectAbsurdFee=false, boost::optional bool_nullifiers); struct CNodeStateStats { @@ -640,7 +640,7 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF /** * Check transaction inputs, and make sure any * pay-to-script-hash transactions are evaluating IsStandard scripts - * + * * Why bother? To avoid denial-of-service attacks; an attacker * can submit a standard HASH... OP_EQUAL transaction, * which will get accepted into blocks. The redemption @@ -649,14 +649,14 @@ CAmount GetMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowF * DUP CHECKSIG DROP ... repeated 100 times... OP_1 */ -/** +/** * Check for standard transaction types * @param[in] mapInputs Map of previous transactions that have outputs we're spending * @return True if all inputs (scriptSigs) use only standard transaction forms */ bool AreInputsStandard(const CTransaction& tx, const CCoinsViewCache& mapInputs, uint32_t consensusBranchId); -/** +/** * Count ECDSA signature operations the old-fashioned (pre-0.6) way * @return number of sigops this transaction's outputs will produce when spent * @see CTransaction::FetchInputs @@ -665,7 +665,7 @@ unsigned int GetLegacySigOpCount(const CTransaction& tx); /** * Count ECDSA signature operations in pay-to-script-hash inputs. - * + * * @param[in] mapInputs Map of previous transactions that have outputs we're spending * @return maximum number of sigops required to validate this transaction's inputs * @see CTransaction::FetchInputs @@ -732,9 +732,9 @@ bool IsExpiredTx(const CTransaction &tx, int nBlockHeight); */ bool CheckFinalTx(const CTransaction &tx, int flags = -1); -/** +/** * Closure representing one script verification - * Note that this stores references to the spending transaction + * Note that this stores references to the spending transaction */ class CScriptCheck { From 6f84a8cb23871049ba37449298edd6e2b204de26 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 00:10:41 +0800 Subject: [PATCH 22/26] try --- src/main.cpp | 6 +++--- src/main.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 5415705c7..e6cca73bc 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, boost::optional bool_nullifiers) +bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransaction &tx, bool fLimitFree,bool* pfMissingInputs, bool fRejectAbsurdFee, bool fNullifiers) { AssertLockHeld(cs_main); if (pfMissingInputs) @@ -1391,7 +1391,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa return false; } } - if (!bool_nullifiers) + if (fNullifiers == true) { BOOST_FOREACH(const JSDescription &joinsplit, tx.vjoinsplit) { @@ -4316,7 +4316,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,1) == false ); + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ); invalidtxs++; fprintf(stderr, "added mempool tx back to mempool\n"); } diff --git a/src/main.h b/src/main.h index 7e2c0fe9f..244817a61 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, boost::optional bool_nullifiers); + bool* pfMissingInputs, bool fRejectAbsurdFee=false, bool fNullifiers=false); struct CNodeStateStats { From 87d899fb9aeac1f4437cc57e9a6ee44392decdd2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 00:13:02 +0800 Subject: [PATCH 23/26] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e6cca73bc..a8405aaad 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) { From 53476dff15227ff38134acf198ff275e5132b94b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 00:23:15 +0800 Subject: [PATCH 24/26] fix --- src/main.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index a8405aaad..d8a32f3c7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1454,12 +1454,14 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } } // are the joinsplit's requirements met? - if (!view.HaveJoinSplitRequirements(tx)) + if ( fNullifiers == true ) { - //fprintf(stderr,"accept failure.2\n"); - return state.Invalid(error("AcceptToMemoryPool: joinsplit requirements not met"),REJECT_DUPLICATE, "bad-txns-joinsplit-requirements-not-met"); + 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"); + } } - // Bring the best block into scope view.GetBestBlock(); From b6a9ea6c3a6fc4c06cff2b4897f0972b4f7d8c87 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 01:19:44 +0800 Subject: [PATCH 25/26] fix --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index d8a32f3c7..16994e0e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4320,7 +4320,8 @@ 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++; - fprintf(stderr, "added mempool tx back to mempool\n"); + else + fprintf(stderr, "added mempool tx back to mempool\n"); } fprintf(stderr, "number of invalid txs: %d\n",invalidtxs ); // empty the temp mempool for next time. From 3d7a5f943409165446225c7c14a83a3c6b585bc4 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Tue, 30 Oct 2018 01:26:59 +0800 Subject: [PATCH 26/26] fix --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 16994e0e3..34492dc9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4318,7 +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 ); + if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees,true) == false ) invalidtxs++; else fprintf(stderr, "added mempool tx back to mempool\n");