diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index 8e1a16d7e..6f1293408 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -137,7 +137,7 @@ char *basilisk_finish(struct supernet_info *myinfo,struct basilisk_item *ptr,int if ( jobj(item,"myip") == 0 ) jaddstr(item,"myip",myinfo->ipaddr); jaddi(retarray,item); - } + } else printf("couldnt parse.(%s)\n",str); free(str); } retstr = jprint(retarray,1); @@ -208,7 +208,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ memset(cmd,0,sizeof(cmd)); sprintf(cmd,"SuperNET%s",type); r = rand(); - //portable_mutex_lock(&Allcoins_mutex); + portable_mutex_lock(&myinfo->allcoins_mutex); HASH_ITER(hh,myinfo->allcoins,coin,tmp) { if ( coin->peers == 0 ) @@ -265,7 +265,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ if ( n >= IGUANA_MAXPEERS*IGUANA_MAXCOINS ) break; } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); free(alreadysent); return(n); } @@ -335,12 +335,12 @@ char *basilisk_waitresponse(struct supernet_info *myinfo,char *CMD,char *symbol, while ( OS_milliseconds() < ptr->expiration ) { //if ( (retstr= basilisk_iscomplete(ptr)) != 0 ) - if ( (retstr= ptr->retstr) != 0 ) + if ( ptr->numresults >= ptr->numrequired || (retstr= ptr->retstr) != 0 ) break; usleep(50000); } if ( retstr == 0 ) - retstr = basilisk_finish(myinfo,ptr,-1,"[{\"error\":\"basilisk timeout\"}]"); + retstr = basilisk_finish(myinfo,ptr,-1,"[{\"error\":\"basilisk wait timeout\"}]"); } basilisk_sendback(myinfo,CMD,symbol,remoteaddr,ptr->basilisktag,retstr); return(retstr); @@ -826,7 +826,7 @@ void basilisk_geckoresult(struct supernet_info *myinfo,struct basilisk_item *ptr void basilisk_pending_result(struct supernet_info *myinfo,struct basilisk_item *ptr,struct basilisk_item *pending) { - int32_t n; struct basilisk_item *parent; basilisk_metricfunc metricfunc; + int32_t n; basilisk_metricfunc metricfunc; if ( (n= pending->numresults) < sizeof(pending->results)/sizeof(*pending->results) ) { pending->numresults++; @@ -848,11 +848,11 @@ void basilisk_pending_result(struct supernet_info *myinfo,struct basilisk_item * if ( strcmp(ptr->CMD,"RET") == 0 || strcmp(ptr->CMD,"GET") == 0 ) { printf("got return for tag.%d parent.%p\n",pending->basilisktag,pending->parent); - if ( (parent= pending->parent) != 0 ) + /*if ( (parent= pending->parent) != 0 ) { pending->parent = 0; parent->childrendone++; - } + }*/ if ( strcmp(ptr->CMD,"GET") == 0 ) basilisk_geckoresult(myinfo,ptr); } @@ -917,7 +917,7 @@ int32_t basilisk_issued_iteration(struct supernet_info *myinfo,struct basilisk_i void basilisks_loop(void *arg) { - struct iguana_info *btcd,*virt,*hhtmp; struct basilisk_item *ptr,*tmp,*pending; int32_t iter,maxmillis,flag; struct supernet_info *myinfo = arg; + struct basilisk_item *ptr,*tmp,*pending; int32_t iter,flag; struct supernet_info *myinfo = arg; iter = 0; while ( 1 ) { @@ -940,21 +940,6 @@ void basilisks_loop(void *arg) { flag += basilisk_issued_iteration(myinfo,pending); } - if ( flag == 0 && myinfo->allcoins_numvirts > 0 && (btcd= iguana_coinfind("BTCD")) != 0 ) - { - maxmillis = (1000 / myinfo->allcoins_numvirts) + 1; - //portable_mutex_lock(&Allcoins_mutex); - HASH_ITER(hh,myinfo->allcoins,virt,hhtmp) - { - if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) - { - //fprintf(stderr,"h"); - gecko_iteration(myinfo,btcd,virt,maxmillis); - flag++; - } - } - //portable_mutex_unlock(&Allcoins_mutex); - } } //fprintf(stderr,"i "); //for (i=0; iallcoins_mutex); HASH_ITER(hh,myinfo->allcoins,coin,tmp) { balance = 0.; @@ -477,7 +477,7 @@ cJSON *BALANCES(struct exchange_info *exchange,cJSON *argjson) if ( unspents != 0 ) free(unspents); } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); return(retjson); } diff --git a/iguana/iguana777.c b/iguana/iguana777.c index cfe3e1193..64ee7d7c6 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -31,13 +31,15 @@ struct iguana_info *iguana_coinfind(char *symbol) sleep(1); } symbolcrc = calc_crc32(0,symbol,(int32_t)strlen(symbol)); - HASH_FIND(hh,myinfo->allcoins,&symbolcrc,sizeof(coin->symbolcrc),coin); + portable_mutex_lock(&myinfo->allcoins_mutex); + HASH_FIND(hh,myinfo->allcoins,&symbolcrc,sizeof(coin->symbolcrc),coin); + portable_mutex_unlock(&myinfo->allcoins_mutex); return(coin); } struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson) { - struct iguana_info *coin,*tmp; uint32_t symbolcrc; char *privatechain; int32_t j; struct supernet_info *myinfo = SuperNET_MYINFO(0); + struct iguana_info *coin; uint32_t symbolcrc; char *privatechain; int32_t j; struct supernet_info *myinfo = SuperNET_MYINFO(0); if ( (coin= iguana_coinfind(symbol)) == 0 ) { portable_mutex_lock(&myinfo->allcoins_mutex); @@ -74,14 +76,12 @@ struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson) basilisk_functions(coin,coin->protocol); printf("ADD ALLCOINS.(%s) name.(%s) size %ld numvirts.%d\n",symbol,name,sizeof(*coin),myinfo->allcoins_numvirts); coin->symbolcrc = symbolcrc = calc_crc32(0,symbol,(int32_t)strlen(symbol)); - HASH_ADD(hh,myinfo->allcoins,symbolcrc,sizeof(coin->symbolcrc),coin); + portable_mutex_lock(&myinfo->allcoins_mutex); + HASH_ADD(hh,myinfo->allcoins,symbolcrc,sizeof(coin->symbolcrc),coin); + portable_mutex_unlock(&myinfo->allcoins_mutex); myinfo->allcoins_being_added = 0; } portable_mutex_unlock(&myinfo->allcoins_mutex); - HASH_ITER(hh,myinfo->allcoins,coin,tmp) - { - printf("HASH_ITER.(%s)\n",coin->symbol); - } if ( (coin= iguana_coinfind(symbol)) == 0 ) printf("error finding justadded.(%s)\n",symbol); } @@ -549,8 +549,8 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert void iguana_helper(void *arg) { static int32_t maxhelperid; - cJSON *argjson=0; int32_t iter,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; - struct iguana_helper *ptr; struct iguana_info *coin,*btcd,*tmp; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; struct supernet_info *myinfo = SuperNET_MYINFO(0); + cJSON *argjson=0; int32_t iter,n,j,maxmillis,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; + struct iguana_helper *ptr; struct iguana_info *coin,*btcd,*virt,*tmp; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; struct supernet_info *myinfo = SuperNET_MYINFO(0); if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) helperid = juint(argjson,"helperid"); if ( helperid > maxhelperid ) @@ -571,16 +571,32 @@ void iguana_helper(void *arg) sleep(2); while ( 1 ) { - if ( helperid == 0 && (btcd= iguana_coinfind("BTCD")) != 0 ) + if ( (btcd= iguana_coinfind("BTCD")) != 0 ) { - if ( myinfo->numrelays > 0 && myinfo->genesisresults == 0 ) + if ( helperid == 0 && myinfo->numrelays > 0 && myinfo->genesisresults == 0 ) basilisk_geckogenesis(myinfo,btcd,0,0,GENESIS_PUBKEY,0,0); + if ( myinfo->allcoins_numvirts > 0 ) + { + maxmillis = (10000 / myinfo->allcoins_numvirts) + 1; + flag = 0; + portable_mutex_lock(&myinfo->allcoins_mutex); + HASH_ITER(hh,myinfo->allcoins,virt,tmp) + { + if ( virt->started != 0 && virt->active != 0 && virt->virtualchain != 0 ) + { + //fprintf(stderr,"h"); + if ( (flag++ % IGUANA_NUMHELPERS) == helperid ) + gecko_iteration(myinfo,btcd,virt,maxmillis); + } + } + portable_mutex_unlock(&myinfo->allcoins_mutex); + } } //iguana_jsonQ(); cant do this here flag = 0; allcurrent = 2; polltimeout = 100; - //portable_mutex_lock(&Allcoins_mutex); + portable_mutex_lock(&myinfo->allcoins_mutex); HASH_ITER(hh,myinfo->allcoins,coin,tmp) { if ( coin->spendvectorsaved == 1 ) @@ -592,7 +608,7 @@ void iguana_helper(void *arg) iguana_bundlevalidate(coin,bp,0); } } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); n = queue_size(&bundlesQ); for (iter=0; iterallcoins_mutex); HASH_ITER(hh,myinfo->allcoins,coin,tmp) { if ( coin->chain->rpcport == port ) break; else coin = 0; } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); } if ( coin == 0 && symbol[0] != 0 ) coin = iguana_coinfind(symbol); diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 8908fd5d4..691f17674 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -930,7 +930,7 @@ STRING_ARG(bitcoinrpc,validateaddress,address) cJSON_AddTrueToObject(retjson,"ismine"); } else cJSON_AddFalseToObject(retjson,"ismine"); - //portable_mutex_lock(&Allcoins_mutex); + portable_mutex_lock(&myinfo->allcoins_mutex); HASH_ITER(hh,myinfo->allcoins,other,tmp) { if ( strcmp(other->symbol,coin->symbol) != 0 ) @@ -939,7 +939,7 @@ STRING_ARG(bitcoinrpc,validateaddress,address) jaddstr(retjson,other->symbol,str); } } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); return(jprint(retjson,1)); } diff --git a/iguana/main.c b/iguana/main.c index 24d6c9243..04ab60469 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -414,7 +414,7 @@ void mainloop(struct supernet_info *myinfo) if ( 1 ) { coin = 0; - //portable_mutex_lock(&Allcoins_mutex); + portable_mutex_lock(&myinfo->allcoins_mutex); HASH_ITER(hh,myinfo->allcoins,coin,tmp) { if ( coin->current != 0 && coin->active != 0 && coin->started != 0 ) @@ -467,7 +467,7 @@ void mainloop(struct supernet_info *myinfo) printf("call RT update busy.%d\n",coin->RTramchain_busy); } } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); } //pangea_queues(SuperNET_MYINFO(0)); if ( flag == 0 ) @@ -1932,12 +1932,12 @@ STRING_ARG(SuperNET,getpeers,activecoin) max = SuperNET_coinpeers(coin,SNjson,rawjson,max); else { - //portable_mutex_lock(&Allcoins_mutex); + portable_mutex_lock(&myinfo->allcoins_mutex); HASH_ITER(hh,myinfo->allcoins,coin,tmp) { max = SuperNET_coinpeers(coin,SNjson,rawjson,max); } - //portable_mutex_unlock(&Allcoins_mutex); + portable_mutex_unlock(&myinfo->allcoins_mutex); } if ( max != 64 ) {