diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 66ea29680..54397f82c 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -485,9 +485,9 @@ struct iguana_info //portable_mutex_t scripts_mutex[2]; FILE *scriptsfp[2]; void *scriptsptr[2]; long scriptsfilesize[2]; //struct scriptinfo *scriptstable[2]; struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; - struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; + struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; bits256 RThash1; int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified; - uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime; + uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime; double backstopmillis; bits256 backstophash2; int64_t spaceused; int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes; bits256 reqtxids[64]; void *launched,*started; diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 1c99c170b..27fdcea5e 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -448,7 +448,7 @@ void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_block *blocks,int32_t n) { - struct iguana_bundlereq *req; + struct iguana_bundlereq *req; int32_t i,num; if ( addr != 0 ) { static uint32_t hdrsreceived[IGUANA_MAXPEERS]; @@ -465,6 +465,13 @@ void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct if ( addr->pendhdrs > 0 ) addr->pendhdrs--; //printf("%s blocks[%d] ht.%d gotheaders pend.%d %.0f\n",addr->ipaddr,n,blocks[0].height,addr->pendhdrs,milliseconds()); + if ( bits256_cmp(blocks[1].RO.hash2,coin->RThash1) == 0 ) + { + num = (n < coin->chain->bundlesize ? n : coin->chain->bundlesize); + for (i=0; iRThashes[i] = blocks[i].RO.hash2; + addr->numRThashes = num; + } } req = iguana_bundlereq(coin,addr,'H',0); req->blocks = blocks, req->n = n; @@ -475,18 +482,24 @@ void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *blockhashes,int32_t n) { - struct iguana_bundlereq *req; + struct iguana_bundlereq *req; int32_t num; if ( addr != 0 ) { addr->recvhdrs++; if ( addr->pendhdrs > 0 ) addr->pendhdrs--; + if ( bits256_cmp(blockhashes[1],coin->RThash1) == 0 ) + { + num = (n < coin->chain->bundlesize ? n : coin->chain->bundlesize); + memcpy(addr->RThashes,blockhashes,num * sizeof(*addr->RThashes)); + addr->numRThashes = num; + } } req = iguana_bundlereq(coin,addr,'S',0); req->hashes = blockhashes, req->n = n; char str[65]; - if ( 0 && n > 2 ) - printf("bundlesQ blockhashes.%s [%d]\n",bits256_str(str,blockhashes[1]),n); + if ( 1 && n > 2 && addr != 0 ) + printf("addr.%d %s [%d]\n",addr->rank,bits256_str(str,blockhashes[1]),n); queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); if ( n > coin->chain->bundlesize ) iguana_sendblockreqPT(coin,addr,0,-1,blockhashes[1],0); @@ -792,7 +805,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); - if ( 0 && num >= coin->chain->bundlesize ) + if ( 1 && 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_unspents.c b/iguana/iguana_unspents.c index 3b9301f0c..e19b0e5a1 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -1851,14 +1851,42 @@ void iguana_rdatarestore(struct iguana_ramchain *dest,struct iguana_ramchaindata src->H.spendind = rdest->numspends; } +void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t numaddrs) +{ + int32_t datalen,i; uint8_t serialized[512]; char str[65]; struct iguana_peer *addr; + for (i=0; ipeers.numranked; i++) + { + queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); + if ( 0 && (addr= coin->peers.ranked[i]) != 0 && (datalen= iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0]))) > 0 ) + { + //printf("UNSTICK HDR.[%d]\n",bp->hdrsi); + iguana_send(coin,addr,serialized,datalen); + addr->pendhdrs++; + } + } +} + int32_t iguana_realtime_update(struct iguana_info *coin) { double startmillis0; static double totalmillis0; static int32_t num0; - struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t bundlei,i,n,flag=0; bits256 hash2; + struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t bundlei,i,n,flag=0; bits256 hash2; struct iguana_peer *addr; struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR; if ( (bp= coin->current) != 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi == coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && (coin->RTheight < coin->blocks.hwmchain.height-3 || time(NULL) > bp->lastRT) )//&& coin->blocks.hwmchain.height >= coin->longestchain-1 && coin->RTramchain.H.data->numblocks < bp->n ) { + if ( bits256_cmp(coin->RThash1,bp->hashes[1]) != 0 ) + coin->RThash1 = bp->hashes[1]; bp->lastRT = (uint32_t)time(NULL); + if ( coin->peers.numranked > 0 && time(NULL) > coin->RThdrstime+10 ) + { + iguana_RThdrs(coin,bp,coin->peers.numranked); + coin->RThdrstime = bp->lastRT; + for (i=0; ipeers.numranked; i++) + { + if ( (addr= coin->peers.ranked[i]) != 0 ) + printf("%d ",addr->numRThashes); + } + printf("RTheaders\n"); + } iguana_RTramchainalloc(coin,bp); bp->isRT = 1; while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height ) @@ -1878,8 +1906,8 @@ int32_t iguana_realtime_update(struct iguana_info *coin) block = iguana_bundleblock(coin,&hash2,bp,bundlei+i); if ( i == 0 || (bits256_nonz(hash2) != 0 && (block == 0 || block->txvalid == 0)) ) { - uint8_t serialized[512]; int32_t len; struct iguana_peer *addr; - char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block); + uint8_t serialized[512]; int32_t len; + //char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,i,bits256_str(str,hash2),block); addr = coin->peers.ranked[rand() % 8]; if ( addr != 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 ) iguana_send(coin,addr,serialized,len);