diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 12b267be4..8ecb2f118 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -380,7 +380,7 @@ void iguana_balancesQ(struct iguana_info *coin,struct iguana_bundle *bp) void iguana_helper(void *arg) { - cJSON *argjson=0; int32_t iter,retval,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; + cJSON *argjson=0; int32_t iter,n,retval,polltimeout,type,helperid=rand(),flag,allcurrent,idle=0; struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; struct iguana_bundle *bp; if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) helperid = juint(argjson,"helperid"); @@ -396,7 +396,7 @@ void iguana_helper(void *arg) { //iguana_jsonQ(); cant do this here flag = 0; - allcurrent = 1; + allcurrent = 2; polltimeout = 100; //printf("helper.%d\n",helperid); /*if ( ((ptr= queue_dequeue(&emitQ,0)) != 0 || (ptr= queue_dequeue(&helperQ,0)) != 0) ) @@ -415,7 +415,8 @@ void iguana_helper(void *arg) }*/ if ( (type & (1 << 0)) != 0 ) { - for (iter=0; iter<2048; iter++) + n = queue_size(&bundlesQ); + for (iter=0; iteractive.%d\n",bp->hdrsi,bp->nexttime,time(NULL)-bp->nexttime,coin->active); - allcurrent = 0; + allcurrent--; iguana_bundleQ(ptr->coin,bp,1000); } } @@ -485,8 +486,11 @@ void iguana_helper(void *arg) allcurrent = 0; if ( flag != 0 ) usleep(polltimeout * 250); - else if ( allcurrent != 0 ) + else if ( allcurrent > 0 ) + { + //printf("bundlesQ allcurrent\n"); usleep(polltimeout * 100000); + } else usleep(polltimeout * 100); } } diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index b1e686bec..e5f1ae2c3 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -57,8 +57,9 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin } while ( depth != 0 ) { - printf("%s blockhashset.%d depth.%d\n",debugstr,height,depth); - printf("%d\n",1/(1 - depth/depth)); + printf(">>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",debugstr,height,depth); + fprintf(stderr,">>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",debugstr,height,depth); + //printf("%d\n",1/(1 - depth/depth)); } depth++; HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); @@ -67,8 +68,9 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin depth--; while ( depth != 0 ) { - printf("%s match blockhashset.%d depth.%d\n",debugstr,height,depth); - printf("%d\n",1/(1 - depth/depth)); + printf(">>>>>>>>>> OK only if rare%s match blockhashset.%d depth.%d\n",debugstr,height,depth); + fprintf(stderr,">>>>>>>>>> OK only if rare%s match blockhashset.%d depth.%d\n",debugstr,height,depth); + //printf("%d\n",1/(1 - depth/depth)); } return(block); } @@ -101,8 +103,9 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin depth--; while ( depth != 0 ) { - printf("%s create blockhashset.%d depth.%d\n",debugstr,height,depth); - printf("%d\n",1/(1 - depth/depth)); + printf(">>>>>>>>>> OK only if rare%s create blockhashset.%d depth.%d\n",debugstr,height,depth); + fprintf(stderr,">>>>>>>>>> OK only if rare%s create blockhashset.%d depth.%d\n",debugstr,height,depth); + //printf("%d\n",1/(1 - depth/depth)); } return(block); } @@ -324,8 +327,11 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl } else { - char str[65]; printf("chainlink error: cant find prev.(%s)\n",bits256_str(str,block->RO.prev_block)); - memset(&block->RO.prev_block.bytes,0,sizeof(block->RO.prev_block)); + char str[65]; + if ( bits256_nonz(block->RO.prev_block) != 0 ) + printf("chainlink error: cant find prev.(%s)\n",bits256_str(str,block->RO.prev_block)); + iguana_blockunmark(coin,block,0,-1,0); + //memset(&block->RO.prev_block.bytes,0,sizeof(block->RO.prev_block)); //getchar(); return(0); } diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 20467ee1c..d144f342c 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -978,10 +978,10 @@ double iguana_bundlemissings(struct iguana_info *coin,struct iguana_bundle *bp,d void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) { - int32_t i,n,m,j,numv,numconverted,count,starti,lasti,pending,capacity,dispflag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit; struct iguana_block *block; bits256 hash2; + int32_t i,n,m,j,numv,numconverted,count,starti,lasti,pending,capacity,displag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit; struct iguana_block *block; bits256 hash2; int64_t spaceused=0,estsize = 0; struct iguana_bundle *currentbp,*lastbp,*bp,*lastpending = 0,*firstgap = 0; uint32_t now; double aveduration,recentduration = 0.; now = (uint32_t)time(NULL); - dispflag = 1;//(rand() % 1000) == 0; + displag = (now - coin->lastdisp); numrecv = numhashes = numcached = numconverted = numsaved = numemit = done = numutxo = numbalances = 0; count = coin->bundlescount; currentbp = coin->current; @@ -1010,13 +1010,13 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) { for (j=0; jn; j++) { - if ( bp->blocks[j] == 0 ) + if ( bp->blocks[j] == 0 && bits256_nonz(bp->hashes[j]) != 0 ) bp->blocks[j] = iguana_blockfind("bundlestats2",coin,bp->hashes[j]); } } else { - if ( bp->hdrsi >= starti && bp->hdrsi < lasti ) + if ( bp->hdrsi >= starti && bp->hdrsi < lasti && (displag % 3) == 2 ) { if ( (aveduration= iguana_bundlemissings(coin,bp,recentduration,lag)) != 0 ) dxblend(&recentduration,aveduration,.5); @@ -1027,7 +1027,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) { //if ( bp->blocks[j] == 0 && bp->speculative != 0 && bits256_nonz(bp->speculative[j]) != 0 ) // bp->blocks[j] = iguana_blockhashset("speculative3",coin,bp->bundleheight+j,bp->speculative[j],1); - if ( bp->speculativecache[j] != 0 ) + if ( bp->blocks[j] == 0 && bp->speculativecache[j] != 0 ) { if ( (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0 && block->processed == 0 ) iguana_cacheprocess(coin,bp,j); @@ -1131,7 +1131,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) coin->stucktime = (uint32_t)time(NULL); coin->stuckiters = 0; } - else if ( coin->stucktime != 0 ) + else if ( coin->stucktime != 0 && (displag % 3) == 1 ) { uint8_t missings[IGUANA_MAXBUNDLESIZE/8+1]; struct iguana_blockreq *breq; double aveduration; int32_t tmp,tmp2,n,priority=3,lag; lag = (int32_t)time(NULL) - coin->stucktime; diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 2cf10c94d..df682f0ae 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -1032,7 +1032,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin) } } lflag = 1; - while ( coin->active != 0 && iters < 10*IGUANA_MAXITERATIONS ) + while ( coin->active != 0 && iters < coin->longestchain/3+1 ) { iters++; lflag = 0; diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 2c56e8b5c..16c8455b7 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -1311,6 +1311,7 @@ void iguana_RTramchainfree(struct iguana_info *coin) { iguana_utxoupdate(coin,-1,0,0,0,0,-1); // free hashtables coin->RTheight = coin->balanceswritten * coin->chain->bundlesize; + coin->RTgenesis = 0; iguana_ramchain_free(coin,&coin->RTramchain,1); } @@ -1397,13 +1398,13 @@ int32_t iguana_realtime_update(struct iguana_info *coin) if ( (block= bp->blocks[bundlei]) != 0 && bits256_nonz(block->RO.prev_block) != 0 ) { iguana_blocksetcounters(coin,block,dest); - B[bundlei] = block->RO; startmillis0 = OS_milliseconds(); if ( iguana_ramchainfile(coin,dest,&blockR,bp,bundlei,block) == 0 ) { - iguana_RTramchainfree(coin); + //iguana_RTramchainfree(coin); return(-1); } else iguana_ramchain_free(coin,&blockR,1); + B[bundlei] = block->RO; totalmillis0 += (OS_milliseconds() - startmillis0); num0++; flag++; @@ -1608,16 +1609,16 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu int32_t iguana_balancenormal(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight) { uint32_t starttime; int32_t j=0,n; struct iguana_bundle *prevbp; - n = coin->bundlescount; + n = coin->bundlescount - 1; for (j=0; jbundles[j]) == 0 ) break; - if ( prevbp->balancefinish <= 1 || (j < bp->hdrsi && prevbp->utxofinish <= 1) ) + if ( prevbp->utxofinish <= 1 || (j < bp->hdrsi && prevbp->balancefinish <= 1) ) break; } //printf("B [%d] j.%d u.%u b.%u\n",bp->hdrsi,j,bp->utxofinish,bp->balancefinish); - if ( j == n && bp->bundleheight+bp->n <= coin->blocks.hwmchain.height && bp->utxofinish > 1 && bp->balancefinish <= 1 ) + if ( (j == n || bp->hdrsi == 0) && bp->bundleheight+bp->n <= coin->blocks.hwmchain.height && bp->utxofinish > 1 && bp->balancefinish <= 1 ) { if ( bp->hdrsi >= coin->balanceswritten ) { @@ -1757,7 +1758,20 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int if ( m == n-1 ) iguana_spendvectorsaves(coin); } - } //else printf("error with invalid tmpspends.[%d]\n",bp->hdrsi), getchar(); + } + else + { + for (i=0; ibundlescount-1; i++) + { + if ( coin->bundles[i] == 0 || coin->bundles[i]->emitfinish <= 1 ) + break; + } + if ( i == coin->bundlescount-1 ) + { + printf("must be restart after all the spendvectors are saved\n"); + coin->spendvectorsaved = (uint32_t)time(NULL); + } + } } else retval = iguana_balancenormal(coin,bp,startheight,endheight); if ( retval < 0 ) { diff --git a/iguana/main.c b/iguana/main.c index b606c1c1c..df730cfb9 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -346,7 +346,7 @@ mksquashfs DB/BTC BTC.squash1M -b 1048576 void mainloop(struct supernet_info *myinfo) { - int32_t i,flag,isRT,numpeers; struct iguana_info *coin; struct iguana_helper *ptr; struct iguana_bundle *bp; + int32_t i,n,iter,flag,isRT,numpeers; struct iguana_info *coin; struct iguana_helper *ptr; struct iguana_bundle *bp; sleep(3); printf("mainloop\n"); while ( 1 ) @@ -365,28 +365,32 @@ void mainloop(struct supernet_info *myinfo) { isRT *= coin->isRT; numpeers += coin->peers.numranked; - if ( queue_size(&bundlesQ) < 2 && (ptr= queue_dequeue(&balancesQ,0)) != 0 ) + n = queue_size(&balancesQ); + for (iter=0; iterbp; - if ( ptr->coin != coin || bp == 0 || time(NULL) < bp->nexttime ) + if ( queue_size(&bundlesQ) < 2 && (ptr= queue_dequeue(&balancesQ,0)) != 0 ) { - if ( 0 && bp != 0 ) - printf("skip.%d lag.%ld\n",bp->hdrsi,bp->nexttime-time(NULL)); - bp->nexttime = (uint32_t)time(NULL); - queue_enqueue("balanceQ",&balancesQ,&ptr->DL,0); - continue; - } - flag++; - if ( coin != 0 ) - { - iguana_balancecalc(coin,bp,bp->bundleheight,bp->bundleheight+bp->n-1); - if ( coin->active == 0 ) + bp = ptr->bp; + if ( ptr->coin != coin || bp == 0 || time(NULL) < bp->nexttime ) + { + if ( 0 && bp != 0 ) + printf("skip.%d lag.%ld\n",bp->hdrsi,bp->nexttime-time(NULL)); + //bp->nexttime = (uint32_t)time(NULL); + queue_enqueue("balanceQ",&balancesQ,&ptr->DL,0); + continue; + } + flag++; + if ( coin != 0 ) { - printf("detected autopurge after account filecreation. restarting.%s\n",coin->symbol); - coin->active = 1; + iguana_balancecalc(coin,bp,bp->bundleheight,bp->bundleheight+bp->n-1); + if ( coin->active == 0 ) + { + printf("detected autopurge after account filecreation. restarting.%s\n",coin->symbol); + coin->active = 1; + } } + myfree(ptr,ptr->allocsize); } - myfree(ptr,ptr->allocsize); } if ( (bp= coin->current) != 0 && coin->stucktime != 0 && coin->isRT == 0 && coin->RTheight == 0 && (time(NULL) - coin->stucktime) > coin->MAXSTUCKTIME ) {