From 397276a6a1759c0a6b41703519e9d8545ef0b54b Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 1 Apr 2016 21:02:08 -0600 Subject: [PATCH] test --- iguana/iguana777.h | 2 +- iguana/iguana_bundles.c | 13 +++++++++---- iguana/iguana_recv.c | 35 ++++++++++++++++++++++++----------- iguana/iguana_unspents.c | 16 ++++++++-------- iguana/main.c | 2 +- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 4a1828361..ea502e449 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -43,7 +43,7 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t #define IGUANA_TAILPERCENTAGE 1.0 #define IGUANA_MAXPENDHDRS 1 #define IGUANA_MAXPENDINGREQUESTS 2 -#define IGUANA_PENDINGREQUESTS 64 +#define IGUANA_PENDINGREQUESTS 512 #define IGUANA_MINPENDBUNDLES 2 #define IGUANA_MAXPENDBUNDLES 128 #define IGUANA_BUNDLELOOP 77 diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 7435de25b..fed6ed3fc 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -221,7 +221,7 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo { if ( (block->hdrsi != bp->hdrsi || block->bundlei != bundlei) && (block->hdrsi != 0 || block->bundlei != 0) ) { - printf("blockadd warning: %d[%d] <- %d[%d]\n",block->hdrsi,block->bundlei,bp->hdrsi,bundlei); + char str[65]; printf("blockadd warning: %d[%d] <- %d[%d] %s\n",block->hdrsi,block->bundlei,bp->hdrsi,bundlei,bits256_str(str,hash2)); err |= 2; exit(-1); } @@ -600,11 +600,16 @@ int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32 if ( 0 && bp->isRT == 0 && (bp->hdrsi == coin->bundlescount-1 || bp == coin->current) ) printf("hdr ITERATE.%d bundle.%d vs %d: h.%d n.%d r.%d s.%d c.%d finished.%d spec.%p[%d]\n",bp->hdrsi,bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->numcached,bp->emitfinish,bp->speculative,bp->numspec); dist = 30 + (coin->current != 0 ? bp->hdrsi - coin->current->hdrsi : 0); + if ( bp == coin->current ) + dist = 3; if ( time(NULL) > bp->hdrtime+dist && (bp->hdrsi >= coin->bundlescount-2 || (coin->enableCACHE != 0 && bp->numhashes < bp->n && (bp->speculative == 0 || bp->hdrsi >= coin->longestchain/bp->n))) ) { char str[64]; bp->hdrtime = (uint32_t)time(NULL); - printf("iguana_bundlehdr.[%d] %s\n",bp->hdrsi,bits256_str(str,bp->hashes[0])); + if ( bp == coin->current ) + { + printf("iguana_bundlehdr.[%d] %d %s\n",bp->hdrsi,bp->numspec,bits256_str(str,bp->hashes[0])); + } queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); } if ( bp->hdrsi == coin->bundlescount-1 && bp->speculative != 0 && bits256_nonz(bp->nextbundlehash2) == 0 ) @@ -891,7 +896,7 @@ double iguana_bundlemissings(struct iguana_info *coin,struct iguana_bundle *bp,d } if ( queue_size(&coin->priorityQ) < (4 * bp->n)/(dist+1) ) { - printf("[%d] dist.%d numcached.%d priority.%d\n",bp->hdrsi,dist,bp->numcached,priority); + //printf("[%d] dist.%d numcached.%d priority.%d\n",bp->hdrsi,dist,bp->numcached,priority); for (i=0; in; i++) { if ( bits256_nonz(bp->hashes[i]) != 0 ) @@ -901,7 +906,7 @@ double iguana_bundlemissings(struct iguana_info *coin,struct iguana_bundle *bp,d else continue; if ( GETBIT(missings,i) != 0 && bits256_nonz(hash2) != 0 ) { - if ( bp == coin->current ) + if ( 0 && bp == coin->current ) printf("issue.[%d:%d]\n",bp->hdrsi,i); iguana_blockQ("missings",coin,bp,i,hash2,1); } diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index e1b8cea7e..26af5d04c 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -592,7 +592,7 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in if ( coin->enableCACHE != 0 && bp->numhashes < bp->n && bundlei == 0 && bp->speculative == 0 && bp->bundleheight < coin->longestchain-coin->chain->bundlesize ) { char str[65]; bits256_str(str,bp->hashes[0]); - fprintf(stderr,"Afound block -> %d %d hdr.%s\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str); + //fprintf(stderr,"Afound block -> %d %d hdr.%s\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); } /*else if ( bp->speculative != 0 && bundlei < bp->numspec && memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)) == 0 ) @@ -818,11 +818,10 @@ void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp) struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *blockhashes,int32_t num) { - int32_t bundlei,i,len; struct iguana_bundle *bp; bits256 allhash,zero; uint8_t serialized[512]; struct iguana_peer *addr; struct iguana_block *block; + int32_t bundlei,i,len,starti; struct iguana_bundle *bp; bits256 allhash,zero; uint8_t serialized[512]; struct iguana_peer *addr; struct iguana_block *block; char str[65],str2[65]; memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); - char str[65]; if ( 0 && num > 2 ) printf("blockhashes[%d] %d of %d %s bp.%d[%d]\n",num,bp==0?-1:bp->hdrsi,coin->bundlescount,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei); if ( num < 2 ) @@ -868,14 +867,18 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct } else if ( num >= coin->chain->bundlesize ) { - for (i=coin->bundlescount-1; i>=0; i--) + starti = coin->current != 0 ? coin->current->hdrsi : 0; + for (i=coin->bundlescount-1; i>=starti; i--) { - if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 ) + if ( (bp= coin->bundles[i]) != 0 )//&& bp->emitfinish > 1 ) { blockhashes[0] = bp->hashes[0]; vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes)); + if ( i == starti ) + printf("vcalc.(%s) [%d].(%s)\n",bits256_str(str,allhash),bp->hdrsi,bits256_str(str2,bp->hashes[0])); if ( bits256_cmp(allhash,bp->allhash) == 0 ) { + printf("matched allhashes.[%d]\n",bp->hdrsi); if ( bp->queued != 0 ) bp->queued = 0; if ( iguana_allhashcmp(coin,bp,blockhashes,coin->chain->bundlesize) > 0 ) @@ -890,7 +893,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct } } } - //printf("no match to allhashes issue block1\n"); + printf("%s no match to allhashes\n",bits256_str(str,blockhashes[1])); struct iguana_block *block; if ( (block= iguana_blockhashset(coin,-1,blockhashes[1],1)) != 0 ) { @@ -928,7 +931,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundlereq *req,struct iguana_block *origblock,int32_t numtx,int32_t datalen,int32_t recvlen,int32_t *newhwmp) { - struct iguana_bundle *bp=0; int32_t numsaved=0,bundlei = -2; struct iguana_block *block,*tmpblock; char str[65]; + struct iguana_bundle *bp=0,*prev; int32_t numsaved=0,bundlei = -2; struct iguana_block *block,*tmpblock; char str[65]; if ( (bp= iguana_bundleset(coin,&block,&bundlei,origblock)) != 0 && bp == coin->current && block != 0 && bp->speculative != 0 && bundlei >= 0 ) { if ( bp->speculative != 0 && bp->numspec <= bundlei ) @@ -938,7 +941,16 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana } } if ( bp != 0 ) + { bp->dirty++; + if ( block != 0 && block->mainchain != 0 && bundlei == 0 && bp->hdrsi > 0 ) + { + if ( (prev= coin->bundles[bp->hdrsi - 1]) != 0 ) + { + printf("found adjacent [%d:%d] speculative.%p\n",prev->hdrsi,bp->n-1,prev->speculative); + } + } + } if ( 0 )//&& bp != 0 && bp->hdrsi == coin->bundlescount-1 ) { int32_t i; static int32_t numrecv; @@ -951,7 +963,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana } fprintf(stderr,"%s [%d:%d] block.%x | s.%d r.%d copy.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,numsaved,numrecv,req->copyflag); } - if ( 1 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && coin->enableCACHE != 0 && bp->speculative == 0 && bp == coin->current ) + if ( 0 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && coin->enableCACHE != 0 && bp->speculative == 0 && bp == coin->current ) { printf("reissue hdrs request for [%d]\n",bp->hdrsi); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); @@ -1197,7 +1209,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin) { for (i=0; ibundlescount; i++) { - if ( (bp= coin->bundles[i]) != 0 && (bp->hdrsi == coin->longestchain/coin->chain->bundlesize || i == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->speculative == 0)) ) + if ( (bp= coin->bundles[i]) != 0 && (bp == coin->current || bp->hdrsi == coin->longestchain/coin->chain->bundlesize || i == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->speculative == 0)) ) { if ( bp == coin->current ) lag = 7; @@ -1363,11 +1375,12 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) } if ( bp == 0 || bp->speculative == 0 || bp == coin->current || bp->hdrsi == coin->bundlescount-1 ) { - //printf("%s request HDR.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp!=0?bp->numhashes:0); + if ( bp == coin->current ) + printf("%s request HDR.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp!=0?bp->numhashes:0); iguana_send(coin,addr,serialized,datalen); addr->pendhdrs++; flag++; - } //else printf("skip hdrreq.%s m.%d z.%d bp.%p longest.%d queued.%d\n",hashstr,m,z,bp,bp->coin->longestchain,bp->queued); + } else printf("skip hdrreq.%s m.%d z.%d bp.%p longest.%d queued.%d\n",hashstr,m,z,bp,bp->coin->longestchain,bp->queued); } free_queueitem(hashstr); return(flag); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index b23a1ad7e..73af50cca 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -462,9 +462,9 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre iguana_ramchain_prefetch(coin,&spentbp->ramchain); spentbp->lastprefetch = (uint32_t)time(NULL); } - else if ( duration > 1 && duration > (10 * coin->txidfind_totalmillis)/coin->txidfind_num && time(NULL) >= spentbp->lastprefetch+coin->PREFETCHLAG && (rand() % 10) == 0 ) + else if ( duration > 1 && duration > (10 * coin->txidfind_totalmillis)/coin->txidfind_num && time(NULL) >= spentbp->lastprefetch+coin->PREFETCHLAG && (rand() % IGUANA_NUMHELPERS) == 0 ) { - printf("slow txidfind %.2f vs %.2f prefetch[%d] from.[%d] lag.%ld last.%u\n",duration,coin->txidfind_totalmillis/coin->txidfind_num,spentbp->hdrsi,ramchain->H.data->height/coin->chain->bundlesize,time(NULL) - spentbp->lastprefetch,spentbp->lastprefetch); + //printf("slow txidfind %.2f vs %.2f prefetch[%d] from.[%d] lag.%ld last.%u\n",duration,coin->txidfind_totalmillis/coin->txidfind_num,spentbp->hdrsi,ramchain->H.data->height/coin->chain->bundlesize,time(NULL) - spentbp->lastprefetch,spentbp->lastprefetch); iguana_ramchain_prefetch(coin,&spentbp->ramchain); spentbp->lastprefetch = (uint32_t)time(NULL); } @@ -671,13 +671,13 @@ void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON free(rmdarray); } -void iguana_prefetch(struct iguana_info *coin,struct iguana_bundle *bp) +void iguana_prefetch(struct iguana_info *coin,struct iguana_bundle *bp,int32_t width) { int32_t i; struct iguana_bundle *spentbp; uint32_t starttime = (uint32_t)time(NULL); - if ( bp->hdrsi > 5 ) + if ( bp->hdrsi > width ) { - //printf("start prefetch4 for [%d]\n",bp->hdrsi); - for (i=1; i<5; i++) + //printf("start prefetch.%d for [%d]\n",width,bp->hdrsi); + for (i=1; ibundles[bp->hdrsi - i]) != 0 ) { @@ -685,7 +685,7 @@ void iguana_prefetch(struct iguana_info *coin,struct iguana_bundle *bp) spentbp->lastprefetch = starttime; } } - //printf("end prefetch4 for [%d] elapsed %d\n",bp->hdrsi,(uint32_t)time(NULL)-starttime); + //printf("end prefetch.%d for [%d] elapsed %d\n",width,bp->hdrsi,(uint32_t)time(NULL)-starttime); } } @@ -1263,7 +1263,7 @@ void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp) dest->externalind = dest->H.stacksize = 0; dest->H.scriptoffset = 1; if ( coin->PREFETCHLAG != 0 ) - iguana_prefetch(coin,bp); + iguana_prefetch(coin,bp,22); } } diff --git a/iguana/main.c b/iguana/main.c index 1cc04ebf8..a4b9cf3f0 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -1191,7 +1191,7 @@ void iguana_main(void *arg) if ( 1 ) { sleep(1); - if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"startpend\":512,\"endpend\":512,\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":512,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":8,\"poll\":1}"),0,myinfo->rpcport)) != 0 ) + if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"startpend\":128,\"endpend\":64,\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":512,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":8,\"poll\":1}"),0,myinfo->rpcport)) != 0 ) { free(str); if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0,myinfo->rpcport)) != 0 )