From 8d61613402578446cb27e05215734f1f25e805e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 04:45:20 -1100 Subject: [PATCH 001/252] -print --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index f6c8520d8..837e380de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4322,7 +4322,7 @@ bool CheckBlock(int32_t *futureblockp,int32_t height,CBlockIndex *pindex,const C if (AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees) == 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 7287d8c59011c0f9f321bd708d574ed54da38d6b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 06:26:15 -1100 Subject: [PATCH 002/252] Return value in crosschainproof --- src/rpccrosschain.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rpccrosschain.cpp b/src/rpccrosschain.cpp index 09f1b21d1..2059ab452 100644 --- a/src/rpccrosschain.cpp +++ b/src/rpccrosschain.cpp @@ -50,7 +50,9 @@ UniValue assetchainproof(const UniValue& params, bool fHelp) UniValue crosschainproof(const UniValue& params, bool fHelp) { - + UniValue ret(UniValue::VOBJ); + fprintf(stderr,"crosschainproof needs to be implemented\n"); + return(ret); } From 1a0239ba0dde4911a1b83886d976f79de7d12943 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 06:49:02 -1100 Subject: [PATCH 003/252] Fix compiler issues --- src/komodo_bitcoind.h | 2 +- src/komodo_globals.h | 2 +- src/rpcserver.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 73a49e10c..76216efee 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1164,7 +1164,7 @@ int8_t komodo_segid(int32_t nocache,int32_t height) return(segid); } -int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) +void komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n) { static uint8_t prevhashbuf[100]; static int32_t prevheight; int32_t i; diff --git a/src/komodo_globals.h b/src/komodo_globals.h index 1ebfdd16c..6d0b10328 100644 --- a/src/komodo_globals.h +++ b/src/komodo_globals.h @@ -58,7 +58,7 @@ uint64_t KOMODO_INTERESTSUM,KOMODO_WALLETBALANCE; uint64_t ASSETCHAINS_ENDSUBSIDY,ASSETCHAINS_REWARD,ASSETCHAINS_HALVING,ASSETCHAINS_DECAY,ASSETCHAINS_COMMISSION,ASSETCHAINS_STAKED,ASSETCHAINS_SUPPLY = 10; uint32_t KOMODO_INITDONE; -char KMDUSERPASS[8192],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; +char KMDUSERPASS[8192+512+1],BTCUSERPASS[8192]; uint16_t KMD_PORT = 7771,BITCOIND_RPCPORT = 7771; uint64_t PENDING_KOMODO_TX; extern int32_t KOMODO_LOADINGBLOCKS; unsigned int MAX_BLOCK_SIGOPS = 20000; diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index d41d77056..f9abbc44f 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -242,7 +242,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; UniValue stop(const UniValue& params, bool fHelp) { - char buf[64]; + char buf[66]; // Accept the deprecated and ignored 'detach' boolean argument if (fHelp || params.size() > 1) throw runtime_error( diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6ca3c8ed4..4ec42d117 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4532,7 +4532,7 @@ int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); extern std::string NOTARY_PUBKEY; uint32_t komodo_stake(int32_t validateflag,arith_uint256 bnTarget,int32_t nHeight,uint256 hash,int32_t n,uint32_t blocktime,uint32_t prevtime,char *destaddr); int8_t komodo_stakehash(uint256 *hashp,char *address,uint8_t *hashbuf,uint256 txid,int32_t vout); -int32_t komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); +void komodo_segids(uint8_t *hashbuf,int32_t height,int32_t n); int32_t komodo_notaryvin(CMutableTransaction &txNew,uint8_t *notarypub33) { From 8fded6d999a34433e7374c239b816d68291862aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:02:39 -1100 Subject: [PATCH 004/252] Fix compiler warning --- src/rpcserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp index f9abbc44f..393545a63 100644 --- a/src/rpcserver.cpp +++ b/src/rpcserver.cpp @@ -242,7 +242,7 @@ extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN]; UniValue stop(const UniValue& params, bool fHelp) { - char buf[66]; + char buf[66+128]; // Accept the deprecated and ignored 'detach' boolean argument if (fHelp || params.size() > 1) throw runtime_error( From 7fe7c221581bbb84a6e54c74b40570d2e3204f55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:11:29 -1100 Subject: [PATCH 005/252] fix Compiler warnings --- src/cc/CCtx.cpp | 3 +-- src/cc/CCutils.cpp | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 60b52fba0..eb606f385 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -33,9 +33,8 @@ bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScrip UpdateTransaction(mtx,vini,sigdata); return(true); } else fprintf(stderr,"signing error for SignTx vini.%d %.8f\n",vini,(double)utxovalue/COIN); -#else - return(false); #endif + return(false); } std::string FinalizeCCTx(uint64_t CCmask,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey mypk,uint64_t txfee,CScript opret) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index d4de992f7..ce736ba7a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -74,6 +74,7 @@ CC* GetCryptoCondition(CScript const& scriptSig) std::vector ffbin; if (scriptSig.GetOp(pc, opcode, ffbin)) return cc_readFulfillmentBinary((uint8_t*)ffbin.data(), ffbin.size()-1); + else return(0); } bool IsCCInput(CScript const& scriptSig) From 0d888fcd328d535e4744dc0fdd6c19d6b4d5728f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 1 Nov 2018 11:16:57 -0700 Subject: [PATCH 006/252] Add jsindex to z_listreceivedbyaddress to uniquely identify them --- src/wallet/rpcwallet.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e7c8e2bdd..3d419a734 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3419,6 +3419,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) " \"txid\": xxxxx, (string) the transaction id\n" " \"amount\": xxxxx, (numeric) the amount of value in the note\n" " \"memo\": xxxxx, (string) hexademical string representation of memo field\n" + " \"jsindex\": xxxxx, (numeric) the JoinSplit index\n" "}\n" "\nExamples:\n" + HelpExampleCli("z_listreceivedbyaddress", "\"ztfaW34Gj9FrnGUEf833ywDVL62NWXBM81u6EQnM6VR45eYnXhwztecW1SjxA7JrmAXKJhxhj3vDNEpVCQoSvVoSpmbhtjf\"") @@ -3460,6 +3461,7 @@ UniValue z_listreceivedbyaddress(const UniValue& params, bool fHelp) obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.plaintext.value)))); std::string data(entry.plaintext.memo.begin(), entry.plaintext.memo.end()); obj.push_back(Pair("memo", HexStr(data))); + obj.push_back(Pair("jsindex", entry.jsop.js)); result.push_back(obj); } return result; From 0751d17dadb127c0c2fc41e585e5bf7d428dec3e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:17:40 -1100 Subject: [PATCH 007/252] Fix --- src/cc/lotto.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 7129bfcd8..dcde90e78 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -295,6 +295,7 @@ std::string LottoCreate(uint64_t txfee,char *planstr,int64_t funding,int32_t tic mtx.vout.push_back(MakeCC1vout(EVAL_LOTTO,funding,lottopk)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,CScript() << OP_RETURN << E_MARSHAL(ss << (uint8_t)EVAL_LOTTO << (uint8_t)'F' << sbits << ticketsize << odds << firstheight << period << hentropy))); } + return(""); } std::string LottoTicket(uint64_t txfee,uint256 lottoid,int64_t numtickets) From 0cf7cae07c6d9afb96acc563a7954f2fd2255e91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:25:45 -1100 Subject: [PATCH 008/252] Syntax --- src/cc/channels.cpp | 4 ++-- src/cc/gateways.cpp | 2 +- src/cc/oracles.cpp | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index d92186d26..ec5f7aa9c 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -692,7 +692,7 @@ std::string ChannelRefund(uint64_t txfee,uint256 opentxid,uint256 closetxid) UniValue ChannelsInfo(uint256 channeltxid) { UniValue result(UniValue::VOBJ); CTransaction tx,opentx; uint256 txid,tmp_txid,hashBlock,param3,opentxid,hashchain,prevtxid; - struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[256],str2[256]; int32_t vout,numvouts,param1,numpayments; + struct CCcontract_info *cp,C; char myCCaddr[65],addr[65],str1[512],str2[256]; int32_t vout,numvouts,param1,numpayments; int64_t nValue,param2,payment; CPubKey srcpub,destpub,mypk; std::vector > txids; @@ -768,4 +768,4 @@ UniValue ChannelsInfo(uint256 channeltxid) } } return(result); -} \ No newline at end of file +} diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 26c800a98..b6fcb2136 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -143,7 +143,7 @@ */ -int32_t GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) +void GatewaysAddQueue(std::string coin,uint256 txid,CScript scriptPubKey,int64_t nValue) { char destaddr[64],str[65]; Getscriptaddress(destaddr,scriptPubKey); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 0c7d9e6e2..524eba9c2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -440,6 +440,7 @@ int64_t correlate_price(int32_t height,int64_t *prices,int32_t n) for (i=0; i %llu ht.%d\n",(long long)price,height); + return(price); } int64_t OracleCorrelatedPrice(int32_t height,std::vector origprices) From dbf864cfccf2aa063062b369add8bca8c404ff55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 1 Nov 2018 07:33:41 -1100 Subject: [PATCH 009/252] Return 0 for unfound epoch --- src/consensus/upgrades.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index c913c7ea0..1dd3fe706 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -69,6 +69,7 @@ int CurrentEpoch(int nHeight, const Consensus::Params& params) { return idxInt; } } + return(0); // jl777 seems the right value to return } uint32_t CurrentEpochBranchId(int nHeight, const Consensus::Params& params) { From 74bb69faef553d4b798a64dd20c189fad8ea00e5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 02:08:56 -1100 Subject: [PATCH 010/252] Disable checktx in miner loop --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index fcc8d6127..ee3f7e680 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -335,6 +335,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) //fprintf(stderr,"dont have inputs\n"); continue; } + if ( 0 ) { CValidationState state; auto verifier = libzcash::ProofVerifier::Disabled(); From 62259bc366c61b2862b4cabbd5779ee685e26279 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 02:14:53 -1100 Subject: [PATCH 011/252] +print --- src/miner.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index ee3f7e680..17e39cf7e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -194,7 +194,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { - //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); continue; } if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) @@ -272,7 +272,10 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) porphan->feeRate = feeRate; } else + { vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); + fprintf(stderr,"."); + } } // Collect transactions into block @@ -299,7 +302,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx { - //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } @@ -307,7 +310,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) { - //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); continue; } // Skip free transactions if we're past the minimum block size: @@ -317,7 +320,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) { - //fprintf(stderr,"fee rate skip\n"); + fprintf(stderr,"fee rate skip\n"); continue; } // Prioritise by fee once past the priority size or we run out of high-priority @@ -332,7 +335,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (!view.HaveInputs(tx)) { - //fprintf(stderr,"dont have inputs\n"); + fprintf(stderr,"dont have inputs\n"); continue; } if ( 0 ) From fa2254513b791ff3c81ac3120d920d98a06b5afb Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 04:22:14 -1100 Subject: [PATCH 012/252] -prints --- src/miner.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 17e39cf7e..ee3f7e680 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -194,7 +194,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { - fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); continue; } if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,nHeight,(uint32_t)pblock->nTime,0) < 0 ) @@ -272,10 +272,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) porphan->feeRate = feeRate; } else - { vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); - fprintf(stderr,"."); - } } // Collect transactions into block @@ -302,7 +299,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx { - fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } @@ -310,7 +307,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) unsigned int nTxSigOps = GetLegacySigOpCount(tx); if (nBlockSigOps + nTxSigOps >= MAX_BLOCK_SIGOPS-1) { - fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); + //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); continue; } // Skip free transactions if we're past the minimum block size: @@ -320,7 +317,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) { - fprintf(stderr,"fee rate skip\n"); + //fprintf(stderr,"fee rate skip\n"); continue; } // Prioritise by fee once past the priority size or we run out of high-priority @@ -335,7 +332,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn,int32_t gpucount) if (!view.HaveInputs(tx)) { - fprintf(stderr,"dont have inputs\n"); + //fprintf(stderr,"dont have inputs\n"); continue; } if ( 0 ) From 744882bedf9b198edabf16fe7b7c2010b6c79e94 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 05:09:29 -1100 Subject: [PATCH 013/252] Fix txfee for dice finish --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c5bebeba0..58dac192e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1025,7 +1025,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 winlosetimeout = 0; } } - if ( AddNormalinputs(mtx,mypk,txfee,1) == 0 ) + if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 7f34ac4227d4b5266289d09d4a3d6a864a6aa478 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 2 Nov 2018 05:11:03 -1100 Subject: [PATCH 014/252] Reallocate utxo --- 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 58dac192e..247ac9f7f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1025,7 +1025,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 winlosetimeout = 0; } } - if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) + if ( AddNormalinputs(mtx,mypk,2*txfee,4) == 0 ) { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1077,7 +1077,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,56,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From c680de514ac64fa25560a7eda46ed9b32042b162 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:19:20 -1100 Subject: [PATCH 015/252] +prints --- src/cc/dice.cpp | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 247ac9f7f..9c35e3947 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1016,7 +1016,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 return(""); } fundingpk = DiceFundingPk(fundingPubKey); - if ( winlosetimeout != 0 ) + if ( winlosetimeout != 0 ) // must be dealernode { scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; if ( scriptPubKey != fundingPubKey ) @@ -1033,39 +1033,49 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { + if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) + { + CCerror = "bettxid already spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - if ( winlosetimeout != 0 ) - winlosetimeout = iswin; - if ( iswin == winlosetimeout ) + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) - { - CCerror = "bettxid already spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - //fprintf(stderr,"iswin.%d matches\n",iswin); + CCerror = "bettxid already spent in mempool"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + if ( winlosetimeout != 0 ) // dealernode + { + fprintf(stderr,"set winlosetimeout <- %d\n",winlosetimeout,iswin); + if ( (winlosetimeout= iswin) > 0 ) + funcid = 'W'; + else funcid = 'L'; + } + if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here + { + fprintf(stderr,"iswin.%d matches\n",iswin); mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); - if ( iswin == 0 ) + if ( iswin == 0 && funcid != 'L' && funcid != 'W' ) // normal node path { - funcid = 'T'; if ( DiceVerifyTimeout(betTx,timeoutblocks) == 0 ) // hasnt timed out yet { return(""); } else { + funcid = 'T'; hentropy = hentropyproof = zeroid; iswin = 1; + fprintf(stderr,"set timeout win T\n"); } } - if ( iswin > 0 ) + if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { - if ( funcid != 'T' ) - funcid = 'W'; odds = (betTx.vout[2].nValue - txfee); if ( odds < 1 || odds > maxodds ) { @@ -1092,13 +1102,13 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); mtx.vout.push_back(CTxOut((odds+1) * betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); } - else + else // dealernode 'L' path { funcid = 'L'; mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue + betTx.vout[1].nValue,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } - if ( winlosetimeout != 0 ) + if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; //char str[65],str2[65]; From f437dbbd26ab6127e4cbfe0b08ff3596de6faebb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:20:42 -1100 Subject: [PATCH 016/252] Fix --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9c35e3947..005fcd69b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1050,7 +1050,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( winlosetimeout != 0 ) // dealernode { - fprintf(stderr,"set winlosetimeout <- %d\n",winlosetimeout,iswin); + fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); if ( (winlosetimeout= iswin) > 0 ) funcid = 'W'; else funcid = 'L'; From ba7490562d73cdf227e375348ec700b60241be22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:28:09 -1100 Subject: [PATCH 017/252] spentindex --- src/cc/dice.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 005fcd69b..c1fe8962a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1033,12 +1033,25 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { - if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) + CSpentIndexKey key(bettxid, 0); + CSpentIndexValue value; + CSpentIndexKey key2(bettxid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + /*if ( CCtxidvalue(cp->unspendableCCaddr,bettxid,0) != 0 && CCtxidvalue(cp->unspendableCCaddr,bettxid,1) != 0 ) // already confirmed + { + if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) // but not unspent -> spent + { + CCerror = "bettxid already spent"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { From 3e4aad6087a23fdabec81277698a524ced115d1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:41:32 -1100 Subject: [PATCH 018/252] -print --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c1fe8962a..7d3c15fb8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -641,13 +641,15 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { char str[65],sstr[16]; unstringbits(sstr,sbits); - fprintf(stderr,"(%c) %.8f %s %s\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); if ( sbits == refsbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' ) { if ( total != 0 && maxinputs != 0 ) + { + fprintf(stderr,"use (%c) %.8f %s %s\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid)); mtx.vin.push_back(CTxIn(txid,vout,CScript())); + } totalinputs += it->second.satoshis; n++; if ( (total > 0 && totalinputs >= total) || (maxinputs > 0 && n >= maxinputs) ) From 5d593cb7f8037ea4bc41f8bf943b35ff60422a84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:44:33 -1100 Subject: [PATCH 019/252] +print --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7d3c15fb8..160646daf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -284,7 +284,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t break; } } - //fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); + fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From 65e3f4086a53219338995a9aaf5d6ac82c197958 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:50:02 -1100 Subject: [PATCH 020/252] Test --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 160646daf..30a9ea4f5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -242,7 +242,6 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t fprintf(stderr,"%s\n", CCerror.c_str() ); return(0); } - //fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,houseentropy),uint256_str(str2,bettorentropy)); endiancpy(buf,(uint8_t *)&houseentropy,32); endiancpy(&buf[32],(uint8_t *)&bettorentropy,32); @@ -254,6 +253,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; + fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256 *)&house),uint256_str(str2,(uint256 *)&bettor)); if ( odds > 1 ) { if ( 0 ) @@ -1123,6 +1123,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue + betTx.vout[1].nValue,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } + fprintf(stderr,"make tx.%c\n",funcid); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; From 83944791499608c58bf1e539a2cf60c6ef9416c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:52:06 -1100 Subject: [PATCH 021/252] Fix --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 30a9ea4f5..de542485e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -253,7 +253,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; - fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256 *)&house),uint256_str(str2,(uint256 *)&bettor)); + fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256)house),uint256_str(str2,(uint256)bettor)); if ( odds > 1 ) { if ( 0 ) From 4475f431782cac1e070c8d68e95616d01649999f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 5 Nov 2018 23:53:13 -1100 Subject: [PATCH 022/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index de542485e..6646a78f4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -253,7 +253,7 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; - fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,(uint256)house),uint256_str(str2,(uint256)bettor)); + fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,*(uint256 *)&house),uint256_str(str2,*(uint256 *)&bettor)); if ( odds > 1 ) { if ( 0 ) From 6d402bbec6790de17ffd5aba42cef100d026adaa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:07:29 -1100 Subject: [PATCH 023/252] Track entropy used --- src/cc/dice.cpp | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6646a78f4..56b4da4a0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -103,19 +103,19 @@ struct dicefinish_info int32_t iswin; }; -bool mySendrawtransaction(std::string res) +bool mySendrawtransaction(std::string res,uint256 entropyused) { CTransaction tx; char str[65]; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { - fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); + //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); - fprintf(stderr,"added to mempool and broadcast\n"); + fprintf(stderr,"added to mempool and broadcast entropy.%s txid.%s\n",entropyused.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); @@ -125,7 +125,7 @@ bool mySendrawtransaction(std::string res) void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; + char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; sleep(3); // wait for bettxid to be in mempool for (i=0; iiswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); if ( duplicate == 0 ) { - res = DiceBetFinish(&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySendrawtransaction(res); + mySendrawtransaction(res,entropyused); } free(ptr); return(0); @@ -1006,9 +1006,10 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,entropyused; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + entropyused = zeriod; *resultp = 0; //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -1065,6 +1066,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 } if ( winlosetimeout != 0 ) // dealernode { + entropyused = hentropyproof; fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); if ( (winlosetimeout= iswin) > 0 ) funcid = 'W'; @@ -1145,7 +1147,7 @@ std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropy,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1166,10 +1168,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - res = DiceBetFinish(&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySendrawtransaction(res); + mySendrawtransaction(res,entropyused); n++; } else { @@ -1206,11 +1208,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); + else res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySendrawtransaction(res); + mySendrawtransaction(res,entropyused); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From 2931bccdfa2a8f243a1f82c0d4f56f550109e2af Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:20:38 -1100 Subject: [PATCH 024/252] Track entropy/bettxid/finishtx --- src/cc/CCinclude.h | 1 - src/cc/dice.cpp | 30 +++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 8be4bce29..2a2d41ef0 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -96,7 +96,6 @@ bool myAddtomempool(CTransaction &tx); //uint64_t myGettxout(uint256 hash,int32_t n); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); -bool mySendrawtransaction(std::string res); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 56b4da4a0..471401588 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -103,7 +103,7 @@ struct dicefinish_info int32_t iswin; }; -bool mySendrawtransaction(std::string res,uint256 entropyused) +bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) { CTransaction tx; char str[65]; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -115,7 +115,7 @@ bool mySendrawtransaction(std::string res,uint256 entropyused) if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); - fprintf(stderr,"added to mempool and broadcast entropy.%s txid.%s\n",entropyused.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + fprintf(stderr,"added to mempool and broadcast entropyused.%s bettxid.%s -> txid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); @@ -151,7 +151,7 @@ void *dicefinish(void *_ptr) { res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySendrawtransaction(res,entropyused); + mySenddicetransaction(res,entropyused,ptr->bettxid); } free(ptr); return(0); @@ -224,12 +224,15 @@ int32_t dice_5nibbles(uint8_t *fivevals) return(((int32_t)fivevals[0]<<16) + ((int32_t)fivevals[1]<<12) + ((int32_t)fivevals[2]<<8) + ((int32_t)fivevals[3]<<4) + ((int32_t)fivevals[4])); } -uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) +uint64_t DiceCalc(int64_t bet,int64_t vout2,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks,uint256 houseentropy,uint256 bettorentropy) { - uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t winnings; arith_uint256 house,bettor; char str[65],str2[65]; int32_t i,modval; - if ( odds < 10000 ) + uint8_t buf[64],_house[32],_bettor[32],_hash[32],hash[32],hash16[64]; uint64_t odds,winnings; arith_uint256 house,bettor; char str[65],str2[65]; int32_t i,modval; + if ( vout2 <= 10000 ) + { + fprintf(stderr,"unexpected vout2.%llu\n",(long long)vout2); return(0); - else odds -= 10000; + } + else odds = (vout2 - 10000); if ( bet < minbet || bet > maxbet ) { CCerror = strprintf("bet size violation %.8f",(double)bet/COIN); @@ -963,7 +966,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet error = "bet must be positive"; return(""); } - if ( odds < 1 || odds > 9999 ) + if ( odds < 2 || odds > 9999 ) { error = "odds must be between 1 and 9999"; return(""); @@ -1036,6 +1039,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { + entropytxid = betTx.vin[0].prevout.hash; CSpentIndexKey key(bettxid, 0); CSpentIndexValue value; CSpentIndexKey key2(bettxid, 1); @@ -1171,7 +1175,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySendrawtransaction(res,entropyused); + mySenddicetransaction(res,entropyused,txid); n++; } else { @@ -1180,15 +1184,15 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( 0 && scriptPubKey == fundingPubKey ) + /*if ( 0 && scriptPubKey == fundingPubKey ) { for (i=0; i<=n; i++) { res = DiceAddfunding(txfee,planstr,fundingtxid,COIN); fprintf(stderr,"ENTROPY tx:\n"); - mySendrawtransaction(res); + mySenddicetransaction(res,entropyused,bettxid); } - } + }*/ return(n); } else @@ -1212,7 +1216,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySendrawtransaction(res,entropyused); + mySenddicetransaction(res,entropyused,bettxid); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From 159985c954c106f9a6607c2ea34553c15b3e91eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:23:08 -1100 Subject: [PATCH 025/252] Fix --- src/cc/CCdice.h | 2 +- src/wallet/rpcwallet.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index a01ddd295..0a4cf21ee 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); -std::string DiceBetFinish(int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 1811ff7dc..52409f4c3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6183,7 +6183,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicefinish(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid,bettxid; std::string hex; int32_t r; + UniValue result(UniValue::VOBJ); char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -6197,7 +6197,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(&r,0,name,fundingtxid,bettxid,1); + hex = DiceBetFinish(entropyused,&r,0,name,fundingtxid,bettxid,1); if ( CCerror != "" ) { ERR_RESULT(CCerror); From 6a0e165e304ef34d040383299a082449830c4315 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:25:02 -1100 Subject: [PATCH 026/252] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 471401588..c5af7f37c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1011,8 +1011,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,entropyused; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; - entropyused = zeriod; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + entropyused = zeroid; *resultp = 0; //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) @@ -1151,7 +1151,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropy,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropyused,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; From add9d4fe7eda25fe662760caad4f50424bdba57d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:26:24 -1100 Subject: [PATCH 027/252] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c5af7f37c..57e04c6a5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1172,7 +1172,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { mySenddicetransaction(res,entropyused,txid); @@ -1212,8 +1212,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(&entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); + else res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid); From f66948660d1d0bad6b0e1ce7bb91b5c11d38ecc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 00:39:40 -1100 Subject: [PATCH 028/252] -print --- 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 57e04c6a5..fb7e5cda3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -256,7 +256,7 @@ uint64_t DiceCalc(int64_t bet,int64_t vout2,int64_t minbet,int64_t maxbet,int64_ vcalc_sha256(0,(uint8_t *)&_bettor,buf,64); endiancpy((uint8_t *)&bettor,_bettor,32); winnings = 0; - fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,*(uint256 *)&house),uint256_str(str2,*(uint256 *)&bettor)); + //fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,*(uint256 *)&house),uint256_str(str2,*(uint256 *)&bettor)); if ( odds > 1 ) { if ( 0 ) @@ -968,7 +968,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } if ( odds < 2 || odds > 9999 ) { - error = "odds must be between 1 and 9999"; + error = "odds must be between 2 and 9999"; return(""); } if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) From 912ab71c94e0bd08c879916048a847c3e66d8f7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:10:09 -1100 Subject: [PATCH 029/252] Detect reused entropy --- src/cc/dice.cpp | 60 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fb7e5cda3..0b7bdd6be 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -94,7 +94,9 @@ WARNING: there is an attack vector that precludes betting any large amounts, it #include "../compat/endian.h" -static uint256 bettxids[128]; +#define MAX_ENTROPYUSED 8192 + +static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable struct dicefinish_info { @@ -103,6 +105,21 @@ struct dicefinish_info int32_t iswin; }; +int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) +{ + int32_t i; + if ( entropyused == zeroid || bettxid == zeroid ) + return(0); + for (i=0; i txid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) + { + for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); @@ -128,7 +162,7 @@ void *dicefinish(void *_ptr) char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; sleep(3); // wait for bettxid to be in mempool - for (i=0; ibettxid ) { duplicate = 1; @@ -136,13 +170,13 @@ void *dicefinish(void *_ptr) } if ( duplicate == 0 ) { - for (i=0; ibettxid; break; } - if ( i == sizeof(bettxids)/sizeof(*bettxids) ) + if ( i == MAX_ENTROPYUSED ) bettxids[rand() % i] = ptr->bettxid; } unstringbits(name,ptr->sbits); @@ -510,7 +544,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vout[0] != entropy nValue for bet"); else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[1] constrain violation for bet"); - else if ( tx.vout[2].nValue > txfee+maxodds || tx.vout[2].nValue < txfee ) + else if ( tx.vout[2].nValue > txfee+maxodds || tx.vout[2].nValue <= txfee ) return eval->Invalid("vout[2] nValue violation for bet"); else if ( eval->GetTxUnconfirmed(vinTx.vin[0].prevout.hash,vinofvinTx,hashBlock) == 0 || vinofvinTx.vout.size() < 1 ) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); @@ -884,7 +918,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) + if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 2 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1071,14 +1105,20 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); + if ( DiceEntropyUsed(entropyused,bettxid) < 0 ) + { + CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + //fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); if ( (winlosetimeout= iswin) > 0 ) funcid = 'W'; else funcid = 'L'; } if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here { - fprintf(stderr,"iswin.%d matches\n",iswin); + //fprintf(stderr,"iswin.%d matches\n",iswin); mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); if ( iswin == 0 && funcid != 'L' && funcid != 'W' ) // normal node path @@ -1098,7 +1138,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); - if ( odds < 1 || odds > maxodds ) + if ( odds < 2 || odds > maxodds ) { CCerror = strprintf("illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); fprintf(stderr,"%s\n", CCerror.c_str() ); From edbc54c0725cca87b5fe52f8b341a510e4dced6c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:10:52 -1100 Subject: [PATCH 030/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0b7bdd6be..a780a883b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -122,7 +122,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) { - CTransaction tx; char str[65]; + CTransaction tx; char str[65]; int32_t i; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) From 5e90003b1304cf2391d0d74412e36acda9e180f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:11:30 -1100 Subject: [PATCH 031/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a780a883b..b28178b58 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -135,7 +135,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) { for (i=0; i Date: Tue, 6 Nov 2018 01:15:39 -1100 Subject: [PATCH 032/252] Test --- 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 b28178b58..c328c552b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -94,7 +94,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it #include "../compat/endian.h" -#define MAX_ENTROPYUSED 8192 +#define MAX_ENTROPYUSED 3 static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -321,7 +321,7 @@ uint64_t DiceCalc(int64_t bet,int64_t vout2,int64_t minbet,int64_t maxbet,int64_ break; } } - fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); + //fprintf(stderr,"modval %d vs %d\n",modval,(int32_t)(10000/(odds+1))); if ( modval < 10000/(odds+1) ) winnings = bet * (odds+1); } From 6933a0c17b5a19c9c6bb6c36212e5764b14cbdde Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:30:19 -1100 Subject: [PATCH 033/252] Test --- src/cc/dice.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c328c552b..bd4c2950c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1210,6 +1210,20 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx vout = (int32_t)it->first.index; if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + CSpentIndexKey key(txid, 0); + CSpentIndexValue value; + CSpentIndexKey key2(txid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); + continue; + } + if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; + } if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); @@ -1217,10 +1231,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid); n++; - } else - { - error = res; - } + } else error = res; } } } From 0e887331d3c5ed38515ad367576a7681864ca772 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:51:06 -1100 Subject: [PATCH 034/252] Test --- src/cc/dice.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bd4c2950c..c14245577 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -94,7 +94,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it #include "../compat/endian.h" -#define MAX_ENTROPYUSED 3 +#define MAX_ENTROPYUSED 8192 static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -1208,24 +1208,24 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - CSpentIndexKey key(txid, 0); - CSpentIndexValue value; - CSpentIndexKey key2(txid, 1); - CSpentIndexValue value2; - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); - continue; - } - if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; - } if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { + CSpentIndexKey key(txid, 0); + CSpentIndexValue value; + CSpentIndexKey key2(txid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); + continue; + } + if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) + { + fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; + } res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { From 1f168f18da10fa737200bfa7e0520ba636867687 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 01:57:24 -1100 Subject: [PATCH 035/252] Test --- 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 c14245577..b7f97725d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1138,7 +1138,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); - if ( odds < 2 || odds > maxodds ) + if ( odds < 1 || odds > maxodds ) { CCerror = strprintf("illegal odds.%d vs maxodds.%d\n",(int32_t)odds,(int32_t)maxodds); fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1218,7 +1218,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx CSpentIndexValue value2; if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); + //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) From e057cde6ea39445307304c9e4c66a7d13e78cdb0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 02:28:05 -1100 Subject: [PATCH 036/252] Prevent double spending entropy --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b7f97725d..e864612f1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -131,9 +131,9 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { - RelayTransaction(tx); if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) { + RelayTransaction(tx); for (i=0; i Date: Tue, 6 Nov 2018 02:29:49 -1100 Subject: [PATCH 037/252] Fix --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e864612f1..12143acc2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -128,10 +128,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - LOCK(cs_main); - if ( myAddtomempool(tx) != 0 ) + if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) { - if ( DiceEntropyUsed(entropyused,bettxid) == 0 ) + LOCK(cs_main); + if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + return(true); } - return(true); } else fprintf(stderr,"error adding to mempool\n"); } else fprintf(stderr,"error decoding hex\n"); } From 4ed6e1d12d51f7ecc01d1604c3dbb0f33eb757f2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 02:30:51 -1100 Subject: [PATCH 038/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 12143acc2..e00a46c40 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1268,7 +1268,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid); - sleep(1); + usleep(100000); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) From 587899e2dcf3a08253ffebc558aa05b5c42d8425 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 02:57:41 -1100 Subject: [PATCH 039/252] Test --- src/cc/dice.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e00a46c40..0af61f02d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -109,12 +109,16 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) { int32_t i; if ( entropyused == zeroid || bettxid == zeroid ) + { + fprintf(stderr,"null entropyused or bettxid\n"); return(0); + } for (i=0; i= 0 ) { LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) From 8f8100e3d0820c6c99291832cba45db9efe4bf53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 04:47:54 -1100 Subject: [PATCH 040/252] Test --- src/cc/dice.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0af61f02d..53ff64e23 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -658,6 +658,16 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return(true); } +// jl777: need to make it bestfit +/* fix: bidTx.0281db86a2b45bf73a0e674ec40ca4866fc54298c677d42c5dd8c71254d127f1 +entropyTx.671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c v0 +entropyTx vin0 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 v0 +76a9141f64ce357cb254464c2d5a9c06ca8d0c0ca9be9488ac script vs 210354ad90c26923962bbdfc7fd4956cb52db73682b58df9ee3ffc4751e61c8d465dac (B) entropy vin.0 fundingPubKey mismatch 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 +CC Eval EVAL_DICE Invalid: vin1 of entropy tx not fundingPubKey for bet spending tx 671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c*/ + +/*make tx.L +CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae96b78bd46965066fed7f7fa5838faed9588e62bcd4a406f478eecd5*/ + uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; @@ -668,7 +678,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 1000000 ) + if ( it->second.satoshis < 10000 ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j Date: Tue, 6 Nov 2018 04:55:23 -1100 Subject: [PATCH 041/252] Test --- src/cc/CCtx.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index eb606f385..d323c7e63 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -341,6 +341,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { + fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { for (i=0; itxid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; - //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); + fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); if ( n >= maxutxos ) break; } From 37aa6f8a7255bb87e2c23c6388a9254c28dff40d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 04:59:35 -1100 Subject: [PATCH 042/252] Test --- src/cc/CCtx.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d323c7e63..ea1136e00 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -341,6 +341,8 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { + if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/64 ) + continue; fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { @@ -365,7 +367,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); - if ( n >= maxutxos ) + if ( n >= maxinputs ) break; } } From 2efca535933955c84a93b2ba5612c504627bf59d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 05:05:10 -1100 Subject: [PATCH 043/252] Test --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index ea1136e00..4787903c2 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -367,7 +367,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); - if ( n >= maxinputs ) + if ( n >= maxutxos ) break; } } From 9f9e730f0346fb891642508928de953d32c23408 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 05:11:30 -1100 Subject: [PATCH 044/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 53ff64e23..fbf1baa73 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -627,7 +627,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) 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); + fprintf(stderr,"inputs %.8f != outputs %.8f (%.8f %.8f %.8f %.8f)\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[0].nValue/COIN,(double)tx.vout[1].nValue/COIN,(double)tx.vout[2].nValue/COIN,(double)tx.vout[3].nValue/COIN); return eval->Invalid("CC funds mismatch for win/timeout"); } else if ( tx.vout[3].scriptPubKey != fundingPubKey ) From 22a5147c2ef556df0e8b92e77875ff88bce92ed3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 05:14:26 -1100 Subject: [PATCH 045/252] -print --- src/cc/CCtx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 4787903c2..6db32ddc4 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -341,9 +341,9 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/64 ) + if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/16 ) continue; - fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); + //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { for (i=0; itxid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; - fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); + //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); if ( n >= maxutxos ) break; } From 5d4f7deada3a1a97d7db5876fca68690bd2b3042 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 09:34:27 -1100 Subject: [PATCH 046/252] Add inputs thresholding --- src/cc/CCtx.cpp | 5 +++-- src/cc/dice.cpp | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 6db32ddc4..9603d68fd 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -326,13 +326,14 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); + threshold = total/maxinputs; BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) @@ -341,7 +342,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( (maxinputs == 1 && out.tx->vout[out.i].nValue < total) || out.tx->vout[out.i].nValue < total/16 ) + if ( (out.tx->vout[out.i].nValue < threshold ) continue; //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fbf1baa73..26d33545f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -670,15 +670,18 @@ CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + if ( maxinputs > 0 ) + threshold = total / maxinputs; + else threshold = total / 64; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 10000 ) + if ( it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j Date: Tue, 6 Nov 2018 09:35:02 -1100 Subject: [PATCH 047/252] -( --- src/cc/CCtx.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 9603d68fd..cee9d3a81 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -342,7 +342,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 vout = out.i; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( (out.tx->vout[out.i].nValue < threshold ) + if ( out.tx->vout[out.i].nValue < threshold ) continue; //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) From ce99447bb48643e19dee8fdd0a523377485718ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 11:54:11 -1100 Subject: [PATCH 048/252] Threshold check in all CC addinputs --- src/cc/CCassetstx.cpp | 6 ++++-- src/cc/MofN.cpp | 1 + src/cc/auction.cpp | 1 + src/cc/dice.cpp | 19 ++++++------------- src/cc/faucet.cpp | 5 ++++- src/cc/fsm.cpp | 1 + src/cc/gateways.cpp | 5 ++++- src/cc/lotto.cpp | 1 + src/cc/payments.cpp | 1 + src/cc/pegs.cpp | 1 + src/cc/prices.cpp | 1 + src/cc/rewards.cpp | 5 +++-- src/cc/triggers.cpp | 1 + 13 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index 5c933bd77..4bc1adc42 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -17,15 +17,17 @@ int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t j,vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); - + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; for (j=0; j origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 7b5f106d0..d0d8db0bb 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -120,6 +120,7 @@ bool AuctionValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t int64_t AddAuctionInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 26d33545f..1f1164a0d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -88,7 +88,7 @@ WARNING: there is an attack vector that precludes betting any large amounts, it Actually a much better solution to this is possible, which allows to retain the realtime response aspect of dice CC, which is critical to its usage. - +What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy */ @@ -138,6 +138,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); + // check to make sure it got accepted + for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } - } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } return(false); @@ -202,6 +204,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr->bettxid = bettxid; ptr->sbits = sbits; ptr->iswin = iswin; + // check for duplicates here!!! if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); @@ -658,16 +661,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return(true); } -// jl777: need to make it bestfit -/* fix: bidTx.0281db86a2b45bf73a0e674ec40ca4866fc54298c677d42c5dd8c71254d127f1 -entropyTx.671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c v0 -entropyTx vin0 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 v0 -76a9141f64ce357cb254464c2d5a9c06ca8d0c0ca9be9488ac script vs 210354ad90c26923962bbdfc7fd4956cb52db73682b58df9ee3ffc4751e61c8d465dac (B) entropy vin.0 fundingPubKey mismatch 8b1af6ba594a887f6cfc1c4593b486bfcb1c10dbc76b0ba1f933e93d03891f05 -CC Eval EVAL_DICE Invalid: vin1 of entropy tx not fundingPubKey for bet spending tx 671d8e77e3d0aff928b83c2f0dcada42930fa33c70b4cefa7e1301668f7e9e6c*/ - -/*make tx.L -CC Eval EVAL_DICE Invalid: vin0 or vin1 normal vin for bet spending tx a39a74cae96b78bd46965066fed7f7fa5838faed9588e62bcd4a406f478eecd5*/ - uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hash,proof,hashBlock,fundingtxid; CTransaction tx; int32_t j,vout,n = 0; uint8_t funcid; diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index 676cb152c..3bf8a3476 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -142,14 +142,17 @@ bool FaucetValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx int64_t AddFaucetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { - char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; + char coinaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; //char str[65]; fprintf(stderr,"check %s/v%d %.8f`\n",uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); // no need to prevent dup if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 41601b437..9f9accbb5 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -122,6 +122,7 @@ bool FSMValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) int64_t AddFSMInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index b6fcb2136..a9fc6a4cd 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -332,15 +332,18 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & int64_t AddGatewaysInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 refassetid,int64_t total,int32_t maxinputs) { - char coinaddr[64],destaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; + char coinaddr[64],destaddr[64]; int64_t threshold,nValue,price,totalinputs = 0; uint256 assetid,txid,hashBlock; std::vector origpubkey; std::vector vopret; CTransaction vintx; int32_t j,vout,n = 0; uint8_t evalcode,funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; fprintf(stderr,"check %s for gateway inputs\n",coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( it->second.satoshis < threshold ) + continue; for (j=0; j origpubkey; CTransaction vintx; int32_t n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 6cd751b8d..f3cd40ba2 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -115,6 +115,7 @@ bool PaymentsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & int64_t AddPaymentsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index d9074bd49..21e371b4a 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -122,6 +122,7 @@ bool PegsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx) int64_t AddPegsInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs) { + // add threshold check char coinaddr[64]; int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index 6ee0364e2..3d69ceec1 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -129,6 +129,7 @@ bool PricesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx int64_t AddTokensInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,char *destaddr,uint256 tolenid,int64_t total,int32_t maxinputs) { + // add threshold check int64_t nValue,price,totalinputs = 0; uint256 txid,hashBlock; std::vector origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,destaddr); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index a70071af9..e7a3750f3 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -325,15 +325,16 @@ static uint64_t myIs_unlockedtx_inmempool(uint256 &txid,int32_t &vout,uint64_t r // 'L' vs 'F' and 'A' int64_t AddRewardsInputs(CScript &scriptPubKey,uint64_t maxseconds,struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,int64_t total,int32_t maxinputs,uint64_t refsbits,uint256 reffundingtxid) { - char coinaddr[64],str[65]; uint64_t sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t threshold,sbits,nValue,totalinputs = 0; uint256 txid,hashBlock,fundingtxid; CTransaction tx; int32_t numblocks,j,vout,n = 0; uint8_t funcid; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); SetCCunspents(unspentOutputs,coinaddr); + threshold = total/maxinputs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < 1000000 ) + if ( it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; j origpubkey; CTransaction vintx; int32_t vout,n = 0; std::vector > unspentOutputs; GetCCaddress(cp,coinaddr,pk); From e3df80b29ce1ece5553406f90812fa270ca080f1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 11:57:28 -1100 Subject: [PATCH 049/252] -print --- 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 1f1164a0d..63d429ffb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -463,7 +463,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction if ( hentropy == hentropy2 ) { winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + //char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { @@ -1179,7 +1179,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue + betTx.vout[1].nValue,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } - fprintf(stderr,"make tx.%c\n",funcid); + //fprintf(stderr,"make tx.%c\n",funcid); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; From 6e8402f5c15d824f7220f50d124f0ed6804bf4ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:06:22 -1100 Subject: [PATCH 050/252] Test --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 63d429ffb..84e15f282 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -95,6 +95,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 +extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -577,7 +578,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) if ( (iswin= DiceIsWinner(entropy,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { // will only happen for fundingPubKey - DiceQueue(iswin,sbits,fundingtxid,txid); + if ( KOMODO_INSYNC != 0 ) + DiceQueue(iswin,sbits,fundingtxid,txid); } break; // make sure all funding txid are from matching sbits and fundingtxid!! From 7a4eb293dd2a24b7ba2a688087c22d4ddebc68e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:07:42 -1100 Subject: [PATCH 051/252] +print --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 84e15f282..ee1d04f22 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -157,7 +157,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) } fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } else fprintf(stderr,"error adding to mempool\n"); + } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } From cd67001ea6adcd0119e725e8868407ba7aa1111c Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:20:44 -1100 Subject: [PATCH 052/252] Timing prints --- src/cc/dice.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ee1d04f22..3cd0d3fde 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -90,6 +90,8 @@ WARNING: there is an attack vector that precludes betting any large amounts, it What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy + need to speed up dealer dicestatus loop (or in parallel) + */ #include "../compat/endian.h" @@ -1220,28 +1222,37 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; + fprintf(stderr,"A "); if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { + fprintf(stderr,"B "); if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { + fprintf(stderr,"C "); CSpentIndexKey key(txid, 0); CSpentIndexValue value; CSpentIndexKey key2(txid, 1); CSpentIndexValue value2; + fprintf(stderr,"D "); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } + fprintf(stderr,"E "); if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } + fprintf(stderr,"["); res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + fprintf(stderr,"]"); if ( result > 0 ) { + fprintf(stderr,"("); mySenddicetransaction(res,entropyused,txid); + fprintf(stderr,"("); n++; } else error = res; } @@ -1280,7 +1291,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid); - usleep(100000); + sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) From 7e65cfea526e48c443438b4bb55d5593c2daac11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:27:49 -1100 Subject: [PATCH 053/252] +prints --- src/cc/dice.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3cd0d3fde..c26304092 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1069,6 +1069,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + fprintf(stderr,"0 "); fundingpk = DiceFundingPk(fundingPubKey); if ( winlosetimeout != 0 ) // must be dealernode { @@ -1079,14 +1080,17 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c winlosetimeout = 0; } } + fprintf(stderr,"1 "); if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + fprintf(stderr,"2 "); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { + fprintf(stderr,"3 "); entropytxid = betTx.vin[0].prevout.hash; CSpentIndexKey key(bettxid, 0); CSpentIndexValue value; @@ -1107,15 +1111,18 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c return(""); } }*/ + fprintf(stderr,"4 "); bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { + fprintf(stderr,"5 "); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { CCerror = "bettxid already spent in mempool"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + fprintf(stderr,"6 "); if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; @@ -1130,6 +1137,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c funcid = 'W'; else funcid = 'L'; } + fprintf(stderr,"7 "); if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here { //fprintf(stderr,"iswin.%d matches\n",iswin); @@ -1149,6 +1157,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"set timeout win T\n"); } } + fprintf(stderr,"8 "); if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); @@ -1184,11 +1193,13 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } //fprintf(stderr,"make tx.%c\n",funcid); + fprintf(stderr,"9 "); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; //char str[65],str2[65]; //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); + fprintf(stderr,"z "); return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); } else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout); } @@ -1222,24 +1233,24 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - fprintf(stderr,"A "); + //fprintf(stderr,"A "); if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - fprintf(stderr,"B "); + //fprintf(stderr,"B "); if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - fprintf(stderr,"C "); + //fprintf(stderr,"C "); CSpentIndexKey key(txid, 0); CSpentIndexValue value; CSpentIndexKey key2(txid, 1); CSpentIndexValue value2; - fprintf(stderr,"D "); + //fprintf(stderr,"D "); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } - fprintf(stderr,"E "); + //fprintf(stderr,"E "); if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); From 0173de95240baf2a77219cd93a7aad34d44adb86 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 12:53:58 -1100 Subject: [PATCH 054/252] Remove mutex inside mutex --- src/cc/CCtx.cpp | 4 ++-- src/cc/dice.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index cee9d3a81..29942377e 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -330,7 +330,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); threshold = total/maxinputs; @@ -340,7 +340,7 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 { txid = out.tx->GetHash(); vout = out.i; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { if ( out.tx->vout[out.i].nValue < threshold ) continue; diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c26304092..bf36d48c1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1263,7 +1263,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { fprintf(stderr,"("); mySenddicetransaction(res,entropyused,txid); - fprintf(stderr,"("); + fprintf(stderr,")"); n++; } else error = res; } From d8b84e4ef760502f170def437d2aad8144b8ef8b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:00:15 -1100 Subject: [PATCH 055/252] Speed up addnormalinputs --- src/cc/CCtx.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 29942377e..e6a31fff6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -326,14 +326,16 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=1024; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->AvailableCoins(vecOutputs, false, NULL, true); utxos = (struct CC_utxo *)calloc(maxutxos,sizeof(*utxos)); threshold = total/maxinputs; + if ( maxinputs > maxutxos ) + maxutxos = maxinputs; BOOST_FOREACH(const COutput& out, vecOutputs) { if ( out.fSpendable != 0 ) From 44a4e411eb48d119a48f83cc12f6641bcf30f3eb Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:09:53 -1100 Subject: [PATCH 056/252] Test --- src/cc/CCtx.cpp | 10 +++++----- src/cc/dice.cpp | 24 ------------------------ 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index e6a31fff6..320cd967d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -326,7 +326,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int32_t maxinputs) { - int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; + int32_t abovei,belowi,ind,vout,i,n = 0,maxutxos=64; int64_t sum,threshold,above,below; int64_t remains,nValue,totalinputs = 0; uint256 txid,hashBlock; std::vector vecOutputs; CTransaction tx; struct CC_utxo *utxos,*up; #ifdef ENABLE_WALLET const CKeyStore& keystore = *pwalletMain; assert(pwalletMain != NULL); @@ -336,16 +336,15 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 threshold = total/maxinputs; if ( maxinputs > maxutxos ) maxutxos = maxinputs; + sum = 0; BOOST_FOREACH(const COutput& out, vecOutputs) { - if ( out.fSpendable != 0 ) + if ( out.fSpendable != 0 && out.tx->vout[out.i].nValue >= threshold ) { txid = out.tx->GetHash(); vout = out.i; if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && vout < tx.vout.size() && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() == 0 ) { - if ( out.tx->vout[out.i].nValue < threshold ) - continue; //fprintf(stderr,"check %.8f to vins array.%d of %d %s/v%d\n",(double)out.tx->vout[out.i].nValue/COIN,n,maxutxos,txid.GetHex().c_str(),(int32_t)vout); if ( mtx.vin.size() > 0 ) { @@ -369,8 +368,9 @@ int64_t AddNormalinputs(CMutableTransaction &mtx,CPubKey mypk,int64_t total,int3 up->txid = txid; up->nValue = out.tx->vout[out.i].nValue; up->vout = vout; + sum += up->nValue; //fprintf(stderr,"add %.8f to vins array.%d of %d\n",(double)up->nValue/COIN,n,maxutxos); - if ( n >= maxutxos ) + if ( n >= maxutxos || sum >= total ) break; } } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bf36d48c1..8084d1890 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1069,7 +1069,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - fprintf(stderr,"0 "); fundingpk = DiceFundingPk(fundingPubKey); if ( winlosetimeout != 0 ) // must be dealernode { @@ -1080,17 +1079,14 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c winlosetimeout = 0; } } - fprintf(stderr,"1 "); if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! { CCerror = "no txfee inputs for win/lose"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - fprintf(stderr,"2 "); if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { - fprintf(stderr,"3 "); entropytxid = betTx.vin[0].prevout.hash; CSpentIndexKey key(bettxid, 0); CSpentIndexValue value; @@ -1102,27 +1098,15 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - /*if ( CCtxidvalue(cp->unspendableCCaddr,bettxid,0) != 0 && CCtxidvalue(cp->unspendableCCaddr,bettxid,1) != 0 ) // already confirmed - { - if ( CCutxovalue(cp->unspendableCCaddr,bettxid,0) == 0 || CCutxovalue(cp->unspendableCCaddr,bettxid,1) == 0 ) // but not unspent -> spent - { - CCerror = "bettxid already spent"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } - }*/ - fprintf(stderr,"4 "); bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - fprintf(stderr,"5 "); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { CCerror = "bettxid already spent in mempool"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - fprintf(stderr,"6 "); if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; @@ -1137,7 +1121,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c funcid = 'W'; else funcid = 'L'; } - fprintf(stderr,"7 "); if ( iswin == winlosetimeout ) // dealernode and normal node paths should always get here { //fprintf(stderr,"iswin.%d matches\n",iswin); @@ -1157,7 +1140,6 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c fprintf(stderr,"set timeout win T\n"); } } - fprintf(stderr,"8 "); if ( iswin > 0 && funcid != 0 ) // dealernode 'W' or normal node 'T' path { odds = (betTx.vout[2].nValue - txfee); @@ -1193,13 +1175,11 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); } //fprintf(stderr,"make tx.%c\n",funcid); - fprintf(stderr,"9 "); if ( funcid == 'L' || funcid == 'W' ) // dealernode only hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); *resultp = 1; //char str[65],str2[65]; //fprintf(stderr,"iswin.%d house entropy %s vs bettor %s\n",iswin,uint256_str(str,hentropyproof),uint256_str(str2,bettorentropy)); - fprintf(stderr,"z "); return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,hentropy,hentropyproof))); } else fprintf(stderr,"iswin.%d does not match.%d\n",iswin,winlosetimeout); } @@ -1256,14 +1236,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - fprintf(stderr,"["); res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); - fprintf(stderr,"]"); if ( result > 0 ) { - fprintf(stderr,"("); mySenddicetransaction(res,entropyused,txid); - fprintf(stderr,")"); n++; } else error = res; } From 22496dcbc3e57b5cee8745efacf09b956f768006 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:22:43 -1100 Subject: [PATCH 057/252] Remove lock from DiceStatus rpc, rely on internal locks --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 52409f4c3..15eb594bd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6217,7 +6217,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK2(cs_main, pwalletMain->cs_wallet); + //LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); From 82ee887ff66543610b23efd6094761335eff2b5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 13:29:59 -1100 Subject: [PATCH 058/252] +print --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8084d1890..b6323eaef 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -208,6 +208,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr->sbits = sbits; ptr->iswin = iswin; // check for duplicates here!!! + fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); From 284107e4de9bbe8a3cec702c41bde4a9d93e4ee3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 14:04:29 -1100 Subject: [PATCH 059/252] Limit dicestatus to 100 at a time --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b6323eaef..f5c0e2791 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -170,7 +170,7 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - sleep(3); // wait for bettxid to be in mempool + sleep(1); // wait for bettxid to be in mempool for (i=0; ibettxid ) { @@ -1242,6 +1242,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid); n++; + if ( n >= 100 ) + break; } else error = res; } } From b4568046f05d09126a2b164a98be1683f7ced3cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:43:01 -1100 Subject: [PATCH 060/252] Dicequeue dealer betstatus --- src/cc/dice.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f5c0e2791..5acf2ba94 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1197,7 +1197,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx; uint256 entropyused,hash,proof,txid,hashBlock,spenttxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1214,37 +1214,39 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - //fprintf(stderr,"A "); - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { - //fprintf(stderr,"B "); if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - //fprintf(stderr,"C "); CSpentIndexKey key(txid, 0); CSpentIndexValue value; CSpentIndexKey key2(txid, 1); CSpentIndexValue value2; - //fprintf(stderr,"D "); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); continue; } - //fprintf(stderr,"E "); if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + DiceQueue(iswin,sbits,fundingtxid,txid); + if ( n++ >= 100 ) + break; + } + /*res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { mySenddicetransaction(res,entropyused,txid); n++; if ( n >= 100 ) break; - } else error = res; + } else error = res;*/ } } } From 73b7c27c92940b8b69d2b2aa900fd599e0dc00c0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:47:10 -1100 Subject: [PATCH 061/252] Revert --- src/cc/dice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5acf2ba94..e4cca9218 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1232,21 +1232,21 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - bettorentropy = DiceGetEntropy(betTx,'B'); + /*bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { DiceQueue(iswin,sbits,fundingtxid,txid); - if ( n++ >= 100 ) + if ( ++n >= 100 ) break; - } - /*res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + }*/ + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { mySenddicetransaction(res,entropyused,txid); n++; if ( n >= 100 ) break; - } else error = res;*/ + } else error = res; } } } From 2ade69f479c65373ccb71a0785822647e3da54e8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:54:51 -1100 Subject: [PATCH 062/252] Filter dice queue --- src/cc/dice.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e4cca9218..ffa7e6dd8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -202,12 +202,26 @@ void *dicefinish(void *_ptr) void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) { - struct dicefinish_info *ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); + struct dicefinish_info *ptr; CSpentIndexValue value,value2; + CSpentIndexKey key(bettxid, 0); + CSpentIndexKey key2(bettxid, 1); + CSpentIndexValue value2; + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",txid.GetHex().c_str()); + return; + } + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + { + fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; + } + // check for duplicates here!!! + ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); ptr->fundingtxid = fundingtxid; ptr->bettxid = bettxid; ptr->sbits = sbits; ptr->iswin = iswin; - // check for duplicates here!!! fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { From 80f325e58ac45af93231e88467ae5e723f92ba7b Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:57:24 -1100 Subject: [PATCH 063/252] Syntax --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ffa7e6dd8..202425f10 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -214,7 +214,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; + return; } // check for duplicates here!!! ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); From ed84dd46eb3d2f28d9c824739dc6672b3c6ee8f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:57:56 -1100 Subject: [PATCH 064/252] Syntax --- src/cc/dice.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 202425f10..69e06a258 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -205,7 +205,6 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) struct dicefinish_info *ptr; CSpentIndexValue value,value2; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); - CSpentIndexValue value2; if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",txid.GetHex().c_str()); From 2c081ed1ba419343d24888176614be6bdf43e6c1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:58:19 -1100 Subject: [PATCH 065/252] Syntax --- 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 69e06a258..283941101 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -207,12 +207,12 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",txid.GetHex().c_str()); + fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); return; } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",bettxid.GetHex().c_str()); return; } // check for duplicates here!!! From 3e7c0e4aa8b5ca495b7d56fc70054672cb7b66a3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 19:59:41 -1100 Subject: [PATCH 066/252] -print --- src/komodo.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index e303c2bac..efbc4ddad 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -112,7 +112,7 @@ int32_t komodo_parsestatefile(struct komodo_state *sp,FILE *fp,char *symbol,char errs++; if ( fread(&MoMdepth,1,sizeof(MoMdepth),fp) != sizeof(MoMdepth) ) errs++; - if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else @@ -257,7 +257,7 @@ int32_t komodo_parsestatefiledata(struct komodo_state *sp,uint8_t *filedata,long errs++; if ( memread(&MoMdepth,sizeof(MoMdepth),filedata,&fpos,datalen) != sizeof(MoMdepth) ) errs++; - if ( 1 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) + if ( 0 && ASSETCHAINS_SYMBOL[0] != 0 && sp != 0 ) printf("%s load[%s.%d -> %s] NOTARIZED %d %s MoM.%s %d CCid.%u\n",ASSETCHAINS_SYMBOL,symbol,sp->NUM_NPOINTS,dest,notarized_height,notarized_hash.ToString().c_str(),MoM.ToString().c_str(),MoMdepth&0xffff,(MoMdepth>>16)&0xffff); } else From b80e05fd3865913df3609d5d8555fa474a9a62e7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 20:00:35 -1100 Subject: [PATCH 067/252] +2 seconds sleep --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 283941101..2a4b4626b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -170,7 +170,7 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - sleep(1); // wait for bettxid to be in mempool + sleep(3); // wait for bettxid to be in mempool for (i=0; ibettxid ) { From f19d264d502a2c0eecf5761d3c9f9dc328e845ad Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 20:08:49 -1100 Subject: [PATCH 068/252] +print --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2a4b4626b..b89a1eb59 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -170,7 +170,8 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - sleep(3); // wait for bettxid to be in mempool + usleep(1000000 + (rand() % 4000000)); // wait for bettxid to be in mempool + fprintf(stderr,"process Queue dicefinish %s\n",ptr->bettxid.GetHex().c_str()); for (i=0; ibettxid ) { From 1d6bc78c1ae10c927ddc98df3947856924d208fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 20:22:23 -1100 Subject: [PATCH 069/252] Reduce dice status and dice queue collisions --- src/cc/dice.cpp | 141 ++++++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 64 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b89a1eb59..87cbdd049 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -168,42 +168,21 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid) void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,duplicate=0; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; usleep(1000000 + (rand() % 4000000)); // wait for bettxid to be in mempool - fprintf(stderr,"process Queue dicefinish %s\n",ptr->bettxid.GetHex().c_str()); - for (i=0; ibettxid ) - { - duplicate = 1; - break; - } - if ( duplicate == 0 ) - { - for (i=0; ibettxid; - break; - } - if ( i == MAX_ENTROPYUSED ) - bettxids[rand() % i] = ptr->bettxid; - } unstringbits(name,ptr->sbits); - //fprintf(stderr,"duplicate.%d dicefinish.%d %s funding.%s bet.%s\n",duplicate,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - if ( duplicate == 0 ) - { - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid); - } + fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid); free(ptr); return(0); } void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) { - struct dicefinish_info *ptr; CSpentIndexValue value,value2; + struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) @@ -217,16 +196,33 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) return; } // check for duplicates here!!! - ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); - ptr->fundingtxid = fundingtxid; - ptr->bettxid = bettxid; - ptr->sbits = sbits; - ptr->iswin = iswin; - fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); - if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) + for (i=0; ifundingtxid = fundingtxid; + ptr->bettxid = bettxid; + ptr->sbits = sbits; + ptr->iswin = iswin; + fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); + if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) + { + //fprintf(stderr,"DiceQueue.%d\n",iswin); + } // small memory leak per DiceQueue + } } CPubKey DiceFundingPk(CScript scriptPubKey) @@ -1211,7 +1207,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1232,35 +1228,52 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - CSpentIndexKey key(txid, 0); - CSpentIndexValue value; - CSpentIndexKey key2(txid, 1); - CSpentIndexValue value2; - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) - { - //fprintf(stderr,"status bettxid.%s already spent\n",txid.GetHex().c_str()); - continue; - } - if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; - } - /*bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) - { - DiceQueue(iswin,sbits,fundingtxid,txid); - if ( ++n >= 100 ) + for (i=0; i 0 ) + } + if ( duplicate == 0 ) { - mySenddicetransaction(res,entropyused,txid); - n++; - if ( n >= 100 ) - break; - } else error = res; + for (i=0; i= 100 ) + break; + }*/ + res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + if ( result > 0 ) + { + mySenddicetransaction(res,entropyused,txid); + n++; + if ( n >= 100 ) + break; + } //else error = res; + } } } } From 9c54755c5d487173ac415a84e17b969f742662b0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:25:52 -1100 Subject: [PATCH 070/252] Store betTx --- src/cc/dice.cpp | 56 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 87cbdd049..d11abe234 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -100,15 +100,17 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable +static CTransaction betTxs[MAX_ENTROPYUSED]; struct dicefinish_info { uint256 fundingtxid,bettxid; uint64_t sbits; int32_t iswin; + CTransaction betTx; }; -int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) +int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; if ( entropyused == zeroid || bettxid == zeroid ) @@ -117,6 +119,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid) return(0); } for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( DiceEntropyUsed(entropyused,bettxid) >= 0 ) + if ( DiceEntropyUsed(entropyused,bettxid,betTx) >= 0 ) { LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { RelayTransaction(tx); // check to make sure it got accepted - - for (i=0; i txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -170,24 +171,24 @@ void *dicefinish(void *_ptr) { char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - usleep(1000000 + (rand() % 4000000)); // wait for bettxid to be in mempool + usleep(1000000 + (rand() % 3000000)); // wait for bettxid to be in mempool unstringbits(name,ptr->sbits); fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid); + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); free(ptr); return(0); } -void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) +void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); + //fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); return; } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -215,9 +216,10 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid) ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); ptr->fundingtxid = fundingtxid; ptr->bettxid = bettxid; + ptr->betTx = betTx; ptr->sbits = sbits; ptr->iswin = iswin; - fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); + //fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) { //fprintf(stderr,"DiceQueue.%d\n",iswin); @@ -1121,7 +1123,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( DiceEntropyUsed(entropyused,bettxid) < 0 ) + if ( DiceEntropyUsed(entropyused,bettxid,betTx) < 0 ) { CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1268,7 +1270,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,txid); + mySenddicetransaction(res,entropyused,txid,betTx); n++; if ( n >= 100 ) break; @@ -1309,7 +1311,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid); + mySenddicetransaction(res,entropyused,bettxid,betTx); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From cd5fa72d42cedd2a1dba3fe7106def2e66d02727 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:29:21 -1100 Subject: [PATCH 071/252] Test --- src/cc/dice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d11abe234..7b6bf07e9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -132,15 +132,16 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) entropytxids[i][0] = entropyused; entropytxids[i][1] = bettxid; betTxs[i] = betTx; - return(0); + fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); + return(0); } } i = (rand() % MAX_ENTROPYUSED); - fprintf(stderr,"entropytxids full, pick rand.%d\n",i); entropytxids[i][0] = entropyused; entropytxids[i][1] = bettxid; betTxs[i] = betTx; - return(0); + fprintf(stderr,"added to rand mempool.[%d] and broadcast entropyused.%s bettxid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); + return(0); } bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx) @@ -154,11 +155,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C if ( DiceEntropyUsed(entropyused,bettxid,betTx) >= 0 ) { LOCK(cs_main); + RelayTransaction(tx); if ( myAddtomempool(tx) != 0 ) { - RelayTransaction(tx); - // check to make sure it got accepted - fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> txid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + //RelayTransaction(tx); return(true); } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); @@ -594,7 +594,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) - DiceQueue(iswin,sbits,fundingtxid,txid); + DiceQueue(iswin,sbits,fundingtxid,txid,tx); } break; // make sure all funding txid are from matching sbits and fundingtxid!! From 00f28499e9c80bdf7a53f9ac1967722b96b5387f Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:38:36 -1100 Subject: [PATCH 072/252] Check bettxid in mempool --- src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 22 ++++++++++++++++------ src/rpcblockchain.cpp | 12 ++++++++++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 2a2d41ef0..749d676e9 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -95,6 +95,7 @@ int32_t is_hexstr(char *str,int32_t n); bool myAddtomempool(CTransaction &tx); //uint64_t myGettxout(uint256 hash,int32_t n); bool myIsutxo_spentinmempool(uint256 txid,int32_t vout); +bool mytxid_inmempool(uint256 txid); int32_t myIsutxo_spent(uint256 &spenttxid,uint256 txid,int32_t vout); int32_t decode_hex(uint8_t *bytes,int32_t n,char *hex); int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7b6bf07e9..ae3e90c21 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -169,14 +169,24 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t result; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; - usleep(1000000 + (rand() % 3000000)); // wait for bettxid to be in mempool unstringbits(name,ptr->sbits); - fprintf(stderr,"dicefinish.%d %s funding.%s bet.%s\n",ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + usleep((rand() % 100000) + 10000); + for (i=0; i<600; i++) + { + usleep(100000); + if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + { + fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + break; + } + } + if ( i == 100 ) + fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); } diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 815860c7d..868431f6f 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -378,6 +378,18 @@ bool myIsutxo_spentinmempool(uint256 txid,int32_t vout) return(false); } +bool mytxid_inmempool(uint256 txid) +{ + BOOST_FOREACH(const CTxMemPoolEntry &e,mempool.mapTx) + { + const CTransaction &tx = e.GetTx(); + const uint256 &hash = tx.GetHash(); + if ( txid == hash ) + return(true); + } + return(false); +} + UniValue mempoolToJSON(bool fVerbose = false) { if (fVerbose) From a6b21d0d44c3f9c4efb499050723618883d51534 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 21:58:18 -1100 Subject: [PATCH 073/252] Guard adding to entropyused list --- src/cc/dice.cpp | 51 +++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ae3e90c21..29e9f9985 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -116,7 +116,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) if ( entropyused == zeroid || bettxid == zeroid ) { fprintf(stderr,"null entropyused or bettxid\n"); - return(0); + return(1); } for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( DiceEntropyUsed(entropyused,bettxid,betTx) >= 0 ) + if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) >= 0 ) { + if ( retval == 0 ) + { + for (i=0; i %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); @@ -172,7 +175,7 @@ void *dicefinish(void *_ptr) char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); - usleep((rand() % 100000) + 10000); + usleep((rand() % 1000000) + 100000); for (i=0; i<600; i++) { usleep(100000); @@ -185,7 +188,7 @@ void *dicefinish(void *_ptr) break; } } - if ( i == 100 ) + if ( i == 600 ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); @@ -1082,7 +1085,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); @@ -1133,9 +1136,11 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( DiceEntropyUsed(entropyused,bettxid,betTx) < 0 ) + if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) != 0 ) { - CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; + if ( retval < 0 ) + CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; + else CCerror = "DiceBetFinish: duplicate betTx"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } From e101468702fdb6b84738d4af4961e5a47f8d45b7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:05:51 -1100 Subject: [PATCH 074/252] Test --- src/cc/dice.cpp | 6 +++++- src/main.cpp | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 29e9f9985..4056caa44 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -123,12 +123,16 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) if ( entropytxids[i][0] == entropyused ) { if ( bettxid == entropytxids[i][1] ) + { + fprintf(stderr,"found identical entropy used.%d\n",i); return(i+1); + } fprintf(stderr,"duplicate entropyused %s\n",entropyused.GetHex().c_str()); return(-1); } } - return(0); + fprintf(stderr,"cant find entropy used\n"); + return(0); } bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx) diff --git a/src/main.cpp b/src/main.cpp index 837e380de..1ba872d93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1681,8 +1681,10 @@ bool myAddtomempool(CTransaction &tx) { CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) + { + fprintf(stderr,"call AcceptToMemoryPool\n"); return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); - else return(true); + } else return(true); } bool myGetTransaction(const uint256 &hash, CTransaction &txOut, uint256 &hashBlock) From 4a2e5ecded4bbb09ce4b2a2436a598c4a4184aa8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:17:27 -1100 Subject: [PATCH 075/252] +print --- src/cc/dice.cpp | 2 +- src/main.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4056caa44..8054b798d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -131,7 +131,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) return(-1); } } - fprintf(stderr,"cant find entropy used\n"); + //fprintf(stderr,"cant find entropy used\n"); return(0); } diff --git a/src/main.cpp b/src/main.cpp index 1ba872d93..65b0afa9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1331,7 +1331,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa } auto verifier = libzcash::ProofVerifier::Strict(); - if ( komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && komodo_validate_interest(tx,chainActive.LastTip()->nHeight+1,chainActive.LastTip()->GetMedianTimePast() + 777,0) < 0 ) { //fprintf(stderr,"AcceptToMemoryPool komodo_validate_interest failure\n"); return error("AcceptToMemoryPool: komodo_validate_interest failed"); @@ -1387,7 +1387,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //static uint32_t counter; // Disable replacement feature for now //if ( counter++ < 100 ) - //fprintf(stderr,"Disable replacement feature for now\n"); + fprintf(stderr,"Disable replacement feature for now\n"); return false; } } @@ -1438,7 +1438,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { if (pfMissingInputs) *pfMissingInputs = true; - //fprintf(stderr,"missing inputs\n"); + fprintf(stderr,"missing inputs\n"); return false; } } @@ -1682,7 +1682,7 @@ bool myAddtomempool(CTransaction &tx) CValidationState state; CTransaction Ltx; bool fMissingInputs,fOverrideFees = false; if ( mempool.lookup(tx.GetHash(),Ltx) == 0 ) { - fprintf(stderr,"call AcceptToMemoryPool\n"); + //fprintf(stderr,"call AcceptToMemoryPool\n"); return(AcceptToMemoryPool(mempool, state, tx, false, &fMissingInputs, !fOverrideFees)); } else return(true); } From da58ee102bf32ca1ca019ed6795de5539514ba42 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:34:33 -1100 Subject: [PATCH 076/252] -print --- src/cc/dice.cpp | 29 +++++++++++++---------------- src/main.cpp | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8054b798d..7d297c87a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -127,7 +127,7 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) fprintf(stderr,"found identical entropy used.%d\n",i); return(i+1); } - fprintf(stderr,"duplicate entropyused %s\n",entropyused.GetHex().c_str()); + fprintf(stderr,"duplicate entropyused %s bettxid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); return(-1); } } @@ -145,29 +145,26 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) >= 0 ) { - if ( retval == 0 ) - { - for (i=0; i %s to mempool\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } @@ -176,23 +173,23 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); usleep((rand() % 1000000) + 100000); - for (i=0; i<600; i++) + for (i=0; ibettxid) != 0 ) // wait for bettxid to be in mempool { - fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); break; } } - if ( i == 600 ) + if ( i == maxiters ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); free(ptr); return(0); diff --git a/src/main.cpp b/src/main.cpp index 65b0afa9c..cc69c215b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1387,7 +1387,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa //static uint32_t counter; // Disable replacement feature for now //if ( counter++ < 100 ) - fprintf(stderr,"Disable replacement feature for now\n"); + //fprintf(stderr,"Disable replacement feature for now\n"); return false; } } @@ -1438,7 +1438,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransa { if (pfMissingInputs) *pfMissingInputs = true; - fprintf(stderr,"missing inputs\n"); + //fprintf(stderr,"missing inputs\n"); return false; } } From 1242e65eff39a01c944db3add0410d861dc25766 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:50:13 -1100 Subject: [PATCH 077/252] make unsupported funcid illegal --- src/cc/assets.cpp | 9 +++++++-- src/cc/channels.cpp | 4 ++++ src/cc/dice.cpp | 7 +++++++ src/cc/oracles.cpp | 4 ++++ src/cc/rewards.cpp | 4 ++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index 1ddbdc4f8..b1896ad9c 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -249,8 +249,8 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } fprintf(stderr,"fillbuy validated\n"); break; - case 'e': // selloffer - break; // disable swaps + //case 'e': // selloffer + // break; // disable swaps case 's': // selloffer //vin.0: normal input //vin.1+: valid CC output for sale @@ -322,6 +322,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"fill validated\n"); break; case 'E': // fillexchange + return(false); break; // disable asset swaps //vin.0: normal input //vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0] @@ -371,6 +372,10 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx } fprintf(stderr,"fill validated\n"); break; + default: + fprintf(stderr,"illegal assets funcid.(%c)\n",funcid); + return(false); + break; } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index ec5f7aa9c..7218177d7 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -348,6 +348,10 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("invalid amount, refund amount and funds in channel must match!"); } break; + default: + fprintf(stderr,"illegal channels funcid.(%c)\n",funcid); + return(false); + break; } } retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7d297c87a..8c5640cfd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -685,6 +685,13 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( DiceVerifyTimeout(vinTx,timeoutblocks) == 0 ) return eval->Invalid("invalid timeout claim for timeout"); break; + case 'R': + fprintf(stderr,"add validation for refunds\n"); + break; + default: + fprintf(stderr,"illegal dice funcid.(%c)\n",funcid); + return(false); + break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 524eba9c2..6ee5b2400 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -651,6 +651,10 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; + default: + fprintf(stderr,"illegal oracles funcid.(%c)\n",funcid); + return(false); + break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index e7a3750f3..1f3408252 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -287,6 +287,10 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unlock tx vout.2 isnt 0"); preventCCvouts = 1; break; + default: + fprintf(stderr,"illegal rewards funcid.(%c)\n",funcid); + return(false); + break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); From 69e54d0cfd6761bcca13e6935b1e5c60d5c92a81 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 22:51:55 -1100 Subject: [PATCH 078/252] Syntax --- src/cc/oracles.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 6ee5b2400..0f636551c 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -652,7 +652,7 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; default: - fprintf(stderr,"illegal oracles funcid.(%c)\n",funcid); + fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); return(false); break; } From a9545b529eca0a9cf5b429b6feba1655e35b80b8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:24:27 -1100 Subject: [PATCH 079/252] Issue refund when entropy is compromised --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 53 +++++++++++++++++++++++++--------------- src/wallet/rpcwallet.cpp | 11 +++++++-- 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 0a4cf21ee..47ecd1d88 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); -std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint8_t funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8c5640cfd..293473c4d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -110,9 +110,10 @@ struct dicefinish_info CTransaction betTx; }; -int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) +int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; + oldbettxid = zeroid; if ( entropyused == zeroid || bettxid == zeroid ) { fprintf(stderr,"null entropyused or bettxid\n"); @@ -127,7 +128,9 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) fprintf(stderr,"found identical entropy used.%d\n",i); return(i+1); } - fprintf(stderr,"duplicate entropyused %s bettxid.%s\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); + oldbettxid = entropytxids[i][1]; + oldbetTx = betTxs[i]; + fprintf(stderr,"duplicate entropyused %s oldbettxid.%s\n",entropyused.GetHex().c_str(),oldbettxid.GetHex().c_str()); return(-1); } } @@ -135,15 +138,15 @@ int32_t DiceEntropyUsed(uint256 entropyused,uint256 bettxid,CTransaction betTx) return(0); } -bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx) +bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx,uint8_t funcid) { - CTransaction tx; int32_t i=0,retval; + CTransaction tx; int32_t i=0,retval=-1; uint256 oldbettxid; CTransaction oldBetTx; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) { //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); - if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) >= 0 ) + if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) { LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) @@ -173,7 +176,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; + char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; uint8_t funcid; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); usleep((rand() % 1000000) + 100000); @@ -183,9 +186,9 @@ void *dicefinish(void *_ptr) if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool { //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx); + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); break; } } @@ -1091,11 +1094,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; uint8_t funcid=0; int32_t retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbetxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; + funcid = 0; //char str[65]; fprintf(stderr,"DiceBetFinish.%s %s\n",planstr,uint256_str(str,bettxid)); if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { @@ -1144,11 +1148,19 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( (retval= DiceEntropyUsed(entropyused,bettxid,betTx)) != 0 ) + if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) { if ( retval < 0 ) - CCerror = "possible 51% attack to reveal entropy, need to generate cancel tx with proofs"; - else CCerror = "DiceBetFinish: duplicate betTx"; + { + fprintf(stderr,"orphan that reveals entropy, generate refund tx with proofs\n"); + mtx.vin.push_back(CTxIn(bettxid,0,CScript())); + mtx.vin.push_back(CTxIn(bettxid,1,CScript())); + funcid = 'R'; + mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey)); + mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); + *resultp = 1; + return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,entropyused,oldbettxid))); // need to change opreturn to include oldbetTx to allow validation + } else CCerror = "DiceBetFinish: duplicate betTx"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1232,7 +1244,7 @@ std::string DiceBetFinish(uint256 &entropyused,int32_t *resultp,uint64_t txfee,c double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1283,17 +1295,18 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - /*bettorentropy = DiceGetEntropy(betTx,'B'); + /*following didnt work: + bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { DiceQueue(iswin,sbits,fundingtxid,txid); if ( ++n >= 100 ) break; }*/ - res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,txid,betTx); + mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; if ( n >= 100 ) break; @@ -1330,11 +1343,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); + else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid,betTx); + mySenddicetransaction(res,entropyused,bettxid,betTx,funcid); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 15eb594bd..02d8f36fd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6183,7 +6183,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) UniValue dicefinish(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; + UniValue result(UniValue::VOBJ); uint8_t funcid; char *name; uint256 entropyused,fundingtxid,bettxid; std::string hex; int32_t r; if ( fHelp || params.size() != 3 ) throw runtime_error("dicefinish name fundingtxid bettxid\n"); if ( ensure_CCrequirements() < 0 ) @@ -6197,7 +6197,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(entropyused,&r,0,name,fundingtxid,bettxid,1); + hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1); if ( CCerror != "" ) { ERR_RESULT(CCerror); @@ -6205,6 +6205,13 @@ UniValue dicefinish(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); + if ( funcid != 0 ) + { + char funcidstr[2]; + funcidstr[0] = funcid; + funcidstr[1] = 0; + result.push_back(Pair("funcid", funcidstr)); + } } else ERR_RESULT( "couldnt create dicefinish transaction"); return(result); } From 59921a1d9b6618dd6380b1215d7da9e49792ca93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:27:00 -1100 Subject: [PATCH 080/252] Send 'R' refund tx --- 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 293473c4d..3a4a9ddbc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -164,10 +164,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C entropytxids[i][0] = entropyused; entropytxids[i][1] = bettxid; betTxs[i] = betTx; - fprintf(stderr,"added to mempool.[%d] and broadcast entropyused.%s bettxid.%s\n",i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str()); } + fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); - } else fprintf(stderr,"error adding E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } else fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } From 21eaa7ce8af644507b8d154d6e058e3a92cd5ae9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:28:48 -1100 Subject: [PATCH 081/252] & --- src/cc/CCdice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 47ecd1d88..692d31462 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); -std::string DiceBetFinish(uint8_t funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); From ef8c10382b413e54265a8455b7e634b548e20869 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:30:23 -1100 Subject: [PATCH 082/252] Test --- 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 3a4a9ddbc..2f48330c4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -140,7 +140,7 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,CTransaction betTx,uint8_t funcid) { - CTransaction tx; int32_t i=0,retval=-1; uint256 oldbettxid; CTransaction oldBetTx; + CTransaction tx; int32_t i=0,retval=-1; uint256 oldbettxid; CTransaction oldbetTx; if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { if ( DecodeHexTx(tx,res) != 0 ) @@ -1096,7 +1096,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) { - CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbetxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; + CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; *resultp = 0; funcid = 0; From 0e364b89b1d0fba406c1426960a10c279d140ffa Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:32:50 -1100 Subject: [PATCH 083/252] Use vout2 for refund --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2f48330c4..e57accbae 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1157,6 +1157,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, mtx.vin.push_back(CTxIn(bettxid,1,CScript())); funcid = 'R'; mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey)); + mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); *resultp = 1; return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,entropyused,oldbettxid))); // need to change opreturn to include oldbetTx to allow validation From 154528f0a18d9f3880a688f247912acf248b1e44 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 6 Nov 2018 23:49:41 -1100 Subject: [PATCH 084/252] Test --- src/cc/dice.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e57accbae..046696997 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -176,24 +176,31 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused; uint8_t funcid; + char str[65],str2[65],name[32]; std::string res; int32_t i=0,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); - usleep((rand() % 1000000) + 100000); - for (i=0; ibettxid,betTx,hashBlock,false) == 0 || hashBlock == zeroid ) { - usleep(100000); - if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + usleep((rand() % 1000000) + 100000); + for (i=0; iiswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - break; + usleep(100000); + if ( mytxid_inmempool(ptr->bettxid) != 0 ) // wait for bettxid to be in mempool + { + //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); + break; + } } - } + } else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); if ( i == maxiters ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); + else + { + res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); + if ( result > 0 ) + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + } free(ptr); return(0); } @@ -417,7 +424,7 @@ uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits } else if ( E_UNMARSHAL(vopret,ss >> e; ss >> f; ss >> sbits; ss >> fundingtxid; ss >> hash; ss >> proof) != 0 ) { - if ( e == EVAL_DICE && (f == 'B' || f == 'W' || f == 'L' || f == 'T' || f == 'E') ) + if ( e == EVAL_DICE && (f == 'R' || f == 'B' || f == 'W' || f == 'L' || f == 'T' || f == 'E') ) return(f); else fprintf(stderr,"mismatched e.%02x f.(%c)\n",e,f); } From 86cecf71d1cef43d5223c65e54b67989494d3f87 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:09:14 -1100 Subject: [PATCH 085/252] Test --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 046696997..c96545e7d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -597,7 +597,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { - if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) + //if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; fprintf(stderr,"bidTx.%s\n",uint256_str(str,txid)); From 4148e39f731e500e0dd4d5a182fab5139b64e76d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:29:34 -1100 Subject: [PATCH 086/252] Return eval->error --- src/cc/assets.cpp | 4 ++-- src/cc/channels.cpp | 2 +- src/cc/dice.cpp | 8 ++++---- src/cc/oracles.cpp | 2 +- src/cc/rewards.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index b1896ad9c..a421f9e44 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -322,7 +322,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx fprintf(stderr,"fill validated\n"); break; case 'E': // fillexchange - return(false); + return eval->Invalid("unexpected assets fillexchange funcid"); break; // disable asset swaps //vin.0: normal input //vin.1: unspendable.(vout.0 assetoshis from selloffer) sellTx.vout[0] @@ -374,7 +374,7 @@ bool AssetsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx break; default: fprintf(stderr,"illegal assets funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected assets funcid"); break; } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 7218177d7..4a209fb36 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -350,7 +350,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & break; default: fprintf(stderr,"illegal channels funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected channels funcid"); break; } } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c96545e7d..70f686725 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -597,11 +597,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { - if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) - //if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + //if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) + if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - fprintf(stderr,"bidTx.%s\n",uint256_str(str,txid)); + fprintf(stderr,"betTx.%s\n",uint256_str(str,txid)); fprintf(stderr,"entropyTx.%s v%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n); fprintf(stderr,"entropyTx vin0 %s v%d\n",uint256_str(str,vinTx.vin[0].prevout.hash),(int32_t)vinTx.vin[0].prevout.n); ptr0 = (uint8_t *)vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey.data(); @@ -701,7 +701,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) break; default: fprintf(stderr,"illegal dice funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected dice funcid"); break; } } diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 0f636551c..2955ad6a2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -653,7 +653,7 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t break; default: fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); - return(false); + return eval->Invalid("unexpected OraclesValidate funcid"); break; } } diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 1f3408252..99046e51c 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -289,7 +289,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t break; default: fprintf(stderr,"illegal rewards funcid.(%c)\n",funcid); - return(false); + return eval->Invalid("unexpected rewards funcid"); break; } } From 9bd498e60e9ae82674213ec6ab09b32aa8570121 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:41:45 -1100 Subject: [PATCH 087/252] Revert default case in oracles --- src/cc/dice.cpp | 3 ++- src/cc/oracles.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 70f686725..dbf2fca1e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -801,7 +801,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) { //fprintf(stderr,"check first\n"); - if ( fundingPubKey == tx.vout[1].scriptPubKey ) + if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { @@ -826,6 +826,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } //else fprintf(stderr,"not E or is funding\n"); entropytxid = txid; entropyval = tx.vout[0].nValue; + fprintf(stderr,"entropytxid.%s val %.8f\n",txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 2955ad6a2..89ad89ff2 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -651,10 +651,10 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; - default: - fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); - return eval->Invalid("unexpected OraclesValidate funcid"); - break; + //default: + // fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); + // return eval->Invalid("unexpected OraclesValidate funcid"); + // break; } } return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); From 013c54955c3e562011439f3748dcb414dc568dd4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 00:53:32 -1100 Subject: [PATCH 088/252] Better error checking --- src/cc/channels.cpp | 2 +- src/cc/dice.cpp | 2 +- src/cc/oracles.cpp | 10 +++++----- src/cc/rewards.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 4a209fb36..672e426a8 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -353,7 +353,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & return eval->Invalid("unexpected channels funcid"); break; } - } + } else return eval->Invalid("unexpected channels missing funcid"); retval = PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts); if ( retval != 0 ) fprintf(stderr,"Channel tx validated\n"); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dbf2fca1e..645af3f67 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -704,7 +704,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("unexpected dice funcid"); break; } - } + } else return eval->Invalid("unexpected dice missing funcid"); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } return(true); diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index 89ad89ff2..8fe1fe6d3 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -651,12 +651,12 @@ bool OraclesValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t } return eval->Invalid("unexpected OraclesValidate 'D' tx invalid"); break; - //default: - // fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); - // return eval->Invalid("unexpected OraclesValidate funcid"); - // break; + default: + fprintf(stderr,"illegal oracles funcid.(%c)\n",script[1]); + return eval->Invalid("unexpected OraclesValidate funcid"); + break; } - } + } else return eval->Invalid("unexpected oracles missing funcid"); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } return(true); diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 99046e51c..649a9a9e6 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -292,7 +292,7 @@ bool RewardsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &t return eval->Invalid("unexpected rewards funcid"); break; } - } + } else return eval->Invalid("unexpected rewards missing funcid"); return(PreventCC(eval,tx,preventCCvins,numvins,preventCCvouts,numvouts)); } return(true); From 15e05e69f23441f2cef613908443d6ef0174ee82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:07:07 -1100 Subject: [PATCH 089/252] Fix dicestatus for specific bettxid from dealer node --- 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 645af3f67..203a59395 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -826,7 +826,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } //else fprintf(stderr,"not E or is funding\n"); entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"entropytxid.%s val %.8f\n",txid.GetHex().c_str(),(double)entropyval/COIN); + fprintf(stderr,"first.%d entropytxid.%s val %.8f\n",first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); @@ -1363,7 +1363,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) { - if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) + if ( funcid == 'L' )//betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) //if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) return(0.); else return((double)spenttx.vout[2].nValue/COIN); From 56691a028a3a7f907f34ba48818d3e3d94b0b7ba Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:30:47 -1100 Subject: [PATCH 090/252] test --- 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 203a59395..cebc48d23 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,9 +805,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.isCoinBase() != 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d]\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size()); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),vinTx.isCoinBase()); continue; } if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) From 8858150393daee9f0adf9d75ae8362e1785655f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:33:44 -1100 Subject: [PATCH 091/252] Test --- 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 cebc48d23..6d1b5392b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,9 +805,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.isCoinBase() != 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin[0].prevout.n < 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),vinTx.isCoinBase()); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin[0].prevout.n); continue; } if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) From 6c7532d1ecdb80048f725fbb0709b3dd2ac59b6d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:43:21 -1100 Subject: [PATCH 092/252] Test --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6d1b5392b..06a843483 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -805,11 +805,12 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin[0].prevout.n < 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin[0].prevout.n); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } + printf("vinsize.%d\n",(int32_t)vinTx.vin.size()); if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; From ef17e6579d9844a1d4afd0bfaa6ead6142956ee2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:46:37 -1100 Subject: [PATCH 093/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 06a843483..117de98b9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -803,7 +803,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) + if ( fundingtxid != tx.vin[0].prevout.hash ) { if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) { From dac41d3209fda980b19b6c3e9824fb24d3ec3c20 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:50:08 -1100 Subject: [PATCH 094/252] Test --- src/cc/dice.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 117de98b9..fd9bc37c1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -803,14 +803,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( fundingtxid != tx.vin[0].prevout.hash ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) + { + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); + continue; + } + if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) - { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); - continue; - } - printf("vinsize.%d\n",(int32_t)vinTx.vin.size()); if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; From d16e3918e3485e519aae9becd43df04bb2d70b5a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 01:59:34 -1100 Subject: [PATCH 095/252] Test --- src/cc/dice.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fd9bc37c1..f8cbb74db 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -808,9 +808,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } - if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) + if ( funcid == 'E' ) { - if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; ptr0 = (uint8_t *)vinTx.vout[tx.vin[0].prevout.n].scriptPubKey.data(); @@ -823,7 +823,16 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr," (%c) entropy vin.%d fundingPubKey mismatch %s\n",funcid,tx.vin[0].prevout.n,uint256_str(str,tx.vin[0].prevout.hash)); continue; } - } //else fprintf(stderr,"not E or is funding\n"); + } + else + { + fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n); + if ( vinTx.vin[0].prevout.n < 0 ) + { + fprintf(stderr,"skip coinbase\n"); + continue; + } + } entropytxid = txid; entropyval = tx.vout[0].nValue; fprintf(stderr,"first.%d entropytxid.%s val %.8f\n",first,txid.GetHex().c_str(),(double)entropyval/COIN); From 47ed5efd3380020449526cc62fa2e29fddf587cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 02:06:13 -1100 Subject: [PATCH 096/252] Test --- src/cc/dice.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f8cbb74db..a6a0a4fd1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -469,7 +469,7 @@ int64_t DiceAmounts(uint64_t &inputs,uint64_t &outputs,struct CCcontract_info *c return eval->Invalid("always should find vin, but didnt"); else { - if ( (assetoshis= IsDicevout(cp,vinTx,tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) + if ( (assetoshis= IsDicevout(cp,vinTx,(int32_t)tx.vin[i].prevout.n,refsbits,reffundingtxid)) != 0 ) inputs += assetoshis; } } @@ -587,7 +587,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vin.0, but didnt for bet"); else if ( vinTx.vout[1].scriptPubKey != fundingPubKey ) return eval->Invalid("entropy tx not fundingPubKey for bet"); - else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) + else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) return eval->Invalid("vout[0] != entropy nValue for bet"); else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[1] constrain violation for bet"); @@ -598,7 +598,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { //if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) - if ( vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; fprintf(stderr,"betTx.%s\n",uint256_str(str,txid)); @@ -803,9 +803,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || vinTx.vin.size() == 0 ) + if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || (int32_t)tx.vin[0].prevout.n < 0 ) { - fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); + fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } if ( funcid == 'E' ) @@ -826,8 +826,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } else { - fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n); - if ( vinTx.vin[0].prevout.n < 0 ) + fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); + if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) { fprintf(stderr,"skip coinbase\n"); continue; From a33d12fcbd1e5f6c3761a48972c596529224ae40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 02:09:54 -1100 Subject: [PATCH 097/252] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a6a0a4fd1..1eef3f44f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -826,10 +826,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } else { - fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); + //fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) { - fprintf(stderr,"skip coinbase\n"); + //fprintf(stderr,"skip coinbase\n"); continue; } } @@ -1082,8 +1082,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } 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); + //funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 385f323d76cb5911ab08bc4bc45e09576004cba5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 02:12:05 -1100 Subject: [PATCH 098/252] Test --- 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 1eef3f44f..cefb8a2f8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1082,8 +1082,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; - //funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 77fb34804d56265acec751378c80c5d208349283 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 03:42:31 -1100 Subject: [PATCH 099/252] Test --- src/cc/dice.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cefb8a2f8..76715fc0d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -792,10 +792,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { - if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) + if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { //fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); - if ( funcid != 'F' && funcid != 'T' ) + if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; totalinputs += nValue; if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) @@ -808,6 +808,11 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } + if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) + { + //fprintf(stderr,"skip coinbase\n"); + continue; + } if ( funcid == 'E' ) { if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) @@ -824,18 +829,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit continue; } } - else - { - //fprintf(stderr,"txid.%s vinTx.vin[0].prevout.n %d %d\n",txid.GetHex().c_str(),(int32_t)vinTx.vin[0].prevout.n,(int32_t)vinTx.vin[0].prevout.n < 0); - if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) - { - //fprintf(stderr,"skip coinbase\n"); - continue; - } - } entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"first.%d entropytxid.%s val %.8f\n",first,txid.GetHex().c_str(),(double)entropyval/COIN); + fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); From c68644d19c2ec93686a47eda6953cbfc677f47dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:04:05 -1100 Subject: [PATCH 100/252] Test --- src/cc/dice.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 76715fc0d..228404ad8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -813,19 +813,20 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"skip coinbase\n"); continue; } - if ( funcid == 'E' ) + //if ( funcid == 'E' ) { - if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - ptr0 = (uint8_t *)vinTx.vout[tx.vin[0].prevout.n].scriptPubKey.data(); + ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); ptr1 = (uint8_t *)fundingPubKey.data(); - for (i=0; i Date: Wed, 7 Nov 2018 04:25:53 -1100 Subject: [PATCH 101/252] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 228404ad8..3c17e9b1f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -407,6 +407,8 @@ CScript EncodeDiceOpRet(uint8_t funcid,uint64_t sbits,uint256 fundingtxid,uint25 uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits,uint256 &fundingtxid,uint256 &hash,uint256 &proof) { std::vector vopret; uint8_t *script,e,f,funcid; int64_t minbet,maxbet,maxodds,timeoutblocks; + script = (uint8_t *)scriptPubKey.data(); + fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); GetOpReturnData(scriptPubKey,vopret); if ( vopret.size() > 2 ) { From bcc7be98b14e36877732afaddd66427ca803f2bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:31:57 -1100 Subject: [PATCH 102/252] Test --- 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 3c17e9b1f..142b70e22 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -408,9 +408,9 @@ uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits { std::vector vopret; uint8_t *script,e,f,funcid; int64_t minbet,maxbet,maxodds,timeoutblocks; script = (uint8_t *)scriptPubKey.data(); - fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); + //fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 ) + if ( vopret.size() > 2 && script[0] == 0x6a ) { script = (uint8_t *)vopret.data(); if ( script[0] == EVAL_DICE ) From b14d87fa6bd484e98ae5032bb6426bc506a96dbf Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:44:32 -1100 Subject: [PATCH 103/252] Auto entropy on dealer dice status --- src/cc/dice.cpp | 54 ++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 142b70e22..6001e2702 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -815,22 +815,19 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"skip coinbase\n"); continue; } - //if ( funcid == 'E' ) + //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) + if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { - //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) - if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) - { - uint8_t *ptr0,*ptr1; int32_t i; char str[65]; - ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); - ptr1 = (uint8_t *)fundingPubKey.data(); - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) + { + if ( DecodeHexTx(tx,res) != 0 ) + { + //LOCK(cs_main); + if ( myAddtomempool(tx) != 0 ) + { + fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,mintxs - entropytxs); + RelayTransaction(tx); + } + } + } + } } - }*/ + } return(n); } else From e37833a3444ace90990388491af6e06c0592e73b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 04:52:13 -1100 Subject: [PATCH 104/252] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6001e2702..dbf49ea10 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1040,7 +1040,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 } if ( scriptPubKey == fundingPubKey ) { - if ( AddNormalinputs(mtx,mypk,amount+2*txfee,60) > 0 ) + if ( AddNormalinputs(mtx,mypk,amount+2*txfee,10) > 0 ) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); @@ -1348,9 +1348,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,mintxs - entropytxs); RelayTransaction(tx); - } - } - } + } else break; + } else break; + } else break; } } } From 481667776c79a0af97e90405722637801c643050 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 05:12:01 -1100 Subject: [PATCH 105/252] Test --- src/cc/dice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dbf49ea10..644ddadde 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -590,7 +590,10 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( vinTx.vout[1].scriptPubKey != fundingPubKey ) return eval->Invalid("entropy tx not fundingPubKey for bet"); else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) + { + fprintf(stderr,"prevout.%d %.8f\n",(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); return eval->Invalid("vout[0] != entropy nValue for bet"); + } else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[1] constrain violation for bet"); else if ( tx.vout[2].nValue > txfee+maxodds || tx.vout[2].nValue <= txfee ) From a4cd90f11381a3cf374bc995426108d172c1a2d7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 05:12:54 -1100 Subject: [PATCH 106/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 644ddadde..3be553873 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -591,7 +591,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("entropy tx not fundingPubKey for bet"); else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) { - fprintf(stderr,"prevout.%d %.8f\n",(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); + fprintf(stderr,"%s prevout.%d %.8f\n",tx.vin[0].prevout.hash.GetHex().c_str(),(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); return eval->Invalid("vout[0] != entropy nValue for bet"); } else if ( ConstrainVout(tx.vout[1],1,cp->unspendableCCaddr,0) == 0 ) From ccea0f71143f5fde25f55f52049aa85d2d4fdf2e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 05:20:05 -1100 Subject: [PATCH 107/252] Int64 != int32 --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3be553873..12f4f8dd6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -589,7 +589,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vin.0, but didnt for bet"); else if ( vinTx.vout[1].scriptPubKey != fundingPubKey ) return eval->Invalid("entropy tx not fundingPubKey for bet"); - else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int32_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) + else if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,(int64_t)vinTx.vout[tx.vin[0].prevout.n].nValue) == 0 ) { fprintf(stderr,"%s prevout.%d %.8f\n",tx.vin[0].prevout.hash.GetHex().c_str(),(int32_t)tx.vin[0].prevout.n,(double)vinTx.vout[tx.vin[0].prevout.n].nValue/COIN); return eval->Invalid("vout[0] != entropy nValue for bet"); From b2004c4a6d2e8237fa34d2ccae8043cf8e241bc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:02:23 -1100 Subject: [PATCH 108/252] Test --- src/cc/dice.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 12f4f8dd6..6e7607360 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -407,10 +407,10 @@ CScript EncodeDiceOpRet(uint8_t funcid,uint64_t sbits,uint256 fundingtxid,uint25 uint8_t DecodeDiceOpRet(uint256 txid,const CScript &scriptPubKey,uint64_t &sbits,uint256 &fundingtxid,uint256 &hash,uint256 &proof) { std::vector vopret; uint8_t *script,e,f,funcid; int64_t minbet,maxbet,maxodds,timeoutblocks; - script = (uint8_t *)scriptPubKey.data(); + //script = (uint8_t *)scriptPubKey.data(); //fprintf(stderr,"decode %02x %02x %02x\n",script[0],script[1],script[2]); GetOpReturnData(scriptPubKey,vopret); - if ( vopret.size() > 2 && script[0] == 0x6a ) + if ( vopret.size() > 2 )//&& script[0] == 0x6a ) { script = (uint8_t *)vopret.data(); if ( script[0] == EVAL_DICE ) @@ -792,14 +792,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit vout = (int32_t)it->first.index; if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { - //char str[65],str2[65]; if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { - //fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); + fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; totalinputs += nValue; From 280a6285f9bab3b06c812f1886c7ec89aed57087 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:07:54 -1100 Subject: [PATCH 109/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6e7607360..18a104ff3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -790,6 +790,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } txid = it->first.txhash; vout = (int32_t)it->first.index; + fprintf(stderr,"%d: %s.(%c %.8f) total %.8f\n",n,uint256_str(str,txid),funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN); if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) @@ -798,7 +799,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { - fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid == 'L' || funcid == 'W' || funcid == 'E' ) n++; totalinputs += nValue; From d3738119ee64739a39f4779ffee185db64590e1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:16:25 -1100 Subject: [PATCH 110/252] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 18a104ff3..d57182e14 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -781,6 +781,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit int startfrom = rand()%numtxs; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { + txid = it->first.txhash; + vout = (int32_t)it->first.index; + sum += it->second.satoshis; + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); loops++; if (random) { if ( loops < startfrom ) @@ -788,9 +792,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - txid = it->first.txhash; - vout = (int32_t)it->first.index; - fprintf(stderr,"%d: %s.(%c %.8f) total %.8f\n",n,uint256_str(str,txid),funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN); if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) From 1285c77569d91421faf58a5bf8f281eb6c1a93f9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:17:22 -1100 Subject: [PATCH 111/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d57182e14..f86da8163 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -784,7 +784,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit txid = it->first.txhash; vout = (int32_t)it->first.index; sum += it->second.satoshis; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); loops++; if (random) { if ( loops < startfrom ) @@ -796,6 +795,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) From 9d94f533f41b2c903e7f04bba1503abada4e6096 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:18:31 -1100 Subject: [PATCH 112/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f86da8163..cbc1dec40 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -765,7 +765,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { - char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; From ad92d45ca15985d47c843397ae37164e35918142 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:37:39 -1100 Subject: [PATCH 113/252] test --- 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 cbc1dec40..1331aa4e2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1326,8 +1326,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 100 ) - break; + //if ( n >= 100 ) + // break; } //else error = res; } } From ae262835506b12c6778eccc635d695e864ebb43d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:40:29 -1100 Subject: [PATCH 114/252] Test --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1331aa4e2..77b3d0956 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1283,6 +1283,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { + duplicate = 0; for (i=0; i Date: Wed, 7 Nov 2018 06:40:53 -1100 Subject: [PATCH 115/252] Test --- 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 77b3d0956..7b7f5dc60 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1327,8 +1327,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - //if ( n >= 100 ) - // break; + if ( n >= 100 ) + break; } //else error = res; } } From 853848e0c75c630ae3b2401a32f0f767f901945c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:43:04 -1100 Subject: [PATCH 116/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7b7f5dc60..05e39a900 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1327,7 +1327,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 100 ) + if ( n >= 1000 ) break; } //else error = res; } From 4b586cc17efb4a23baebaaa0c869e9a01c3de374 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 07:03:23 -1100 Subject: [PATCH 117/252] Test --- src/cc/dice.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05e39a900..589a73a17 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -765,7 +765,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbits,struct CCcontract_info *cp,CPubKey dicepk,uint256 reffundingtxid, int32_t &entropytxs,bool random) { - char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0; uint8_t funcid; + char coinaddr[64],str[65]; uint64_t sbits; int64_t nValue,sum,totalinputs = 0; uint256 hash,txid,proof,hashBlock,fundingtxid; CScript fundingPubKey; CTransaction tx,vinTx; int32_t vout,first=0,n=0,i=0,pendingbets=0; uint8_t funcid; std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; @@ -795,7 +795,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + if ( funcid == 'B' ) + pendingbets++; + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) @@ -859,7 +861,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } i = i + 1; } if (!random) { - fprintf(stderr,"numentropy tx %d: %.8f\n",n,(double)totalinputs/COIN); + fprintf(stderr,"pendingbets.%d numentropy tx %d: %.8f\n",pendingbets,n,(double)totalinputs/COIN); entropytxs = n; return(totalinputs); } else { From 80a625e1262119bdb8a7cb54e94bf54b7e7a6108 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 07:56:31 -1100 Subject: [PATCH 118/252] Test --- src/cc/dice.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 589a73a17..98b9d2ec1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -91,6 +91,8 @@ WARNING: there is an attack vector that precludes betting any large amounts, it What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy need to speed up dealer dicestatus loop (or in parallel) + validate refund + change to hashtables */ @@ -796,8 +798,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { if ( funcid == 'B' ) + { pendingbets++; - //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) From 318fa91646f94e808001cb5bc8e1c38325e82a57 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:01:51 -1100 Subject: [PATCH 119/252] Test --- src/cc/dice.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 98b9d2ec1..5e50e5dfc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -780,7 +780,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropyval = 0; int loops = 0; int numtxs = unspentOutputs.size()/2; - int startfrom = rand()%numtxs; + int startfrom = rand() % (numtxs+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; @@ -1289,23 +1289,23 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - duplicate = 0; + /*duplicate = 0; for (i=0; i Date: Wed, 7 Nov 2018 08:02:18 -1100 Subject: [PATCH 120/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5e50e5dfc..c2264e68c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -800,7 +800,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { From 1ca7f316acbde97494b51a629fa5785a780d59a2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:12:10 -1100 Subject: [PATCH 121/252] Test --- src/cc/dice.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c2264e68c..58f26a06b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1289,23 +1289,15 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - /*duplicate = 0; + duplicate = 0; for (i=0; i 0 ) { + for (i=0; i= 1000 ) From 9092cc4b0bd78ac3b7248561b91a50dd3c67d556 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:15:22 -1100 Subject: [PATCH 122/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 58f26a06b..213ac0d1d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1342,7 +1342,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } if ( scriptPubKey == fundingPubKey ) { - CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=5000; + CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < mintxs ) { From 2303eb840af19b0127ac8e059633e09fac87d5d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:24:09 -1100 Subject: [PATCH 123/252] test --- 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 213ac0d1d..18c79ff90 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1290,12 +1290,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { duplicate = 0; - for (i=0; i Date: Wed, 7 Nov 2018 08:27:08 -1100 Subject: [PATCH 124/252] test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 18c79ff90..d35907c09 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 8192 +#define MAX_ENTROPYUSED 512 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable From af49ac2489746db393b9674d0c1585a1bf430b1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:35:57 -1100 Subject: [PATCH 125/252] Test --- 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 d35907c09..135198d0a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 512 +#define MAX_ENTROPYUSED 128 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -1333,7 +1333,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx bettxids[rand() % MAX_ENTROPYUSED] = txid; mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 1000 ) + if ( n >= 100 ) break; } //else error = res; } From b15d0d99b840da16589dfdcd8f125ee5e64df279 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:44:31 -1100 Subject: [PATCH 126/252] Test --- src/cc/dice.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 135198d0a..52cec336a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -223,22 +223,22 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } // check for duplicates here!!! - for (i=0; ifundingtxid = fundingtxid; ptr->bettxid = bettxid; @@ -1323,14 +1323,14 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { - for (i=0; i= 100 ) From bb396525cbebf77697683a870e19b18b7fbab9fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:48:26 -1100 Subject: [PATCH 127/252] Test --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 52cec336a..805a364df 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,6 +121,7 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro fprintf(stderr,"null entropyused or bettxid\n"); return(1); } + return(1); for (i=0; i Date: Wed, 7 Nov 2018 08:54:30 -1100 Subject: [PATCH 128/252] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 805a364df..3b4f9dc08 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,7 +121,7 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro fprintf(stderr,"null entropyused or bettxid\n"); return(1); } - return(1); + return(0); for (i=0; i %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); From 1698dba1f713c433687242b1cafe93de74bebff7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 08:58:43 -1100 Subject: [PATCH 129/252] Test --- 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 3b4f9dc08..691d24d8b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -195,7 +195,7 @@ void *dicefinish(void *_ptr) break; } } - } else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); + } //else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); if ( i == maxiters ) fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); else @@ -801,7 +801,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { From 528ed2ecb68f2c7a0a49f344cb8f0b6164ff7c91 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:01:34 -1100 Subject: [PATCH 130/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 691d24d8b..a732c5e1b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1286,7 +1286,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 3 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { From 1a78c1143700d87ad86cdf2f7d62909e2882a9a4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:10:50 -1100 Subject: [PATCH 131/252] Test --- src/cc/dice.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a732c5e1b..7c1a9890d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,7 +98,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 128 +#define MAX_ENTROPYUSED 1024 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable @@ -154,6 +154,14 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { + for (i=0; i 0 ) { - /*for (i=0; i= 100 ) From 16770709d9ba2de481a2811de049dbafefc09624 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:14:36 -1100 Subject: [PATCH 132/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7c1a9890d..282fe21a1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1334,7 +1334,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { mySenddicetransaction(res,entropyused,txid,betTx,funcid); n++; - if ( n >= 100 ) + if ( n >= 1000 ) break; } //else error = res; } From db555c55f3d017901cebd141dbe3fb4019d173f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:21:24 -1100 Subject: [PATCH 133/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 282fe21a1..365ae2181 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1234,7 +1234,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,56,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,6,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); From a9fef224190a36eb892b9dd88614b3e6688254c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 09:54:07 -1100 Subject: [PATCH 134/252] Test --- 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 365ae2181..bd5c3a185 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -739,7 +739,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK { txid = it->first.txhash; vout = (int32_t)it->first.index; - if ( it->second.satoshis < threshold ) + if ( vout != 0 || it->second.satoshis < threshold ) continue; //fprintf(stderr,"(%s) %s/v%d %.8f\n",coinaddr,uint256_str(str,txid),vout,(double)it->second.satoshis/COIN); for (j=0; jsecond.satoshis; From ec76cfdbd19bf6ff25bff2a1baf2326aeea44b06 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:09:57 -1100 Subject: [PATCH 135/252] Test --- src/cc/dice.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bd5c3a185..4af122da3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1277,7 +1277,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { error = "Diceinit error in status"; @@ -1294,17 +1294,18 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; + sum += it->second.satoshis; if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 3 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { duplicate = 0; - for (i=0; i= 1000 ) break; } //else error = res; } + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } } From 88fadf9a014e39a4c0b6072d8b55c4511fdda271 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:10:39 -1100 Subject: [PATCH 136/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4af122da3..f99741f51 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1340,7 +1340,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx break; } //else error = res; } - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } } From d5749db5e660430ab7950d935eab35a3dbd582a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:23:14 -1100 Subject: [PATCH 137/252] Test --- src/cc/dice.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f99741f51..fc7ffffd6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,7 +121,6 @@ int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entro fprintf(stderr,"null entropyused or bettxid\n"); return(1); } - return(0); for (i=0; i %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); From d3f0b4269dd367d453ccdf27ede86ccadd1ca3af Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 7 Nov 2018 13:30:29 -0800 Subject: [PATCH 138/252] Clean up dicebet/dicestatus error handling and add new macro to make things easier --- src/cc/dice.cpp | 32 +++++++++++++++++--------------- src/wallet/rpcwallet.cpp | 9 +++------ src/wallet/wallet.h | 2 ++ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dbf49ea10..3fe258f54 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1057,24 +1057,26 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 return(""); } -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds, std::string &error) +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds) { CMutableTransaction mtx; CScript fundingPubKey; CPubKey mypk,dicepk; uint64_t sbits,entropyval; int64_t funding,minbet,maxbet,maxodds,timeoutblocks; uint256 entropytxid,entropy,hentropy; struct CCcontract_info *cp,C; if ( bet < 0 ) { - error = "bet must be positive"; + CCerror = "bet must be positive"; return(""); } if ( odds < 2 || odds > 9999 ) { - error = "odds must be between 2 and 9999"; + CCerror = "odds must be between 2 and 9999"; return(""); } - if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { + CCerror = "error in Diceinit"; return(""); + } if ( bet < minbet || bet > maxbet || odds > maxodds ) { - 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); + CCerror = 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; @@ -1083,12 +1085,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { - error = "Your dealer is broke, find a new casino."; + CCerror = "Your dealer is broke, find a new casino."; return(""); } if ( myIsutxo_spentinmempool(entropytxid,0) != 0 ) { - error = "entropy txid is spent"; + CCerror = "entropy txid is spent"; return(""); } mtx.vin.push_back(CTxIn(entropytxid,0,CScript())); @@ -1099,12 +1101,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet mtx.vout.push_back(MakeCC1vout(cp->evalcode,bet,dicepk)); mtx.vout.push_back(CTxOut(txfee+odds,CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG)); return(FinalizeCCTx(0,cp,mtx,mypk,txfee,EncodeDiceOpRet('B',sbits,fundingtxid,entropy,zeroid))); - } else error = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; + } else CCerror = "cant find enough normal inputs for %.8f, plan funding %.8f\n"; } if ( entropyval == 0 && funding != 0 ) - error = "cant find dice entropy inputs"; + CCerror = "cant find dice entropy inputs"; else - error = "cant find dice input"; + CCerror = "cant find dice input"; return(""); } @@ -1257,12 +1259,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return("couldnt find bettx or entropytx"); } -double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error) +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { - error = "Diceinit error in status"; + CCerror = "Diceinit error in status"; return(0.); } fundingpk = DiceFundingPk(fundingPubKey); @@ -1369,7 +1371,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(0.); else return((double)spenttx.vout[2].nValue/COIN); } - error = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); + CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid); return(-1.); } else if ( scriptPubKey == fundingPubKey ) @@ -1389,8 +1391,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else return((double)spenttx.vout[2].nValue/COIN); } else return(0.); } - error = "didnt find dicefinish tx"; - } else error = res; + CCerror = "didnt find dicefinish tx"; + } else CCerror = res; return(-1.); } return(0.); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 02d8f36fd..0a1c04d1e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6168,12 +6168,11 @@ UniValue dicebet(const UniValue& params, bool fHelp) } if (amount > 0 && odds > 0) { hex = DiceBet(0,name,fundingtxid,amount,odds,error); + RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else if ( error[0] != 0 ) { - ERR_RESULT(error); } } else { ERR_RESULT("amount and odds must be positive"); @@ -6235,10 +6234,8 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); winnings = DiceStatus(0,name,fundingtxid,bettxid,error); - if ( error[0] != 0 ) { - ERR_RESULT(error); - return(result); - } + RETURN_IF_ERROR(CCerror); + result.push_back(Pair("result", "success")); if ( winnings >= 0. ) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 70df32bef..67b81ea77 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1208,4 +1208,6 @@ public: /** Error status printout */ #define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); +#define RETURN_IF_ERROR(CCerror) if ( CCerror != "" ) { ERR_RESULT(CCerror); return(result); } + #endif // BITCOIN_WALLET_WALLET_H From 5eda38a264bc83f337f5a17e0fd8e8eb75bc80f3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:48:11 -1100 Subject: [PATCH 139/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 29f8d7539..6d4ea7e90 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -150,7 +150,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) { - LOCK(cs_main); + //LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { for (i=0; i Date: Wed, 7 Nov 2018 10:49:34 -1100 Subject: [PATCH 140/252] Test --- src/wallet/rpcwallet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 0a1c04d1e..f7fad3dc1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6167,7 +6167,7 @@ UniValue dicebet(const UniValue& params, bool fHelp) return(result); } if (amount > 0 && odds > 0) { - hex = DiceBet(0,name,fundingtxid,amount,odds,error); + hex = DiceBet(0,name,fundingtxid,amount,odds); RETURN_IF_ERROR(CCerror); if ( hex.size() > 0 ) { @@ -6233,7 +6233,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) memset(&bettxid,0,sizeof(bettxid)); if ( params.size() == 3 ) bettxid = Parseuint256((char *)params[2].get_str().c_str()); - winnings = DiceStatus(0,name,fundingtxid,bettxid,error); + winnings = DiceStatus(0,name,fundingtxid,bettxid); RETURN_IF_ERROR(CCerror); result.push_back(Pair("result", "success")); From b1c61bbc95b4e51dde2e64dc318959c2755311cd Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 10:52:36 -1100 Subject: [PATCH 141/252] syntax --- src/cc/CCdice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 692d31462..4a848b40f 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -23,9 +23,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); -std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds,std::string &error); +std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); -double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,std::string &error); +double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); UniValue DiceInfo(uint256 diceid); From 1ef2ca6e19c70cc090be60f504ef20f8a5c5337b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 17:55:11 -1100 Subject: [PATCH 142/252] Test --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index f7fad3dc1..b1c27fe2e 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6223,7 +6223,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - //LOCK2(cs_main, pwalletMain->cs_wallet); + LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX)); From e0e3f61f15afd8000783c5b4cca49466b139b948 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 22:19:19 -1100 Subject: [PATCH 143/252] Streamline --- src/cc/dice.cpp | 79 +++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 48 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6d4ea7e90..840f893bd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1150,12 +1150,6 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, winlosetimeout = 0; } } - if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! - { - CCerror = "no txfee inputs for win/lose"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; @@ -1165,7 +1159,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, CSpentIndexValue value2; if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - //CCerror = "bettxid already spent"; + CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } @@ -1178,6 +1172,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } + if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! + { + CCerror = "no txfee inputs for win/lose"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; @@ -1295,54 +1295,37 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( vout != 0 ) + continue; sum += it->second.satoshis; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 3 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - duplicate = 0; - /*for (i=0; i= 100 ) - break; - }*/ - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); - if ( result > 0 ) - { - mySenddicetransaction(res,entropyused,txid,betTx,funcid); - n++; - fprintf(stderr,"send "); - if ( n >= 1000 ) - break; - } //else error = res; + fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); + continue; } - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + /*following didnt work: + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + DiceQueue(iswin,sbits,fundingtxid,txid); + if ( ++n >= 100 ) + break; + }*/ + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + if ( result > 0 ) + { + mySenddicetransaction(res,entropyused,txid,betTx,funcid); + n++; + fprintf(stderr,"send "); + if ( n >= 100 ) + break; + } //else error = res; } + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } if ( scriptPubKey == fundingPubKey ) From 001b6c97098e9c08806035c7dc3b9283e6c0669c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 22:44:34 -1100 Subject: [PATCH 144/252] Test --- src/cc/dice.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 840f893bd..d13707ead 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -101,6 +101,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #define MAX_ENTROPYUSED 1024 extern int32_t KOMODO_INSYNC; + static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; @@ -112,6 +113,12 @@ struct dicefinish_info CTransaction betTx; }; +struct dicebet_info +{ + struct dicebet_info *prev,*next; + struct dicefinish_info D; +}; + int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; @@ -787,12 +794,14 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int numtxs = unspentOutputs.size()/2; + int numtxs = unspentOutputs.size()/8; int startfrom = rand() % (numtxs+1); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { txid = it->first.txhash; vout = (int32_t)it->first.index; + if ( vout != 0 ) + continue; sum += it->second.satoshis; loops++; if (random) { @@ -801,7 +810,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 )//&& myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { From 0fe89bda151c0cebc993b423b6a5e5745e986e77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 22:54:48 -1100 Subject: [PATCH 145/252] Test --- src/cc/dice.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d13707ead..a390835fd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1316,14 +1316,14 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; } - /*following didnt work: - bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) - { - DiceQueue(iswin,sbits,fundingtxid,txid); - if ( ++n >= 100 ) - break; - }*/ + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + fprintf(stderr,"%d: iswin.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + n++; + //DiceQueue(iswin,sbits,fundingtxid,txid); + } + /* res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); if ( result > 0 ) { @@ -1332,9 +1332,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx fprintf(stderr,"send "); if ( n >= 100 ) break; - } //else error = res; + } //else error = res;*/ } - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f\n",n,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } if ( scriptPubKey == fundingPubKey ) From 1903c351c62424ca72f27c84bafaa5362cdd844d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 23:03:24 -1100 Subject: [PATCH 146/252] Test --- src/cc/dice.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a390835fd..f5313c4c6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1287,12 +1287,13 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; return(0.); } + win = loss = 0; fundingpk = DiceFundingPk(fundingPubKey); scriptPubKey = CScript() << ParseHex(HexStr(mypk)) << OP_CHECKSIG; GetCCaddress(cp,coinaddr,dicepk); @@ -1319,7 +1320,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - fprintf(stderr,"%d: iswin.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + if ( iswin > 0 ) + win++; + else if ( iswin < 0 ) + loss++; + fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; //DiceQueue(iswin,sbits,fundingtxid,txid); } @@ -1342,7 +1347,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < mintxs ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From f3a1581fd1178e18989b5c4a6ce6c00d1fc41a31 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:36:36 -1100 Subject: [PATCH 147/252] Add queueing --- src/cc/dice.cpp | 211 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 170 insertions(+), 41 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f5313c4c6..472e0403c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -98,30 +98,33 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" -#define MAX_ENTROPYUSED 1024 +#define MAX_ENTROPYUSED 8192 extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; +pthread_mutex_t DICE_MUTEX,DICEWIN_MUTEX; + +struct dicefinish_utxo { uint256 txid; int32_t vout; }; + struct dicefinish_info { + struct dicefinish_info *prev,*next; + struct dicefinish_utxo vin0; uint256 fundingtxid,bettxid; uint64_t sbits; + int64_t winamount; int32_t iswin; + uint32_t bettxid_ready; CTransaction betTx; -}; - -struct dicebet_info -{ - struct dicebet_info *prev,*next; - struct dicefinish_info D; -}; +} *DICEFINISH_LIST,*DICEWIN_LIST; int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; + return(0); oldbettxid = zeroid; if ( entropyused == zeroid || bettxid == zeroid ) { @@ -191,10 +194,126 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C return(false); } +int32_t _dicehash_find(uint256 bettxid) +{ + for (i=0; i > unspentOutputs; + SetCCunspents(unspentOutputs,coinaddr); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) + { + if ( myIsutxo_spentinmempool(it->first.txhash,utxos[n].vout) == 0 ) + { + if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) + continue; + utxos[n].txid = it->first.txhash; + utxos[n].vout = (int32_t)it->first.index; + if ( ++n >= max ) + break; + } + } + return(n); +} + +void *dicewin(void *_ptr) +{ + char CCaddr[64]; struct CCcontract_info *cp; int32_t n; struct dicefinish_info *ptr,*tmp; + sleep(3); + cp = CCinit(C,EVAL_DICE); + GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); + fprintf(stderr,"start dicewin thread %s\n",CCaddr); + while ( 1 ) + { + n = 0; + DL_FOREACH_SAFE(DICEWIN_LIST,ptr,tmp) + { + DL_DELETE(DICEWIN_LIST,ptr); + free(ptr); + n++; + } + if ( n > 0 ) + fprintf(stderr,"freed %d wins\n",n); + sleep(1); + } +} + void *dicefinish(void *_ptr) { - char str[65],str2[65],name[32]; std::string res; int32_t i=0,result,maxiters=600; struct dicefinish_info *ptr; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - ptr = (struct dicefinish_info *)_ptr; + std::vector mypk; char str[65],str2[65],name[32],coinaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result,maxiters=600; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + sleep(3); + mypk = Mypubkey(); + pubkey2addr(coinaddr,mypk.data()); + fprintf(stderr,"start dicefinish thread %s\n",coinaddr); + while ( 1 ) + { + vins_needed = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + { + if ( ptr->bettxid_ready == 0 ) + { + if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) != 0 && hashBlock != zeroid ) + ptr->bettxid_ready = (uint32_t)time(NULL); + else if ( mytxid_inmempool(ptr->bettxid) != 0 ) + ptr->bettxid_ready = (uint32_t)time(NULL); + } + if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin < 0 ) + vin0_needed++; + } + if ( vin0_needed > 0 ) + { + utxos = calloc(vin0_needed,sizeof(*utxos)); + if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) + { + m = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + { + if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin != 0 ) + { + DL_DELETE(DICEFINISH_LIST,ptr); + if ( ptr->iswin > 0 ) + { + pthread_mutex_lock(&DICEWIN_MUTEX); + DL_APPEND(DICEWIN_LIST,ptr); + pthread_mutex_unlock(&DICEWIN_MUTEX); + fprintf(stderr,"queue win %s %.8f\n",ptr->bettxid.GetHex().c_str(),(double)ptr->winamount/COIN); + } + else + { + ptr->vin0.txid = utxos[m].txid; + ptr->vin0.vout = utxos[m].vout; + fprintf(stderr,"%d of %d process loss using %s/v%d\n",m,n,ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); + free(ptr); + if ( ++m >= n ) + break; + } + } + } + } + free(utxos); + } + usleep(100000); + } + /*ptr = (struct dicefinish_info *)_ptr; unstringbits(name,ptr->sbits); hashBlock = zeroid; if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) == 0 || hashBlock == zeroid ) @@ -218,18 +337,19 @@ void *dicefinish(void *_ptr) if ( result > 0 ) mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); } - free(ptr); + free(ptr);*/ return(0); } void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { + static int32_t didinit; struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - //fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); + fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); return; } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -237,35 +357,44 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",bettxid.GetHex().c_str()); return; } - // check for duplicates here!!! - for (i=0; ifundingtxid = fundingtxid; - ptr->bettxid = bettxid; - ptr->betTx = betTx; - ptr->sbits = sbits; - ptr->iswin = iswin; - //fprintf(stderr,"Queue dicefinish %s\n",bettxid.GetHex().c_str()); - if ( ptr != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,(void *)ptr) != 0 ) + if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicewin,0) != 0 ) { - //fprintf(stderr,"DiceQueue.%d\n",iswin); - } // small memory leak per DiceQueue + pthread_mutex_init(&DICE_MUTEX); + pthread_mutex_init(&DICEWIN_MUTEX); + didinit = 1; + } + else + { + fprintf(stderr,"error launching dicefinish thread\n"); + return; + } } + pthread_mutex_lock(&DICE_MUTEX); + if ( _dicehash_find(bettxid) != 0 ) + { + pthread_mutex_unlock(&DICE_MUTEX); + fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + return; + } + if ( _dicehash_add(bettxid) == 0 ) + { + pthread_mutex_unlock(&DICE_MUTEX); + fprintf(stderr,"DiceQueue status error adding bettxid.%s\n",bettxid.GetHex().c_str()); + return; + } + ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); + ptr->fundingtxid = fundingtxid; + ptr->bettxid = bettxid; + ptr->betTx = betTx; + ptr->sbits = sbits; + ptr->iswin = iswin; + ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->vin0.vout = -1; + DL_APPEND(DICEFINISH_LIST,ptr); + pthread_mutex_unlock(&DICE_MUTEX); + fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } CPubKey DiceFundingPk(CScript scriptPubKey) @@ -1312,11 +1441,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) + /*if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) { fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); continue; - } + }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { @@ -1326,7 +1455,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx loss++; fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; - //DiceQueue(iswin,sbits,fundingtxid,txid); + DiceQueue(iswin,sbits,fundingtxid,txid,betTx); } /* res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); From ef1cd183f209f28ce1a32426bdcdc1042ca11a1b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:39:37 -1100 Subject: [PATCH 148/252] Test --- src/cc/CCinclude.h | 3 +++ src/cc/dice.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 749d676e9..9a1f41b31 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -48,6 +48,8 @@ one other technical note is that komodod has the insight-explorer extensions bui #include #include #include "../komodo_defs.h" +#include "../utlist.h" +#include "../uthash.h" extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; extern uint32_t ASSETCHAINS_CC; @@ -134,6 +136,7 @@ bool IsCCInput(CScript const& scriptSig); int32_t unstringbits(char *buf,uint64_t bits); uint64_t stringbits(char *str); uint256 revuint256(uint256 txid); +bool pubkey2addr(char *destaddr,uint8_t *pubkey33); char *uint256_str(char *dest,uint256 txid); char *pubkey33_str(char *dest,uint8_t *pubkey33); uint256 Parseuint256(char *hexstr); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 472e0403c..d9b214c15 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -196,6 +196,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C int32_t _dicehash_find(uint256 bettxid) { + int32_t i; for (i=0; i Date: Thu, 8 Nov 2018 00:44:49 -1100 Subject: [PATCH 149/252] Test --- src/cc/dice.cpp | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d9b214c15..53c11c75d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -240,7 +240,7 @@ void *dicewin(void *_ptr) { char CCaddr[64]; struct CCcontract_info *cp,C; int32_t n; struct dicefinish_info *ptr,*tmp; sleep(3); - cp = CCinit(C,EVAL_DICE); + cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicewin thread %s\n",CCaddr); while ( 1 ) @@ -267,7 +267,7 @@ void *dicefinish(void *_ptr) fprintf(stderr,"start dicefinish thread %s\n",coinaddr); while ( 1 ) { - vins_needed = 0; + vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { if ( ptr->bettxid_ready == 0 ) @@ -282,7 +282,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { - utxos = calloc(vin0_needed,sizeof(*utxos)); + utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) { m = 0; @@ -362,8 +362,8 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, { if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) != 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicewin,0) != 0 ) { - pthread_mutex_init(&DICE_MUTEX); - pthread_mutex_init(&DICEWIN_MUTEX); + pthread_mutex_init(&DICE_MUTEX,NULL); + pthread_mutex_init(&DICEWIN_MUTEX,NULL); didinit = 1; } else @@ -373,29 +373,21 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, } } pthread_mutex_lock(&DICE_MUTEX); - if ( _dicehash_find(bettxid) != 0 ) + if ( _dicehash_find(bettxid) == 0 ) { - pthread_mutex_unlock(&DICE_MUTEX); - fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); - return; - } - if ( _dicehash_add(bettxid) == 0 ) - { - pthread_mutex_unlock(&DICE_MUTEX); - fprintf(stderr,"DiceQueue status error adding bettxid.%s\n",bettxid.GetHex().c_str()); - return; - } - ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); - ptr->fundingtxid = fundingtxid; - ptr->bettxid = bettxid; - ptr->betTx = betTx; - ptr->sbits = sbits; - ptr->iswin = iswin; - ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); - ptr->vin0.vout = -1; - DL_APPEND(DICEFINISH_LIST,ptr); + _dicehash_add(bettxid); + ptr = (struct dicefinish_info *)calloc(1,sizeof(*ptr)); + ptr->fundingtxid = fundingtxid; + ptr->bettxid = bettxid; + ptr->betTx = betTx; + ptr->sbits = sbits; + ptr->iswin = iswin; + ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->vin0.vout = -1; + DL_APPEND(DICEFINISH_LIST,ptr); + fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); - fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } CPubKey DiceFundingPk(CScript scriptPubKey) @@ -1064,7 +1056,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { struct CCcontract_info *cp; int32_t cmpflag; - cp = CCinit(C,EVAL_DICE); + cp = CCinit(&C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); From f1b829ca29ee5b292748c172325c33a1cab8ce33 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:46:28 -1100 Subject: [PATCH 150/252] Test --- 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 53c11c75d..9c65f26ea 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -345,7 +345,7 @@ void *dicefinish(void *_ptr) void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { static int32_t didinit; - struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; + struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; uint64_t txfee = 10000; CSpentIndexKey key(bettxid, 0); CSpentIndexKey key2(bettxid, 1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) @@ -1056,7 +1056,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,struct CCcontract_info *C,char *planstr,uint64_t &txfee,CPubKey &mypk,CPubKey &dicepk,uint64_t &sbits,int64_t &minbet,int64_t &maxbet,int64_t &maxodds,int64_t &timeoutblocks) { struct CCcontract_info *cp; int32_t cmpflag; - cp = CCinit(&C,EVAL_DICE); + cp = CCinit(C,EVAL_DICE); if ( txfee == 0 ) txfee = 10000; mypk = pubkey2pk(Mypubkey()); From 409b36b5fed41234d9c478928b5c1ca40a9c1536 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:54:17 -1100 Subject: [PATCH 151/252] Test --- src/cc/dice.cpp | 79 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 23 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9c65f26ea..c19fcb9a0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -121,6 +121,61 @@ struct dicefinish_info CTransaction betTx; } *DICEFINISH_LIST,*DICEWIN_LIST; +int32_t _dicehash_find(uint256 bettxid) +{ + int32_t i; + for (i=0; i Date: Thu, 8 Nov 2018 00:55:20 -1100 Subject: [PATCH 152/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c19fcb9a0..326a9612c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1496,7 +1496,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( scriptPubKey == fundingPubKey ) + if ( 0 && scriptPubKey == fundingPubKey ) { CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); From 585306789a39832255cd181a8b4b5d92bfdcaee7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 00:56:24 -1100 Subject: [PATCH 153/252] Test --- src/cc/dice.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 326a9612c..4a7893b2c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -163,17 +163,16 @@ int32_t _dicerevealed_find(uint256 entropyused,uint256 bettxid) void _dicerevealed_add(uint256 entropyused,uint256 bettxid,CTransaction betTx) { int32_t i; + for (i=0; i Date: Thu, 8 Nov 2018 01:00:13 -1100 Subject: [PATCH 154/252] Test --- src/cc/dice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4a7893b2c..1c4a1d903 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -293,7 +293,8 @@ void *dicewin(void *_ptr) void *dicefinish(void *_ptr) { std::vector mypk; char str[65],str2[65],name[32],coinaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result,maxiters=600; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - sleep(3); + fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); + sleep(10); mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); fprintf(stderr,"start dicefinish thread %s\n",coinaddr); @@ -314,6 +315,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { + fprintf(stderr,"vin0_needed.%d\n",vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) { From 76d0c0d0df3b047507e1c2dc504d5a2c9e6d34c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:01:48 -1100 Subject: [PATCH 155/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1c4a1d903..0aac0bfda 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -336,7 +336,7 @@ void *dicefinish(void *_ptr) { ptr->vin0.txid = utxos[m].txid; ptr->vin0.vout = utxos[m].vout; - fprintf(stderr,"%d of %d process loss using %s/v%d\n",m,n,ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); + fprintf(stderr,"%d of %d process loss %s using %s/v%d\n",m,n,ptr->bettxid.GetHex().c_str(),ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); free(ptr); if ( ++m >= n ) break; From 1f51d14dcc472f3b55656b62b555c40015e0e3aa Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:04:01 -1100 Subject: [PATCH 156/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0aac0bfda..8d8f21add 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -255,7 +255,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( myIsutxo_spentinmempool(it->first.txhash,utxos[n].vout) == 0 ) + if ( myIsutxo_spentinmempool(it->first.txhash,(int32_t)it->first.index) == 0 ) { if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) continue; From bf8e5c4189fb8b495d024877b469def847131bf9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:22:08 -1100 Subject: [PATCH 157/252] Test --- src/cc/dice.cpp | 69 +++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8d8f21add..ca146649a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -105,21 +105,20 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; -pthread_mutex_t DICE_MUTEX,DICEWIN_MUTEX; +pthread_mutex_t DICE_MUTEX; struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; - struct dicefinish_utxo vin0; uint256 fundingtxid,bettxid; uint64_t sbits; int64_t winamount; int32_t iswin; uint32_t bettxid_ready; CTransaction betTx; -} *DICEFINISH_LIST,*DICEWIN_LIST; +} *DICEFINISH_LIST; int32_t _dicehash_find(uint256 bettxid) { @@ -268,7 +267,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin return(n); } -void *dicewin(void *_ptr) +/*void *dicewin(void *_ptr) { char CCaddr[64]; struct CCcontract_info *cp,C; int32_t n; struct dicefinish_info *ptr,*tmp; sleep(3); @@ -288,7 +287,7 @@ void *dicewin(void *_ptr) fprintf(stderr,"freed %d wins\n",n); sleep(1); } -} +}*/ void *dicefinish(void *_ptr) { @@ -300,51 +299,42 @@ void *dicefinish(void *_ptr) fprintf(stderr,"start dicefinish thread %s\n",coinaddr); while ( 1 ) { - vin0_needed = 0; - DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + for (iter=-1; iter<=1; iter+=2) { - if ( ptr->bettxid_ready == 0 ) + vin0_needed = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) != 0 && hashBlock != zeroid ) - ptr->bettxid_ready = (uint32_t)time(NULL); - else if ( mytxid_inmempool(ptr->bettxid) != 0 ) - ptr->bettxid_ready = (uint32_t)time(NULL); - } - if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin < 0 ) - vin0_needed++; - } - if ( vin0_needed > 0 ) - { - fprintf(stderr,"vin0_needed.%d\n",vin0_needed); - utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); - if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) - { - m = 0; - DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + if ( ptr->bettxid_ready == 0 ) { - if ( ptr->bettxid_ready != 0 && ptr->vin0.vout < 0 && ptr->iswin != 0 ) + if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) != 0 && hashBlock != zeroid ) + ptr->bettxid_ready = (uint32_t)time(NULL); + else if ( mytxid_inmempool(ptr->bettxid) != 0 ) + ptr->bettxid_ready = (uint32_t)time(NULL); + } + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) + vin0_needed++; + } + if ( vin0_needed > 0 ) + { + fprintf(stderr,"vin0_needed.%d\n",vin0_needed); + utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); + if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) + { + m = 0; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - DL_DELETE(DICEFINISH_LIST,ptr); - if ( ptr->iswin > 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { - pthread_mutex_lock(&DICEWIN_MUTEX); - DL_APPEND(DICEWIN_LIST,ptr); - pthread_mutex_unlock(&DICEWIN_MUTEX); - fprintf(stderr,"queue win %s %.8f\n",ptr->bettxid.GetHex().c_str(),(double)ptr->winamount/COIN); - } - else - { - ptr->vin0.txid = utxos[m].txid; - ptr->vin0.vout = utxos[m].vout; - fprintf(stderr,"%d of %d process loss %s using %s/v%d\n",m,n,ptr->bettxid.GetHex().c_str(),ptr->vin0.txid.GetHex().c_str(),ptr->vin0.vout); + DL_DELETE(DICEFINISH_LIST,ptr); + fprintf(stderr,"%d of %d process %s %s using %s/v%d\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout); free(ptr); if ( ++m >= n ) break; } } } + free(utxos); } - free(utxos); } usleep(100000); } @@ -394,10 +384,9 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, } if ( didinit == 0 ) { - if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 && pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicewin,0) == 0 ) + if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 ) { pthread_mutex_init(&DICE_MUTEX,NULL); - pthread_mutex_init(&DICEWIN_MUTEX,NULL); didinit = 1; } else From f29012df356cc54f4977a45aaa1e0acf11dd1a8f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:24:34 -1100 Subject: [PATCH 158/252] Test --- src/cc/dice.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ca146649a..7a4966441 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -291,12 +291,14 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { - std::vector mypk; char str[65],str2[65],name[32],coinaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result,maxiters=600; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); sleep(10); mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); - fprintf(stderr,"start dicefinish thread %s\n",coinaddr); + cp = CCinit(&C,EVAL_DICE); + GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); + fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); while ( 1 ) { for (iter=-1; iter<=1; iter+=2) @@ -326,7 +328,7 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); - fprintf(stderr,"%d of %d process %s %s using %s/v%d\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout); + fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); free(ptr); if ( ++m >= n ) break; From 83dcf61cd66a430b5aed5eb1a9a0ab7dc561c36a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:24:59 -1100 Subject: [PATCH 159/252] Test --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7a4966441..6892dd16b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -291,7 +291,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,i=0,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); sleep(10); mypk = Mypubkey(); @@ -408,7 +408,6 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); - ptr->vin0.vout = -1; DL_APPEND(DICEFINISH_LIST,ptr); fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); From 2ea2821c6aed53e686ad6075ec08c882f2bda40d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:40:05 -1100 Subject: [PATCH 160/252] Vin0 utxo --- src/cc/CCdice.h | 2 +- src/cc/dice.cpp | 33 +++++++++++++++++++++++---------- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 4a848b40f..bd8d1d5fa 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -24,7 +24,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction &tx); std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet,int32_t odds); -std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout); +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout); double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid); std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks); std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t amount); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6892dd16b..33e4df7d2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -292,7 +292,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - fprintf(stderr,"wait dicefinish thread %s\n",coinaddr); + fprintf(stderr,"wait dicefinish thread\n"); sleep(10); mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); @@ -329,6 +329,11 @@ void *dicefinish(void *_ptr) { DL_DELETE(DICEFINISH_LIST,ptr); fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + unstringbits(name,ptr->sbits); + result = 0; + res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + //if ( result > 0 ) + // mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); free(ptr); if ( ++m >= n ) break; @@ -409,7 +414,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); - fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } @@ -1282,7 +1287,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } -std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout) +std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp,uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid,int32_t winlosetimeout,uint256 vin0txid,int32_t vin0vout) { CMutableTransaction mtx; CScript scriptPubKey,fundingPubKey; CTransaction oldbetTx,betTx,entropyTx; uint256 hentropyproof,entropytxid,hashBlock,bettorentropy,entropy,hentropy,oldbettxid; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int64_t inputs=0,CCchange=0,odds,fundsneeded,minbet,maxbet,maxodds,timeoutblocks; int32_t retval,iswin=0; uint64_t entropyval,sbits; entropyused = zeroid; @@ -1327,11 +1332,19 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } - if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! + if ( vin0txid == zeroid || vin0vout < 0 ) { - CCerror = "no txfee inputs for win/lose"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); + if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! + { + CCerror = "no txfee inputs for win/lose"; + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } + } + else + { + fprintf(stderr,"use vin0 %s/%d\n",vin0txid.GetHex().c_str(),vin0vout); + mtx.vin.push_back(CTxIn(vin0txid,vin0vout,CScript())); } if ( winlosetimeout != 0 ) // dealernode { @@ -1390,7 +1403,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,6,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) > 0 ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); @@ -1530,8 +1543,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(-1.); } else if ( scriptPubKey == fundingPubKey ) - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1); - else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,1,zeroid,-1); + else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0,zeroid,-1); if ( result > 0 ) { mySenddicetransaction(res,entropyused,bettxid,betTx,funcid); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b1c27fe2e..4b5ef8a1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6196,7 +6196,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) } fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); bettxid = Parseuint256((char *)params[2].get_str().c_str()); - hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1); + hex = DiceBetFinish(funcid,entropyused,&r,0,name,fundingtxid,bettxid,1,zeroid,-1); if ( CCerror != "" ) { ERR_RESULT(CCerror); From dae973ae0fba77734c4138e1b4cab28fd5522ab2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 01:58:01 -1100 Subject: [PATCH 161/252] Test --- src/cc/dice.cpp | 97 +++++++++++++++---------------------------------- 1 file changed, 29 insertions(+), 68 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 33e4df7d2..3ce5ec689 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -105,7 +105,7 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; -pthread_mutex_t DICE_MUTEX; +pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; struct dicefinish_utxo { uint256 txid; int32_t vout; }; @@ -141,7 +141,7 @@ void _dicehash_add(uint256 bettxid) bettxids[rand() % MAX_ENTROPYUSED] = bettxid; } -int32_t _dicerevealed_find(uint256 entropyused,uint256 bettxid) +int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) { int32_t i; for (i=0; i %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); @@ -267,28 +240,6 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin return(n); } -/*void *dicewin(void *_ptr) -{ - char CCaddr[64]; struct CCcontract_info *cp,C; int32_t n; struct dicefinish_info *ptr,*tmp; - sleep(3); - cp = CCinit(&C,EVAL_DICE); - GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); - fprintf(stderr,"start dicewin thread %s\n",CCaddr); - while ( 1 ) - { - n = 0; - DL_FOREACH_SAFE(DICEWIN_LIST,ptr,tmp) - { - DL_DELETE(DICEWIN_LIST,ptr); - free(ptr); - n++; - } - if ( n > 0 ) - fprintf(stderr,"freed %d wins\n",n); - sleep(1); - } -}*/ - void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; @@ -318,7 +269,6 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { - fprintf(stderr,"vin0_needed.%d\n",vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) { @@ -332,8 +282,10 @@ void *dicefinish(void *_ptr) unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); - //if ( result > 0 ) + if ( result > 0 ) + { // mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + } else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) break; @@ -394,6 +346,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 ) { pthread_mutex_init(&DICE_MUTEX,NULL); + pthread_mutex_init(&DICEREVEALED_MUTEX,NULL); didinit = 1; } else @@ -1403,16 +1356,24 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, fundsneeded = txfee + (odds+1)*betTx.vout[1].nValue; if ( CCchange >= fundsneeded ) CCchange -= fundsneeded; - else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) > 0 ) + else if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,1,sbits,fundingtxid)) >= fundsneeded ) { if ( inputs > fundsneeded ) CCchange += (inputs - fundsneeded); } else { - CCerror = strprintf("not enough inputs for %.8f\n",(double)fundsneeded/COIN); - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); + if ( (inputs= AddDiceInputs(cp,mtx,dicepk,fundsneeded,60,sbits,fundingtxid)) > 0 ) + { + if ( inputs > fundsneeded ) + CCchange += (inputs - fundsneeded); + } + else + { + CCerror = strprintf("not enough inputs for %.8f\n",(double)fundsneeded/COIN); + fprintf(stderr,"%s\n", CCerror.c_str() ); + return(""); + } } mtx.vout.push_back(MakeCC1vout(cp->evalcode,CCchange,dicepk)); mtx.vout.push_back(CTxOut(txfee,fundingPubKey)); @@ -1551,7 +1512,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) { if ( funcid == 'L' )//betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) //if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) From 2ea6863c0862d0b0e4e6af0e958526d960e2e014 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:06:40 -1100 Subject: [PATCH 162/252] Test --- src/cc/dice.cpp | 53 +++++++++++-------------------------------------- src/main.cpp | 2 +- src/miner.cpp | 2 +- 3 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3ce5ec689..2ef16df7d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -242,9 +242,7 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - fprintf(stderr,"wait dicefinish thread\n"); - sleep(10); + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -252,6 +250,13 @@ void *dicefinish(void *_ptr) fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); while ( 1 ) { + if ( (newht= KOMODO_INSYNC) == 0 || lastheight == newht ) + { + sleep(1); + continue; + } + lastheight = newht; + fprintf(stderr,"process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; @@ -278,14 +283,15 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); - fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { - // mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } else fprintf(stderr,"error doing the dicefinish\n"); + //mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + } + else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) break; @@ -297,31 +303,6 @@ void *dicefinish(void *_ptr) } usleep(100000); } - /*ptr = (struct dicefinish_info *)_ptr; - unstringbits(name,ptr->sbits); - hashBlock = zeroid; - if ( GetTransaction(ptr->bettxid,betTx,hashBlock,false) == 0 || hashBlock == zeroid ) - { - usleep((rand() % 1000000) + 100000); - for (i=0; ibettxid) != 0 ) // wait for bettxid to be in mempool - { - //fprintf(stderr,"i.%d dicefinish.%d %s funding.%s bet.%s\n",i,ptr->iswin,name,uint256_str(str,ptr->fundingtxid),uint256_str(str2,ptr->bettxid)); - break; - } - } - } //else fprintf(stderr,">>>>>>> bettxid already confirmed\n"); - if ( i == maxiters ) - fprintf(stderr,"dicefinish.%d %s bet.%s didnt arrive in mempool\n",ptr->iswin,name,uint256_str(str,ptr->bettxid)); - else - { - res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin); - if ( result > 0 ) - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } - free(ptr);*/ return(0); } @@ -1448,16 +1429,6 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); } - /* - res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); - if ( result > 0 ) - { - mySenddicetransaction(res,entropyused,txid,betTx,funcid); - n++; - fprintf(stderr,"send "); - if ( n >= 100 ) - break; - } //else error = res;*/ } } } diff --git a/src/main.cpp b/src/main.cpp index cc69c215b..115920264 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3582,7 +3582,7 @@ bool static ConnectTip(CValidationState &state, CBlockIndex *pindexNew, CBlock * LogPrint("bench", " - Connect postprocess: %.2fms [%.2fs]\n", (nTime6 - nTime5) * 0.001, nTimePostConnect * 0.000001); LogPrint("bench", "- Connect block: %.2fms [%.2fs]\n", (nTime6 - nTime1) * 0.001, nTimeTotal * 0.000001); if ( KOMODO_LONGESTCHAIN != 0 && pindexNew->nHeight >= KOMODO_LONGESTCHAIN ) - KOMODO_INSYNC = 1; + KOMODO_INSYNC = (int32_t)pindexNew->nHeight; else KOMODO_INSYNC = 0; //fprintf(stderr,"connect.%d insync.%d\n",(int32_t)pindexNew->nHeight,KOMODO_INSYNC); if ( ASSETCHAINS_SYMBOL[0] == 0 && KOMODO_INSYNC != 0 ) diff --git a/src/miner.cpp b/src/miner.cpp index ee3f7e680..3b245b286 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -940,7 +940,7 @@ void static BitcoinMiner() { fprintf(stderr,"Mining when blockchain might not be in sync longest.%d vs %d\n",KOMODO_LONGESTCHAIN,Mining_height); if ( KOMODO_LONGESTCHAIN != 0 && Mining_height >= KOMODO_LONGESTCHAIN ) - KOMODO_INSYNC = 1; + KOMODO_INSYNC = Mining_height; sleep(3); } // Hash state From 25ccf7fb27223a587ee9e059735a3b88569c7496 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:18:33 -1100 Subject: [PATCH 163/252] Test --- src/cc/dice.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2ef16df7d..bf5b9f332 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -220,9 +220,10 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C return(false); } -int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coinaddr) +int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t max,char *coinaddr) { int32_t n = 0; int64_t threshold = 2 * 10000; + total = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) @@ -231,18 +232,25 @@ int32_t dicefinish_utxosget(struct dicefinish_utxo *utxos,int32_t max,char *coin { if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) continue; - utxos[n].txid = it->first.txhash; - utxos[n].vout = (int32_t)it->first.index; - if ( ++n >= max ) - break; + total++; + if ( n < max ) + { + if ( utxos != 0 ) + { + utxos[n].txid = it->first.txhash; + utxos[n].vout = (int32_t)it->first.index; + } + n++; + } } } + total -= n; return(n); } void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -275,7 +283,7 @@ void *dicefinish(void *_ptr) if ( vin0_needed > 0 ) { utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); - if ( (n= dicefinish_utxosget(utxos,vin0_needed,coinaddr)) > 0 ) + if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) @@ -902,7 +910,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { @@ -1432,7 +1440,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } } } - if ( 0 && scriptPubKey == fundingPubKey ) + if ( scriptPubKey == fundingPubKey ) { CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); @@ -1455,6 +1463,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else break; } } + pubkey2addr(coinaddr,mypk.data()); + dicefinish_utxosget(entropytx,0,0,coinaddr); + if ( entropytx < mintxs ) + { + fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytx); + } } return(n); } From e1d687adf1df4843b61bed92b5ae223b06753ee0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:19:28 -1100 Subject: [PATCH 164/252] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bf5b9f332..a7af1cc3b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1463,9 +1463,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else break; } } - pubkey2addr(coinaddr,mypk.data()); - dicefinish_utxosget(entropytx,0,0,coinaddr); - if ( entropytx < mintxs ) + pubkey2addr(coinaddr,mypk.ptr()); + dicefinish_utxosget(entropytxs,0,0,coinaddr); + if ( entropytxs < mintxs ) { fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytx); } From f8f1896625e6ac35341b0300420eecfbebbfd4ca Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:20:12 -1100 Subject: [PATCH 165/252] Test --- 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 a7af1cc3b..ad0592870 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1463,11 +1463,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else break; } } - pubkey2addr(coinaddr,mypk.ptr()); + pubkey2addr(coinaddr,Mypubkey().data()); dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytx); + fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytxs); } } return(n); From 2c467cf6e9ea743edf2ef6e48ca9bbfffcd5755f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:23:46 -1100 Subject: [PATCH 166/252] Test --- src/cc/dice.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ad0592870..203f2d2a5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -291,15 +291,14 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); - //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); unstringbits(name,ptr->sbits); result = 0; res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { + fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); //mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } - else fprintf(stderr,"error doing the dicefinish\n"); + } else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) break; @@ -1285,7 +1284,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, } else { - fprintf(stderr,"use vin0 %s/%d\n",vin0txid.GetHex().c_str(),vin0vout); + //fprintf(stderr,"use vin0 %s/%d\n",vin0txid.GetHex().c_str(),vin0vout); mtx.vin.push_back(CTxIn(vin0txid,vin0vout,CScript())); } if ( winlosetimeout != 0 ) // dealernode @@ -1421,11 +1420,6 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - /*if ( myIsutxo_spentinmempool(txid,0) != 0 || myIsutxo_spentinmempool(txid,1) != 0 ) - { - fprintf(stderr,"status bettxid.%s already spent in mempool\n",txid.GetHex().c_str()); - continue; - }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { From 02e4584f809a94d1bd8e3192e800937b03a15150 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:24:08 -1100 Subject: [PATCH 167/252] Test --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 203f2d2a5..bcee97b0a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -256,6 +256,7 @@ void *dicefinish(void *_ptr) cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); + sleep(10); while ( 1 ) { if ( (newht= KOMODO_INSYNC) == 0 || lastheight == newht ) From 09c4edb1c3e51b335f224d280f72e41dc2a1546b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:30:00 -1100 Subject: [PATCH 168/252] Test --- src/cc/dice.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index bcee97b0a..685c80ccc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -256,14 +256,11 @@ void *dicefinish(void *_ptr) cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); + while ( (newht= KOMODO_INSYNC) == 0 ) + sleep(1); sleep(10); while ( 1 ) { - if ( (newht= KOMODO_INSYNC) == 0 || lastheight == newht ) - { - sleep(1); - continue; - } lastheight = newht; fprintf(stderr,"process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) @@ -309,7 +306,11 @@ void *dicefinish(void *_ptr) free(utxos); } } - usleep(100000); + while ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) + { + sleep(1); + continue; + } } return(0); } From 8cf8f3688c939cc2377f864f3e84179d085abf97 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:35:03 -1100 Subject: [PATCH 169/252] Test --- src/cc/dice.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 685c80ccc..3dee0a31d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,6 +268,13 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { + if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + { + fprintf(stderr,"dicefinish loop bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + continue; + } if ( ptr->bettxid_ready == 0 ) { if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) != 0 && hashBlock != zeroid ) @@ -286,6 +293,13 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { + if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + { + fprintf(stderr,"dicefinish loop2 bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + continue; + } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { DL_DELETE(DICEFINISH_LIST,ptr); @@ -904,7 +918,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 )//&& myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { From 9d5b969fd6b9e8e9d01de5902970fa7e7437f32a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:46:16 -1100 Subject: [PATCH 170/252] Test --- src/cc/dice.cpp | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 40 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 3dee0a31d..01ed33085 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -248,9 +248,28 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t return(n); } +int32_t dice_betspent(char *debugstr,uint256 bettxid) +{ + CSpentIndexValue value,value2; + CSpentIndexKey key(bettxid,0); + CSpentIndexKey key2(bettxid,1); + if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + { + fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + return(-1); + } + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + { + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); + return(-1); + } + return(0); +} + void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; + mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -268,9 +287,8 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + if ( dice_betspent("dicefinish loop",ptr->bettxid) < 0 ) { - fprintf(stderr,"dicefinish loop bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); continue; @@ -293,9 +311,8 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( myIsutxo_spentinmempool(ptr->bettxid,0) != 0 || myIsutxo_spentinmempool(ptr->bettxid,1) != 0 ) + if ( dice_betspent("dicefinish loop2",ptr->bettxid) < 0 ) { - fprintf(stderr,"dicefinish loop2 bettxid.%s already spent in mempool\n",ptr->bettxid.GetHex().c_str()); DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); continue; @@ -332,19 +349,7 @@ void *dicefinish(void *_ptr) void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,CTransaction betTx) { static int32_t didinit; - struct dicefinish_info *ptr; CSpentIndexValue value,value2; int32_t i,duplicate=0; uint64_t txfee = 10000; - CSpentIndexKey key(bettxid, 0); - CSpentIndexKey key2(bettxid, 1); - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) - { - fprintf(stderr,"DiceQueue status bettxid.%s already spent\n",bettxid.GetHex().c_str()); - return; - } - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) - { - fprintf(stderr,"DiceQueue status bettxid.%s already spent in mempool\n",bettxid.GetHex().c_str()); - return; - } + struct dicefinish_info *ptr; int32_t i,duplicate=0; uint64_t txfee = 10000; if ( didinit == 0 ) { if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dicefinish,0) == 0 ) @@ -359,6 +364,8 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } + if ( dice_betspent("DiceQueue",ptr->bettxid) < 0 ) + return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) { @@ -861,7 +868,7 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK break; if ( j != mtx.vin.size() ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { @@ -894,7 +901,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit std::vector > unspentOutputs; entropyval = 0; entropytxid = zeroid; - if ( GetTransaction(reffundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) + if ( myGetTransaction(reffundingtxid,tx,hashBlock) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) != 0 ) { fundingPubKey = tx.vout[1].scriptPubKey; } else return(0); @@ -918,7 +925,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( (rand() % 100) < 90 ) continue; } - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) { if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) { @@ -939,7 +946,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //fprintf(stderr,"check first\n"); if ( tx.vout.size() > 1 && fundingPubKey == tx.vout[1].scriptPubKey ) { - if ( GetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock,false) == 0 || (int32_t)tx.vin[0].prevout.n < 0 ) + if ( myGetTransaction(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 || (int32_t)tx.vin[0].prevout.n < 0 ) { fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; @@ -1007,7 +1014,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac if ( fundingtxid != zeroid ) // avoid scan unless creating new funding plan { //fprintf(stderr,"check fundingtxid\n"); - if ( GetTransaction(fundingtxid,tx,hashBlock,false) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) + if ( myGetTransaction(fundingtxid,tx,hashBlock) != 0 && tx.vout.size() > 1 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { @@ -1023,7 +1030,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac txid = it->first.txhash; if ( fundingtxid != zeroid && txid != fundingtxid ) continue; - if ( GetTransaction(txid,tx,hashBlock,false) != 0 && tx.vout.size() > 0 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) + if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout.size() > 0 && ConstrainVout(tx.vout[0],1,CCaddr,0) != 0 ) { if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' ) { @@ -1062,7 +1069,7 @@ struct CCcontract_info *Diceinit(CScript &fundingPubKey,uint256 reffundingtxid,s UniValue DiceInfo(uint256 diceid) { UniValue result(UniValue::VOBJ); CPubKey dicepk; uint256 hashBlock,entropytxid; CTransaction vintx; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t sbits,funding,entropyval; char str[67],numstr[65]; struct CCcontract_info *cp,C; - if ( GetTransaction(diceid,vintx,hashBlock,false) == 0 ) + if ( myGetTransaction(diceid,vintx,hashBlock) == 0 ) { fprintf(stderr,"cant find fundingtxid\n"); ERR_RESULT("cant find fundingtxid"); @@ -1103,7 +1110,7 @@ UniValue DiceList() for (std::vector >::const_iterator it=addressIndex.begin(); it!=addressIndex.end(); it++) { txid = it->first.txhash; - if ( GetTransaction(txid,vintx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,vintx,hashBlock) != 0 ) { if ( vintx.vout.size() > 0 && DecodeDiceFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) != 0 ) { @@ -1267,14 +1274,10 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, winlosetimeout = 0; } } - if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - CSpentIndexKey key(bettxid, 0); - CSpentIndexValue value; - CSpentIndexKey key2(bettxid, 1); - CSpentIndexValue value2; - if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) + if ( dice_betspent("DiceBetFinish",bettxid) < 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1283,12 +1286,6 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) - { - CCerror = "bettxid already spent in mempool"; - fprintf(stderr,"%s\n", CCerror.c_str() ); - return(""); - } if ( vin0txid == zeroid || vin0vout < 0 ) { if ( AddNormalinputs(mtx,mypk,2*txfee,1) == 0 ) // must be a single vin!! @@ -1432,7 +1429,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( vout != 0 ) continue; sum += it->second.satoshis; - if ( GetTransaction(txid,betTx,hashBlock,false) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && GetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock,false) != 0 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { @@ -1488,7 +1485,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { //fprintf(stderr,"bettx is spent\n"); - if ( GetTransaction(bettxid,betTx,hashBlock,false) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() > 2 ) + if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() > 2 ) { //fprintf(stderr,"found spenttxid %s\n",uint256_str(str,spenttxid)); if ( betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) @@ -1507,7 +1504,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { - if ( myGetTransaction(txid,betTx,hashBlock) != 0 && GetTransaction(spenttxid,spenttx,hashBlock,false) != 0 && spenttx.vout.size() >= 2 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && myGetTransaction(spenttxid,spenttx,hashBlock) != 0 && spenttx.vout.size() >= 2 ) { if ( funcid == 'L' )//betTx.vout[1].scriptPubKey.IsPayToCryptoCondition() == 0 || betTx.vout[2].scriptPubKey.IsPayToCryptoCondition() != 0 || spenttx.vout[2].scriptPubKey != betTx.vout[2].scriptPubKey ) //if ( spenttx.vout[2].scriptPubKey == fundingPubKey || ((uint8_t *)spenttx.vout[2].scriptPubKey.data())[0] == 0x6a ) From 4a957f42ff6b795ac3ef9e095bf0a21526751383 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:47:42 -1100 Subject: [PATCH 171/252] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 01ed33085..e79150208 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -287,7 +287,7 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent("dicefinish loop",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) < 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); @@ -311,7 +311,7 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent("dicefinish loop2",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) < 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); @@ -364,7 +364,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent("DiceQueue",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"DiceQueue",ptr->bettxid) < 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1277,7 +1277,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent("DiceBetFinish",bettxid) < 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid) < 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From d1df996b5373080b0e310aad2eba78e2cf4109e9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:49:20 -1100 Subject: [PATCH 172/252] Fix --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e79150208..9c1452da4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -364,7 +364,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) < 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) From 2ca168e4e61a2721e3afe9f2ecfdb7bbc960e783 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 02:50:57 -1100 Subject: [PATCH 173/252] Test --- 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 9c1452da4..1656aa4e4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -325,8 +325,8 @@ void *dicefinish(void *_ptr) res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { - fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - //mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); + //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); } else fprintf(stderr,"error doing the dicefinish\n"); free(ptr); if ( ++m >= n ) From 9f5075e53dc17023ef8e552be0f606a620b493a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:09:51 -1100 Subject: [PATCH 174/252] Test --- src/cc/dice.cpp | 55 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1656aa4e4..4cd22742e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -112,12 +112,14 @@ struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; - uint256 fundingtxid,bettxid; + uint256 fundingtxid,bettxid,entropyused; uint64_t sbits; int64_t winamount; int32_t iswin; uint32_t bettxid_ready; CTransaction betTx; + std::string rawtx; + uint8_t funcid; } *DICEFINISH_LIST; int32_t _dicehash_find(uint256 bettxid) @@ -210,10 +212,17 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C pthread_mutex_lock(&DICEREVEALED_MUTEX); _dicerevealed_add(entropyused,bettxid,betTx); pthread_mutex_unlock(&DICEREVEALED_MUTEX); + fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } - fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + return(true); - } else fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } + else + { + ptr->rawtx.clear(); + fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); + } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); } @@ -256,7 +265,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); - return(-1); + return(1); } if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { @@ -268,8 +277,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 entropyused,hashBlock; uint8_t funcid; CTransaction betTx; - + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -281,13 +289,13 @@ void *dicefinish(void *_ptr) while ( 1 ) { lastheight = newht; - fprintf(stderr,"process ht.%d\n",newht); + fprintf(stderr,"dicefinish process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) > 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); @@ -301,7 +309,12 @@ void *dicefinish(void *_ptr) ptr->bettxid_ready = (uint32_t)time(NULL); } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) - vin0_needed++; + { + if ( ptr->rawtx.size() > 0 ) + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + if ( ptr->rawtx.size() == 0 ) + vin0_needed++; + } } if ( vin0_needed > 0 ) { @@ -311,24 +324,28 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) < 0 ) + if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) > 0 ) { DL_DELETE(DICEFINISH_LIST,ptr); free(ptr); continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) { - DL_DELETE(DICEFINISH_LIST,ptr); unstringbits(name,ptr->sbits); result = 0; - res = DiceBetFinish(funcid,entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); + res = DiceBetFinish(ptr->funcid,ptr->entropyused,&result,0,name,ptr->fundingtxid,ptr->bettxid,ptr->iswin,utxos[m].txid,utxos[m].vout); if ( result > 0 ) { - //fprintf(stderr,"%d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - mySenddicetransaction(res,entropyused,ptr->bettxid,ptr->betTx,funcid); - } else fprintf(stderr,"error doing the dicefinish\n"); - free(ptr); + ptr->rawtx = res; + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + } + else + { + fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + } if ( ++m >= n ) break; } @@ -364,7 +381,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) < 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1277,7 +1294,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid) < 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 7393776cddf1a241d757310b4807227fa4286de9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:21:59 -1100 Subject: [PATCH 175/252] Test --- src/cc/dice.cpp | 58 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4cd22742e..b849a5c1e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -145,16 +145,26 @@ void _dicehash_add(uint256 bettxid) int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) { - int32_t i; + int32_t i; struct dicefinish_info *ptr,*tmp; + DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) + { + if ( ptr->entropyused == entropyused ) + { + if ( ptr->bettxid == bettxid ) + return(i+1); + fprintf(stderr,"found identical entropy used.%d different bettxid!\n",i); + oldbettxid = ptr->bettxid; + oldbetTx = ptr->betTx; + return(-1); + } + } for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -209,9 +219,14 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C RelayTransaction(tx); if ( retval == 0 ) { - pthread_mutex_lock(&DICEREVEALED_MUTEX); - _dicerevealed_add(entropyused,bettxid,betTx); - pthread_mutex_unlock(&DICEREVEALED_MUTEX); + if ( ptr != 0 ) + ptr->revealed = (uint32_t)time(NULL); + else + { + pthread_mutex_lock(&DICEREVEALED_MUTEX); + _dicerevealed_add(entropyused,bettxid,betTx); + pthread_mutex_unlock(&DICEREVEALED_MUTEX); + } fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -297,8 +312,12 @@ void *dicefinish(void *_ptr) { if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) > 0 ) { - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) + { + fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + } continue; } if ( ptr->bettxid_ready == 0 ) @@ -311,7 +330,7 @@ void *dicefinish(void *_ptr) if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( ptr->rawtx.size() > 0 ) - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); if ( ptr->rawtx.size() == 0 ) vin0_needed++; } @@ -326,8 +345,12 @@ void *dicefinish(void *_ptr) { if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) > 0 ) { - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) + { + fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + } continue; } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) @@ -338,13 +361,14 @@ void *dicefinish(void *_ptr) if ( result > 0 ) { ptr->rawtx = res; - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid); + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + ptr->rawtx.clear(); + //DL_DELETE(DICEFINISH_LIST,ptr); + //free(ptr); } if ( ++m >= n ) break; @@ -1517,7 +1541,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx else res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,bettxid,0,zeroid,-1); if ( result > 0 ) { - mySenddicetransaction(res,entropyused,bettxid,betTx,funcid); + mySenddicetransaction(res,entropyused,bettxid,betTx,funcid,0); sleep(1); if ( (vout= myIsutxo_spent(spenttxid,bettxid,1)) >= 0 ) { From 52e473dd6cd8a793c1b074109edbe06a0f2aba21 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:22:37 -1100 Subject: [PATCH 176/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b849a5c1e..c115c7af3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -116,7 +116,7 @@ struct dicefinish_info uint64_t sbits; int64_t winamount; int32_t iswin; - uint32_t bettxid_ready; + uint32_t bettxid_ready,revealed; CTransaction betTx; std::string rawtx; uint8_t funcid; From 79e277533ab4ea83024ebc8234624f119bae4d74 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:24:48 -1100 Subject: [PATCH 177/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c115c7af3..17da7d110 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -405,7 +405,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) > 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) From 6f67a6c3b14ebc590f782e1faae5e1b6c985cc63 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:27:24 -1100 Subject: [PATCH 178/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 17da7d110..c013908a2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1318,7 +1318,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid) != 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid) > 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 17e9e78da657cc2a42c1f26ca3ae2c238f0a616d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:33:05 -1100 Subject: [PATCH 179/252] Test --- src/cc/dice.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c013908a2..5616f2b83 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -272,20 +272,33 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t return(n); } -int32_t dice_betspent(char *debugstr,uint256 bettxid) +int32_t dice_betspent(char *debugstr,uint256 bettxid,int32_t mode) { - CSpentIndexValue value,value2; + int32_t numblocks; + /*CSpentIndexValue value,value2; CSpentIndexKey key(bettxid,0); CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); - } - if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + }*/ + if ( mode > 0 ) { - fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); - return(-1); + CCduration(numblocks,bettxid); + if ( numblocks > 0 ) + { + fprintf(stderr,"%s bettxid.%s already confirmed %d\n",debugstr,bettxid.GetHex().c_str(),numblocks); + return(1); + } + } + else + { + if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) + { + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); + return(-1); + } } return(0); } @@ -310,7 +323,7 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid) > 0 ) + if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid,1) > 0 ) { if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { @@ -343,7 +356,7 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid) > 0 ) + if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid,1) != 0 ) { if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { @@ -405,7 +418,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) > 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid,1) != 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1318,7 +1331,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid) > 0 ) + if ( dice_betspent((char *)"DiceBetFinish",bettxid,1) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); From 2874830f6e094b9e92cdbaa6c30d478f139fabc8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:41:41 -1100 Subject: [PATCH 180/252] Test --- src/cc/dice.cpp | 54 ++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5616f2b83..500621b6f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -112,7 +112,7 @@ struct dicefinish_utxo { uint256 txid; int32_t vout; }; struct dicefinish_info { struct dicefinish_info *prev,*next; - uint256 fundingtxid,bettxid,entropyused; + uint256 fundingtxid,bettxid,entropyused,txid; uint64_t sbits; int64_t winamount; int32_t iswin; @@ -210,6 +210,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C { if ( DecodeHexTx(tx,res) != 0 ) { + if ( ptr != 0 ) + ptr->txid = tx.GetHash(); //fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash())); if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) >= 0 ) { @@ -236,6 +238,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C else { ptr->rawtx.clear(); + ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); @@ -272,31 +275,31 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t return(n); } -int32_t dice_betspent(char *debugstr,uint256 bettxid,int32_t mode) +int32_t dice_betspent(char *debugstr,uint256 bettxid) { - int32_t numblocks; + /*int32_t numblocks; /*CSpentIndexValue value,value2; - CSpentIndexKey key(bettxid,0); - CSpentIndexKey key2(bettxid,1); + CSpentIndexKey key(txid,0); + CSpentIndexKey key2(txid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s bettxid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + fprintf(stderr,"%s txid.%s already spent\n",debugstr,txid.GetHex().c_str()); return(1); - }*/ + } if ( mode > 0 ) { - CCduration(numblocks,bettxid); + CCduration(numblocks,txid); if ( numblocks > 0 ) { - fprintf(stderr,"%s bettxid.%s already confirmed %d\n",debugstr,bettxid.GetHex().c_str(),numblocks); + fprintf(stderr,"%s txid.%s already confirmed %d\n",debugstr,txid.GetHex().c_str(),numblocks); return(1); } } - else + else*/ { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,txid.GetHex().c_str()); return(-1); } } @@ -323,14 +326,11 @@ void *dicefinish(void *_ptr) vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop",ptr->bettxid,1) > 0 ) + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { - if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) - { - fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); - } + fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); continue; } if ( ptr->bettxid_ready == 0 ) @@ -356,14 +356,11 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( dice_betspent((char *)"dicefinish loop2",ptr->bettxid,1) != 0 ) + if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { - if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) - { - fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); - } + fprintf(stderr,"purge2 %s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); continue; } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) @@ -380,6 +377,7 @@ void *dicefinish(void *_ptr) { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); ptr->rawtx.clear(); + ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); //free(ptr); } @@ -418,7 +416,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid,1) != 0 ) + if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) @@ -1331,12 +1329,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( myGetTransaction(bettxid,betTx,hashBlock) != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { entropytxid = betTx.vin[0].prevout.hash; - if ( dice_betspent((char *)"DiceBetFinish",bettxid,1) != 0 ) + /*if ( dice_betspent((char *)"DiceBetFinish",bettxid) != 0 ) { CCerror = "bettxid already spent"; fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); - } + }*/ bettorentropy = DiceGetEntropy(betTx,'B'); if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { From 0cc5c16676af6dd418508c214d2d0ca650cbadba Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:42:16 -1100 Subject: [PATCH 181/252] Fix --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 500621b6f..877430a81 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -299,7 +299,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) { if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { - fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,txid.GetHex().c_str()); + fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); return(-1); } } From 40ffbabbc0dec5dfd460b202fb38f52425992d0d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:43:49 -1100 Subject: [PATCH 182/252] Test --- 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 877430a81..9e633730c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -416,8 +416,8 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, return; } } - if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) - return; + //if ( dice_betspent((char *)"DiceQueue",bettxid) != 0 ) + // return; pthread_mutex_lock(&DICE_MUTEX); if ( _dicehash_find(bettxid) == 0 ) { From 00f45e5f2f7c01d7992446b37862db09db7c5d09 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:48:27 -1100 Subject: [PATCH 183/252] Test --- src/cc/dice.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9e633730c..c30a2bc51 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -145,19 +145,7 @@ void _dicehash_add(uint256 bettxid) int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,uint256 entropyused,uint256 bettxid) { - int32_t i; struct dicefinish_info *ptr,*tmp; - DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) - { - if ( ptr->entropyused == entropyused ) - { - if ( ptr->bettxid == bettxid ) - return(i+1); - fprintf(stderr,"found identical entropy used.%d different bettxid!\n",i); - oldbettxid = ptr->bettxid; - oldbetTx = ptr->betTx; - return(-1); - } - } + int32_t i; for (i=0; irevealed = (uint32_t)time(NULL); - else - { - pthread_mutex_lock(&DICEREVEALED_MUTEX); - _dicerevealed_add(entropyused,bettxid,betTx); - pthread_mutex_unlock(&DICEREVEALED_MUTEX); - } + pthread_mutex_lock(&DICEREVEALED_MUTEX); + _dicerevealed_add(entropyused,bettxid,betTx); + pthread_mutex_unlock(&DICEREVEALED_MUTEX); fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); @@ -429,6 +414,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); + ptr->rawtx.clear(); DL_APPEND(DICEFINISH_LIST,ptr); //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); From 5e41721ecb47aaeed67a7ce4e438e0418ece45b2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:53:34 -1100 Subject: [PATCH 184/252] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c30a2bc51..4110c11d4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,7 +222,8 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C } else { - ptr->rawtx.clear(); + if ( ptr->rawtx != 0 ) + ptr->rawtx.clear(); ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); } @@ -361,7 +362,8 @@ void *dicefinish(void *_ptr) else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - ptr->rawtx.clear(); + if ( ptr->rawtx != 0 ) + ptr->rawtx.clear(); ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); //free(ptr); @@ -414,7 +416,6 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->sbits = sbits; ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); - ptr->rawtx.clear(); DL_APPEND(DICEFINISH_LIST,ptr); //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); From 489049a7371f172bd49e88690179a1ac82337563 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:54:24 -1100 Subject: [PATCH 185/252] Test --- 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 4110c11d4..467ceaf50 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,7 +222,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C } else { - if ( ptr->rawtx != 0 ) + if ( ptr->rawtx.IsNull() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); @@ -362,7 +362,7 @@ void *dicefinish(void *_ptr) else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - if ( ptr->rawtx != 0 ) + if ( ptr->rawtx.IsNull() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); From fcdbc5abb8734016790a37ded21a3088a38b2fe2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 03:56:06 -1100 Subject: [PATCH 186/252] Test --- 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 467ceaf50..14c9fb08d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,7 +222,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C } else { - if ( ptr->rawtx.IsNull() == 0 ) + if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); @@ -362,7 +362,7 @@ void *dicefinish(void *_ptr) else { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); - if ( ptr->rawtx.IsNull() == 0 ) + if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; //DL_DELETE(DICEFINISH_LIST,ptr); From 2f62195ccd49c53d408e4bca68618e4b085038c3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:01:16 -1100 Subject: [PATCH 187/252] Test --- src/cc/dice.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 14c9fb08d..38d435313 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -294,7 +294,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -328,9 +328,13 @@ void *dicefinish(void *_ptr) } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { - if ( ptr->rawtx.size() > 0 ) - mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); - if ( ptr->rawtx.size() == 0 ) + if ( ptr->txid != zeroid ) + { + CCduration(numblocks,ptr->txid); + if ( numblocks == 0 ) + mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + } + if ( ptr->txid == zeroid ) vin0_needed++; } } From 1796fc60f5aa813829830aa790a3c9365088022a Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:09:44 -1100 Subject: [PATCH 188/252] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 38d435313..e812194c5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -217,15 +217,16 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); - return(true); } else { - if ( ptr->rawtx.empty() == 0 ) + RelayTransaction(tx); + fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + /*if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; - fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); + fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size());*/ } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); From 00da0164e812d30be434a2f5e11f0f0cff75f04d Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:14:31 -1100 Subject: [PATCH 189/252] Test --- src/cc/dice.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e812194c5..5f529a26f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -222,11 +222,11 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C else { RelayTransaction(tx); - fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); - /*if ( ptr->rawtx.empty() == 0 ) + fprintf(stderr,"rebroadcast.%c and clear [%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; - fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size());*/ + //fprintf(stderr,"error adding funcid.%c E.%s bet.%s -> %s to mempool, probably Disable replacement feature size.%d\n",funcid,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str(),(int32_t)ptr->rawtx.size()); } } else fprintf(stderr,"error duplicate entropyused different bettxid\n"); } else fprintf(stderr,"error decoding hex\n"); From 6f8f7bff118b4072f146cd13c6fd7cb616a66b55 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:21:01 -1100 Subject: [PATCH 190/252] Test --- src/cc/dice.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5f529a26f..8e296185f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -215,8 +215,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,uint256 bettxid,C _dicerevealed_add(entropyused,bettxid,betTx); pthread_mutex_unlock(&DICEREVEALED_MUTEX); fprintf(stderr,"added.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); - } - else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); + } else fprintf(stderr,"rebroadcast.%c to mempool.[%d] and broadcast entropyused.%s bettxid.%s -> %s\n",funcid,i,entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),tx.GetHash().GetHex().c_str()); return(true); } else @@ -295,7 +294,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -306,7 +305,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { - lastheight = newht; + if ( newht != 0 && lastheight != newht ) + { + lastheight = newht; + newblock = 1; + } else newblock = 0; fprintf(stderr,"dicefinish process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { @@ -329,7 +332,7 @@ void *dicefinish(void *_ptr) } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { - if ( ptr->txid != zeroid ) + if ( newblock != 0 && ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); if ( numblocks == 0 ) @@ -370,8 +373,6 @@ void *dicefinish(void *_ptr) if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); ptr->txid = zeroid; - //DL_DELETE(DICEFINISH_LIST,ptr); - //free(ptr); } if ( ++m >= n ) break; @@ -381,11 +382,8 @@ void *dicefinish(void *_ptr) free(utxos); } } - while ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) - { + if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) sleep(1); - continue; - } } return(0); } From 23e5c2663431a2dc546dae3e27899eae3421fedb Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:39:29 -1100 Subject: [PATCH 191/252] Test --- src/cc/dice.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8e296185f..e80950917 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -263,8 +263,7 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t int32_t dice_betspent(char *debugstr,uint256 bettxid) { - /*int32_t numblocks; - /*CSpentIndexValue value,value2; + CSpentIndexValue value,value2; CSpentIndexKey key(txid,0); CSpentIndexKey key2(txid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) @@ -272,7 +271,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) fprintf(stderr,"%s txid.%s already spent\n",debugstr,txid.GetHex().c_str()); return(1); } - if ( mode > 0 ) + /*if ( mode > 0 ) { CCduration(numblocks,txid); if ( numblocks > 0 ) @@ -305,12 +304,12 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; } else newblock = 0; - fprintf(stderr,"dicefinish process ht.%d\n",newht); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; @@ -357,7 +356,13 @@ void *dicefinish(void *_ptr) free(ptr); continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 ) + if ( ptr->txid != zeroid ) + { + CCduration(numblocks,ptr->txid); + if ( numblocks > 0 ) + continue; + } + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent("dicefinish",ptr->bettxid) == 0 ) { unstringbits(name,ptr->sbits); result = 0; From 2bbf50e165fa1e2c96b92aa4dfef306d44026e7e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:41:13 -1100 Subject: [PATCH 192/252] Test --- src/cc/dice.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e80950917..754b9a900 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -264,11 +264,11 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t int32_t dice_betspent(char *debugstr,uint256 bettxid) { CSpentIndexValue value,value2; - CSpentIndexKey key(txid,0); - CSpentIndexKey key2(txid,1); + CSpentIndexKey key(bettxid,0); + CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s txid.%s already spent\n",debugstr,txid.GetHex().c_str()); + fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -362,7 +362,7 @@ void *dicefinish(void *_ptr) if ( numblocks > 0 ) continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent("dicefinish",ptr->bettxid) == 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) == 0 ) { unstringbits(name,ptr->sbits); result = 0; @@ -1006,7 +1006,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[1].scriptPubKey != fundingPubKey ) { - uint8_t *ptr0,*ptr1; int32_t i; char str[65]; + /*uint8_t *ptr0,*ptr1; int32_t i; char str[65]; ptr0 = (uint8_t *)vinTx.vout[1].scriptPubKey.data(); ptr1 = (uint8_t *)fundingPubKey.data(); for (i=0; i Date: Thu, 8 Nov 2018 04:46:51 -1100 Subject: [PATCH 193/252] Test --- src/cc/CCutils.cpp | 5 +++-- src/cc/dice.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index ce736ba7a..889b6fdd4 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -391,7 +391,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) } else if ( hashBlock == zeroid ) { - fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid)); + //fprintf(stderr,"CCduration no hashBlock for txid %s\n",uint256_str(str,txid)); return(0); } else if ( (pindex= mapBlockIndex[hashBlock]) == 0 || (txtime= pindex->nTime) == 0 || (txheight= pindex->nHeight) <= 0 ) @@ -401,7 +401,8 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) } else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight ) { - fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); + if ( pindex->nTime < txtime ) + fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); return(0); } numblocks = (pindex->nHeight - txheight); diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 754b9a900..d2ef49587 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,7 +268,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -304,11 +304,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { - fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; for (iter=-1; iter<=1; iter+=2) { @@ -360,7 +360,10 @@ void *dicefinish(void *_ptr) { CCduration(numblocks,ptr->txid); if ( numblocks > 0 ) + { + fprintf(stderr,"alread confirmed %s\n",ptr->txid.GetHex().c_str()); continue; + } } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) == 0 ) { @@ -426,7 +429,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); - } else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } From 5b8a3ef0a061c06b8075aa94ed1b87e3b17866c6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 04:57:41 -1100 Subject: [PATCH 194/252] Test --- src/cc/dice.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d2ef49587..553c0326f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,7 +268,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -304,11 +304,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; - fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; for (iter=-1; iter<=1; iter+=2) { @@ -343,9 +343,11 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { + fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { + fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -359,9 +361,9 @@ void *dicefinish(void *_ptr) if ( ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); + fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); if ( numblocks > 0 ) { - fprintf(stderr,"alread confirmed %s\n",ptr->txid.GetHex().c_str()); continue; } } From d9cdfd351c0a6d53e421e9e949c754ae6520e1a1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:07:23 -1100 Subject: [PATCH 195/252] Test --- src/cc/dice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 553c0326f..6db95049d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -304,11 +304,11 @@ void *dicefinish(void *_ptr) sleep(10); while ( 1 ) { - fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); if ( newht != 0 && lastheight != newht ) { lastheight = newht; newblock = 1; + fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; for (iter=-1; iter<=1; iter+=2) { @@ -336,6 +336,7 @@ void *dicefinish(void *_ptr) CCduration(numblocks,ptr->txid); if ( numblocks == 0 ) mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); + else continue; } if ( ptr->txid == zeroid ) vin0_needed++; @@ -347,7 +348,7 @@ void *dicefinish(void *_ptr) utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { - fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); + //fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n); m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { @@ -367,7 +368,7 @@ void *dicefinish(void *_ptr) continue; } } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) == 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 ) { unstringbits(name,ptr->sbits); result = 0; From 8ceead3cc848bb8367ded771a5ad31bd45ceec5e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:12:43 -1100 Subject: [PATCH 196/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6db95049d..e79186842 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -431,7 +431,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); - //fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } From 139fd784f3ca1bbb7cce5a616b0677007869d7b1 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:21:08 -1100 Subject: [PATCH 197/252] -print --- src/cc/dice.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e79186842..d530727af 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -362,11 +362,9 @@ void *dicefinish(void *_ptr) if ( ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); - fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); + //fprintf(stderr,"numblocks %s %d\n",ptr->txid.GetHex().c_str(),numblocks); if ( numblocks > 0 ) - { continue; - } } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 ) { From a8dd451570f30be1105ef8382ad4d70dd4b554a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:25:19 -1100 Subject: [PATCH 198/252] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d530727af..015749207 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -299,9 +299,9 @@ void *dicefinish(void *_ptr) cp = CCinit(&C,EVAL_DICE); GetCCaddress(cp,CCaddr,GetUnspendable(cp,0)); fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr); - while ( (newht= KOMODO_INSYNC) == 0 ) - sleep(1); - sleep(10); + if ( (newht= KOMODO_INSYNC) == 0 ) + sleep(7); + sleep(3); while ( 1 ) { if ( newht != 0 && lastheight != newht ) @@ -1023,7 +1023,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } entropytxid = txid; entropyval = tx.vout[0].nValue; - fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); + //fprintf(stderr,"funcid.%c first.%d entropytxid.%s val %.8f\n",funcid,first,txid.GetHex().c_str(),(double)entropyval/COIN); first = 1; if (random) { fprintf(stderr, "chosen entropy on loop: %d\n",loops); From 4446bdb00f15a924b0ae66ba9226077592c251c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:26:10 -1100 Subject: [PATCH 199/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 015749207..66e31b965 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1491,7 +1491,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx win++; else if ( iswin < 0 ) loss++; - fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + //fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); } From c395355cd004168e018c04c66d89b156574079e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:29:55 -1100 Subject: [PATCH 200/252] -print --- 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 66e31b965..06265778c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -268,7 +268,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) CSpentIndexKey key2(bettxid,1); if ( GetSpentIndex(key,value) != 0 || GetSpentIndex(key2,value2) != 0 ) { - fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); + //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } /*if ( mode > 0 ) @@ -344,7 +344,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { - fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); + //fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) { From 80c20a679a535d2db1e664913ace4a385ccf09dd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:37:43 -1100 Subject: [PATCH 201/252] Test --- src/cc/CCinclude.h | 1 + src/cc/dice.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index 9a1f41b31..aa5e731b3 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -53,6 +53,7 @@ one other technical note is that komodod has the insight-explorer extensions bui extern int32_t KOMODO_CONNECTING,KOMODO_CCACTIVATE; extern uint32_t ASSETCHAINS_CC; +extern char ASSETCHAINS_SYMBOL[]; extern std::string CCerror; #define SMALLVAL 0.000000000000001 diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 06265778c..c1d1d3acb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1525,7 +1525,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - fprintf(stderr,"need to generate %d 0.0002\n",mintxs - entropytxs); + char *cmd = malloc(100 * 128); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + printf("%s\n",cmd); + //for (i=0; i<=(mintxs - entropytxs)/100; i++) + system(cmd); + free(cmd); } } return(n); From f232fc4b1332bce80b5d14fd73d17625c7170d93 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:42:12 -1100 Subject: [PATCH 202/252] Test --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index c1d1d3acb..0d3dd769d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1525,11 +1525,12 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - char *cmd = malloc(100 * 128); + char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); printf("%s\n",cmd); //for (i=0; i<=(mintxs - entropytxs)/100; i++) - system(cmd); + if (system(cmd) != 0 ) + fprintf(stderr,"system error issuing.(%s)\n",cmd); free(cmd); } } From 2e646703126ad9a38b0dd0761db845677115472e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:45:52 -1100 Subject: [PATCH 203/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0d3dd769d..b03439899 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1526,7 +1526,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( entropytxs < mintxs ) { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); printf("%s\n",cmd); //for (i=0; i<=(mintxs - entropytxs)/100; i++) if (system(cmd) != 0 ) From b46196bd400dd456addc6d690b2815abdbdd63de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 05:49:21 -1100 Subject: [PATCH 204/252] esc --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b03439899..8f46338ac 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1526,7 +1526,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( entropytxs < mintxs ) { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002,\"%s\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); printf("%s\n",cmd); //for (i=0; i<=(mintxs - entropytxs)/100; i++) if (system(cmd) != 0 ) From 84aa184a5f52f7c66009a7f2623d4c83b1841a77 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:00:18 -1100 Subject: [PATCH 205/252] Test --- src/cc/dice.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8f46338ac..4aafc6541 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1525,13 +1525,17 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx dicefinish_utxosget(entropytxs,0,0,coinaddr); if ( entropytxs < mintxs ) { - char *cmd = (char *)malloc(100 * 128); + /*char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - printf("%s\n",cmd); - //for (i=0; i<=(mintxs - entropytxs)/100; i++) - if (system(cmd) != 0 ) - fprintf(stderr,"system error issuing.(%s)\n",cmd); - free(cmd); + printf("%s\n",cmd);*/ + for (i=0; i<=(mintxs - entropytxs)/100; i++) + { + if ( system("./sendmany") != 0 ) + { + fprintf(stderr,"system error issuing.(./sendmany)\n"); + break; + } + } } } return(n); From b7d5bb40f1e7d6b47148ad6eb6739f57c90252a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:05:42 -1100 Subject: [PATCH 206/252] scripts --- src/cc/dapps/diceloop | 7 +++++++ src/cc/dapps/sendmany | 3 +++ src/cc/dice.cpp | 1 + 3 files changed, 11 insertions(+) create mode 100755 src/cc/dapps/diceloop create mode 100755 src/cc/dapps/sendmany diff --git a/src/cc/dapps/diceloop b/src/cc/dapps/diceloop new file mode 100755 index 000000000..07d320c3b --- /dev/null +++ b/src/cc/dapps/diceloop @@ -0,0 +1,7 @@ +cat loop +while true +do +./c dicestatus KMDICE 5be49570c56d036abb08b6d084da93a8a86f58fc48db4a1086be95540d752d6f + +sleep 10 +done diff --git a/src/cc/dapps/sendmany b/src/cc/dapps/sendmany new file mode 100755 index 000000000..3941c2c89 --- /dev/null +++ b/src/cc/dapps/sendmany @@ -0,0 +1,3 @@ +export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo" +./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" + diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4aafc6541..fbdda9c42 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1530,6 +1530,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx printf("%s\n",cmd);*/ for (i=0; i<=(mintxs - entropytxs)/100; i++) { + fprintf(stderr,"sendmany.%d of %d\n",i,1 + (mintxs - entropytxs)/100); if ( system("./sendmany") != 0 ) { fprintf(stderr,"system error issuing.(./sendmany)\n"); From 9d271fd991a4318eb85dc785a2b9941ed2aadc32 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:09:38 -1100 Subject: [PATCH 207/252] test --- 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 fbdda9c42..653324146 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1531,9 +1531,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx for (i=0; i<=(mintxs - entropytxs)/100; i++) { fprintf(stderr,"sendmany.%d of %d\n",i,1 + (mintxs - entropytxs)/100); - if ( system("./sendmany") != 0 ) + if ( system("cc/dapps/sendmany") != 0 ) { - fprintf(stderr,"system error issuing.(./sendmany)\n"); + fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n"); break; } } From b8f6ec6be7847961988caa5552c5fc64b440b179 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:10:13 -1100 Subject: [PATCH 208/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 653324146..863f67673 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1232,7 +1232,7 @@ std::string DiceAddfunding(uint64_t txfee,char *planstr,uint256 fundingtxid,int6 } if ( scriptPubKey == fundingPubKey ) { - if ( AddNormalinputs(mtx,mypk,amount+2*txfee,10) > 0 ) + if ( AddNormalinputs(mtx,mypk,amount+2*txfee,1) > 0 ) { hentropy = DiceHashEntropy(entropy,mtx.vin[0].prevout.hash); mtx.vout.push_back(MakeCC1vout(cp->evalcode,amount,dicepk)); From c79be9fc441ccff4e4e713d8129e93139d2a3122 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:33:16 -1100 Subject: [PATCH 209/252] Reduce --- src/cc/dapps/diceloop | 1 - src/cc/dapps/sendmany | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dapps/diceloop b/src/cc/dapps/diceloop index 07d320c3b..44550b46a 100755 --- a/src/cc/dapps/diceloop +++ b/src/cc/dapps/diceloop @@ -1,4 +1,3 @@ -cat loop while true do ./c dicestatus KMDICE 5be49570c56d036abb08b6d084da93a8a86f58fc48db4a1086be95540d752d6f diff --git a/src/cc/dapps/sendmany b/src/cc/dapps/sendmany index 3941c2c89..08ad34269 100755 --- a/src/cc/dapps/sendmany +++ b/src/cc/dapps/sendmany @@ -1,3 +1,3 @@ export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo" -./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" +./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" From f8ec508842abb852256fcbd1fcaf6b734b48bf5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 06:43:37 -1100 Subject: [PATCH 210/252] Test --- src/cc/dice.cpp | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 863f67673..1c671c3b3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -99,6 +99,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 +#define DICE_MINUTXOS 2500 extern int32_t KOMODO_INSYNC; @@ -344,6 +345,7 @@ void *dicefinish(void *_ptr) } if ( vin0_needed > 0 ) { + num = 0; //fprintf(stderr,"iter.%d vin0_needed.%d\n",iter,vin0_needed); utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos)); if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 ) @@ -389,6 +391,18 @@ void *dicefinish(void *_ptr) } } free(utxos); + if ( newblock != 0 && num < DICE_MINUTXOS ) + { + char *cmd = (char *)malloc(100 * 128); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); + if ( system(cmd) != 0 ) + { + fprintf(stderr,"system error issuing.(%s)\n",cmd); + break; + } + free(cmd); + } } } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) @@ -1500,11 +1514,11 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } if ( scriptPubKey == fundingPubKey ) { - CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,mintxs=2000; + CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs; DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - if ( entropytxs < mintxs ) + if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) @@ -1514,30 +1528,13 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx //LOCK(cs_main); if ( myAddtomempool(tx) != 0 ) { - fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,mintxs - entropytxs); + fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,DICE_MINUTXOS - entropytxs); RelayTransaction(tx); } else break; } else break; } else break; } } - pubkey2addr(coinaddr,Mypubkey().data()); - dicefinish_utxosget(entropytxs,0,0,coinaddr); - if ( entropytxs < mintxs ) - { - /*char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - printf("%s\n",cmd);*/ - for (i=0; i<=(mintxs - entropytxs)/100; i++) - { - fprintf(stderr,"sendmany.%d of %d\n",i,1 + (mintxs - entropytxs)/100); - if ( system("cc/dapps/sendmany") != 0 ) - { - fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n"); - break; - } - } - } } return(n); } From 55a94d56dd3dc8fa8256100d63cbea098523b44b Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 07:06:02 -1100 Subject: [PATCH 211/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1c671c3b3..cb26f0466 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -389,7 +389,7 @@ void *dicefinish(void *_ptr) break; } } - } + } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); if ( newblock != 0 && num < DICE_MINUTXOS ) { From 3db0fd1d4811aaffe5021a62b3321444123a8e99 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 07:40:32 -1100 Subject: [PATCH 212/252] Ignore <0 syncheight peers in longest chain calc --- src/rpcnet.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index db6ffbc14..97bf5001d 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -179,6 +179,8 @@ int32_t komodo_longestchain() //fprintf(stderr,"komodo_longestchain iter.%d\n",n); CNodeStateStats statestats; bool fStateStats = GetNodeStateStats(stats.nodeid,statestats); + if ( statestats.nSyncHeight < 0 ) + continue; ht = 0; if ( stats.nStartingHeight > ht ) ht = stats.nStartingHeight; @@ -190,7 +192,6 @@ int32_t komodo_longestchain() maxheight = ht, num = 1; else if ( ht > maxheight*0.99 ) num++; - n++; if ( ht > height ) height = ht; } From 85700b4d387a21266df6545906c6036688d23201 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 07:53:44 -1100 Subject: [PATCH 213/252] Boost minute --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cb26f0466..19c3cd33c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -99,7 +99,7 @@ What is needed is for the dealer node to track the entropy tx that was already b #include "../compat/endian.h" #define MAX_ENTROPYUSED 8192 -#define DICE_MINUTXOS 2500 +#define DICE_MINUTXOS 7777 extern int32_t KOMODO_INSYNC; From 4435d2a327f0a76c7893c68e46adcc6b02b21dc4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:12:27 -1100 Subject: [PATCH 214/252] Limit to 10 entropy per dice status --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 19c3cd33c..858336484 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1518,7 +1518,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From b8893893bb3f6147028837e4ddf0497056ba3e60 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:18:36 -1100 Subject: [PATCH 215/252] 1 entropy per iter --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 858336484..8cfa3aef7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1518,7 +1518,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From 80671b17bd65d5b3ddb91ec8d06035acb0ac2a64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:36:56 -1100 Subject: [PATCH 216/252] Sendrawtransaction --- src/cc/dice.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 8cfa3aef7..def8b932d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -105,6 +105,7 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; +static std::string DICE_ENTROPYTX; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -403,6 +404,15 @@ void *dicefinish(void *_ptr) } free(cmd); } + res = DICE_ENTROPYTX; + if ( res.empty() == 0 && res.size() > 64 ) + { + char cmdbuf[8192]; std::string res; + sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,res.c_str()); + fprintf(stderr,"(%s)\n",cmdbuf); + if ( system(cmdbuf) != 0 ) + fprintf(stderr,"error (%s)\n",cmdbuf); + } } } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) @@ -1523,6 +1533,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceAddfunding(txfee,planstr,fundingtxid,COIN/100); if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { + DICE_ENTROPYTX = res; if ( DecodeHexTx(tx,res) != 0 ) { //LOCK(cs_main); From 60152b4ea6f9c9efd7c860027311249ead637987 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:42:46 -1100 Subject: [PATCH 217/252] Test --- src/cc/dice.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index def8b932d..0515cdc0a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -404,11 +404,11 @@ void *dicefinish(void *_ptr) } free(cmd); } - res = DICE_ENTROPYTX; - if ( res.empty() == 0 && res.size() > 64 ) + std::string entropyrawtx = DICE_ENTROPYTX; + if ( entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) { - char cmdbuf[8192]; std::string res; - sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,res.c_str()); + char cmdbuf[8192]; + sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); fprintf(stderr,"(%s)\n",cmdbuf); if ( system(cmdbuf) != 0 ) fprintf(stderr,"error (%s)\n",cmdbuf); From 8753790c0f793583ab174309584628023eba5b10 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:43:32 -1100 Subject: [PATCH 218/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0515cdc0a..f18202a82 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -405,7 +405,7 @@ void *dicefinish(void *_ptr) free(cmd); } std::string entropyrawtx = DICE_ENTROPYTX; - if ( entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) + if ( newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) { char cmdbuf[8192]; sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); From 25d97099312bbb084b631086c4a766180da099df Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:47:11 -1100 Subject: [PATCH 219/252] -print --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f18202a82..9ee5414d9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -409,7 +409,7 @@ void *dicefinish(void *_ptr) { char cmdbuf[8192]; sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); - fprintf(stderr,"(%s)\n",cmdbuf); + //fprintf(stderr,"(%s)\n",cmdbuf); if ( system(cmdbuf) != 0 ) fprintf(stderr,"error (%s)\n",cmdbuf); } From 97a4ab754d90830544a10388aa9dd5c2bd8b2d23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 09:48:21 -1100 Subject: [PATCH 220/252] Test --- 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 9ee5414d9..a434a40ea 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -405,7 +405,7 @@ void *dicefinish(void *_ptr) free(cmd); } std::string entropyrawtx = DICE_ENTROPYTX; - if ( newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) + if ( 0 && newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) { char cmdbuf[8192]; sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); @@ -1528,7 +1528,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { - for (i=0; i 64 && is_hexstr((char *)res.c_str(),0) > 64 ) From 097324e1b0bd7f5dd4237087a769b58588109304 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 10:28:49 -1100 Subject: [PATCH 221/252] Test --- src/cc/dice.cpp | 24 ++++++++++++++---------- src/wallet/rpcwallet.cpp | 2 ++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a434a40ea..fedb8a25c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -241,21 +241,24 @@ int32_t dicefinish_utxosget(int32_t &total,struct dicefinish_utxo *utxos,int32_t total = 0; std::vector > unspentOutputs; SetCCunspents(unspentOutputs,coinaddr); - for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( myIsutxo_spentinmempool(it->first.txhash,(int32_t)it->first.index) == 0 ) + LOCK(mempool.cs); + for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { - if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) - continue; - total++; - if ( n < max ) + if ( myIsutxo_spentinmempool(it->first.txhash,(int32_t)it->first.index) == 0 ) { - if ( utxos != 0 ) + if ( it->second.satoshis < threshold || it->second.satoshis > 10*threshold ) + continue; + total++; + if ( n < max ) { - utxos[n].txid = it->first.txhash; - utxos[n].vout = (int32_t)it->first.index; + if ( utxos != 0 ) + { + utxos[n].txid = it->first.txhash; + utxos[n].vout = (int32_t)it->first.index; + } + n++; } - n++; } } } @@ -284,6 +287,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) } else*/ { + LOCK(mempool.cs); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4b5ef8a1f..4aaaef33c 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6188,6 +6188,7 @@ UniValue dicefinish(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; + LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { @@ -6223,6 +6224,7 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; + LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { From 071796aeabc556eabd64c84416f9a7fbba09c356 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 10:33:37 -1100 Subject: [PATCH 222/252] Test --- src/wallet/rpcwallet.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4aaaef33c..4b5ef8a1f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -6188,7 +6188,6 @@ UniValue dicefinish(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { @@ -6224,7 +6223,6 @@ UniValue dicestatus(const UniValue& params, bool fHelp) if ( ensure_CCrequirements() < 0 ) throw runtime_error("to use CC contracts, you need to launch daemon with valid -pubkey= for an address in your wallet\n"); const CKeyStore& keystore = *pwalletMain; - LOCK(mempool.cs); LOCK2(cs_main, pwalletMain->cs_wallet); name = (char *)params[0].get_str().c_str(); if (!VALID_PLAN_NAME(name)) { From 18780bac5464b7201e273ef7c92ad840bc379813 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 11:01:58 -1100 Subject: [PATCH 223/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fedb8a25c..e71477836 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -287,7 +287,7 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) } else*/ { - LOCK(mempool.cs); + //LOCK(mempool.cs); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) { fprintf(stderr,"%s bettxid.%s already spent in mempool\n",debugstr,bettxid.GetHex().c_str()); From 452a53884c3ddf7cfb4aff48fd488febf85440c8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 11:20:07 -1100 Subject: [PATCH 224/252] Test --- src/cc/dice.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e71477836..655282f8d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -335,6 +335,13 @@ void *dicefinish(void *_ptr) else if ( mytxid_inmempool(ptr->bettxid) != 0 ) ptr->bettxid_ready = (uint32_t)time(NULL); } + else if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) + { + fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); + continue; + } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( newblock != 0 && ptr->txid != zeroid ) From 0cfa09657d15f8b68e1f1d53b9e864d94befad01 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:01:23 -1100 Subject: [PATCH 225/252] +print --- src/cc/dice.cpp | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 655282f8d..7af6eba0e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -90,10 +90,9 @@ WARNING: there is an attack vector that precludes betting any large amounts, it What is needed is for the dealer node to track the entropy tx that was already broadcast into the mempool with its entropy revealed. Then before processing a dicebet, it is checked against the already revealed list. If it is found, the dicebet is refunded with proof that a different dicebet was already used to reveal the entropy - need to speed up dealer dicestatus loop (or in parallel) - validate refund change to hashtables - + validate refund + */ #include "../compat/endian.h" @@ -276,16 +275,6 @@ int32_t dice_betspent(char *debugstr,uint256 bettxid) //fprintf(stderr,"%s txid.%s already spent\n",debugstr,bettxid.GetHex().c_str()); return(1); } - /*if ( mode > 0 ) - { - CCduration(numblocks,txid); - if ( numblocks > 0 ) - { - fprintf(stderr,"%s txid.%s already confirmed %d\n",debugstr,txid.GetHex().c_str(),numblocks); - return(1); - } - } - else*/ { //LOCK(mempool.cs); if ( myIsutxo_spentinmempool(bettxid,0) != 0 || myIsutxo_spentinmempool(bettxid,1) != 0 ) @@ -464,7 +453,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->iswin = iswin; ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); - fprintf(stderr,"queued iswin.%d %s\n",iswin,bettxid.GetHex().c_str()); + fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); pthread_mutex_unlock(&DICE_MUTEX); } @@ -1018,7 +1007,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit if ( funcid == 'B' ) { pendingbets++; - //fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); + fprintf(stderr,"%d: %s/v%d (%c %.8f) %.8f %.8f\n",n,uint256_str(str,txid),vout,funcid,(double)it->second.satoshis/COIN,(double)totalinputs/COIN,(double)sum/COIN); } if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid ) { From 0a14ecfbc82a68ccbd986042c85e63fad9aab0cc Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:09:42 -1100 Subject: [PATCH 226/252] Test --- src/cc/dice.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7af6eba0e..b7d952585 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -132,6 +132,18 @@ int32_t _dicehash_find(uint256 bettxid) return(0); } +int32_t _dicehash_clear(uint256 bettxid) +{ + int32_t i; + for (i=0; ibettxid); + pthread_mutex_unlock(&DICE_MUTEX); + DL_DELETE(DICEFINISH_LIST,ptr); + free(ptr); +} + void *dicefinish(void *_ptr) { std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; @@ -313,8 +334,7 @@ void *dicefinish(void *_ptr) if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + dicefinish_delete(ptr); continue; } if ( ptr->bettxid_ready == 0 ) @@ -327,8 +347,7 @@ void *dicefinish(void *_ptr) else if ( myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + dicefinish_delete(ptr); continue; } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) @@ -358,8 +377,7 @@ void *dicefinish(void *_ptr) if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { fprintf(stderr,"purge2 %s\n",ptr->bettxid.GetHex().c_str()); - DL_DELETE(DICEFINISH_LIST,ptr); - free(ptr); + dicefinish_delete(ptr); continue; } if ( ptr->txid != zeroid ) From f9da823ed128131561afade6f229c2edbb2470de Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:20:03 -1100 Subject: [PATCH 227/252] Test --- src/cc/dice.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b7d952585..a64ae898d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -472,7 +472,12 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); DL_APPEND(DICEFINISH_LIST,ptr); fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); - } //else fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + } + else + { + fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); + _dicehash_clear(bettxid); + } pthread_mutex_unlock(&DICE_MUTEX); } From c485a6e2be7f66eb0c5a4f5f0f718a586c3d3ce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:34:28 -1100 Subject: [PATCH 228/252] Test --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a64ae898d..6a3ab4b33 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1538,10 +1538,9 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx win++; else if ( iswin < 0 ) loss++; - //fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } + } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); } } } From e2fff7f788315b5e97fb5ecaa2049554d88f5699 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:42:38 -1100 Subject: [PATCH 229/252] +print --- src/cc/dice.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6a3ab4b33..99d14d9e1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1527,20 +1527,23 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( vout != 0 ) continue; sum += it->second.satoshis; - if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 && myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) + if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) { - bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { - if ( iswin > 0 ) - win++; - else if ( iswin < 0 ) - loss++; - n++; - DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + if ( iswin > 0 ) + win++; + else if ( iswin < 0 ) + loss++; + n++; + DiceQueue(iswin,sbits,fundingtxid,txid,betTx); + } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + } else fprintf(stderr,"bettxid.%s cant find entropyTx.%s\n",txid.GetHex().c_str(),betTx.vin[0].prevout.hash.GetHex().c_str()); } } } From bdb4fe1df37c48514fb358dd0939143028562aa4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:50:31 -1100 Subject: [PATCH 230/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 99d14d9e1..0f17d5916 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -749,7 +749,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction } } else fprintf(stderr,"hentropy != hentropy2\n"); } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); - } //else fprintf(stderr,"notmine or not CC\n"); + } else fprintf(stderr,"notmine.%d or not CC\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); } From 0536c75beb99706a05fcf4e5487a58421c468148 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 12:51:17 -1100 Subject: [PATCH 231/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0f17d5916..51046a818 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -749,7 +749,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction } } else fprintf(stderr,"hentropy != hentropy2\n"); } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); - } else fprintf(stderr,"notmine.%d or not CC\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); + } else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); } From 44b59c3cf6478adf1dabc6495937acecd08a116e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:06:38 -1100 Subject: [PATCH 232/252] Test --- src/cc/dice.cpp | 50 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 51046a818..10e16c5d9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -855,7 +855,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) DiceQueue(iswin,sbits,fundingtxid,txid,tx); - } + } // else return eval->Invalid(); break; // make sure all funding txid are from matching sbits and fundingtxid!! case 'L': @@ -1049,9 +1049,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr,"cant find entropy vin0 %s or vin0prev %d vouts[%d], iscoinbase.%d\n",uint256_str(str,tx.vin[0].prevout.hash),(int32_t)tx.vin[0].prevout.n,(int32_t)vinTx.vout.size(),(int32_t)vinTx.vin.size()); continue; } - if ( (int32_t)vinTx.vin[0].prevout.n < 0 ) + if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinTx.vout.size() < 2 ) { - //fprintf(stderr,"skip coinbase\n"); + //fprintf(stderr,"skip coinbase or strange entropy tx\n"); continue; } //if ( fundingtxid != tx.vin[0].prevout.hash && vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) @@ -1382,7 +1382,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return(""); }*/ bettorentropy = DiceGetEntropy(betTx,'B'); - if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + if ( winlosetimeout == 0 || ((iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 || iswin == 0) ) { if ( vin0txid == zeroid || vin0vout < 0 ) { @@ -1401,7 +1401,12 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) + if ( iswin == 0 ) + { + retval = -1; + fprintf(stderr,"invalid dicebet %s\n",bettxid.GetHex().c_str()); + } else retval = 0; + if ( retval < 0 || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) { if ( retval < 0 ) { @@ -1506,7 +1511,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; @@ -1533,16 +1538,31 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { - bettorentropy = DiceGetEntropy(betTx,'B'); - if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + flag = 0; + if ( scriptPubKey == fundingPubKey ) { - if ( iswin > 0 ) - win++; - else if ( iswin < 0 ) - loss++; - n++; - DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } else fprintf(stderr,"%d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + bettorentropy = DiceGetEntropy(betTx,'B'); + if ( (iswin= DiceIsWinner(hentropyproof,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) + { + if ( iswin > 0 ) + win++; + else if ( iswin < 0 ) + loss++; + n++; + DiceQueue(iswin,sbits,fundingtxid,txid,betTx); + } else flag = 1; + } + if ( flag != 0 || scriptPubKey != fundingPubKey ) + { + if ( flag != 0 ) + fprintf(stderr,"illegal bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); + res = DiceBetFinish(&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + if ( result > 0 ) + { + mySendrawtransaction(res); + n++; + } + } } else fprintf(stderr,"bettxid.%s cant find entropyTx.%s\n",txid.GetHex().c_str(),betTx.vin[0].prevout.hash.GetHex().c_str()); } } From 2c574a7ed03044d0bdee5d5cac9004673d8a3bb8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:09:29 -1100 Subject: [PATCH 233/252] Test --- 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 10e16c5d9..7e4178618 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1556,10 +1556,10 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx { if ( flag != 0 ) fprintf(stderr,"illegal bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN); - res = DiceBetFinish(&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey); + res = DiceBetFinish(funcid,entropyused,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey,zeroid,-1); if ( result > 0 ) { - mySendrawtransaction(res); + mySenddicetransaction(res,entropyused,txid,betTx,funcid,0); n++; } } From da81001b821d48b90a09f352641546c1d77b7fd9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:22:21 -1100 Subject: [PATCH 234/252] Test --- src/cc/dice.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7e4178618..2783896e9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -763,7 +763,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]; + uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,refsbits=0,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]; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -772,7 +772,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else { txid = tx.GetHash(); - if ( (funcid= DecodeDiceOpRet(txid,tx.vout[numvouts-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) + if ( (funcid= DecodeDiceOpRet(txid,tx.vout[numvouts-1].scriptPubKey,refsbits,fundingtxid,hash,proof)) != 0 ) { if ( eval->GetTxUnconfirmed(fundingtxid,fundingTx,hashBlock) == 0 ) return eval->Invalid("cant find fundingtxid"); @@ -781,6 +781,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) if ( maxodds > 9999 ) return eval->Invalid("maxodds too big"); fundingPubKey = fundingTx.vout[1].scriptPubKey; + if ( sbits != refsbits ) + { + fprintf(stderr,"VALIDATION ERROR: sbits %llx != refsbits %llx\n",(long long)sbits,(long long)refsbits)); + //return eval->Invalid("mismatched diceplan"); + } switch ( funcid ) { case 'F': @@ -855,7 +860,12 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) // will only happen for fundingPubKey if ( KOMODO_INSYNC != 0 ) DiceQueue(iswin,sbits,fundingtxid,txid,tx); - } // else return eval->Invalid(); + } + else + { + fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid\n"); + //return eval->Invalid("invalid dicebet bettxid"); + } break; // make sure all funding txid are from matching sbits and fundingtxid!! case 'L': @@ -1025,7 +1035,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit } if ( myGetTransaction(txid,tx,hashBlock) != 0 && tx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) //we want consensus safe results myIsutxo_spentinmempool(txid,vout) == 0 ) { - if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 ) + if ( (funcid= DecodeDiceOpRet(txid,tx.vout[tx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof)) != 0 && sbits == refsbits ) { if ( funcid == 'B' ) { @@ -1382,7 +1392,7 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, return(""); }*/ bettorentropy = DiceGetEntropy(betTx,'B'); - if ( winlosetimeout == 0 || ((iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 || iswin == 0) ) + if ( winlosetimeout == 0 || (iswin= DiceIsWinner(hentropyproof,bettxid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 ) { if ( vin0txid == zeroid || vin0vout < 0 ) { @@ -1401,16 +1411,17 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, if ( winlosetimeout != 0 ) // dealernode { entropyused = hentropyproof; - if ( iswin == 0 ) + /*if ( iswin == 0 ) { retval = -1; fprintf(stderr,"invalid dicebet %s\n",bettxid.GetHex().c_str()); - } else retval = 0; - if ( retval < 0 || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) + } else retval = 0;*/ + if ( (retval= DiceEntropyUsed(oldbetTx,oldbettxid,entropyused,bettxid,betTx)) != 0 ) { if ( retval < 0 ) { fprintf(stderr,"orphan that reveals entropy, generate refund tx with proofs\n"); + // make sure we dont refund wrong amounts mtx.vin.push_back(CTxIn(bettxid,0,CScript())); mtx.vin.push_back(CTxIn(bettxid,1,CScript())); funcid = 'R'; @@ -1511,8 +1522,8 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettxid) { - CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits; char coinaddr[64]; std::string res; uint8_t funcid; - if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) + CScript fundingPubKey,scriptPubKey; CTransaction spenttx,betTx,entropyTx; uint256 hentropyproof,entropyused,hash,proof,txid,hashBlock,spenttxid,bettorentropy; CPubKey mypk,dicepk,fundingpk; struct CCcontract_info *cp,C; int32_t i,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid; + if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) { CCerror = "Diceinit error in status"; return(0.); @@ -1534,7 +1545,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx sum += it->second.satoshis; if ( myGetTransaction(txid,betTx,hashBlock) != 0 && betTx.vout.size() >= 4 && betTx.vout[vout].scriptPubKey.IsPayToCryptoCondition() != 0 ) { - if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' ) + if ( DecodeDiceOpRet(txid,betTx.vout[betTx.vout.size()-1].scriptPubKey,sbits,fundingtxid,hash,proof) == 'B' && sbits == refsbits ) { if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 ) { @@ -1550,7 +1561,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx loss++; n++; DiceQueue(iswin,sbits,fundingtxid,txid,betTx); - } else flag = 1; + } //else flag = 1; } if ( flag != 0 || scriptPubKey != fundingPubKey ) { @@ -1570,7 +1581,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx if ( scriptPubKey == fundingPubKey ) { CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs; - DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,fundingtxid,entropytxs,false); if ( entropytxs < DICE_MINUTXOS ) { for (i=0; i Date: Thu, 8 Nov 2018 13:23:06 -1100 Subject: [PATCH 235/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2783896e9..f38cd42e5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -783,7 +783,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) fundingPubKey = fundingTx.vout[1].scriptPubKey; if ( sbits != refsbits ) { - fprintf(stderr,"VALIDATION ERROR: sbits %llx != refsbits %llx\n",(long long)sbits,(long long)refsbits)); + fprintf(stderr,"VALIDATION ERROR: sbits %llx != refsbits %llx\n",(long long)sbits,(long long)refsbits); //return eval->Invalid("mismatched diceplan"); } switch ( funcid ) From 025f3658ebda8b984980679bb74d00af219d9757 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 13:33:14 -1100 Subject: [PATCH 236/252] Test --- src/cc/dice.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f38cd42e5..c4021bcdf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -397,7 +397,7 @@ void *dicefinish(void *_ptr) ptr->rawtx = res; mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); } - else + else if ( result != -2 ) { fprintf(stderr,"error doing the dicefinish %d of %d process %s %s using %s/v%d need %.8f\n",m,n,iter<0?"loss":"win",ptr->bettxid.GetHex().c_str(),utxos[m].txid.GetHex().c_str(),utxos[m].vout,(double)(iter<0 ? 0 : ptr->winamount)/COIN); if ( ptr->rawtx.empty() == 0 ) @@ -749,7 +749,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction } } else fprintf(stderr,"hentropy != hentropy2\n"); } else fprintf(stderr,"funcid.%c sbits %llx vs %llx cmp.%d\n",funcid,(long long)sbits,(long long)vinsbits,fundingtxid == vinfundingtxid); - } else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); + } //else fprintf(stderr,"notmine.%d or not CC.%d\n",DiceIsmine(vinTx.vout[1].scriptPubKey) != 0,vinTx.vout[0].scriptPubKey.IsPayToCryptoCondition() != 0); return(0); } @@ -863,7 +863,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid\n"); + fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; @@ -1430,8 +1430,13 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t *resultp, mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey)); *resultp = 1; return(FinalizeCCTx(0,cp,mtx,fundingpk,txfee,EncodeDiceOpRet(funcid,sbits,fundingtxid,entropyused,oldbettxid))); // need to change opreturn to include oldbetTx to allow validation - } else CCerror = "DiceBetFinish: duplicate betTx"; - fprintf(stderr,"%s\n", CCerror.c_str() ); + } + else + { + CCerror = "DiceBetFinish: duplicate betTx"; + *resultp = -2; // demote error to warning + } + //fprintf(stderr,"%s\n", CCerror.c_str() ); return(""); } //fprintf(stderr,"set winlosetimeout %d <- %d\n",winlosetimeout,iswin); From c9a55cd48ac63479ec6e4e6634a5716f66dad3fd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 14:19:28 -1100 Subject: [PATCH 237/252] Test --- 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 c4021bcdf..edf07f38b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -476,7 +476,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, else { fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str()); - _dicehash_clear(bettxid); + //_dicehash_clear(bettxid); } pthread_mutex_unlock(&DICE_MUTEX); } @@ -863,7 +863,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); + //fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; From 8ae9e63b092958ef13389c02bc18f768312af0f7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 14:56:27 -1100 Subject: [PATCH 238/252] Test --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index edf07f38b..9a8f36341 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -435,6 +435,7 @@ void *dicefinish(void *_ptr) } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) sleep(1); + else usleep(100000); } return(0); } @@ -863,7 +864,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - //fprintf(stderr,"VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); + fprintf(stderr,"why does node1 get VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; From c0a342250e13483a8883cd53579860159f6d75e0 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 14:56:55 -1100 Subject: [PATCH 239/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9a8f36341..30dadcc65 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -864,7 +864,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - fprintf(stderr,"why does node1 get VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); + //fprintf(stderr,"why does node1 get VALIDATION ERROR: invalid dicebet bettxid %s\n",txid.GetHex().c_str()); //return eval->Invalid("invalid dicebet bettxid"); } break; From b7a556e8382d56f2b41417a5791ec310e07a5ac8 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 19:42:44 -1100 Subject: [PATCH 240/252] -komodo_interestsum() for non-KMD --- src/bitcoind.cpp | 2 +- src/komodo_gateway.h | 3 ++- src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 36fea57bf..f05b522fa 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -62,7 +62,7 @@ void WaitForShutdown(boost::thread_group* threadGroup) } else { - komodo_interestsum(); + //komodo_interestsum(); komodo_longestchain(); MilliSleep(20000); } diff --git a/src/komodo_gateway.h b/src/komodo_gateway.h index 379224b48..400ded593 100644 --- a/src/komodo_gateway.h +++ b/src/komodo_gateway.h @@ -1380,7 +1380,8 @@ void komodo_passport_iteration() } if ( komodo_chainactive_timestamp() > lastinterest ) { - komodo_interestsum(); + if ( ASSETCHAINS_SYMBOL[0] == 0 ) + komodo_interestsum(); komodo_longestchain(); lastinterest = komodo_chainactive_timestamp(); } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 4b5ef8a1f..5f5cb5b28 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2750,7 +2750,7 @@ UniValue listunspent(const UniValue& params, bool fHelp) uint64_t komodo_interestsum() { #ifdef ENABLE_WALLET - if ( GetBoolArg("-disablewallet", false) == 0 ) + if ( ASSETCHAINS_SYMBOL[0] == 0 && GetBoolArg("-disablewallet", false) == 0 ) { uint64_t interest,sum = 0; int32_t txheight; uint32_t locktime; vector vecOutputs; From 6d5a5a0195de2f1cf5e6beb3e631b6b71955e974 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 19:52:48 -1100 Subject: [PATCH 241/252] Check for orphaned finish taxied --- src/cc/dice.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 30dadcc65..2678e2f46 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -350,6 +350,13 @@ void *dicefinish(void *_ptr) dicefinish_delete(ptr); continue; } + else if ( ptr->txid != zeroid && myGetTransaction(ptr->txid,betTx,hashBlock) == 0 ) + { + fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( ptr->rawtx.empty() == 0 ) + ptr->rawtx.clear(); + ptr->txid = zeroid; + } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( newblock != 0 && ptr->txid != zeroid ) From 4806dcf059276aee4d99447b7233fa07c63ddc53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:06:00 -1100 Subject: [PATCH 242/252] Test --- src/cc/dice.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 2678e2f46..a30d678db 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -309,7 +309,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -350,18 +350,23 @@ void *dicefinish(void *_ptr) dicefinish_delete(ptr); continue; } - else if ( ptr->txid != zeroid && myGetTransaction(ptr->txid,betTx,hashBlock) == 0 ) + else if ( ptr->txid != zeroid ) { - fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); - if ( ptr->rawtx.empty() == 0 ) - ptr->rawtx.clear(); - ptr->txid = zeroid; + fprintf(stderr,"monitoring finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) + { + fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); + if ( ptr->rawtx.empty() == 0 ) + ptr->rawtx.clear(); + ptr->txid = zeroid; + } } if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) { if ( newblock != 0 && ptr->txid != zeroid ) { CCduration(numblocks,ptr->txid); + fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str()); if ( numblocks == 0 ) mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->bettxid,ptr->betTx,ptr->funcid,ptr); else continue; @@ -394,7 +399,7 @@ void *dicefinish(void *_ptr) if ( numblocks > 0 ) continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 ) + if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 && ptr->txid == zeroid ) { unstringbits(name,ptr->sbits); result = 0; From 9ca2a941365661d5537360080f1ab5990860f966 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:14:14 -1100 Subject: [PATCH 243/252] Print --- src/cc/dice.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a30d678db..37bd3308c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -352,7 +352,6 @@ void *dicefinish(void *_ptr) } else if ( ptr->txid != zeroid ) { - fprintf(stderr,"monitoring finish txid.%s\n",ptr->txid.GetHex().c_str()); if ( myGetTransaction(ptr->txid,finishTx,hashBlock) == 0 ) { fprintf(stderr,"ORPHANED finish txid.%s\n",ptr->txid.GetHex().c_str()); @@ -422,7 +421,7 @@ void *dicefinish(void *_ptr) } } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( newblock != 0 && num < DICE_MINUTXOS ) + if ( num < DICE_MINUTXOS ) //newblock != 0 && { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); From 630f95cca4d7c227dc1304f959c1f6c72deadf30 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:22:53 -1100 Subject: [PATCH 244/252] Gen utxos --- 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 37bd3308c..5809c2c22 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -421,10 +421,10 @@ void *dicefinish(void *_ptr) } } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( num < DICE_MINUTXOS ) //newblock != 0 && + if ( newblock != 0 && num < DICE_MINUTXOS ) // { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.023,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) { From 1bb800272e85fd647d86582c27a38a9bd781cce5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:28:52 -1100 Subject: [PATCH 245/252] Test --- 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 5809c2c22..ef989dce3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -421,10 +421,10 @@ void *dicefinish(void *_ptr) } } else dicefinish_utxosget(num,0,0,coinaddr); free(utxos); - if ( newblock != 0 && num < DICE_MINUTXOS ) // + if ( newblock != 0 && num < DICE_MINUTXOS ) { char *cmd = (char *)malloc(100 * 128); - sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.023,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); + sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) { From f81a6da8372a4e12435f2b70287d376f63044d11 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:46:37 -1100 Subject: [PATCH 246/252] Minimal validation of refund --- src/cc/dice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef989dce3..5280c5b0e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -425,7 +425,7 @@ void *dicefinish(void *_ptr) { char *cmd = (char *)malloc(100 * 128); sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); - fprintf(stderr,"num utxos.%d < %d\n",num,DICE_MINUTXOS); + fprintf(stderr,"num normal 0.0002 utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) { fprintf(stderr,"system error issuing.(%s)\n",cmd); @@ -954,7 +954,12 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("invalid timeout claim for timeout"); break; case 'R': - fprintf(stderr,"add validation for refunds\n"); + if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) + return eval->Invalid("always should find vin.0, but didnt for refund"); + else if ( vinTx.vout[tx.vin[0].prevout.].scriptPubKey != fundingPubKey ) + return eval->Invalid("vin.0 not from fundingPubKey for refund"); + if ( (rand() % 100) == 0 ) + fprintf(stderr,"add more validation for refunds\n"); break; default: fprintf(stderr,"illegal dice funcid.(%c)\n",funcid); From 1969001bf258a5347d83d3f0d2250ca4be389f2e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:47:43 -1100 Subject: [PATCH 247/252] N --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 5280c5b0e..1e2e8931f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -956,7 +956,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) case 'R': if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt for refund"); - else if ( vinTx.vout[tx.vin[0].prevout.].scriptPubKey != fundingPubKey ) + else if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) return eval->Invalid("vin.0 not from fundingPubKey for refund"); if ( (rand() % 100) == 0 ) fprintf(stderr,"add more validation for refunds\n"); From 696af1e532d3fc56ed073e6ba1a22eecf0edd647 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:51:56 -1100 Subject: [PATCH 248/252] Test --- src/cc/dapps/sendmany | 2 +- src/cc/dice.cpp | 20 ++++++-------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/cc/dapps/sendmany b/src/cc/dapps/sendmany index 08ad34269..45560b505 100755 --- a/src/cc/dapps/sendmany +++ b/src/cc/dapps/sendmany @@ -1,3 +1,3 @@ export addr="RXgCPfi6wccRr3Eai3X9duTTkAirhcQLNo" -./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002,\"$addr\":0.0002}" +./komodo-cli -ac_name=KMDICE sendmany "" "{\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023,\"$addr\":0.023}" diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1e2e8931f..f49c92d3a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -104,7 +104,6 @@ extern int32_t KOMODO_INSYNC; static uint256 bettxids[MAX_ENTROPYUSED],entropytxids[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; -static std::string DICE_ENTROPYTX; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -427,20 +426,14 @@ void *dicefinish(void *_ptr) sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr); fprintf(stderr,"num normal 0.0002 utxos.%d < %d\n",num,DICE_MINUTXOS); if ( system(cmd) != 0 ) - { fprintf(stderr,"system error issuing.(%s)\n",cmd); - break; - } free(cmd); - } - std::string entropyrawtx = DICE_ENTROPYTX; - if ( 0 && newblock != 0 && entropyrawtx.empty() == 0 && entropyrawtx.size() > 64 ) - { - char cmdbuf[8192]; - sprintf(cmdbuf,"./komodo-cli -ac_name=%s sendrawtransaction %s",ASSETCHAINS_SYMBOL,entropyrawtx.c_str()); - //fprintf(stderr,"(%s)\n",cmdbuf); - if ( system(cmdbuf) != 0 ) - fprintf(stderr,"error (%s)\n",cmdbuf); + if ( (rand() % 100) == 0 ) + { + fprintf(stderr,"make 0.023 utxos\n"); + if ( system("cc/dapps/sendmany") != 0 ) + fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n"); + } } } } @@ -1611,7 +1604,6 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx res = DiceAddfunding(txfee,planstr,fundingtxid,COIN/100); if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 ) { - DICE_ENTROPYTX = res; if ( DecodeHexTx(tx,res) != 0 ) { //LOCK(cs_main); From eafdbeb6ed33b6168001a16d31b5da48a5adad24 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 20:52:28 -1100 Subject: [PATCH 249/252] Test --- src/cc/dice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f49c92d3a..f83b1d1f5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -428,7 +428,7 @@ void *dicefinish(void *_ptr) if ( system(cmd) != 0 ) fprintf(stderr,"system error issuing.(%s)\n",cmd); free(cmd); - if ( (rand() % 100) == 0 ) + //if ( (rand() % 100) == 0 ) { fprintf(stderr,"make 0.023 utxos\n"); if ( system("cc/dapps/sendmany") != 0 ) From eb36c925f19b4ab6d115880df05d2c64e0ef44bd Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 21:04:47 -1100 Subject: [PATCH 250/252] Cmp refund to fundingaddr --- src/cc/dice.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index f83b1d1f5..ac8be528b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -842,7 +842,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("always should find vinofvin.0, but didnt for bet"); else if ( vinTx.vin[0].prevout.hash != fundingtxid ) { - //if ( vinofvinTx.vout[1].scriptPubKey != fundingPubKey ) if ( (int32_t)vinTx.vin[0].prevout.n < 0 || vinofvinTx.vout[vinTx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) { uint8_t *ptr0,*ptr1; int32_t i; char str[65]; @@ -950,7 +949,16 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) if ( eval->GetTxUnconfirmed(tx.vin[0].prevout.hash,vinTx,hashBlock) == 0 ) return eval->Invalid("always should find vin.0, but didnt for refund"); else if ( vinTx.vout[tx.vin[0].prevout.n].scriptPubKey != fundingPubKey ) - return eval->Invalid("vin.0 not from fundingPubKey for refund"); + { + char fundingaddr[64],cmpaddr[64]; + Getscriptaddress(fundingaddr,fundingPubKey); + Getscriptaddress(cmpaddr,vinTx.vout[tx.vin[0].prevout.n].scriptPubKey); + if ( strcmp(cmpaddr,fundingaddr) != 0 ) + { + fprintf(stderr,"cmpaddr.%s != fundingaddr.%s\n",cmpaddr,fundingaddr); + return eval->Invalid("vin.0 not from fundingPubKey for refund"); + } + } if ( (rand() % 100) == 0 ) fprintf(stderr,"add more validation for refunds\n"); break; From c11899560869df55c5e63df85a6735d61b2546a9 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 21:06:57 -1100 Subject: [PATCH 251/252] -prints --- 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 ac8be528b..425cc03f8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -428,7 +428,7 @@ void *dicefinish(void *_ptr) if ( system(cmd) != 0 ) fprintf(stderr,"system error issuing.(%s)\n",cmd); free(cmd); - //if ( (rand() % 100) == 0 ) + if ( (rand() % 100) == 0 ) { fprintf(stderr,"make 0.023 utxos\n"); if ( system("cc/dapps/sendmany") != 0 ) @@ -959,7 +959,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin.0 not from fundingPubKey for refund"); } } - if ( (rand() % 100) == 0 ) + if ( (rand() % 1000) == 0 ) fprintf(stderr,"add more validation for refunds\n"); break; default: From 9780765e5154e730e6db6ad095e5efefe09bf826 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Nov 2018 21:18:43 -1100 Subject: [PATCH 252/252] Reduce CPU usage --- src/cc/dice.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 425cc03f8..95056509d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -308,7 +308,7 @@ void dicefinish_delete(struct dicefinish_info *ptr) void *dicefinish(void *_ptr) { - std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; + std::vector mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock; CTransaction betTx,finishTx; mypk = Mypubkey(); pubkey2addr(coinaddr,mypk.data()); cp = CCinit(&C,EVAL_DICE); @@ -325,12 +325,15 @@ void *dicefinish(void *_ptr) newblock = 1; fprintf(stderr,"dicefinish process lastheight.%d <- newht.%d\n",lastheight,newht); } else newblock = 0; + now = (uint32_t)time(NULL); for (iter=-1; iter<=1; iter+=2) { vin0_needed = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { - if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) + if ( ptr->iswin != iter ) + continue; + if ( ptr->revealed != 0 && now > ptr->revealed+3600 ) { fprintf(stderr,"purge %s\n",ptr->bettxid.GetHex().c_str()); dicefinish_delete(ptr); @@ -359,7 +362,7 @@ void *dicefinish(void *_ptr) ptr->txid = zeroid; } } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter ) + if ( ptr->bettxid_ready != 0 ) { if ( newblock != 0 && ptr->txid != zeroid ) { @@ -384,6 +387,8 @@ void *dicefinish(void *_ptr) m = 0; DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp) { + if ( ptr->iswin != iter ) + continue; if ( ptr->revealed != 0 && time(NULL) > ptr->revealed+3600 ) { fprintf(stderr,"purge2 %s\n",ptr->bettxid.GetHex().c_str()); @@ -397,7 +402,7 @@ void *dicefinish(void *_ptr) if ( numblocks > 0 ) continue; } - if ( ptr->bettxid_ready != 0 && ptr->iswin == iter && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 && ptr->txid == zeroid ) + if ( ptr->bettxid_ready != 0 && ptr->rawtx.size() == 0 && dice_betspent((char *)"dicefinish",ptr->bettxid) <= 0 && ptr->txid == zeroid ) { unstringbits(name,ptr->sbits); result = 0; @@ -418,7 +423,9 @@ void *dicefinish(void *_ptr) break; } } - } else dicefinish_utxosget(num,0,0,coinaddr); + } + else if ( newblock != 0 ) + dicefinish_utxosget(num,0,0,coinaddr); free(utxos); if ( newblock != 0 && num < DICE_MINUTXOS ) { @@ -438,8 +445,8 @@ void *dicefinish(void *_ptr) } } if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight ) - sleep(1); - else usleep(100000); + sleep(3); + else usleep(500000); } return(0); }