diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index e4b85d431..219fe020b 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -270,10 +270,12 @@ int32_t iguana_blockunmain(struct iguana_info *coin,struct iguana_block *block) struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_block *newblock) { int32_t valid,bundlei,height=-1; struct iguana_block *hwmchain,*block = 0,*prev=0,*next; - bits256 *hash2p=0; double prevPoW = 0.; + bits256 *hash2p=0; double prevPoW = 0.; struct iguana_bundle *bp; if ( newblock == 0 ) return(0); hwmchain = &coin->blocks.hwmchain; + if ( hwmchain->height > 0 && ((bp= coin->current) == 0 || hwmchain->height/coin->chain->bundlesize > bp->hdrsi) ) + return(0); if ( (block= iguana_blockfind(coin,newblock->RO.hash2)) != 0 ) { if ( memcmp(coin->chain->genesis_hashdata,block->RO.hash2.bytes,sizeof(bits256)) == 0 ) diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 824ed9a57..a2204f617 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -227,13 +227,16 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo } else { -//char str[65]; printf(">>>>>>>>>>>>>> bundlehash2.(%s) ht.(%d %d)\n",bits256_str(str,hash2),bp->bundleheight,bundlei); + char str[65]; block->hdrsi = bp->hdrsi; block->bundlei = bundlei; bp->hashes[bundlei] = block->RO.hash2; if ( bp->speculative != 0 && bundlei < bp->numspec ) bp->speculative[bundlei] = bp->hashes[bundlei]; - bp->blocks[bundlei] = block; + if ( bp->blocks[bundlei] == 0 ) + bp->blocks[bundlei] = block; + else if ( bp->blocks[bundlei] != block ) + printf(">>>>>>>>>>>>>> bundlehash2.(%s) ht.(%d %d) block.%p there\n",bits256_str(str,hash2),bp->bundleheight,bundlei,bp->blocks[bundlei]); otherbp = 0; if ( (otherbp= iguana_bundlefind(coin,&otherbp,&otherbundlei,hash2)) != 0 || (bundlei % (bundlesize-1)) == 0) { @@ -399,17 +402,9 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int starti = coin->current->hdrsi; else starti = 0; priority = (bp->hdrsi < starti + coin->peers.numranked); - /*lag = (bp->hdrsi - starti); - lag *= lag; - if ( (i= sqrt(bp->hdrsi)) < 2 ) - i = 2; - if ( lag < i ) - lag = i; - else if ( lag > 10*i ) - lag = 10*i;*/ if ( strcmp("BTC",coin->symbol) == 0 ) - lag = 30; - else lag = 3; + lag = 30 + (bp->hdrsi - starti); + else lag = 3 + (bp->hdrsi - starti)/10; if ( (numpeers= coin->peers.numranked) > 3 )//&& bp->currentflag < bp->n ) { if ( numpeers > 0xff ) @@ -517,7 +512,7 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int bp->issued[i] = block->issued = now; } } - printf("slow peer.%d dead.%u (%s) reissued.%d\n",i,addr->dead,addr->ipaddr,flag); + printf("slow peer.%d dead.%u (%s) reissued.%d [%d]\n",i,addr->dead,addr->ipaddr,flag,bp->hdrsi); } } } @@ -550,8 +545,8 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int if ( flag != 0 && priority != 0 && laggard != 0 && coin->current == bp ) printf("[%d] reissued.%d currentflag.%d ht.%d s.%d finished.%d most.%d laggards.%d maxunfinished.%d\n",bp->hdrsi,flag,bp->currentflag,bp->bundleheight,bp->numsaved,finished,doneval,laggard,maxval); } - if ( bp == coin->current ) - return(counter); + //if ( bp == coin->current ) + // return(counter); } for (i=0; in; i++) { @@ -600,17 +595,19 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp) if ( (block= bp->blocks[i]) != 0 ) { //printf("(%x:%x) ",(uint32_t)block->RO.hash2.ulongs[3],(uint32_t)bp->hashes[i].ulongs[3]); - if ( block->fpipbits == 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(coin,&valid,block,1) < 0 ) + if ( iguana_blockvalidate(coin,&valid,block,1) < 0 || block->fpipbits == 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) ) { - if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1)) == i ) + fname[0] = 0; + if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1)) != i ) + printf("checki.%d vs %d mismatch?\n",checki,i); + if ( fname[0] != 0 ) OS_removefile(fname,0); - char str[65]; printf(">>>>>>> ipbits.%x null prevblock error at ht.%d patch.(%s) and reissue %s\n",block->fpipbits,bp->bundleheight+i,bits256_str(str,block->RO.prev_block),fname); + char str[65]; printf(">>>>>>> ipbits.%x block contents error at ht.%d\n",bp->bundleheight+i); + //patch.(%s) and reissue %s checki.%d vs %d\n",block->fpipbits,bp->bundleheight+i,bits256_str(str,block->RO.prev_block),fname,checki,i); block->fpipbits = 0; block->fpos = -1; block->queued = 0; block->RO.recvlen = 0; - memset(bp->hashes[i].bytes,0,sizeof(bp->hashes[i])); - bp->blocks[i] = 0; //iguana_blockQ("null retry",coin,bp,i,block->RO.hash2,1); } else ready++; } else printf("error getting block (%d:%d) %p\n",bp->hdrsi,i,block); @@ -621,12 +618,12 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp) int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti) { int32_t counter=0; - //if ( bp->speculative != 0 ) - // printf("hdr ITERATE bundle.%d vs %d: h.%d n.%d r.%d s.%d finished.%d speculative.%p\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->emitfinish,bp->speculative); int32_t i; uint32_t now; if ( coin->enableCACHE != 0 && bp->speculative == 0 && bp->numhashes < bp->n ) { char str[64]; + if ( bp == coin->current ) + printf("hdr ITERATE bundle.%d vs %d: h.%d n.%d r.%d s.%d finished.%d speculative.%p\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->emitfinish,bp->speculative); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); } if ( bp->speculative != 0 ) diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index afa166a53..865b3e076 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -508,7 +508,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct iguana_bundlereq *req,struct iguana_block *blocks,int32_t n,int32_t *newhwmp) { - int32_t i,bundlei,match; bits256 *blockhashes,allhash; struct iguana_block *block; struct iguana_bundle *bp,*firstbp = 0; + int32_t i,bundlei,match; struct iguana_block *block; struct iguana_bundle *bp,*firstbp = 0; if ( blocks == 0 ) { printf("iguana_recvblockhdrs null blocks?\n"); @@ -516,7 +516,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig } if ( blocks != 0 && n > 0 ) { - if ( 0 && n >= coin->chain->bundlesize ) + /*if ( 0 && n >= coin->chain->bundlesize ) { blockhashes = malloc(sizeof(*blockhashes) * coin->chain->bundlesize); for (i=0; ichain->bundlesize; i++) @@ -540,7 +540,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig } } free(blockhashes); - } + }*/ for (i=match=0; i 0 ) { coin->backstopmillis = OS_milliseconds(); - iguana_blockQ("mainchain",coin,0,-1,hash2,lag > 100 * threshold); + iguana_blockQ("mainchain",coin,0,-1,hash2,lag > threshold); flag++; char str[65]; if ( 1 && (rand() % 1000) == 0 )//|| bp->bundleheight > coin->longestchain-coin->chain->bundlesize ) @@ -1012,7 +1012,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin) else if ( bp != 0 && bundlei < bp->n-1 && (bits256_nonz(bp->hashes[bundlei+1]) != 0 || (bp->speculative != 0 && bits256_nonz(bp->speculative[bundlei+1]) != 0)) ) { int32_t j; - memset(bp->hashes[bundlei].bytes,0,sizeof(bp->hashes[bundlei])); + //memset(bp->hashes[bundlei].bytes,0,sizeof(bp->hashes[bundlei])); bp->blocks[bundlei] = 0; for (j=0; j<1&&bundlei+j+1n; j++) { diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index cd6e635db..9029fd761 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -387,8 +387,9 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp) printf("unexpected spendbp: height.%d bp.[%d] U%d <- S%d.[%d] [ext.%d %s prev.%d]\n",bp->bundleheight+i,spentbp->hdrsi,spent_unspentind,spendind,bp->hdrsi,s->external,bits256_str(str,prevhash),s->prevout); errs++; } - if ( now > spentbp->lastprefetch+60 || (spentbp->dirty % 100000) == 0 ) + if ( now > spentbp->lastprefetch+10 || (spentbp->dirty % 10000) == 0 ) { + printf("prefetch[%d]\n",spentbp->hdrsi); iguana_ramchain_prefetch(coin,&spentbp->ramchain); spentbp->lastprefetch = now; }