From 30a8281f2f39aad686270f1c77f7f9a1dc335fbd Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 00:43:45 -1100 Subject: [PATCH 01/11] -print --- src/cc/CCutils.cpp | 2 +- src/cc/dice.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index 889b6fdd4..cbd4fba7a 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -386,7 +386,7 @@ int64_t CCduration(int32_t &numblocks,uint256 txid) numblocks = 0; if ( myGetTransaction(txid,tx,hashBlock) == 0 ) { - fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid)); + //fprintf(stderr,"CCduration cant find duration txid %s\n",uint256_str(str,txid)); return(0); } else if ( hashBlock == zeroid ) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 0a6995db1..b36482e3e 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -364,7 +364,7 @@ void *dicefinish(void *_ptr) { ptr->orphaned++; fprintf(stderr,"ORPHANED.%d finish txid.%s\n",ptr->orphaned,ptr->txid.GetHex().c_str()); - if ( ptr->orphaned < 3 ) + if ( ptr->orphaned < 4 ) continue; if ( ptr->rawtx.empty() == 0 ) ptr->rawtx.clear(); From 83040356f58745e685cf38a4d867cf52611c3264 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 00:51:34 -1100 Subject: [PATCH 02/11] Allow 1:1 betting --- 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 b36482e3e..9460bcdc3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -526,7 +526,7 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid, ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1); ptr->entropyvout = entropyvout; DL_APPEND(DICEFINISH_LIST,ptr); - fprintf(stderr,"queued iswin.%d %.8f -> %.8f %s\n",iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); + fprintf(stderr,"queued %dx iswin.%d %.8f -> %.8f %s\n",(int32_t)(betTx.vout[2].nValue - txfee),iswin,(double)betTx.vout[1].nValue/COIN,(double)ptr->winamount/COIN,bettxid.GetHex().c_str()); } else { @@ -1332,7 +1332,7 @@ UniValue DiceList() std::string DiceCreateFunding(uint64_t txfee,char *planstr,int64_t funds,int64_t minbet,int64_t maxbet,int64_t maxodds,int64_t timeoutblocks) { CMutableTransaction mtx; uint256 zero; CScript fundingPubKey; CPubKey mypk,dicepk; int64_t a,b,c,d; uint64_t sbits; struct CCcontract_info *cp,C; - if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 2 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) + if ( funds < 0 || minbet < 0 || maxbet < 0 || maxodds < 1 || maxodds > 9999 || timeoutblocks < 0 || timeoutblocks > 1440 ) { CCerror = "invalid parameter error"; fprintf(stderr,"%s\n", CCerror.c_str() ); @@ -1416,7 +1416,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet CCerror = "bet must be positive"; return(""); } - if ( odds < 2 || odds > 9999 ) + if ( odds < 1 || odds > 9999 ) { CCerror = "odds must be between 2 and 9999"; return(""); From 955d299551c8fbf8dc1e45cbe586815684564d16 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 01:15:34 -1100 Subject: [PATCH 03/11] HASH_TABLE for betted --- src/cc/dice.cpp | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 9460bcdc3..4109cedc3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -102,14 +102,13 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; -static uint256 bettxids[MAX_ENTROPYUSED],Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable +//static uint256 bettxids[MAX_ENTROPYUSED]; +static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable static CTransaction betTxs[MAX_ENTROPYUSED]; static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; -struct dicefinish_utxo { uint256 txid; int32_t vout; }; - struct dicefinish_info { struct dicefinish_info *prev,*next; @@ -123,37 +122,61 @@ struct dicefinish_info uint8_t funcid; } *DICEFINISH_LIST; +struct dicehash_entry +{ + UT_hash_handle hh; + uint256 bettxid; +} *DICEHASH_TABLE; + int32_t _dicehash_find(uint256 bettxid) { - int32_t i; + struct dicehash_entry *ptr; + HASH_FIND(hh,DICEHASH_TABLE,&bettxid,sizeof(bettxid),ptr); + if ( ptr != 0 ) + { + fprintf(stderr,"hash_find %s got %s\n",bettxid.GetHex().c_str(),ptr->bettxid.GetHex().c_str()); + return(1); + } + return(0); + /*int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:16:52 -1100 Subject: [PATCH 04/11] struct dicefinish_utxo { uint256 txid; int32_t vout; }; --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 4109cedc3..13d9156d3 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -109,6 +109,8 @@ static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; +struct dicefinish_utxo { uint256 txid; int32_t vout; }; + struct dicefinish_info { struct dicefinish_info *prev,*next; From 5240f2793f91d518ebedca268277806767da076c Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 01:19:32 -1100 Subject: [PATCH 05/11] struct dicehash_entry * --- 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 13d9156d3..fa229bd48 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -168,8 +168,9 @@ int32_t _dicehash_clear(uint256 bettxid) return(0);*/ } -void _dicehash_add(uint256 bettxid) +struct dicehash_entry *_dicehash_add(uint256 bettxid) { + struct dicehash_entry *ptr; /*int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:23:27 -1100 Subject: [PATCH 06/11] Test --- src/cc/dice.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fa229bd48..a02d3e5b8 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -171,6 +171,8 @@ int32_t _dicehash_clear(uint256 bettxid) struct dicehash_entry *_dicehash_add(uint256 bettxid) { struct dicehash_entry *ptr; + ptr = (struct dicehash_entry *)calloc(1,sizeof(*ptr)); + ptr->bettxid = bettxid; /*int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:40:21 -1100 Subject: [PATCH 07/11] Entropy hash table --- src/cc/dice.cpp | 84 ++++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 36 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index a02d3e5b8..748811a04 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -102,10 +102,9 @@ What is needed is for the dealer node to track the entropy tx that was already b extern int32_t KOMODO_INSYNC; -//static uint256 bettxids[MAX_ENTROPYUSED]; -static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable -static CTransaction betTxs[MAX_ENTROPYUSED]; -static int32_t entropyvouts[MAX_ENTROPYUSED]; +//static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable +//static CTransaction betTxs[MAX_ENTROPYUSED]; +//static int32_t entropyvouts[MAX_ENTROPYUSED]; pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; @@ -130,21 +129,19 @@ struct dicehash_entry uint256 bettxid; } *DICEHASH_TABLE; -int32_t _dicehash_find(uint256 bettxid) +struct dice_entropy +{ + UT_hash_handle hh; + uint256 entropyused,bettxid; + CTransaction betTx; + int32_t entropyvout; +} *DICE_ENTROPY; + +struct dicehash_entry *_dicehash_find(uint256 bettxid) { struct dicehash_entry *ptr; HASH_FIND(hh,DICEHASH_TABLE,&bettxid,sizeof(bettxid),ptr); - if ( ptr != 0 ) - { - fprintf(stderr,"hash_find %s got %s\n",bettxid.GetHex().c_str(),ptr->bettxid.GetHex().c_str()); - return(1); - } - return(0); - /*int32_t i; - for (i=0; ibettxid = bettxid; - /*int32_t i; - for (i=0; ientropyvout ) + { + if ( bettxid == ptr->bettxid ) + { + fprintf(stderr,"identical %s E.%s v.%d\n",bettxid.GetHex().c_str(),entropyused.GetHex().c_str(),entropyvout); + return(entropyvout+1); + } + else + { + fprintf(stderr,"found identical entropy used.%s %s vs %s v.%d vs %d\n",entropyused.GetHex().c_str(),bettxid.GetHex().c_str(),ptr->bettxid.GetHex().c_str(),entropyvout,ptr->entropyvout); + oldbettxid = ptr->bettxid; + oldbetTx = ptr->betTx; + oldentropyvout = ptr->entropyvout; + return(-1); + } + } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,entropyvouts[i]); + } + return(0); + /*int32_t i; for (i=0; ientropyused = entropyused; + ptr->bettxid = bettxid; + ptr->betTx = betTx; + ptr->entropyvout = entropyvout; + HASH_ADD(hh,DICE_ENTROPY,entropyused,sizeof(entropyused),ptr); + return(ptr); +/* int32_t i; for (i=0; i Date: Sun, 11 Nov 2018 01:41:18 -1100 Subject: [PATCH 08/11] Fix --- 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 748811a04..fe42620c9 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -168,7 +168,7 @@ struct dicehash_entry *_dicehash_add(uint256 bettxid) int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &oldentropyvout,uint256 entropyused,uint256 bettxid,int32_t entropyvout) { - struct dicehash_entry *ptr; + struct dice_entropy *ptr; HASH_FIND(hh,DICE_ENTROPY,&entropyused,sizeof(entropyused),ptr); if ( ptr != 0 ) { @@ -187,7 +187,7 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o oldentropyvout = ptr->entropyvout; return(-1); } - } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,entropyvouts[i]); + } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); } return(0); /*int32_t i; From 31bcb93378767902f2adc65096ba2ed94e430298 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 01:47:51 -1100 Subject: [PATCH 09/11] Entropy hash table --- src/cc/dice.cpp | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index fe42620c9..e925ba3dd 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -101,11 +101,6 @@ What is needed is for the dealer node to track the entropy tx that was already b #define DICE_MINUTXOS 7777 extern int32_t KOMODO_INSYNC; - -//static uint256 Entropyused[MAX_ENTROPYUSED][2]; // change to hashtable -//static CTransaction betTxs[MAX_ENTROPYUSED]; -//static int32_t entropyvouts[MAX_ENTROPYUSED]; - pthread_mutex_t DICE_MUTEX,DICEREVEALED_MUTEX; struct dicefinish_utxo { uint256 txid; int32_t vout; }; @@ -176,7 +171,7 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o { if ( bettxid == ptr->bettxid ) { - fprintf(stderr,"identical %s E.%s v.%d\n",bettxid.GetHex().c_str(),entropyused.GetHex().c_str(),entropyvout); + //fprintf(stderr,"identical %s E.%s v.%d\n",bettxid.GetHex().c_str(),entropyused.GetHex().c_str(),entropyvout); return(entropyvout+1); } else @@ -190,24 +185,6 @@ int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &o } else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout); } return(0); - /*int32_t i; - for (i=0; ientropyvout = entropyvout; HASH_ADD(hh,DICE_ENTROPY,entropyused,sizeof(entropyused),ptr); return(ptr); -/* - int32_t i; - for (i=0; i Date: Sun, 11 Nov 2018 02:44:10 -1100 Subject: [PATCH 10/11] Tweak orphan handling --- src/cc/dice.cpp | 2 +- src/cc/heir.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index e925ba3dd..c97d7111b 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -357,7 +357,7 @@ void *dicefinish(void *_ptr) else if ( mytxid_inmempool(ptr->bettxid) != 0 ) ptr->bettxid_ready = (uint32_t)time(NULL); } - else if ( newblock != 0 && myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 ) + else if ( newblock != 0 && (myGetTransaction(ptr->bettxid,betTx,hashBlock) == 0 || now > ptr->bettxid_ready+600) ) { fprintf(stderr,"ORPHANED bettxid.%s\n",ptr->bettxid.GetHex().c_str()); dicefinish_delete(ptr); diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index d4aab932a..c3e7d03e1 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -16,7 +16,8 @@ #include "CCHeir.h" /* - The idea of Heir CC is to allow crypto inheritance + The idea of Heir CC is to allow crypto inheritance. + A special 1of2 CC address is created that is freely spendable by the creator. The heir is only allowed to spend after the specified amount of idle blocks. The idea is that if the address doesnt spend any funds for a year (or whatever amount set), then it is time to allow the heir to spend. The design requires the heir to spend all the funds at once */ // start of consensus code From 84fff7e0972995b5f56792dbf521bef21ef77b28 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 11 Nov 2018 03:47:06 -1100 Subject: [PATCH 11/11] Disable odds 1 as it is broken --- 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 c97d7111b..ced82a4eb 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1421,7 +1421,7 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet CCerror = "bet must be positive"; return(""); } - if ( odds < 1 || odds > 9999 ) + if ( odds < 2 || odds > 9999 ) { CCerror = "odds must be between 2 and 9999"; return("");