From d7c442f9bb24700e0918aeab8001690aee5392b2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:32:49 +0800 Subject: [PATCH 01/48] try --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 491798a98..8cff5d98c 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -398,7 +398,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid)); return(0); } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight ) + else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime+1 || pindex->nHeight <= txheight ) { fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); return(0); From 0e898d9e5521e3bdedbfa6808e5ee62c70a94065 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 00:48:44 +0800 Subject: [PATCH 02/48] no? --- src/cc/CCutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 8cff5d98c..491798a98 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -398,7 +398,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) fprintf(stderr,"CCduration no txtime %u or txheight.%d %p for txid %s\n",txtime,txheight,pindex,uint256_str(str,txid)); return(0); } - else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime+1 || pindex->nHeight <= txheight ) + else if ( (pindex= chainActive.LastTip()) == 0 || pindex->nTime < txtime || pindex->nHeight <= txheight ) { fprintf(stderr,"CCduration backwards timestamps %u %u for txid %s hts.(%d %d)\n",(uint32_t)pindex->nTime,txtime,uint256_str(str,txid),txheight,(int32_t)pindex->nHeight); return(0); From e65938c35e9557895e799b6275e022bb867a4ddc Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:16:12 +0800 Subject: [PATCH 03/48] fix? --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index d4777e5ca..1643d8ad5 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,6 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { + printf("%s\n",uint256_str(str,entropy); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From 22a613b99a57a3d9e3bae5c14122232b6ecf7a27 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:19:58 +0800 Subject: [PATCH 04/48] try --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1643d8ad5..3f1b3e903 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,6 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { + char str[65]; printf("%s\n",uint256_str(str,entropy); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); From 0b52093a3be9e0bc41bc1a78ac5b54f8d9c3584d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:21:30 +0800 Subject: [PATCH 05/48] w --- 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 3f1b3e903..2377a2689 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -414,7 +414,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction if ( hentropy == hentropy2 ) { char str[65]; - printf("%s\n",uint256_str(str,entropy); + printf("%s\n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From 7a4eb1733243bc0d702614ae19b53dfd8855b15d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:22:27 +0800 Subject: [PATCH 06/48] w --- 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 2377a2689..2c2525ad8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,7 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - char str[65]; + //char str[65]; printf("%s\n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); From 39dd777cf2ca845eaa2557fe46b52629eaa7f8a6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:27:42 +0800 Subject: [PATCH 07/48] w --- 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 2c2525ad8..fa36051dc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,8 +413,8 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - //char str[65]; - printf("%s\n",uint256_str(str,entropy)); + char *str; + fprintf(stderr, "%s\n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From f3916237387bff9700f4cc1b0d249d4032e06472 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:30:04 +0800 Subject: [PATCH 08/48] w --- 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 fa36051dc..14adc28d6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,8 +413,7 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - char *str; - fprintf(stderr, "%s\n",uint256_str(str,entropy)); + fprintf(stderr, "%s something \n",uint256_str(str2,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); From 15e09a681e96546a1cc73bc9ef652b1de4011001 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:31:15 +0800 Subject: [PATCH 09/48] lel --- 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 14adc28d6..ef9e9c7ca 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,9 +413,9 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - fprintf(stderr, "%s something \n",uint256_str(str2,entropy)); + fprintf(stderr, "%s something \n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + //har str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { From dc5420fb4b5eba433eb8a359efef2bc37e608f51 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:32:37 +0800 Subject: [PATCH 10/48] a --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ef9e9c7ca..109d12ea4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,9 +413,10 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { + char str[65]; fprintf(stderr, "%s something \n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - //har str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { From 1889b058b62ac5e5048bf0cddffb12fb6af836a2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 01:58:50 +0800 Subject: [PATCH 11/48] w --- 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 109d12ea4..6f8c597f9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -599,11 +599,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } if ( iswin != 0 ) { - //char str[65],str2[65]; + char str[65],str2[65]; entropy = DiceGetEntropy(vinTx,'B'); vcalc_sha256(0,(uint8_t *)&hash,(uint8_t *)&proof,32); - //fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); - //fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); + fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); + fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); winnings = DiceCalc(vinTx.vout[1].nValue,vinTx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,proof,entropy); if ( (winnings == 0 && iswin > 0) || (winnings > 0 && iswin < 0) ) return eval->Invalid("DiceCalc mismatch for win/loss"); From 4b1061a8a284f9c4ef7cebcdba492dc9e35a76d8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 02:49:43 +0800 Subject: [PATCH 12/48] w --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 6f8c597f9..971b3bc57 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,6 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + fprintf(stderr, "vout value: %ld txfee: %ld\n", vinTx.vout[2].nValue,txfee); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 030fce32a9401df4bb9dcc6ceba910b14e5c44b8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:00:03 +0800 Subject: [PATCH 13/48] w --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 971b3bc57..868858519 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,8 +578,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "vout value: %ld txfee: %ld\n", vinTx.vout[2].nValue,txfee); - odds = vinTx.vout[2].nValue - txfee; + fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); + //odds = vinTx.vout[2].nValue - txfee; + odds = 1; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) From cee9c7d9cf73755397f0b3ff90eac910a4790a4e Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:06:49 +0800 Subject: [PATCH 14/48] w --- 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 868858519..88b2b65c0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -579,8 +579,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); - //odds = vinTx.vout[2].nValue - txfee; - odds = 1; + odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) From a6a648d1ca3110a0d849269fe56a7cb1025053eb Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:21:36 +0800 Subject: [PATCH 15/48] a --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 88b2b65c0..564ac83f4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,6 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + LOCK2(cs_main, pwalletMain->cs_wallet); fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) From 767c232780b2657cfaf765d701ba7a67be1c986f Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:28:06 +0800 Subject: [PATCH 16/48] w --- 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 564ac83f4..702709aa3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,8 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - LOCK2(cs_main, pwalletMain->cs_wallet); - fprintf(stderr, "vout value: %ld\n", vinTx.vout[2].nValue); + LOCK2(cs_main); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 36342965cb3e203205d1fc3dd6451630146bc941 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:30:12 +0800 Subject: [PATCH 17/48] w --- 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 702709aa3..b1375f12c 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - LOCK2(cs_main); + LOCK(cs_main); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 936e2ff4a5f68dae67c5b67a466099b097ba05b6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:35:30 +0800 Subject: [PATCH 18/48] w --- 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 b1375f12c..6dfe5b1d0 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - LOCK(cs_main); + usleep(5000) odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From d3e25cfd6b57e8ffd9e66e07758e6db9eef0cd12 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 03:36:48 +0800 Subject: [PATCH 19/48] poo --- 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 6dfe5b1d0..298cee932 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - usleep(5000) + usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 1a9784d156e85848cdf69a4ef16302666d8b57c1 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 09:49:23 +0800 Subject: [PATCH 20/48] try --- src/cc/dice.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 298cee932..790475b66 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -552,7 +552,8 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { CBlockIndex block; if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid("always should find vin.0, but didnt for wlt"); + return eval->Invalid("always should find vin.0, but didnt for wlt"); + fprintf(stderr, "vout2.nvalue = %d\n", vinTx.vout[2].nValue); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); @@ -578,6 +579,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + fprintf(stderr, "%d\n",txfee); usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) @@ -600,11 +602,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } if ( iswin != 0 ) { - char str[65],str2[65]; + //char str[65],str2[65]; entropy = DiceGetEntropy(vinTx,'B'); vcalc_sha256(0,(uint8_t *)&hash,(uint8_t *)&proof,32); - fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); - fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); + //fprintf(stderr,"calculated house hentropy.%s\n",uint256_str(str,hash)); + //fprintf(stderr,"verify house entropy %s vs bettor %s\n",uint256_str(str,proof),uint256_str(str2,entropy)); winnings = DiceCalc(vinTx.vout[1].nValue,vinTx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,proof,entropy); if ( (winnings == 0 && iswin > 0) || (winnings > 0 && iswin < 0) ) return eval->Invalid("DiceCalc mismatch for win/loss"); From 21f53468f33c5af5f13a95bc895d26171cbf84b8 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 09:51:01 +0800 Subject: [PATCH 21/48] try --- 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 790475b66..ff6214e6b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -553,7 +553,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) CBlockIndex block; if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); - fprintf(stderr, "vout2.nvalue = %d\n", vinTx.vout[2].nValue); + fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); @@ -579,7 +579,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "%d\n",txfee); + fprintf(stderr, "%ld\n",txfee); usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) From 09d3bd8cb21d66330dc802190458e230348a3d29 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 10:21:51 +0800 Subject: [PATCH 22/48] a --- src/cc/dice.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index ff6214e6b..66a2c15bf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,9 +551,11 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { CBlockIndex block; + fprintf(stderr, "Got tx unconfirmed!\n"); if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid("always should find vin.0, but didnt for wlt"); - fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); + char str[65]; + fprintf(stderr, "Got tx confirmed in block: %s \n", uint256_str(str,hashBlock)); } else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); @@ -561,6 +563,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("sbits or fundingtxid mismatch for wlt"); else if ( fundingPubKey != tx.vout[1].scriptPubKey ) return eval->Invalid("tx.vout[1] != fundingPubKey for wlt"); + fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); if ( funcid == 'L' ) { //vout.0: funding CC to entropy owner @@ -579,7 +582,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "%ld\n",txfee); + fprintf(stderr, "tx fee: %ld\n",txfee); usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) From adbb327574ac3ce430a73cfc3865cc318f020ff2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 11:05:58 +0800 Subject: [PATCH 23/48] fix finally --- src/cc/dice.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 66a2c15bf..b4ad2dde7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -544,19 +544,16 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vin.3+: funding CC vout.0 from 'F', 'E', 'W', 'L' or 'T' //vout.1: tag to owner address for entropy funds preventCCvouts = 1; + CBlockIndex block; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - CBlockIndex block; - fprintf(stderr, "Got tx unconfirmed!\n"); - if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) - return eval->Invalid("always should find vin.0, but didnt for wlt"); - char str[65]; - fprintf(stderr, "Got tx confirmed in block: %s \n", uint256_str(str,hashBlock)); - } + return eval->Invalid("always should find vin.0, but didnt for wlt"); + } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) + return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) return eval->Invalid("not betTx for vin0/1 for wlt"); else if ( sbits != vinsbits || fundingtxid != vinfundingtxid ) From 05dc40eb3e9195b6eef83223690828b32cb8bf26 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 11:18:34 +0800 Subject: [PATCH 24/48] remove prints --- src/cc/dice.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b4ad2dde7..05cb306cb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,7 +551,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - return eval->Invalid("always should find vin.0, but didnt for wlt"); + return eval->Invalid("always should find vin.0, but didnt for wlt"); } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -560,7 +560,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) return eval->Invalid("sbits or fundingtxid mismatch for wlt"); else if ( fundingPubKey != tx.vout[1].scriptPubKey ) return eval->Invalid("tx.vout[1] != fundingPubKey for wlt"); - fprintf(stderr, "vout2.nvalue = %ld\n", vinTx.vout[2].nValue); if ( funcid == 'L' ) { //vout.0: funding CC to entropy owner @@ -579,8 +578,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - fprintf(stderr, "tx fee: %ld\n",txfee); - usleep(5000); odds = vinTx.vout[2].nValue - txfee; if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); From 2e05c9efce9410113b135f0aace303ecf58c7b94 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 11:55:42 +0800 Subject: [PATCH 25/48] try --- src/cc/dice.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 05cb306cb..00888e230 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -551,7 +551,14 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - return eval->Invalid("always should find vin.0, but didnt for wlt"); + int tries = 0; + while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { + tries++; + sleep(1); + if ( tries > 60 ) { + return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); + } + } } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From e2408f31c351dddc1c2e31c3234d8c9a1a89abea Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:15:12 +0800 Subject: [PATCH 26/48] try --- src/cc/dice.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 00888e230..33efff005 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -745,7 +745,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit fprintf(stderr," (%c) tx vin.%d fundingPubKey mismatch %s\n",funcid,tx.vin[0].prevout.n,uint256_str(str,tx.vin[0].prevout.hash)); } } - } else fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); + } //else fprintf(stderr,"%s %c refsbits.%llx sbits.%llx nValue %.8f\n",uint256_str(str,txid),funcid,(long long)refsbits,(long long)sbits,(double)nValue/COIN); } //else fprintf(stderr,"else case funcid (%c) %d %s vs %s\n",funcid,funcid,uint256_str(str,reffundingtxid),uint256_str(str2,fundingtxid)); } //else fprintf(stderr,"funcid.%d %c skipped %.8f\n",funcid,funcid,(double)tx.vout[vout].nValue/COIN); } i = i + 1; @@ -770,7 +770,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac //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 ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) + if ( DecodeiningOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { fundingPubKey = tx.vout[1].scriptPubKey; return(true); @@ -974,7 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); + printf("first entropy val found: %ld\n",entropyval,); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); + printf("second entropy val found: %ld\n",entropyval,); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From f72bf9aaf08ab9c17ba3e34a51cdf9a27407f9a0 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:17:27 +0800 Subject: [PATCH 27/48] fix prints --- src/cc/dice.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 33efff005..92a0a9952 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -698,13 +698,13 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit { if ( refsbits == sbits && (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) > 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') ) { - fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); + //fprintf(stderr,"%s.(%c %.8f) ",uint256_str(str,txid),funcid,(double)nValue/COIN); if ( funcid != 'F' && funcid != 'T' ) n++; totalinputs += nValue; if ( first == 0 && (funcid == 'E' || funcid == 'W' || funcid == 'L') ) { - fprintf(stderr,"check first\n"); + //fprintf(stderr,"check first\n"); if ( fundingPubKey == tx.vout[1].scriptPubKey ) { if ( funcid == 'E' && fundingtxid != tx.vin[0].prevout.hash ) From e4737a39b3ae17100b54c61cafd7d71bca0a8663 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:19:10 +0800 Subject: [PATCH 28/48] 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 92a0a9952..2d7055782 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -974,9 +974,9 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet } int32_t entropytxs=0,emptyvar=0; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - printf("first entropy val found: %ld\n",entropyval,); + printf("first entropy val found: %ld\n",entropyval); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - printf("second entropy val found: %ld\n",entropyval,); + printf("second entropy val found: %ld\n",entropyval); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From b8069b78390f085df8adc4a22faf36dc1079eb08 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:22:51 +0800 Subject: [PATCH 29/48] wtf --- 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 2d7055782..9c7bc31b7 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -770,7 +770,7 @@ bool DicePlanExists(CScript &fundingPubKey,uint256 &fundingtxid,struct CCcontrac //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 ( DecodeiningOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) + if ( DecodeDiceFundingOpRet(tx.vout[tx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 'F' && sbits == refsbits ) { fundingPubKey = tx.vout[1].scriptPubKey; return(true); From 57797961db87b6024decd121e685fdb3eb01af98 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:27:37 +0800 Subject: [PATCH 30/48] try --- src/cc/dice.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9c7bc31b7..1f31ff652 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -973,10 +973,11 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; + char str[65]; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - printf("first entropy val found: %ld\n",entropyval); + printf("first entropy tx found: %s\n",uint256_str(str,entropytxid)); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - printf("second entropy val found: %ld\n",entropyval); + printf("second entropy tx found: %s\n",uint256_str(str,entropytxid)); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From dc4d2cd7c79462bcee6abf3b6d3cbea31a5b25ba Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:38:02 +0800 Subject: [PATCH 31/48] test --- src/cc/dice.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 1f31ff652..81d9231a1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -681,8 +681,10 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit GetCCaddress(cp,coinaddr,dicepk); SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; + int loops = 0; for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { + loops++; if (random) { if ( (rand() % 100) < 90 ) continue; @@ -731,6 +733,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropytxid = txid; entropyval = tx.vout[0].nValue; first = 1; + fprintf(stderr, "chosen entropy on loop: %d\n",loops); } else { From cdd74f5bb3da7450f3f842cd1915fafeb2e87fec Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:44:09 +0800 Subject: [PATCH 32/48] a --- src/cc/dice.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 81d9231a1..9cb1efced 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -682,6 +682,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; + fprintf(stderr, "number of unspents: %ld\n",unspentOutputs.size()); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; From 7600093c2fce0bfc7e1816e1b5ffb3d68954bb8a Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:53:03 +0800 Subject: [PATCH 33/48] fix --- src/cc/dice.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9cb1efced..ab2a27a34 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -682,13 +682,18 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - fprintf(stderr, "number of unspents: %ld\n",unspentOutputs.size()); + if (random) { + int startfrom = rand()%((unspentOutputs.size()\2)-1 + 1) + 1; + fprintf(stderr, "start from loop: %d\n",startfrom); + } for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; if (random) { + if ( loops < startfrom ) + continue; if ( (rand() % 100) < 90 ) - continue; + continue; } txid = it->first.txhash; vout = (int32_t)it->first.index; From 8b0a16daff2fe2e2c769d78fc300aa6de20e0043 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:54:46 +0800 Subject: [PATCH 34/48] ? --- 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 ab2a27a34..459cd28a1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -683,7 +683,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropyval = 0; int loops = 0; if (random) { - int startfrom = rand()%((unspentOutputs.size()\2)-1 + 1) + 1; + int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; fprintf(stderr, "start from loop: %d\n",startfrom); } for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) From da7291922e02da9b2e8a73485c6154dfa7b2e789 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 12:56:07 +0800 Subject: [PATCH 35/48] try --- src/cc/dice.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 459cd28a1..2e20139c2 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -682,10 +682,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - if (random) { - int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; - fprintf(stderr, "start from loop: %d\n",startfrom); - } + int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; + fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; From 9fc43996cd04e91cb6dee43028da88bdd2bbcd47 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:03:40 +0800 Subject: [PATCH 36/48] fix? --- 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 2e20139c2..3f166eb9f 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -555,7 +555,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { tries++; sleep(1); - if ( tries > 60 ) { + char str[65]; + fprintf(stderr, "tx.%s hashBlock.%s\n",uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); + if ( tries > 20 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } } From cf7d67cb53674561898f83e60d3e1428f0e39958 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:28:53 +0800 Subject: [PATCH 37/48] try --- 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 3f166eb9f..b1629b72d 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -556,7 +556,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) tries++; sleep(1); char str[65]; - fprintf(stderr, "tx.%s hashBlock.%s\n",uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",txid,uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); if ( tries > 20 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } @@ -684,7 +684,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int startfrom = rand()%((unspentOutputs.size()%2)-1 + 1) + 1; + int startfrom = rand()%(unspentOutputs.size()%2); fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 300626dc0c69fc43cadf021d4327e2738c59bc86 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:30:59 +0800 Subject: [PATCH 38/48] 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 b1629b72d..b39f39dbf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -556,7 +556,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) tries++; sleep(1); char str[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",txid,uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); if ( tries > 20 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } From 4aea265846f80efd11a8fd80586c721613a13836 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 13:34:27 +0800 Subject: [PATCH 39/48] try --- src/cc/dice.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index b39f39dbf..cb6103040 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -684,7 +684,8 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit SetCCunspents(unspentOutputs,coinaddr); entropyval = 0; int loops = 0; - int startfrom = rand()%(unspentOutputs.size()%2); + int numtxs = unspentOutputs.size()/2; + int startfrom = rand()%numtxs; fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { From 9f39af9cdd765867cb34fb425950b3a2b1eec07d Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 15:40:02 +0800 Subject: [PATCH 40/48] try --- src/cc/CCtx.cpp | 16 +++++++++++++--- src/cc/dice.cpp | 4 ---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index f29fd05e8..d8c0ceb1d 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -17,12 +17,12 @@ /* FinalizeCCTx is a very useful function that will properly sign both CC and normal inputs, adds normal change and the opreturn. - + This allows the contract transaction functions to create the appropriate vins and vouts and have FinalizeCCTx create a properly signed transaction. - + By using -addressindex=1, it allows tracking of all the CC addresses */ - + bool SignTx(CMutableTransaction &mtx,int32_t vini,int64_t utxovalue,const CScript scriptPubKey) { #ifdef ENABLE_WALLET @@ -274,8 +274,18 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; + int loops = 0; + int numtxs = numunspents/2; + int startfrom = rand()%numtxs; for (above=below=i=0; i 300 ) { + if ( loops < startfrom ) + continue; + if ( (rand() % 100) < 75 ) + continue; + } if ( (atx_value= utxos[i].nValue) <= 0 ) continue; if ( atx_value == value ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index cb6103040..aecfa17d1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -686,7 +686,6 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit int loops = 0; int numtxs = unspentOutputs.size()/2; int startfrom = rand()%numtxs; - fprintf(stderr, "start from loop: %d\n",startfrom); for (std::vector >::const_iterator it=unspentOutputs.begin(); it!=unspentOutputs.end(); it++) { loops++; @@ -983,11 +982,8 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet return(""); } int32_t entropytxs=0,emptyvar=0; - char str[65]; funding = DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,entropytxs,false); - printf("first entropy tx found: %s\n",uint256_str(str,entropytxid)); DicePlanFunds(entropyval,entropytxid,sbits,cp,dicepk,fundingtxid,emptyvar,true); - printf("second entropy tx found: %s\n",uint256_str(str,entropytxid)); if ( ( funding >= 2*bet*odds+txfee && entropyval != 0 ) ) { if ( entropytxs < 100 ) { From 44c1c99ffada44345cfd6817abb48ae70254f818 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:01:27 +0800 Subject: [PATCH 41/48] fix --- src/cc/CCtx.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index d8c0ceb1d..5c2c42e97 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -274,16 +274,10 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * { int32_t i,abovei,belowi; int64_t above,below,gap,atx_value; abovei = belowi = -1; - int loops = 0; - int numtxs = numunspents/2; - int startfrom = rand()%numtxs; for (above=below=i=0; i 300 ) { - if ( loops < startfrom ) - continue; - if ( (rand() % 100) < 75 ) + if ( numunspents > 150 ) { + if ( (rand() % 100) < 80 ) continue; } if ( (atx_value= utxos[i].nValue) <= 0 ) From e054db050515fa644a0dbc8ed5b44eb4b1758cc7 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:15:04 +0800 Subject: [PATCH 42/48] ? --- 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 aecfa17d1..96d372523 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -555,9 +555,9 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { tries++; sleep(1); - char str[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str,tx.vin[1].prevout.hash),uint256_str(str,hashBlock)); - if ( tries > 20 ) { + char str[65],str2[65],str3[65] + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); + if ( tries > 10 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); } } From b888ef1af1df13924da3a82cbb6cf9ce03ac4ee6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:16:56 +0800 Subject: [PATCH 43/48] ; --- 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 96d372523..e2c5c2caf 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -555,7 +555,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { tries++; sleep(1); - char str[65],str2[65],str3[65] + char str[65],str2[65],str3[65]; fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); if ( tries > 10 ) { return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); From 95bb8b29f2be313170525cdeb8d461364b4d5f19 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:30:07 +0800 Subject: [PATCH 44/48] try --- src/cc/dice.cpp | 57 ++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e2c5c2caf..7566fa2f6 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -545,22 +545,18 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.1: tag to owner address for entropy funds preventCCvouts = 1; CBlockIndex block; + int skipped = 0; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); else if ( tx.vin[1].prevout.hash != tx.vin[2].prevout.hash ) return eval->Invalid("vin0 != vin1 prevout.hash for bet"); else if ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - int tries = 0; - while ( eval->GetTxUnconfirmed(tx.vin[1].prevout.hash,vinTx,hashBlock) == 0 ) { - tries++; - sleep(1); - char str[65],str2[65],str3[65]; - fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); - if ( tries > 10 ) { - return eval->Invalid("always should find after 60s of looking vin.0, but didnt for wlt"); - } - } + char str[65],str2[65],str3[65]; + fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); + //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); + skipped = 1; + } } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) @@ -584,27 +580,30 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - //vout.0: funding CC change to entropy owner - //vout.2: normal output to bettor's address - //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof - odds = vinTx.vout[2].nValue - txfee; - if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) - return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); - else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) - return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); - else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) - return eval->Invalid("vout[2] payut mismatch for win/timeout"); - else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) + if ( skipped == 0) { - fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); - return eval->Invalid("CC funds mismatch for win/timeout"); + //vout.0: funding CC change to entropy owner + //vout.2: normal output to bettor's address + //vout.n-1: opreturn 'W' sbits fundingtxid hentropy proof + odds = vinTx.vout[2].nValue - txfee; + if ( ConstrainVout(tx.vout[0],1,cp->unspendableCCaddr,0) == 0 ) + return eval->Invalid("vout[0] != inputs-txfee for win/timeout"); + else if ( tx.vout[2].scriptPubKey != vinTx.vout[2].scriptPubKey ) + return eval->Invalid("vout[2] scriptPubKey mismatch for win/timeout"); + else if ( tx.vout[2].nValue != (odds+1)*vinTx.vout[1].nValue ) + return eval->Invalid("vout[2] payut mismatch for win/timeout"); + else if ( inputs != (outputs + tx.vout[2].nValue) && inputs != (outputs + tx.vout[2].nValue+txfee) ) + { + fprintf(stderr,"inputs %.8f != outputs %.8f + %.8f\n",(double)inputs/COIN,(double)outputs/COIN,(double)tx.vout[2].nValue/COIN); + return eval->Invalid("CC funds mismatch for win/timeout"); + } + else if ( tx.vout[3].scriptPubKey != fundingPubKey ) + { + if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) + return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); + } + iswin = (funcid == 'W'); } - else if ( tx.vout[3].scriptPubKey != fundingPubKey ) - { - if ( tx.vout[3].scriptPubKey.size() == 0 || ((uint8_t *)tx.vout[3].scriptPubKey.data())[0] != 0x6a ) - return eval->Invalid("vout[3] not send to fundingPubKey for win/timeout"); - } - iswin = (funcid == 'W'); } if ( iswin != 0 ) { From be37ffee83dff9c4eef6f1597df1f26ffbd69418 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 16:32:47 +0800 Subject: [PATCH 45/48] fix --- src/cc/dice.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 7566fa2f6..86483d008 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -445,7 +445,7 @@ bool DiceVerifyTimeout(CTransaction &betTx,int32_t timeoutblocks) bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) { uint256 txid,fundingtxid,vinfundingtxid,vinhentropy,vinproof,hashBlock,hash,proof,entropy; int64_t minbet,maxbet,maxodds,timeoutblocks,odds,winnings; uint64_t vinsbits,sbits,amount,inputs,outputs,txfee=10000; int32_t numvins,numvouts,preventCCvins,preventCCvouts,i,iswin; uint8_t funcid; CScript fundingPubKey; CTransaction fundingTx,vinTx,vinofvinTx; char CCaddr[64]; - CBlockIndex block; + CBlockIndex block; int skipped = 0; numvins = tx.vin.size(); numvouts = tx.vout.size(); preventCCvins = preventCCvouts = -1; @@ -545,7 +545,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) //vout.1: tag to owner address for entropy funds preventCCvouts = 1; CBlockIndex block; - int skipped = 0; DiceAmounts(inputs,outputs,cp,eval,tx,sbits,fundingtxid); if ( IsCCInput(tx.vin[1].scriptSig) == 0 || IsCCInput(tx.vin[2].scriptSig) == 0 ) return eval->Invalid("vin0 or vin1 normal vin for bet"); @@ -556,7 +555,6 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) fprintf(stderr, "txid.%s tx.%s hashBlock.%s\n",uint256_str(str,txid),uint256_str(str2,tx.vin[1].prevout.hash),uint256_str(str3,hashBlock)); //return eval->Invalid("always should find looking vin.0, but didnt for wlt"); skipped = 1; - } } else if (hashBlock.IsNull() || !eval->GetBlock(hashBlock, block)) return eval->Invalid(" TX not confirmed! always should find vin.0, but didnt for wlt"); else if ( vinTx.vout.size() < 3 || DecodeDiceOpRet(tx.vin[1].prevout.hash,vinTx.vout[vinTx.vout.size()-1].scriptPubKey,vinsbits,vinfundingtxid,vinhentropy,vinproof) != 'B' ) From e36c6f65ee56169df909a2c49b025fb87ec453c6 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 18:04:29 +0800 Subject: [PATCH 46/48] posibly stable --- src/cc/CCtx.cpp | 2 +- src/cc/dice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 5c2c42e97..3326e9447 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -276,7 +276,7 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * abovei = belowi = -1; for (above=below=i=0; i 150 ) { + if ( numunspents > 500 ) { if ( (rand() % 100) < 80 ) continue; } diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 86483d008..927ab7b95 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -578,7 +578,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx) } else { - if ( skipped == 0) + if ( skipped == 0 ) { //vout.0: funding CC change to entropy owner //vout.2: normal output to bettor's address From d72c39339362553b98c0ebd77ef4cd393439223b Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 18:36:22 +0800 Subject: [PATCH 47/48] done? --- src/cc/CCtx.cpp | 4 ---- src/cc/dice.cpp | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index 3326e9447..71669a0a6 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -276,10 +276,6 @@ int32_t CC_vinselect(int32_t *aboveip,int64_t *abovep,int32_t *belowip,int64_t * abovei = belowi = -1; for (above=below=i=0; i 500 ) { - if ( (rand() % 100) < 80 ) - continue; - } if ( (atx_value= utxos[i].nValue) <= 0 ) continue; if ( atx_value == value ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 927ab7b95..afebfd4e4 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1203,6 +1203,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } error = "didnt find dicefinish tx"; } + error = res; return(-1.); } return(0.); From 6756a2f4f2f39aaee88174ad81f3e84d52d895a2 Mon Sep 17 00:00:00 2001 From: blackjok3r Date: Mon, 29 Oct 2018 20:00:04 +0800 Subject: [PATCH 48/48] done --- src/cc/dice.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index afebfd4e4..67d251bcc 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -413,10 +413,8 @@ int32_t DiceIsWinner(uint256 &entropy,uint256 txid,CTransaction tx,CTransaction hentropy2 = DiceHashEntropy(entropy,vinTx.vin[0].prevout.hash); if ( hentropy == hentropy2 ) { - char str[65]; - fprintf(stderr, "%s something \n",uint256_str(str,entropy)); winnings = DiceCalc(tx.vout[1].nValue,tx.vout[2].nValue,minbet,maxbet,maxodds,timeoutblocks,entropy,bettorentropy); - fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); + char str[65]; fprintf(stderr,"%s winnings %.8f bet %.8f at odds %d:1\n",uint256_str(str,tx.GetHash()),(double)winnings/COIN,(double)tx.vout[1].nValue/COIN,(int32_t)(tx.vout[2].nValue-10000)); //fprintf(stderr,"I am house entropy %.8f entropy.(%s) vs %s -> winnings %.8f\n",(double)vinTx.vout[0].nValue/COIN,uint256_str(str,entropy),uint256_str(str2,hash),(double)winnings/COIN); if ( winnings == 0 ) { @@ -736,7 +734,9 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit entropytxid = txid; entropyval = tx.vout[0].nValue; first = 1; - fprintf(stderr, "chosen entropy on loop: %d\n",loops); + if (random) { + fprintf(stderr, "chosen entropy on loop: %d\n",loops); + } } else { @@ -1202,8 +1202,7 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx } else return(0.); } error = "didnt find dicefinish tx"; - } - error = res; + } else error = res; return(-1.); } return(0.);