From 550b3dd91f245b3ab271bd39adf4930756485e34 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 17 Mar 2016 22:13:01 -0300 Subject: [PATCH] test --- iguana/iguana777.h | 2 +- iguana/iguana_bundles.c | 46 ++++++++++++++++++++++++++++++++++++++--- iguana/iguana_recv.c | 21 ++++++++++++------- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 686ce52b2..6d2c628f5 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -419,7 +419,7 @@ struct iguana_bundle struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp; struct iguana_bloom16 bloom; uint32_t rawscriptspace; uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish,balancefinish,validated,lastspeculative,dirty,nexttime; - int32_t numhashes,numrecv,numsaved,numcached,rank,generrs,checkedtmp; + int32_t numhashes,numrecv,numsaved,numcached,rank,generrs,checkedtmp,currentflag; int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec; double avetime,threshold,metric; uint64_t datasize,estsize; struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE]; uint32_t issued[IGUANA_MAXBUNDLESIZE]; diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 9fa25cd15..580163a78 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -366,12 +366,51 @@ void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp) int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int32_t max,int32_t timelimit) { - int32_t i,counter = 0; uint32_t now; struct iguana_block *block; + int32_t i,j,k,len,numpeers,counter = 0; struct iguana_peer *addr; uint32_t now; + struct iguana_block *block; bits256 hashes[32]; uint8_t serialized[sizeof(hashes) + 256]; if ( bp == 0 ) return(0); now = (uint32_t)time(NULL); if ( bp == coin->current ) { + if ( bp->numhashes >= bp->n && bp->currentflag < bp->n && (numpeers= coin->peers.numranked) > 8 ) + { + for (j=0; jpeers.ranked[j]) != 0 ) + { + now = (uint32_t)time(NULL); + for (i=j,k=0; in; i+=numpeers) + { + if ( bits256_nonz(bp->hashes[i]) != 0 ) + { + if ( (block= bp->blocks[i]) != 0 && block->fpipbits == 0 && (block->numrequests == 0 || now > block->issued+60) ) + { + printf("<%d> ",i); + hashes[k++] = bp->hashes[i]; + block->issued = now; + block->numrequests++; + } + } + bp->issued[i] = now; + } + if ( k > 0 ) + { + if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,hashes,k)) > 0 ) + { + iguana_send(coin,addr,serialized,len); + coin->numreqsent += k; + addr->pendblocks += k; + addr->pendtime = (uint32_t)time(NULL); + bp->currentflag += k; + } + printf("a%d/%d ",j,k); + } + } + } + //printf("currentflag.%d\n",bp->currentflag); + return(counter); + } if ( 0 && time(NULL) > bp->lastspeculative+60 ) { for (i=1,counter=0; in; i++) @@ -389,7 +428,8 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int bp->lastspeculative = (uint32_t)time(NULL); } } - return(counter); + // if ( bp != coin->current ) + return(counter); for (i=counter=0; in; i++) { if ( (block= bp->blocks[i]) != 0 ) @@ -579,7 +619,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct iguana_bundle *bp,int iguana_bundlehdr(coin,bp,starti); else if ( bp->emitfinish > coin->startutc && (retval= iguana_bundlefinish(coin,bp)) < 0 ) return(0); - else if ( bp->emitfinish != 0 && bp->numsaved >= bp->n ) + else if ( bp->emitfinish == 0 && bp->numsaved >= bp->n ) { if ( iguana_bundleready(coin,bp) == bp->n ) { diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 2b2d13f03..d76abe61c 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -411,7 +411,7 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in if ( 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 ) @@ -638,11 +638,18 @@ 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 bundlei = -2; struct iguana_block *block; + struct iguana_bundle *bp=0; int32_t numsaved,bundlei = -2; struct iguana_block *block,*tmpblock; bp = iguana_bundleset(coin,&block,&bundlei,origblock); char str[65]; - //if ( 1 && bp == coin->current ) - fprintf(stderr,"blockRECV %s [%d:%d] block.%08x | h.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,bp!=0?bp->numhashes:-1); + if ( 1 && bp == coin->current && bp != 0 ) + { + int32_t i; static int32_t numrecv; + numrecv++; + for (i=numsaved=0; in; i++) + if ( (tmpblock= bp->blocks[i]) != 0 && tmpblock->fpipbits != 0 && tmpblock->fpos >= 0 ) + numsaved++; + fprintf(stderr,"%s [%d:%d] block.%x | s.%d r.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,numsaved,numrecv); + } if ( bundlei == 1 && bp != 0 && bp->numhashes < bp->n && strcmp(coin->symbol,"BTC") != 0 ) { printf("reissue hdrs request for [%d]\n",bp->hdrsi); @@ -1027,14 +1034,14 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) } if ( bp == 0 || z != 0 ) { - printf("%s request HDR.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp!=0?bp->numhashes:0); + //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); } - free_queueitem(hashstr); - return(flag); + //free_queueitem(hashstr); + //return(flag); } else printf("datalen.%d from gethdrs\n",datalen); free_queueitem(hashstr); hashstr = 0;