From 83df800c7f23ab81ccc042b7874772db30e1a3ff Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 4 Apr 2016 03:36:41 -0500 Subject: [PATCH] test --- iguana/iguana777.c | 2 +- iguana/iguana_bundles.c | 12 ++++++------ iguana/iguana_recv.c | 35 +++++++++++++++++++++++------------ iguana/iguana_unspents.c | 29 +++++++++++++++++------------ 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 853c9e5f1..8e14e90c5 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -477,7 +477,7 @@ void iguana_helper(void *arg) if ( retval > 0 ) { printf("GENERATED UTXO.%d for ht.%d duration %d seconds\n",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL)-bp->startutxo); - } else printf("null retval from iguana_spendvectors.[%d]\n",bp->hdrsi); + } // else printf("null retval from iguana_spendvectors.[%d]\n",bp->hdrsi); bp->utxofinish = (uint32_t)time(NULL); iguana_balancesQ(coin,bp); } else printf("UTXO gen.[%d] utxo error\n",bp->hdrsi); diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 6d4f34958..56c85a2ff 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -667,7 +667,7 @@ int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32 bp->hdrtime = (uint32_t)time(NULL); if ( bp == coin->current && bp->speculative != 0 ) { - printf("iguana_bundlehdr.[%d] %d %s\n",bp->hdrsi,bp->numspec,bits256_str(str,bp->hashes[0])); + //printf("iguana_bundlehdr.[%d] %d %s\n",bp->hdrsi,bp->numspec,bits256_str(str,bp->hashes[0])); //if ( iguana_blocksmissing(coin,&avail,missings,0,bp,0,7) > 0 ) // iguana_bundleissuemissing(coin,bp,missings,3); } @@ -761,7 +761,7 @@ int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp) { struct iguana_bundle *prevbp; int32_t i; #ifdef IGUANA_SERIALIZE_SPENDVECTORGEN - if ( (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)-coin->MAXBUNDLES ) + if ( (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize) - 0*coin->MAXBUNDLES ) return(0); #endif for (i=0; ihdrsi; i++) @@ -1040,9 +1040,9 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) { //if ( bp->blocks[j] == 0 && bp->speculative != 0 && bits256_nonz(bp->speculative[j]) != 0 ) // bp->blocks[j] = iguana_blockhashset("speculative3",coin,bp->bundleheight+j,bp->speculative[j],1); - if ( bp->blocks[j] == 0 && bp->speculativecache[j] != 0 ) + if ( ((block= bp->blocks[j]) == 0 || bp == coin->current) && bp->speculativecache[j] != 0 ) { - if ( (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0 && block->processed == 0 ) + if ( (block != 0 || (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0) && block->processed == 0 ) iguana_cacheprocess(coin,bp,j); numcached++; } @@ -1080,9 +1080,9 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) } //else printf("[%d] emit.%u bp->n.%d numsaved.%d numcached.%d numhashes.%d\n",bp->hdrsi,bp->emitfinish,bp->n,bp->numsaved,bp->numcached,bp->numhashes); - if ( bp->emitfinish == 0 && firstgap != 0 ) + if ( bp->emitfinish == 0 ) { - if ( ++pending == coin->MAXBUNDLES ) + if ( firstgap != 0 && ++pending == coin->MAXBUNDLES ) { lastpending = bp; //printf("SET MAXBUNDLES.%d pend.%d\n",bp->hdrsi,pending); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 74f420944..adf1a2ca2 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -792,7 +792,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 ( 1 && num >= coin->chain->bundlesize ) + if ( 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); @@ -1016,6 +1016,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin) if ( time(NULL) < coin->lastreqtime+2 ) return(0); coin->lastreqtime = (uint32_t)time(NULL); + //printf("reqblocks %u\n",coin->lastreqtime); hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize; if ( (bp= coin->bundles[hdrsi]) != 0 ) { @@ -1231,7 +1232,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle //getchar(); return(-1); } - if ( 1 && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 ) + if ( 1 && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 && block != 0 && block->txvalid != 0 ) { //printf("found valid [%d:%d] in blockQ\n",block!=0?block->hdrsi:-1,block!=0?block->bundlei:-1); return(0); @@ -1424,33 +1425,43 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) int32_t iguana_processrecv(struct iguana_info *coin) // single threaded { - int32_t newhwm = 0,hwmheight,flag = 0; char str[2000]; + int32_t i,newhwm = 0,hwmheight,flag = 0; struct iguana_bundle *bp; struct iguana_block *block; char str[2000]; hwmheight = coin->blocks.hwmchain.height; coin->RTramchain_busy = 1; + flag += iguana_processrecvQ(coin,&newhwm); + flag += iguana_reqhdrs(coin); if ( coin->RTheight != 0 ) { if ( time(NULL) > coin->laststats+2 ) { - flag += iguana_processrecvQ(coin,&newhwm); flag += iguana_reqblocks(coin); - flag += iguana_reqhdrs(coin); iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); coin->laststats = (uint32_t)time(NULL); } - //if ( coin->RTheight < coin->longestchain-3 ) } else { - flag += iguana_processrecvQ(coin,&newhwm); flag += iguana_reqblocks(coin); - flag += iguana_reqhdrs(coin); - if ( time(NULL) > coin->laststats+1 ) + iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); + } + //printf("call _iguana_chainlink\n"); + for (i=coin->blocks.hwmchain.height%coin->chain->bundlesize; ichain->bundlesize; i++) + { + if ( (bp= coin->current) != 0 && (block= bp->blocks[i]) != 0 ) { - iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); - flag += (iguana_realtime_update(coin) > 0); - coin->laststats = (uint32_t)time(NULL); + //printf("i.%d %s main.%d txvalid.%d\n",i,bits256_str(str,block->RO.hash2),block->mainchain,block->txvalid); + if ( _iguana_chainlink(coin,block) == 0 ) + iguana_blockQ("mainchain",coin,bp,-i,block->RO.hash2,1); + //iguana_realtime_update(coin); } } + for (i=0; ichain->bundlesize; i++) + { + if ( iguana_realtime_update(coin) <= 0 ) + break; + //printf("call iguana_realtime_update i.%d\n",i); + } + flag += (i > 0); coin->RTramchain_busy = (coin->RTgenesis == 0 || queue_size(&balancesQ) != 0); iguana_jsonQ(); if ( hwmheight != coin->blocks.hwmchain.height ) diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 7e8092cda..60e3f6477 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -1405,9 +1405,9 @@ void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest, 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,n,flag=0; + struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t bundlei,i,n,flag=0; bits256 hash2; struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR; - if ( (bp= coin->current) != 0 && time(NULL) > bp->lastRT && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi == coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n )//&& coin->blocks.hwmchain.height >= coin->longestchain-1 && coin->RTramchain.H.data->numblocks < bp->n ) + 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 ) { bp->lastRT = (uint32_t)time(NULL); iguana_RTramchainalloc(coin,bp); @@ -1424,15 +1424,19 @@ int32_t iguana_realtime_update(struct iguana_info *coin) startmillis0 = OS_milliseconds(); if ( iguana_ramchainfile(coin,dest,&blockR,bp,bundlei,block) == 0 ) { - //iguana_RTramchainfree(coin); - if ( bits256_nonz(bp->hashes[bundlei]) != 0 ) + for (i=bundlei; in; i++) { - uint8_t serialized[512]; int32_t len; struct iguana_peer *addr; - char str[65]; printf("RT error [%d:%d] %s %p\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),block); - addr = coin->peers.ranked[rand() % 8]; - if ( addr != 0 && (len= iguana_getdata(coin,serialized,MSG_BLOCK,&bp->hashes[bundlei],1)) > 0 ) - iguana_send(coin,addr,serialized,len); - coin->RTgenesis = 0; + 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,bundlei+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); + coin->RTgenesis = 0; + } + break; } return(-1); } else iguana_ramchain_free(coin,&blockR,1); @@ -1451,10 +1455,11 @@ int32_t iguana_realtime_update(struct iguana_info *coin) totalmillis += (OS_milliseconds() - startmillis); num++; //printf("RTutxo.[%d] ave %.2f micros, total %.2f seconds\n",num,(totalmillis*1000.)/num,totalmillis/1000.); + //_iguana_chainlink(coin,block); coin->RTheight++; printf(">>>> RT.%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); coin->RTramchain.H.data->numblocks = bundlei + 1; - } + } else break; } } n = 0; @@ -1480,7 +1485,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin) } } if ( dest != 0 ) - printf(">>>> RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); + printf(">>>>flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize); return(flag); }