From 27fd3246363d98324a4665e879f579185d901a3c Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 25 Aug 2016 23:36:14 -0300 Subject: [PATCH] test --- iguana/iguana777.c | 97 +++++++++++++++++++++++++++++++-------- iguana/iguana_accept.c | 4 +- iguana/iguana_init.c | 3 +- iguana/iguana_recv.c | 13 +++--- iguana/main.c | 74 +++++------------------------ iguana/tests/getinfo | 1 + includes/iguana_funcs.h | 2 +- includes/iguana_structs.h | 2 +- 8 files changed, 106 insertions(+), 90 deletions(-) create mode 100755 iguana/tests/getinfo diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 4b089816f..714b94303 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -567,10 +567,67 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int return(num); } +int32_t iguana_coin_mainiter(struct iguana_info *coin,int32_t *numpeersp) +{ + int32_t n,j,isRT = 0; struct iguana_bundle *bp; + if ( coin->RTheight == 0 && coin->firstRTheight == 0 && coin->current != 0 && coin->active != 0 && coin->started != 0 ) + { + isRT *= (coin->RTheight > 0); + if ( coin->peers != 0 ) + *numpeersp += coin->peers->numranked; + if ( 0 && (rand() % 10) == 0 ) + printf("%s main.%u vs %u, svs %u %d vs %d\n",coin->symbol,(uint32_t)time(NULL),coin->startutc+10,coin->spendvectorsaved ,coin->blocks.hwmchain.height/coin->chain->bundlesize,(coin->longestchain-coin->minconfirms)/coin->chain->bundlesize); + if ( time(NULL) > coin->startutc+60 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->chain->bundlesize)/coin->chain->bundlesize ) + { + n = coin->bundlescount-1; + //printf("%s n.%d emitfinished.%d coin->spendvectorsaved %d\n",coin->symbol,n,iguana_emitfinished(coin,1),coin->spendvectorsaved); + if ( iguana_emitfinished(coin,1) >= n ) + { + if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 ) + { + for (j=0; jbundles[j] != 0 ) + iguana_alloctxbits(coin,&coin->bundles[j]->ramchain); + sleep(3); + } + if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n ) + { + coin->spendvectorsaved = 1; + //printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin)); + } + else + { + coin->spendvectorsaved = (uint32_t)time(NULL); + //printf("already done UTXOGEN (%d %d) (%d %d)\n",iguana_utxofinished(coin),n,iguana_balancefinished(coin),n); + } + } //else printf("only emit.%d vs %d\n",iguana_emitfinished(coin),n); + } + if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME ) + { + if ( 0 ) + { + printf("%s is stuck too long, restarting due to %d\n",coin->symbol,bp->hdrsi); + if ( coin->started != 0 ) + { + iguana_coinpurge(coin); + sleep(3); + while ( coin->started == 0 ) + { + printf("wait for coin to reactivate\n"); + sleep(1); + } + sleep(3); + } + } + } + } + return(isRT); +} + void iguana_helper(void *arg) { static uint64_t helperidbits; - cJSON *argjson=0; int32_t iter,n,j,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; + cJSON *argjson=0; int32_t iter,n,j,numpeers,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; struct iguana_helper *ptr; struct iguana_info *coin,*tmp; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; struct supernet_info *myinfo = SuperNET_MYINFO(0); helperid %= 64; if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) @@ -594,25 +651,30 @@ void iguana_helper(void *arg) { //printf("helperid.%d top of loop\n",helperid); flag = 0; - //iguana_jsonQ(); cant do this here allcurrent = 1; polltimeout = 100; //portable_mutex_lock(&myinfo->allcoins_mutex); - HASH_ITER(hh,myinfo->allcoins,coin,tmp) + if ( helperid == 0 ) { - if ( coin->firstRTheight == 0 ) + numpeers = 0; + HASH_ITER(hh,myinfo->allcoins,coin,tmp) { - if ( coin->spendvectorsaved == 1 ) - iguana_utxogen(myinfo,coin,helperid,0); - else if ( coin->spendvectorsaved > 1 && (coin->spendvalidated & (1 << helperid)) == 0 ) + if ( coin->firstRTheight == 0 ) { - //printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); - for (j=helperid; jbundlescount-1; j+=IGUANA_NUMHELPERS) - if ( (bp= coin->bundles[j]) != 0 ) - iguana_bundlevalidate(coin,bp,0); - coin->spendvalidated |= (1 << helperid); - //printf("DONE %s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); + if ( coin->spendvectorsaved == 1 ) + iguana_utxogen(myinfo,coin,helperid,0); + else if ( coin->spendvectorsaved > 1 && (coin->spendvalidated & (1 << helperid)) == 0 ) + { + //printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); + for (j=helperid; jbundlescount-1; j+=IGUANA_NUMHELPERS) + if ( (bp= coin->bundles[j]) != 0 ) + iguana_bundlevalidate(coin,bp,0); + coin->spendvalidated |= (1 << helperid); + //printf("DONE %s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); + } } + if ( helperid == 0 ) + iguana_coin_mainiter(coin,&numpeers); } } //portable_mutex_unlock(&myinfo->allcoins_mutex); @@ -773,11 +835,11 @@ void iguana_coinloop(void *arg) { coin->peers->lastmetrics = iguana_updatemetrics(myinfo,coin); // ranks peers } - //if ( coin->longestchain+10000 > coin->blocks.maxbits ) - // iguana_recvalloc(coin,coin->longestchain + 100000); if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 || coin->MAXPEERS == 1 ) { + portable_mutex_lock(&coin->allcoins_mutex); flag += iguana_processrecv(myinfo,coin); + portable_mutex_unlock(&coin->allcoins_mutex); if ( strcmp(coin->symbol,"BTCD") == 0 && coin->RTheight > 0 && coin->RTheight > coin->chain->bundlesize ) { int32_t hdrsi,nonz,errs; struct iguana_pkhash *refP; struct iguana_bundle *bp; @@ -786,12 +848,11 @@ void iguana_coinloop(void *arg) bp->weights = iguana_PoS_weights(myinfo,coin,&refP,&bp->supply,&bp->numweights,&nonz,&errs,bp->bundleheight); } } - iguana_jsonQ(); - } //else if ( strcmp(coin->symbol,"BTC") == 0 ) - // printf("skip %s\n",coin->symbol); + } coin->idletime = (uint32_t)time(NULL); } } + //iguana_jsonQ(); //printf("%s flag.%d isRT.%d polltimeout.%d numranked.%d\n",coin->symbol,flag,coin->isRT,coin->polltimeout,coin->peers->numranked); /*if ( flag == 0 && coin->isRT == 0 && coin->peers != 0 ) usleep(coin->polltimeout*1000 + (coin->peers->numranked == 0)*1000000); diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index b5c50e332..04d88734a 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -306,7 +306,7 @@ int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t ma int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2) { int32_t len=0,i,flag=0,height,n,hdrsi,bundlei,bundlesize,firstvout,retval=-1; struct iguana_block *block; struct iguana_bundle *bp; - if ( (firstvout= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,hash2,0,coin->bundlescount-1,0)) != 0 ) + if ( coin->RTheight > 0 && (firstvout= iguana_RTunspentindfind(myinfo,coin,0,0,0,0,&height,hash2,0,coin->bundlescount-1,0)) != 0 ) { bundlesize = coin->chain->bundlesize; hdrsi = (height / bundlesize); @@ -336,6 +336,8 @@ int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *c int32_t iguana_peergetrequest(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,uint8_t *data,int32_t recvlen,int32_t getblock) { int32_t i,reqvers,len,n,flag = 0; bits256 hash2; + if ( coin->RTheight <= 0 ) + return(0); if ( getblock != 0 ) addr->msgcounts.getblocks++; else addr->msgcounts.getheaders++; diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index e382ef68e..eee555a8c 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -64,6 +64,8 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson) portable_mutex_init(&coin->RTmutex); portable_mutex_init(&coin->peers_mutex); portable_mutex_init(&coin->blocks_mutex); + portable_mutex_init(&coin->special_mutex); + portable_mutex_init(&coin->allcoins_mutex); coin->txfee = 10000; iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,coin->blockspacesize,0); iguana_initQs(coin); @@ -74,7 +76,6 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson) usleep(1); coin->startutc++; printf("start.%u\n",coin->startutc); - portable_mutex_init(&coin->special_mutex); coin->startmillis = OS_milliseconds(), coin->starttime = tai_now(); coin->avetime = 1 * 100; //coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES; diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 8dade502d..2b9d82062 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -832,7 +832,7 @@ int32_t iguana_height_estimate(struct iguana_info *coin,struct iguana_block **ma } // main context, ie single threaded -struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock) +struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock) { struct iguana_block *block,*prevblock,*tmp,*mainchain,*hwmblock; bits256 zero,hash2,prevhash2; struct iguana_bundle *prevbp,*bp = 0; int32_t i,newheight,prevbundlei,bundlei = -2; // struct iguana_ramchain blockR; *bundleip = -2; *blockp = 0; @@ -860,6 +860,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl iguana_bundle_set(coin,tmp,newheight-i); if ( (tmp= iguana_blockfind("hwmprev",coin,tmp->RO.prev_block)) == 0 ) break; + iguana_RTnewblock(myinfo,coin,tmp); } if ( mainchain != hwmblock ) iguana_hwmchain_set(coin,mainchain,mainchain->height); // trigger reprocess @@ -973,7 +974,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc if ( bits256_cmp(zblocks[i].RO.prev_block,coin->blocks.hwmchain.RO.hash2) == 0 ) { bp = 0, bundlei = -2; - if ( (bp= iguana_bundleset(coin,&block,&bundlei,(struct iguana_block *)&zblocks[i])) != 0 ) + if ( (bp= iguana_bundleset(myinfo,coin,&block,&bundlei,(struct iguana_block *)&zblocks[i])) != 0 ) { if ( block->height >= 0 && block->height+1 > coin->longestchain ) coin->longestchain = block->height+1; @@ -984,7 +985,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc if ( i > 0 && bits256_cmp(prevhash2,zblocks[i].RO.prev_block) == 0 ) { bp = 0, bundlei = -2; - if ( (bp= iguana_bundleset(coin,&block,&bundlei,(struct iguana_block *)&zblocks[i])) != 0 ) + if ( (bp= iguana_bundleset(myinfo,coin,&block,&bundlei,(struct iguana_block *)&zblocks[i])) != 0 ) { bp->dirty++; if ( 0 && bp->issued[bundlei] == 0 && bp->hdrsi < coin->MAXBUNDLES ) @@ -1243,7 +1244,7 @@ struct iguana_bundlereq *iguana_recvblock(struct supernet_info *myinfo,struct ig coin->longestchain = prevblock->height+1; else iguana_blockQ("prev",coin,0,-1,origblock->RO.prev_block,1); } - if ( (bp= iguana_bundleset(coin,&block,&bundlei,(struct iguana_block *)origblock)) != 0 && bp == coin->current && block != 0 && bp->speculative != 0 && bundlei >= 0 ) + if ( (bp= iguana_bundleset(myinfo,coin,&block,&bundlei,(struct iguana_block *)origblock)) != 0 && bp == coin->current && block != 0 && bp->speculative != 0 && bundlei >= 0 ) { if ( bp->speculative != 0 && bp->numspec <= bundlei ) { @@ -1855,7 +1856,7 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin coin->balanceflush = 0; //iguana_utxoaddr_gen(myinfo,coin,(coin->balanceswritten - 1) * coin->chain->bundlesize); } - if ( (rand() % 10) == 0 ) + /*if ( (rand() % 10) == 0 ) { if ( coin->utxoaddrtable != 0 && coin->RTheight > 0 && coin->RTheight <= coin->blocks.hwmchain.height ) { @@ -1863,7 +1864,7 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) iguana_RTnewblock(myinfo,coin,block); } - } + }*/ flag += iguana_processrecvQ(myinfo,coin,&newhwm); if ( (rand() % 10) == 0 ) flag += iguana_reqblocks(myinfo,coin); diff --git a/iguana/main.c b/iguana/main.c index 02e330b73..abfe3c210 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -392,83 +392,33 @@ rm BTC.xz; mksquashfs DB/BTC BTC.xz -comp xz -b 1048576 -comp xz -Xdict-size 102 https://github.com/vasi/squashfuse */ - void mainloop(struct supernet_info *myinfo) { - int32_t j,n,flag,isRT,numpeers; struct iguana_info *coin,*tmp; struct iguana_bundle *bp; + struct iguana_info *coin,*tmp; int32_t i,depth; portable_mutex_t *stack[IGUANA_MAXCOINS]; sleep(3); printf("mainloop\n"); while ( 1 ) { //printf("main iteration\n"); - flag = 0; - isRT = 1; - numpeers = 0; if ( 1 ) { coin = 0; - //portable_mutex_lock(&myinfo->allcoins_mutex); + depth = 0; HASH_ITER(hh,myinfo->allcoins,coin,tmp) { - if ( coin->RTheight == 0 && coin->firstRTheight == 0 && coin->current != 0 && coin->active != 0 && coin->started != 0 ) - { - isRT *= coin->isRT; - if ( coin->peers != 0 ) - numpeers += coin->peers->numranked; - if ( 0 && (rand() % 10) == 0 ) - printf("%s main.%u vs %u, svs %u %d vs %d\n",coin->symbol,(uint32_t)time(NULL),coin->startutc+10,coin->spendvectorsaved ,coin->blocks.hwmchain.height/coin->chain->bundlesize,(coin->longestchain-coin->minconfirms)/coin->chain->bundlesize); - if ( time(NULL) > coin->startutc+60 && coin->blocks.hwmchain.height/coin->chain->bundlesize >= (coin->longestchain-coin->chain->bundlesize)/coin->chain->bundlesize ) - { - n = coin->bundlescount-1; - //printf("%s n.%d emitfinished.%d coin->spendvectorsaved %d\n",coin->symbol,n,iguana_emitfinished(coin,1),coin->spendvectorsaved); - if ( iguana_emitfinished(coin,1) >= n ) - { - if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 ) - { - for (j=0; jbundles[j] != 0 ) - iguana_alloctxbits(coin,&coin->bundles[j]->ramchain); - sleep(3); - } - if ( iguana_validated(coin) < n || iguana_utxofinished(coin) < n || iguana_balancefinished(coin) < n ) - { - coin->spendvectorsaved = 1; - //printf("update volatile data, need.%d vs utxo.%d balances.%d validated.%d\n",n,iguana_utxofinished(coin),iguana_balancefinished(coin),iguana_validated(coin)); - } - else - { - coin->spendvectorsaved = (uint32_t)time(NULL); - //printf("already done UTXOGEN (%d %d) (%d %d)\n",iguana_utxofinished(coin),n,iguana_balancefinished(coin),n); - } - } //else printf("only emit.%d vs %d\n",iguana_emitfinished(coin),n); - } - if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME ) - { - if ( 0 ) - { - printf("%s is stuck too long, restarting due to %d\n",coin->symbol,bp->hdrsi); - if ( coin->started != 0 ) - { - iguana_coinpurge(coin); - sleep(3); - while ( coin->started == 0 ) - { - printf("wait for coin to reactivate\n"); - sleep(1); - } - sleep(3); - } - } - } - if ( 0 && flag != 0 ) - printf("call RT update busy.%d\n",coin->RTramchain_busy); - } + portable_mutex_lock(&coin->allcoins_mutex); + stack[depth++] = &coin->allcoins_mutex; + } + iguana_jsonQ(); + if ( depth > 0 ) + { + for (i=depth-1; i>=0; i--) + portable_mutex_unlock(stack[i]); } - //portable_mutex_unlock(&myinfo->allcoins_mutex); } //pangea_queues(SuperNET_MYINFO(0)); - if ( flag == 0 ) - usleep(100000 + isRT*100000 + (numpeers == 0)*1000000); + //if ( flag == 0 ) + // usleep(100000 + isRT*100000 + (numpeers == 0)*1000000); //iguana_jsonQ(); // cant do this here safely, need to send to coin specific queue } } diff --git a/iguana/tests/getinfo b/iguana/tests/getinfo new file mode 100755 index 000000000..755bee524 --- /dev/null +++ b/iguana/tests/getinfo @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"method\":\"getinfo\",\"params\":[]}" diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index f28760bd9..80412339f 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -389,7 +389,7 @@ int32_t iguana_balancefinished(struct iguana_info *coin); int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain); void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramchain); int32_t iguana_rwaddr(int32_t rwflag,uint8_t *serialized,struct iguana_msgaddress *addr,int32_t protover); -struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock); +struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock); struct iguana_waddress *iguana_waddresscreate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waccount *wacct,char *coinaddr,char *redeemScript); int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_peer *addr,bits256 hash2); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index aaa66a29f..78552c382 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -443,7 +443,7 @@ struct iguana_info struct OS_memspace TXMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE]; queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ,msgrequestQ; double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; - portable_mutex_t peers_mutex,blocks_mutex,special_mutex,RTmutex; + portable_mutex_t peers_mutex,blocks_mutex,special_mutex,RTmutex,allcoins_mutex; char changeaddr[64]; struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; struct OS_memspace RTrawmem,RTmem,RThashmem; // struct iguana_ramchain RTramchain;