Merge branch 'FSM' of https://github.com/jl777/komodo into mastertest

fixed
This commit is contained in:
blackjok3r
2018-11-13 18:07:25 +08:00
14 changed files with 236 additions and 169 deletions

View File

@@ -98,14 +98,9 @@ What is needed is for the dealer node to track the entropy tx that was already b
#include "../compat/endian.h"
#define MAX_ENTROPYUSED 8192
#define DICE_MINUTXOS 7777
#define DICE_MINUTXOS 10000
extern int32_t KOMODO_INSYNC;
static uint256 bettxids[MAX_ENTROPYUSED],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; };
@@ -123,75 +118,85 @@ struct dicefinish_info
uint8_t funcid;
} *DICEFINISH_LIST;
int32_t _dicehash_find(uint256 bettxid)
struct dicehash_entry
{
int32_t i;
for (i=0; i<MAX_ENTROPYUSED; i++)
if ( bettxids[i] == bettxid )
return(1);
return(0);
UT_hash_handle hh;
uint256 bettxid;
} *DICEHASH_TABLE;
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);
return(ptr);
}
int32_t _dicehash_clear(uint256 bettxid)
{
int32_t i;
for (i=0; i<MAX_ENTROPYUSED; i++)
if ( bettxids[i] == bettxid )
{
bettxids[i] = zeroid;
return(1);
}
return(0);
struct dicehash_entry *ptr;
HASH_FIND(hh,DICEHASH_TABLE,&bettxid,sizeof(bettxid),ptr);
if ( ptr != 0 )
{
fprintf(stderr,"delete %s\n",bettxid.GetHex().c_str());
HASH_DELETE(hh,DICEHASH_TABLE,ptr);
return(0);
} else fprintf(stderr,"hashdelete couldnt find %s\n",bettxid.GetHex().c_str());
return(-1);
}
void _dicehash_add(uint256 bettxid)
struct dicehash_entry *_dicehash_add(uint256 bettxid)
{
int32_t i;
for (i=0; i<MAX_ENTROPYUSED; i++)
if ( bettxids[i] == zeroid )
{
bettxids[i] = bettxid;
return;
}
bettxids[rand() % MAX_ENTROPYUSED] = bettxid;
struct dicehash_entry *ptr;
ptr = (struct dicehash_entry *)calloc(1,sizeof(*ptr));
ptr->bettxid = bettxid;
HASH_ADD(hh,DICEHASH_TABLE,bettxid,sizeof(bettxid),ptr);
return(ptr);
}
int32_t _dicerevealed_find(uint256 &oldbettxid,CTransaction &oldbetTx,int32_t &oldentropyvout,uint256 entropyused,uint256 bettxid,int32_t entropyvout)
{
int32_t i;
for (i=0; i<MAX_ENTROPYUSED; i++)
struct dice_entropy *ptr;
HASH_FIND(hh,DICE_ENTROPY,&entropyused,sizeof(entropyused),ptr);
if ( ptr != 0 )
{
if ( Entropyused[i][0] == entropyused )
if ( entropyvout == ptr->entropyvout )
{
if ( entropyvout == entropyvouts[i] )
if ( bettxid == ptr->bettxid )
{
if ( bettxid == Entropyused[i][1] )
return(i+1);
fprintf(stderr,"found identical entropy used.%d B different bettxid!\n",i);
oldbettxid = Entropyused[i][1];
oldbetTx = betTxs[i];
oldentropyvout = entropyvouts[i];
//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]);
}
}
} else fprintf(stderr,"shared entropy.%s vouts %d vs %d\n",entropyused.GetHex().c_str(),entropyvout,ptr->entropyvout);
}
return(0);
}
void _dicerevealed_add(uint256 entropyused,uint256 bettxid,CTransaction betTx,int32_t entropyvout)
struct dice_entropy *_dicerevealed_add(uint256 entropyused,uint256 bettxid,CTransaction betTx,int32_t entropyvout)
{
int32_t i;
for (i=0; i<MAX_ENTROPYUSED; i++)
{
if ( Entropyused[i][0] == zeroid )
break;
}
if ( i == MAX_ENTROPYUSED )
i = (rand() % MAX_ENTROPYUSED);
Entropyused[i][0] = entropyused;
Entropyused[i][1] = bettxid;
entropyvouts[i] = entropyvout;
betTxs[i] = betTx;
struct dice_entropy *ptr;
ptr = (struct dice_entropy *)calloc(1,sizeof(*ptr));
ptr->entropyused = entropyused;
ptr->bettxid = bettxid;
ptr->betTx = betTx;
ptr->entropyvout = entropyvout;
HASH_ADD(hh,DICE_ENTROPY,entropyused,sizeof(entropyused),ptr);
return(ptr);
}
int32_t DiceEntropyUsed(CTransaction &oldbetTx,uint256 &oldbettxid,int32_t &oldentropyvout,uint256 entropyused,uint256 bettxid,CTransaction betTx,int32_t entropyvout)
@@ -221,7 +226,7 @@ bool mySenddicetransaction(std::string res,uint256 entropyused,int32_t entropyvo
//fprintf(stderr,"%s\n%s\n",res.c_str(),uint256_str(str,tx.GetHash()));
if ( funcid == 'R' || (retval= DiceEntropyUsed(oldbetTx,oldbettxid,oldentropyvout,entropyused,bettxid,betTx,entropyvout)) >= 0 )
{
//LOCK(cs_main);
LOCK(cs_main);
if ( myAddtomempool(tx) != 0 )
{
RelayTransaction(tx);
@@ -314,10 +319,11 @@ void dicefinish_delete(struct dicefinish_info *ptr)
void *dicefinish(void *_ptr)
{
std::vector<uint8_t> mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CTransaction betTx,finishTx;
std::vector<uint8_t> mypk; struct CCcontract_info *cp,C; char name[32],coinaddr[64],CCaddr[64]; std::string res; int32_t newht,newblock,entropyvout,numblocks,lastheight=0,vin0_needed,i,n,m,num,iter,result; struct dicefinish_info *ptr,*tmp; uint32_t now; struct dicefinish_utxo *utxos; uint256 hashBlock,entropyused; CPubKey dicepk; CTransaction betTx,finishTx,tx;
mypk = Mypubkey();
pubkey2addr(coinaddr,mypk.data());
cp = CCinit(&C,EVAL_DICE);
dicepk = GetUnspendable(cp,0);
GetCCaddress(cp,CCaddr,GetUnspendable(cp,0));
fprintf(stderr,"start dicefinish thread %s CCaddr.%s\n",coinaddr,CCaddr);
if ( (newht= KOMODO_INSYNC) == 0 )
@@ -352,7 +358,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);
@@ -364,7 +370,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();
@@ -388,18 +394,28 @@ void *dicefinish(void *_ptr)
fprintf(stderr,"send refund!\n");
mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr);
}
dicefinish_delete(ptr);
continue;
}
}
if ( ptr->bettxid_ready != 0 )
{
if ( newblock != 0 && ptr->txid != zeroid )
if ( now > ptr->bettxid_ready + 2*3600 )
{
CCduration(numblocks,ptr->txid);
//fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str());
if ( numblocks == 0 )
mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr);
else continue;
fprintf(stderr,"purge bettxid_ready %s\n",ptr->bettxid.GetHex().c_str());
dicefinish_delete(ptr);
continue;
}
else if ( newblock != 0 )
{
if ( ptr->txid != zeroid )
{
CCduration(numblocks,ptr->txid);
//fprintf(stderr,"duration finish txid.%s\n",ptr->txid.GetHex().c_str());
if ( numblocks == 0 )
mySenddicetransaction(ptr->rawtx,ptr->entropyused,ptr->entropyvout,ptr->bettxid,ptr->betTx,ptr->funcid,ptr);
else continue;
}
}
if ( ptr->txid == zeroid )
vin0_needed++;
@@ -412,7 +428,7 @@ void *dicefinish(void *_ptr)
utxos = (struct dicefinish_utxo *)calloc(vin0_needed,sizeof(*utxos));
if ( (n= dicefinish_utxosget(num,utxos,vin0_needed,coinaddr)) > 0 )
{
//fprintf(stderr,"iter.%d vin0_needed.%d got %d\n",iter,vin0_needed,n);
//fprintf(stderr,"iter.%d vin0_needed.%d got %d, num 0.0002 %d\n",iter,vin0_needed,n,num);
m = 0;
DL_FOREACH_SAFE(DICEFINISH_LIST,ptr,tmp)
{
@@ -466,24 +482,7 @@ void *dicefinish(void *_ptr)
}
}
}
else if ( newblock != 0 )
dicefinish_utxosget(num,0,0,coinaddr);
free(utxos);
if ( newblock != 0 && num < DICE_MINUTXOS )
{
char *cmd = (char *)malloc(100 * 128);
sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr);
fprintf(stderr,"num normal 0.0002 utxos.%d < %d\n",num,DICE_MINUTXOS);
if ( system(cmd) != 0 )
fprintf(stderr,"system error issuing.(%s)\n",cmd);
free(cmd);
if ( (rand() % 100) == 0 )
{
fprintf(stderr,"make 0.023 utxos\n");
if ( system("cc/dapps/sendmany") != 0 )
fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n");
}
}
}
}
if ( (newht= KOMODO_INSYNC) == 0 || newht == lastheight )
@@ -526,12 +525,12 @@ void DiceQueue(int32_t iswin,uint64_t sbits,uint256 fundingtxid,uint256 bettxid,
ptr->winamount = betTx.vout[1].nValue * ((betTx.vout[2].nValue - txfee)+1);
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
{
//fprintf(stderr,"DiceQueue status bettxid.%s already in list\n",bettxid.GetHex().c_str());
//_dicehash_clear(bettxid);
_dicehash_clear(bettxid);
}
pthread_mutex_unlock(&DICE_MUTEX);
}
@@ -933,7 +932,7 @@ bool DiceValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction &tx)
if ( (iswin= DiceIsWinner(entropy,entropyvout,txid,tx,vinTx,hash,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 )
{
// will only happen for fundingPubKey
if ( KOMODO_INSYNC != 0 )
if ( KOMODO_INSYNC != 0 && KOMODO_DEALERNODE != 0 )
DiceQueue(iswin,sbits,fundingtxid,txid,tx,entropyvout);
}
else
@@ -1073,11 +1072,12 @@ uint64_t AddDiceInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubK
unstringbits(sstr,sbits);
if ( sbits == refsbits && (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid )
{
if ( funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' )
if ( funcid == 'R' || funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T' )
{
if ( total != 0 && maxinputs != 0 )
{
fprintf(stderr,"use (%c) %.8f %s %s/v%d\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid),vout);
if ( funcid == 'R' )
fprintf(stderr,">>>>>>>>>>>> use (%c) %.8f %s %s/v%d\n",funcid,(double)tx.vout[0].nValue/COIN,sstr,uint256_str(str,txid),vout);
mtx.vin.push_back(CTxIn(txid,vout,CScript()));
}
totalinputs += it->second.satoshis;
@@ -1134,7 +1134,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit
if ( (funcid == 'F' && reffundingtxid == txid) || reffundingtxid == fundingtxid )
{
//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 ( (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') )
if ( (nValue= IsDicevout(cp,tx,vout,refsbits,reffundingtxid)) >= 10000 && (funcid == 'R' || funcid == 'F' || funcid == 'E' || funcid == 'W' || funcid == 'L' || funcid == 'T') )
{
if ( funcid == 'L' || funcid == 'W' || funcid == 'E' )
n++;
@@ -1198,7 +1198,7 @@ int64_t DicePlanFunds(uint64_t &entropyval,uint256 &entropytxid,uint64_t refsbit
}
}
}
else if ( funcid != 'B' )
else if ( 0 && funcid != 'B' )
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);
@@ -1335,7 +1335,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() );
@@ -1425,8 +1425,12 @@ std::string DiceBet(uint64_t txfee,char *planstr,uint256 fundingtxid,int64_t bet
return("");
}
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,sbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 ) {
<<<<<<< HEAD
CCerror = "error in Diceinit";
=======
CCerror = "Diceinit error in bet, is your transaction confirmed?";
>>>>>>> 08b2f80458cd1f0313af8089c9fda3b9a82ea68c
return("");
}
if ( bet < minbet || bet > maxbet || odds > maxodds )
@@ -1538,7 +1542,8 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv
mtx.vin.push_back(CTxIn(bettxid,0,CScript()));
mtx.vin.push_back(CTxIn(bettxid,1,CScript()));
funcid = 'R';
mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey));
mtx.vout.push_back(MakeCC1vout(cp->evalcode,betTx.vout[0].nValue,dicepk));
//mtx.vout.push_back(CTxOut(betTx.vout[0].nValue,fundingPubKey));
mtx.vout.push_back(CTxOut(txfee,fundingPubKey));
mtx.vout.push_back(CTxOut(betTx.vout[1].nValue,betTx.vout[2].scriptPubKey));
*resultp = 1;
@@ -1638,9 +1643,72 @@ std::string DiceBetFinish(uint8_t &funcid,uint256 &entropyused,int32_t &entropyv
return("couldnt find bettx or entropytx");
}
static uint256 dealer0_fundingtxid;
void *dealer0_loop(void *_arg)
{
char *planstr = (char *)_arg;
CTransaction tx; CPubKey mypk,dicepk; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs,i,n,num; CScript fundingPubKey; struct CCcontract_info *cp,C; char coinaddr[64]; std::string res; int64_t minbet,maxbet,maxodds,timeoutblocks; uint64_t refsbits,txfee = 10000;
if ( (cp= Diceinit(fundingPubKey,dealer0_fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
{
fprintf(stderr,"error initializing dealer0_loop\n");
exit(-1);
}
fprintf(stderr,"dealer0 node running\n");
while ( 1 )
{
DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,dealer0_fundingtxid,entropytxs,false);
if ( entropytxs < DICE_MINUTXOS )
{
n = sqrt(DICE_MINUTXOS - entropytxs) + 10;
for (i=0; i<DICE_MINUTXOS - entropytxs && i<n; i++)
{
res = DiceAddfunding(txfee,planstr,dealer0_fundingtxid,COIN/100);
if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 )
{
if ( DecodeHexTx(tx,res) != 0 )
{
LOCK(cs_main);
if ( myAddtomempool(tx) != 0 )
{
fprintf(stderr,"ENTROPY %s: %d of %d, %d\n",tx.GetHash().GetHex().c_str(),i,n,DICE_MINUTXOS - entropytxs);
RelayTransaction(tx);
} else break;
} else break;
} else break;
}
}
pubkey2addr(coinaddr,Mypubkey().data());
dicefinish_utxosget(num,0,0,coinaddr);
fprintf(stderr,"have %d 0.0002 utxos, need %d\n",num,DICE_MINUTXOS);
if ( num < DICE_MINUTXOS ) // this deadlocks, need to put it in a different thread
{
char *cmd = (char *)malloc(100 * 128);
sprintf(cmd,"./komodo-cli -ac_name=%s sendmany \"\" \"{\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002,\\\"%s\\\":0.0002}\"",ASSETCHAINS_SYMBOL,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr,coinaddr);
n = sqrt((DICE_MINUTXOS - num) / 100)*2 + 1;
fprintf(stderr,"num normal 0.0002 utxos.%d < %d -> n.%d\n",num,DICE_MINUTXOS,n);
for (i=0; i<n; i++)
{
fprintf(stderr,"%d of %d: ",i,n);
if ( system(cmd) != 0 )
fprintf(stderr,"system error issuing.(%s)\n",cmd);
}
free(cmd);
if ( (rand() % 100) == 0 )
{
fprintf(stderr,"make 0.023 utxos\n");
if ( system("cc/dapps/sendmany") != 0 )
fprintf(stderr,"system error issuing.(cc/dapps/sendmany)\n");
}
}
sleep(60);
}
return(0);
}
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,entropyvout,flag,win,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid;
static int32_t didinit; static char _planstr[64];
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,entropyvout,flag,win,num,loss,duplicate=0,result,iswin,vout,n=0; int64_t minbet,maxbet,maxodds,timeoutblocks,sum=0; uint64_t sbits,refsbits; char coinaddr[64]; std::string res; uint8_t funcid;
if ( (cp= Diceinit(fundingPubKey,fundingtxid,&C,planstr,txfee,mypk,dicepk,refsbits,minbet,maxbet,maxodds,timeoutblocks)) == 0 )
{
CCerror = "Diceinit error in status";
@@ -1667,8 +1735,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
{
if ( myGetTransaction(betTx.vin[0].prevout.hash,entropyTx,hashBlock) != 0 )
{
flag = 0;
if ( scriptPubKey == fundingPubKey )
flag = KOMODO_DEALERNODE != 0;
if ( KOMODO_DEALERNODE != 0 && scriptPubKey == fundingPubKey )
{
bettorentropy = DiceGetEntropy(betTx,'B');
if ( (iswin= DiceIsWinner(hentropyproof,entropyvout,txid,betTx,entropyTx,bettorentropy,sbits,minbet,maxbet,maxodds,timeoutblocks,fundingtxid)) != 0 )
@@ -1679,46 +1747,30 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
loss++;
n++;
DiceQueue(iswin,sbits,fundingtxid,txid,betTx,entropyvout);
} //else flag = 1;
}
}
if ( flag != 0 || scriptPubKey != fundingPubKey )
if ( scriptPubKey != fundingPubKey )
{
if ( flag != 0 )
fprintf(stderr,"illegal bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN);
fprintf(stderr,"serialized bettxid %d: iswin.%d W.%d L.%d %s/v%d (%c %.8f) %.8f\n",n,iswin,win,loss,txid.GetHex().c_str(),vout,funcid,(double)it->second.satoshis/COIN,(double)sum/COIN);
res = DiceBetFinish(funcid,entropyused,entropyvout,&result,txfee,planstr,fundingtxid,txid,scriptPubKey == fundingPubKey,zeroid,-1);
if ( result > 0 )
{
mySenddicetransaction(res,entropyused,entropyvout,txid,betTx,funcid,0);
n++;
if ( n > 10 )
break;
}
}
} else fprintf(stderr,"bettxid.%s cant find entropyTx.%s\n",txid.GetHex().c_str(),betTx.vin[0].prevout.hash.GetHex().c_str());
}
}
}
if ( scriptPubKey == fundingPubKey )
if ( didinit == 0 && KOMODO_DEALERNODE == 0 && scriptPubKey == fundingPubKey )
{
CTransaction tx; uint64_t entropyval; uint256 entropytxid; int32_t entropytxs;
DicePlanFunds(entropyval,entropytxid,refsbits,cp,dicepk,fundingtxid,entropytxs,false);
if ( entropytxs < DICE_MINUTXOS )
{
for (i=0; i<DICE_MINUTXOS - entropytxs && i<10; i++)
{
res = DiceAddfunding(txfee,planstr,fundingtxid,COIN/100);
if ( res.empty() == 0 && res.size() > 64 && is_hexstr((char *)res.c_str(),0) > 64 )
{
if ( DecodeHexTx(tx,res) != 0 )
{
//LOCK(cs_main);
if ( myAddtomempool(tx) != 0 )
{
fprintf(stderr,"ENTROPY %s: %d of %d\n",tx.GetHash().GetHex().c_str(),i,DICE_MINUTXOS - entropytxs);
RelayTransaction(tx);
} else break;
} else break;
} else break;
}
}
strcpy(_planstr,planstr);
dealer0_fundingtxid = fundingtxid;
if ( pthread_create((pthread_t *)malloc(sizeof(pthread_t)),NULL,dealer0_loop,_planstr) == 0 )
didinit = 1;
}
return(n);
}