From fb37388fd0abe283be3027d7a336c2c89bb13ec6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 12 Sep 2016 06:29:37 -0300 Subject: [PATCH] improve staying in RT sync --- iguana/iguana_accept.c | 4 ++-- iguana/iguana_realtime.c | 2 +- iguana/iguana_recv.c | 14 +++++++++++++- iguana/iguana_txidfind.c | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index 4d18d407a..95019643f 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -98,12 +98,12 @@ void iguana_acceptloop(void *args) } memcpy(&ipbits,&cli_addr.sin_addr.s_addr,sizeof(ipbits)); expand_ipbits(ipaddr,ipbits); - printf("incoming (%s:%u)\n",ipaddr,cli_addr.sin_port); + printf("incoming %s (%s:%u)\n",coin->symbol,ipaddr,cli_addr.sin_port); for (i=flag=0; ipeers->active[i].ipbits == (uint32_t)ipbits && coin->peers->active[i].usock >= 0 ) { - printf("found existing peer.(%s) in slot[%d]\n",ipaddr,i); + //printf("found existing %s peer.(%s) in slot[%d]\n",coin->symbol,ipaddr,i); close(coin->peers->active[i].usock); coin->peers->active[i].dead = 0; coin->peers->active[i].usock = sock; diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 8949269be..8dc999636 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -954,7 +954,7 @@ void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int3 if ( fwrite(recvlenp,1,sizeof(*recvlenp),fp) != sizeof(*recvlenp) || fwrite(numtxp,1,sizeof(*numtxp),fp) != sizeof(*numtxp) || fwrite(data,1,*recvlenp,fp) != *recvlenp ) printf("error writing %s len.%d numtx.%d\n",bits256_str(str,hash2),*recvlenp,*numtxp); fclose(fp); - printf("numtx.%d len.%d %s hwm.%d L.%d\n",*numtxp,*recvlenp,fname,coin->blocks.hwmchain.height,coin->longestchain); + //printf("numtx.%d len.%d %s hwm.%d L.%d\n",*numtxp,*recvlenp,fname,coin->blocks.hwmchain.height,coin->longestchain); } else printf("couldnt create %s\n",fname); } else if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 ) diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index a0c0183d0..78883346e 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -773,14 +773,22 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru } } if ( bp == 0 ) + { + req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); return; + } for (i=numsaved=0; ichain->bundlesize; i++) { if ( (block= bp->blocks[i]) != 0 && block->fpipbits != 0 && block->fpos >= 0 && block->txvalid != 0 ) numsaved++; } if ( (speculative= iguana_bundlestats_update(coin,&block,bp,bundlei,origtxdata,data,recvlen)) < 0 ) + { + req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); return; + } if ( block == 0 ) block = iguana_blockhashset("noblock",coin,bp->bundleheight+bundlei,origtxdata->zblock.RO.hash2,1); if ( block->hdrsi != bp->hdrsi || block->bundlei != bundlei ) @@ -815,6 +823,8 @@ void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,stru { // printf("DUP s.%d [%d:%d].(%s) %s n%d\n",numsaved,bp!=0?bp->hdrsi:-1,bundlei,bits256_str(str,origtxdata->zblock.RO.hash2),addr->ipaddr,addr->pendblocks); } + req = iguana_recv_bundlereq(coin,addr,0,H,data,recvlen,0,-1,origtxdata); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); return; } txdata = origtxdata; @@ -899,6 +909,8 @@ int32_t iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,str addr->numRThashes = num; } } + if ( strcmp("BTC",coin->symbol) != 0 && n == 2 ) + iguana_sendblockreqPT(coin,addr,0,-1,zblocks[1].RO.hash2,0); for (i=0; ibundlescount; i++) { if ( (bp= coin->bundles[i]) != 0 && bits256_cmp(zblocks[1].RO.hash2,bp->hashes[1]) == 0 && bp->numhashes >= coin->chain->bundlesize ) @@ -1402,7 +1414,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); - if ( 0 && strcmp("BTCD",coin->symbol) == 0 )//0 && num >= coin->chain->bundlesize ) + //if ( 0 && strcmp("BTCD",coin->symbol) == 0 )//0 && num >= coin->chain->bundlesize ) 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 ) return(req); diff --git a/iguana/iguana_txidfind.c b/iguana/iguana_txidfind.c index c567deb8d..5104076ac 100755 --- a/iguana/iguana_txidfind.c +++ b/iguana/iguana_txidfind.c @@ -621,7 +621,7 @@ struct iguana_monitorinfo *iguana_monitorfind(struct iguana_info *coin,bits256 t struct iguana_monitorinfo *iguana_txidreport(struct iguana_info *coin,bits256 txid,struct iguana_peer *addr) { - struct iguana_monitorinfo *ptr; char str[65]; + struct iguana_monitorinfo *ptr; //char str[65]; if ( (ptr= iguana_monitorfind(coin,txid)) != 0 ) { if ( GETBIT(ptr->peerbits,addr->addrind) == 0 ) @@ -630,7 +630,7 @@ struct iguana_monitorinfo *iguana_txidreport(struct iguana_info *coin,bits256 tx SETBIT(ptr->peerbits,addr->addrind); ptr->numreported++; } - } else printf("txid.%s not being monitored\n",bits256_str(str,txid)); + } // else printf("%s txid.%s not being monitored\n",coin->symbol,bits256_str(str,txid)); return(0); }