diff --git a/iguana/iguana777.h b/iguana/iguana777.h index f52c633bf..9237b0998 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -446,6 +446,7 @@ struct iguana_info uint64_t bloomsearches,bloomhits,bloomfalse,collisions; uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192]; struct OS_memspace blockMEM; struct iguana_blocks blocks; struct iguana_waccount *wallet; + bits256 *lasthashes; int32_t numlasthashes,lastbundleheight; }; // peers diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index f2b3ff140..09d8f2eef 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -326,7 +326,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl else str2[0] = 0; if ( block->height+1 > coin->longestchain ) coin->longestchain = block->height+1; - if ( (block->height % 1000) == 0 ) + if ( 0 && (block->height % 1000) == 0 ) printf("EXTENDMAIN %s %d <- (%s) n.%u max.%u PoW %f numtx.%d valid.%d\n",str,block->height,str2,hwmchain->height+1,coin->blocks.maxblocks,block->PoW,block->RO.txn_count,block->valid); struct iguana_bundle *bp; if ( (block->height % coin->chain->bundlesize) == 0 ) diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index b5f4b2835..961aa409f 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -269,7 +269,7 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bundleip,int32_t bundleheight,bits256 bundlehash2,bits256 allhash,int32_t issueflag) { - char str[65],str2[65]; struct iguana_bundle *bp = 0; + char str[65]; struct iguana_bundle *bp = 0; if ( bits256_nonz(bundlehash2) > 0 ) { bits256_str(str,bundlehash2); @@ -296,7 +296,8 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund coin->bundles[coin->bundlescount-1]->nextbp = bp; *bundleip = 0; bits256_str(str,bundlehash2); - printf("ht.%d alloc.[%d] new hdrs.%s %s\n",bp->bundleheight,coin->bundlescount,str,bits256_str(str2,allhash)); + fprintf(stderr,"{%d} ",bp->bundleheight); + //printf("ht.%d alloc.[%d] new hdrs.%s %s\n",bp->bundleheight,coin->bundlescount,str,bits256_str(str2,allhash)); iguana_bundlehash2add(coin,0,bp,0,bundlehash2); if ( issueflag != 0 ) { diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 2e9001e71..7aea1da26 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -203,9 +203,11 @@ int32_t iguana_savehdrs(struct iguana_info *coin) void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) { - int32_t j,k,m,c,height,flag,bundlei,bundleheight = -1; char checkstr[1024],line[1024]; - struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,zero; + int32_t j,k,m,c,height,flag,bundlei; char checkstr[1024],line[1024]; + struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,zero,lastbundle; struct iguana_block *block; + memset(&zero,0,sizeof(zero)); + lastbundle = zero; if ( iter == 1 ) { int32_t i; FILE *fp; char fname[512]; struct iguana_blockRO blockRO; @@ -228,7 +230,6 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) } } m = flag = 0; - memset(&zero,0,sizeof(zero)); allhash = zero; while ( fgets(line,sizeof(line),fp) > 0 ) { @@ -281,6 +282,7 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) if ( (bp= iguana_bundlecreate(coin,&bundlei,height,hash2,allhash,0)) != 0 ) { bp->bundleheight = height; + lastbundle = hash2; if ( (block= iguana_blockfind(coin,hash2)) != 0 ) block->mainchain = 1, block->height = height; if ( iguana_bundleload(coin,bp) != 0 ) @@ -299,7 +301,7 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) } } } - init_hexbytes_noT(checkstr,hash2.bytes,sizeof(hash2)); + /*init_hexbytes_noT(checkstr,hash2.bytes,sizeof(hash2)); if ( strncmp(checkstr,line+k+1,64) == 0 ) { if ( (height % coin->chain->bundlesize) == 1 ) @@ -314,10 +316,16 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) } } } - } + }*/ } } } + if ( bits256_nonz(lastbundle) > 0 ) + { + char hashstr[65]; + init_hexbytes_noT(hashstr,lastbundle.bytes,sizeof(bits256)); + queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1); + } } struct iguana_info *iguana_startcoin(struct iguana_info *coin,int32_t initialheight,int32_t mapflags) diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 2e584fd38..b66c8d8c5 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -553,6 +553,8 @@ void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t he //iguana_set_iAddrheight(coin,addr->ipbits,height); addr->height = height; } + if ( height > coin->longestchain ) + coin->longestchain = height; } int32_t iguana_iAddrheight(struct iguana_info *coin,uint32_t ipbits) diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 0dc050963..11e0f628c 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -45,7 +45,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr, coin->numreqsent++; addr->pendblocks++; addr->pendtime = (uint32_t)time(NULL); - //printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1); + printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1); } else printf("MSG_BLOCK null datalen.%d\n",len); return(len); } @@ -406,7 +406,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,flag = 0; struct iguana_bundle *bp; struct iguana_block *block; + int32_t bundlei,i; struct iguana_bundle *bp;// struct iguana_block *block; bp = 0, bundlei = -2, iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); //char str[65]; printf("blockhashes[%d] %s bp.%d[%d]\n",num,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei); if ( bp != 0 ) @@ -420,8 +420,16 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct } if ( bp->hdrsi == coin->bundlescount-1 ) { - printf("FOUND LAST BLOCKHASHES\n"); - for (i=1; ibundleheight); + if ( coin->lasthashes != 0 ) + myfree(coin->lasthashes,sizeof(*coin->lasthashes) * coin->numlasthashes); + coin->lasthashes = blockhashes; + coin->numlasthashes = num; + coin->lastbundleheight = bp->bundleheight; + req->hashes = 0; + iguana_blockQ(coin,0,-1,blockhashes[2],1); + iguana_blockQ(coin,0,-1,blockhashes[num-1],1); + /*for (i=1; iRO.hash2,0), flag++; } } - } + }*/ } } else if ( num >= coin->chain->bundlesize ) @@ -465,12 +473,16 @@ 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 *prevbp=0,*bp=0; int32_t prevbundlei=-2,bundlei = -2; struct iguana_block *prevblock,*block,*next; + struct iguana_bundle *prevbp=0,*bp=0; int32_t prevbundlei=-2,bundlei = -2; struct iguana_block *prevblock,*block; bp = iguana_bundleset(coin,&block,&bundlei,origblock); if ( bp != 0 && bp->hdrsi == coin->bundlescount-1 ) { - if ( block != 0 && (next= block->hh.next) != 0 ) - iguana_blockQ(coin,bp,bundlei+1,next->RO.hash2,0), printf("AUTONEXT %d\n",block->height+1); + //char str[65]; printf("last bundle recv %d %p (%d vs %d) %s\n",bp->bundleheight+bundlei,coin->lasthashes,coin->numlasthashes,bundlei,coin->lasthashes==0?"null":bits256_str(str,coin->lasthashes[bundlei+1])); + if ( coin->lasthashes != 0 && bundlei+1 < coin->numlasthashes && bits256_nonz(coin->lasthashes[bundlei+1]) > 0 ) + { + //printf("req.%d\n",bp->bundleheight+bundlei+1); + iguana_blockQ(coin,bp,bundlei+1,coin->lasthashes[bundlei+1],0); + } } //static int total; char str[65]; printf("RECV %s [%d:%d] block.%08x | %d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,total++); iguana_bundlefind(coin,&prevbp,&prevbundlei,origblock->RO.prev_block); @@ -488,12 +500,24 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana iguana_bundlecreate(coin,&prevbundlei,prevbp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,0); } } - else iguana_bundlehash2add(coin,0,prevbp,prevbundlei+1,block->RO.hash2); + else + { + iguana_bundlehash2add(coin,0,prevbp,prevbundlei+1,block->RO.hash2); + if ( prevbp->hdrsi == coin->bundlescount-1 ) + { + //printf("last (prev) bundle recv %d %p\n",prevbp->bundleheight+prevbundlei+1,coin->lasthashes); + if ( coin->lasthashes != 0 && prevbundlei+2 < coin->numlasthashes && bits256_nonz(coin->lasthashes[prevbundlei+2]) > 0 ) + { + //printf("req.%d\n",prevbp->bundleheight+bundlei+2); + iguana_blockQ(coin,prevbp,bundlei+1,coin->lasthashes[prevbundlei+2],1); + } + } + } } if ( prevbp->numhashes < prevbp->n && prevbundlei == 0 ) { char str[65]; bits256_str(str,prevbp->hashes[0]); - //printf("Afound block -> %d hdr.%s\n",prevbp->bundleheight,str); + printf("Afound block -> %d hdr.%s\n",prevbp->bundleheight,str); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); } //char str[65]; printf("PREV %s prevbp.%p[%d] h.%d\n",bits256_str(str,origblock->RO.prev_block),prevbp,prevbundlei,prevbp->numhashes); @@ -710,7 +734,7 @@ 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->numhashes); + printf("%s request HDR.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp->numhashes); iguana_send(coin,addr,serialized,datalen); addr->pendhdrs++; flag++; @@ -836,5 +860,17 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded } if ( hdrsi != (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize ) iguana_savehdrs(coin); + bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; + static int32_t lastbundlei; static uint32_t lastbundleitime; + if ( coin->lasthashes != 0 && bundlei < coin->numlasthashes ) + { + if ( lastbundlei != bundlei || time(NULL) > lastbundleitime+3 ) + { + lastbundleitime = (uint32_t)time(NULL); + lastbundlei = bundlei; + //printf("Q last\n"); + iguana_blockQ(coin,0,-1,coin->lasthashes[bundlei],0); + } + } return(flag); }