From d3738119ee64739a39f4779ffee185db64590e1d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 7 Nov 2018 06:16:25 -1100 Subject: [PATCH 01/79] 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 02/79] 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 03/79] 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 04/79] 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 05/79] 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 06/79] 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 07/79] 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 08/79] 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 09/79] 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 10/79] 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 11/79] 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 12/79] 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 13/79] 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 14/79] 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 15/79] 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 16/79] 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 17/79] 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 18/79] 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 19/79] 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 20/79] 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 21/79] 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 22/79] 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 23/79] 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 24/79] 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 25/79] 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 26/79] 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 27/79] 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 28/79] 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 29/79] 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 30/79] 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 31/79] 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 32/79] 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 33/79] 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 34/79] 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 35/79] 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 36/79] 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 37/79] 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 38/79] 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 39/79] 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 40/79] 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 41/79] 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 42/79] 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 43/79] 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 44/79] 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 45/79] 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 46/79] 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 47/79] 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 48/79] 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 49/79] 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 50/79] 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 51/79] 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 52/79] 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 53/79] 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 54/79] 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 55/79] 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 56/79] 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 57/79] 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 58/79] 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 59/79] 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 60/79] 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 61/79] 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 62/79] 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 63/79] 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 64/79] 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 65/79] 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 66/79] 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 67/79] 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 68/79] 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 69/79] 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 70/79] 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 71/79] 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 72/79] 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 73/79] 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 74/79] 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 75/79] 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 76/79] 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 77/79] 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 78/79] 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 79/79] 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");