From 114f71f972fdca9858404efdefc739e847a02706 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 21 Mar 2016 19:01:14 -0300 Subject: [PATCH] test --- iguana/iguana777.h | 2 +- iguana/iguana_bundles.c | 6 ++-- iguana/iguana_init.c | 3 +- iguana/iguana_ramchain.c | 2 +- iguana/iguana_recv.c | 71 +++++++++++++++++++++++++--------------- 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/iguana/iguana777.h b/iguana/iguana777.h index ea8d62af5..d62c273d5 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -279,7 +279,7 @@ struct iguana_block struct iguana_blockRO RO; double PoW; // NOT consensus safe, for estimation purposes only int32_t height; uint32_t fpipbits,numrequests,issued; long fpos; - uint16_t hdrsi,bundlei:12,mainchain:1,valid:1,queued:1,txvalid:1,peerid:8; + uint16_t hdrsi,bundlei:11,mainchain:1,valid:1,queued:1,txvalid:1,newtx:1,peerid:8; UT_hash_handle hh; bits256 *blockhashes; struct iguana_bundlereq *req; };// __attribute__((packed)); diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 33ad67b47..eb2fb5abc 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -405,6 +405,8 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int else lag = 3; if ( (numpeers= coin->peers.numranked) > 8 )//&& bp->currentflag < bp->n ) { + if ( numpeers > 0xff ) + numpeers = 0xff; // fit into 8 bitfield if ( bp->currentflag == 0 ) bp->currenttime = now; if ( bp->numhashes >= bp->n ) @@ -550,13 +552,13 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int { if ( (block= bp->blocks[i]) != 0 ) { - if ( block->fpipbits == 0 || block->RO.recvlen == 0 ) + if ( block->fpipbits == 0 )//|| block->RO.recvlen == 0 ) { if ( block->issued == 0 || now > block->issued+lag ) { block->numrequests++; if ( bp == coin->current ) - printf("[%d:%d] ",bp->hdrsi,i); + printf("[%d:%d].%x ",bp->hdrsi,i,block->fpipbits); iguana_blockQ("kick",coin,bp,i,block->RO.hash2,bp == coin->current); bp->issued[i] = block->issued = now; counter++; diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 1792cf3fa..f7d5f6662 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -279,7 +279,8 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) //printf("LOADED bundle.%d %p current %p\n",bp->bundleheight,bp,coin->current); //if ( bp->hdrsi == 0 || coin->bundles[bp->hdrsi-1]->emitfinish != 0 ) { - //bp->startutxo = (uint32_t)time(NULL); + if ( 1 ) + bp->startutxo = bp->utxofinish = (uint32_t)time(NULL); //printf("GENERATE UTXO, verify sigs, etc for ht.%d\n",bp->bundleheight); iguana_bundleQ(coin,bp,1000); } diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index de5bc1b6a..d872cf07b 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -258,9 +258,9 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname, if ( (bp= coin->bundles[0]) != 0 && bp->speculative != 0 ) for (i=0; i<100; i++) printf("(%d %d %d).%d ",bits256_nonz(bp->hashes[i]),bits256_nonz(bp->speculative[i]),bits256_cmp(bp->hashes[i],bp->speculative[i]),bits256_cmp(hash2,bp->hashes[i])); - printf("iguana_peerfname error finding.(%s)\n",bits256_str(str,hash2)); if ( bits256_nonz(prevhash2) == 0 || (bp= iguana_bundlefind(coin,&bp,&bundlei,prevhash2)) == 0 || bundlei >= coin->chain->bundlesize-1 ) { + printf("iguana_peerfname error finding.(%s) spec.%p bp.%p\n",bits256_str(str,hash2),bp!=0?bp->speculative:0,bp); return(-2); } else bundlei++; diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index d02c13eac..7328f3b0d 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -238,7 +238,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i if ( iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->block.RO.txn_count,data,recvlen) >= 0 ) { txdata->block.fpipbits = (uint32_t)addr->ipbits; - txdata->block.fpipbits = recvlen; + txdata->block.RO.recvlen = recvlen; txdata->block.fpos = 0; req->datalen = txdata->datalen; req->ipbits = txdata->block.fpipbits; @@ -256,7 +256,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i } } req->block = txdata->block; - //printf("recvlen.%d prev.(%s)\n",req->recvlen,bits256_str(str,txdata->block.RO.prev_block)); + printf("recvlen.%d ipbits.%x prev.(%s)\n",req->block.RO.recvlen,req->block.fpipbits,bits256_str(str,txdata->block.RO.prev_block)); req->block.RO.txn_count = req->numtx = txdata->block.RO.txn_count; coin->recvcount++; coin->recvtime = (uint32_t)time(NULL); @@ -302,7 +302,9 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi } req = iguana_bundlereq(coin,addr,'S',0); req->hashes = blockhashes, req->n = n; - //printf("bundlesQ blockhashes.%p[%d]\n",blockhashes,n); + char str[65]; + if ( n > 1 ) + printf("bundlesQ blockhashes.%s [%d]\n",bits256_str(str,blockhashes[1]),n); queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); } @@ -565,7 +567,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig 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,*newbp; bits256 allhash,zero; char hashstr[65]; uint8_t serialized[512]; struct iguana_peer *addr; + int32_t bundlei,i,len; struct iguana_bundle *bp,*newbp; bits256 allhash,zero; char hashstr[65]; uint8_t serialized[512]; struct iguana_peer *addr; struct iguana_block *block; memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; if ( num < 2 ) @@ -574,7 +576,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct //iguana_blockQ(coin,0,-1,blockhashes[1],0); //iguana_blockQ(coin,0,-4,blockhashes[1],1); char str[65]; - //if ( 0 && num > 2 )//&& bp->hdrsi == coin->bundlescount-1 ) + if ( 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 ( bp != 0 ) { @@ -652,13 +654,25 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct //char str[65]; printf("REQ.%s\n",bits256_str(str,blockhashes[1])); } } - } else iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],0); // should be RT block + } + else + { + if ( (block= iguana_blockfind(coin,blockhashes[1])) == 0 ) + { + iguana_blockhashset(coin,-1,blockhashes[1],1); + if ( (block= iguana_blockfind(coin,blockhashes[1])) != 0 ) + { + block->newtx = 1; + iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],1); // should be RT block + } + } + } return(req); } 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 i,numsaved=0,bundlei = -2; struct iguana_block *block,*tmpblock; char str[65]; + struct iguana_bundle *bp=0; int32_t i,numsaved=0,bundlei = -2; struct iguana_block *block,*tmpblock,*prev; char str[65]; if ( (bp= iguana_bundleset(coin,&block,&bundlei,origblock)) == 0 ) { if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,origblock->RO.hash2)) != 0 ) @@ -700,6 +714,9 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana } //printf("i.%d ref prev.(%s)\n",i,bits256_str(str,origblock->RO.prev_block)); } + else + { + } if ( 1 )//&& bp != 0 && bp->hdrsi == coin->bundlescount-1 ) { int32_t i; static int32_t numrecv; @@ -717,10 +734,21 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana //printf("reissue hdrs request for [%d]\n",bp->hdrsi); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); } - if ( block != 0 ) + if ( (block= iguana_blockhashset(coin,-1,origblock->RO.hash2,1)) != 0 ) { - block->RO.txn_count = req->numtx; - //block->RO.recvlen = recvlen; + if ( block != origblock ) + iguana_blockcopy(coin,block,origblock); + if ( block->newtx != 0 ) + { + if ( (prev= iguana_blockfind(coin,block->RO.prev_block)) == 0 ) + prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1); + if ( prev != 0 && (bits256_nonz(prev->RO.prev_block) == 0 || prev->fpipbits == 0) ) + { + printf("auto prev newtx %s\n",bits256_str(str,prev->RO.prev_block)); + prev->newtx = 1; + iguana_blockQ("autoprev",coin,0,-1,prev->RO.hash2,0); + } + } if ( req->copyflag != 0 ) { if ( block->queued == 0 && bp != 0 ) @@ -731,23 +759,11 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana queue_enqueue("cacheQ",&coin->cacheQ,&req->DL,0); return(0); } - else + else if ( block->req == 0 ) { - if ( (block= iguana_blockhashset(coin,-1,origblock->RO.hash2,1)) != 0 ) - { - if ( block != origblock ) - { - iguana_blockcopy(coin,block,origblock); - coin->numcached++; - if ( block->req == 0 ) - { - block->req = req; - req = 0; - } //else printf("already have cache entry.(%s)\n",bits256_str(str,origblock->RO.hash2)); - //fprintf(stderr,"bundleset block.%p vs origblock.%p prev.%d bits.%x fpos.%ld\n",block,origblock,bits256_nonz(prevhash2),block->fpipbits,block->fpos); - } else printf("got origblock.%s to cache\n",bits256_str(str,origblock->RO.hash2)); - } - } + block->req = req; + req = 0; + } //else printf("already have cache entry.(%s)\n",bits256_str(str,origblock->RO.hash2)); } //printf("datalen.%d ipbits.%x\n",datalen,req->ipbits); } else printf("cant create origblock.%p block.%p bp.%p bundlei.%d\n",origblock,block,bp,bundlei); @@ -756,6 +772,9 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana struct iguana_bundlereq *iguana_recvtxids(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *txids,int32_t n) { + char str[65]; + if ( n > 0 ) + printf("got txids[%d] %s\n",n,bits256_str(str,txids[0])); return(req); }