Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
2b52416deb
  1. 9
      iguana/iguana_bundles.c
  2. 107
      iguana/iguana_recv.c
  3. 4
      iguana/main.c

9
iguana/iguana_bundles.c

@ -576,11 +576,18 @@ int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32
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);
if ( strcmp(coin->symbol,"BTC") != 0 && bp->speculative == 0 && bp->numhashes < bp->n )
int32_t i; struct iguana_block *block;
if ( coin->enableCACHE != 0 && bp->speculative == 0 && bp->numhashes < bp->n )
{
char str[64];
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
else if ( bp->speculative != 0 )
{
for (i=0; i<bp->numspec; i++)
if ( bits256_nonz(bp->speculative[i]) != 0 && ((block= iguana_blockfind(coin,bp->speculative[i])) == 0 || block->req == 0) )
iguana_blockQ("speculative",coin,0,-1,bp->speculative[i],0);
}
return(counter);
}

107
iguana/iguana_recv.c

@ -192,7 +192,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
}
else if ( coin->enableCACHE != 0 )
printf("validated.(%s)\n",bits256_str(str,origtxdata->block.RO.hash2));
copyflag = coin->enableCACHE * (strcmp(coin->symbol,"BTC") != 0);
copyflag = coin->enableCACHE * (coin->enableCACHE != 0);
bp = 0, bundlei = -2;
if ( copyflag != 0 && recvlen != 0 && ((bp= iguana_bundlefind(coin,&bp,&bundlei,origtxdata->block.RO.hash2)) == 0 || (bp->blocks[bundlei] != 0 && bp->blocks[bundlei]->fpipbits == 0)) )
{
@ -414,7 +414,7 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in
if ( bp->numhashes < bp->n && bundlei == 0 && bp->speculative == 0 && bp->bundleheight < coin->longestchain-coin->chain->bundlesize )
{
char str[65]; bits256_str(str,bp->hashes[0]);
//fprintf(stderr,"Afound block -> %d %d hdr.%s\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str);
fprintf(stderr,"Afound block -> %d %d hdr.%s\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
/*else if ( bp->speculative != 0 && bundlei < bp->numspec && memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)) == 0 )
@ -464,7 +464,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
}
else if ( bp->hdrsi > 0 && (bp= coin->bundles[bp->hdrsi-1]) != 0 )
iguana_bundlehash2add(coin,0,bp,coin->chain->bundlesize-1,prevhash2);
if ( strcmp(coin->symbol,"BTC") != 0 )
if ( coin->enableCACHE != 0 )
iguana_bundlespeculate(coin,bp,bundlei,hash2,1);
}
prevbp = 0, prevbundlei = -2;
@ -487,7 +487,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
//printf("bundlehash2add next %d\n",prevbundlei);
iguana_bundlehash2add(coin,0,prevbp,prevbundlei+1,hash2);
}
if ( strcmp(coin->symbol,"BTC") != 0 )
if ( coin->enableCACHE != 0 )
iguana_bundlespeculate(coin,prevbp,prevbundlei,prevhash2,2);
}
}
@ -679,7 +679,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
break;
}
}
printf("i.%d ref prev.(%s)\n",i,bits256_str(str,origblock->RO.prev_block));
//printf("i.%d ref prev.(%s)\n",i,bits256_str(str,origblock->RO.prev_block));
}
if ( 0 && bp != 0 && bp->hdrsi == coin->bundlescount-1 )
{
@ -693,7 +693,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
}
fprintf(stderr,"%s [%d:%d] block.%x | s.%d r.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,numsaved,numrecv);
}
if ( 0 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && strcmp(coin->symbol,"BTC") != 0 )
if ( 1 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && coin->enableCACHE != 0 )
{
printf("reissue hdrs request for [%d]\n",bp->hdrsi);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
@ -847,7 +847,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
if ( (next= iguana_blockfind(coin,iguana_blockhash(coin,coin->blocks.hwmchain.height+1))) == 0 )
{
if ( (block= iguana_blockfind(coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
next = block->hh.next, block->mainchain = 1;
next = block->hh.next; //, next/block->mainchain = 1;
}
if ( next == 0 && hdrsi < coin->bundlescount && (bp= coin->bundles[hdrsi]) != 0 && (next= bp->blocks[bundlei]) != 0 )
{
@ -879,55 +879,54 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
lflag++, flag++;
//else printf("chainlink error for %d\n",coin->blocks.hwmchain.height+1);
}
if ( strcmp(coin->symbol,"BTC") != 0 && queue_size(&coin->blocksQ) < _IGUANA_MAXPENDING )
}
if ( 1 )//queue_size(&coin->blocksQ) < _IGUANA_MAXPENDING )
{
/*double threshold,lag = OS_milliseconds() - coin->backstopmillis;
threshold = (10 + coin->longestchain - coin->blocksrecv);
if ( threshold < 1 )
threshold = 1.;
if ( (bp= coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize]) != 0 )
threshold = (bp->avetime + coin->avetime) * .5;
else threshold = coin->avetime;
threshold *= 100. * sqrt(threshold) * .000777;*/
double threshold,lag = OS_milliseconds() - coin->backstopmillis;
threshold = 1000;
if ( coin->blocks.hwmchain.height < coin->longestchain && (coin->backstop != coin->blocks.hwmchain.height+1 || lag > threshold) )
{
double threshold,lag = OS_milliseconds() - coin->backstopmillis;
threshold = (10 + coin->longestchain - coin->blocksrecv);
if ( threshold < 1 )
threshold = 1.;
if ( (bp= coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize]) != 0 )
threshold = (bp->avetime + coin->avetime) * .5;
else threshold = coin->avetime;
threshold *= 100. * sqrt(threshold) * .000777;
if ( strcmp(coin->symbol,"BTC") != 0 )
threshold = 1000;
else threshold = 10000;
if ( coin->blocks.hwmchain.height < coin->longestchain && (coin->backstop != coin->blocks.hwmchain.height+1 || lag > threshold) )
coin->backstop = coin->blocks.hwmchain.height+1;
hash2 = iguana_blockhash(coin,coin->backstop);
bp = coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize];
bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize;
if ( bp != 0 && bits256_nonz(hash2) == 0 )
{
coin->backstop = coin->blocks.hwmchain.height+1;
hash2 = iguana_blockhash(coin,coin->backstop);
bp = coin->bundles[(coin->blocks.hwmchain.height+1)/coin->chain->bundlesize];
bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize;
if ( bp != 0 && bits256_nonz(hash2) == 0 )
{
hash2 = bp->hashes[bundlei];
if ( bits256_nonz(hash2) == 0 && bp->speculative != 0 )
hash2 = bp->speculative[bundlei];
}
if ( bits256_nonz(hash2) > 0 )
{
if ( bp != 0 && bits256_nonz(hash2) > 0 )
{
coin->backstopmillis = OS_milliseconds();
iguana_blockQ("mainchain",coin,bp,bundlei,hash2,0);
flag++;
char str[65];
if ( 1 && (rand() % 1000) == 0 || bp->bundleheight > coin->longestchain-coin->chain->bundlesize )
printf("%s MAINCHAIN.%d threshold %.3f %.3f lag %.3f\n",bits256_str(str,hash2),coin->blocks.hwmchain.height+1,threshold,coin->backstopmillis,lag);
}
}
/*else if ( bp != 0 && bundlei < bp->n-1 && bits256_nonz(bp->hashes[bundlei+1]) > 0 )
{
printf("MAINCHAIN skip issue %d\n",bundlei+1);
iguana_blockQ("mainskip",coin,bp,bundlei,bp->hashes[bundlei+1],0);
}
else if ( bp != 0 && time(NULL) > bp->hdrtime+10 )
hash2 = bp->hashes[bundlei];
if ( bits256_nonz(hash2) == 0 && bp->speculative != 0 )
hash2 = bp->speculative[bundlei];
}
if ( bits256_nonz(hash2) > 0 )
{
if ( bp != 0 && bits256_nonz(hash2) > 0 )
{
coin->backstopmillis = OS_milliseconds();
iguana_blockQ("mainchain",coin,bp,bundlei,hash2,0);
flag++;
char str[65];
printf("MAINCHAIN gethdr %d\n",bp->bundleheight);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
bp->hdrtime = (uint32_t)time(NULL);
}*/
if ( 1 && (rand() % 1000) == 0 || bp->bundleheight > coin->longestchain-coin->chain->bundlesize )
printf("%s MAINCHAIN.%d threshold %.3f %.3f lag %.3f\n",bits256_str(str,hash2),coin->blocks.hwmchain.height+1,threshold,coin->backstopmillis,lag);
}
}
else if ( bp != 0 && bundlei < bp->n-1 && bits256_nonz(bp->hashes[bundlei+1]) > 0 )
{
printf("MAINCHAIN skip issue %d\n",bundlei+1);
iguana_blockQ("mainskip",coin,bp,bundlei,bp->hashes[bundlei+1],0);
}
else if ( bp != 0 && time(NULL) > bp->hdrtime+10 )
{
char str[65];
printf("MAINCHAIN gethdr %d\n",bp->bundleheight);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
bp->hdrtime = (uint32_t)time(NULL);
}
}
}
@ -1000,7 +999,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
{
if ( (bp= coin->bundles[i]) != 0 && (bp->numhashes < bp->n || i == coin->bundlescount-1) )
{
lag = 60;
lag = 10;
if ( bp->bundleheight+bp->numhashes < coin->longestchain && time(NULL) > bp->issuetime+lag )
{
//printf("LAG.%ld hdrsi.%d numhashes.%d:%d needhdrs.%d qsize.%d zcount.%d\n",time(NULL)-bp->hdrtime,i,bp->numhashes,bp->n,iguana_needhdrs(coin),queue_size(&coin->hdrsQ),coin->zcount);
@ -1180,7 +1179,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
char str[65];
if ( block != 0 )
block->numrequests++;
if ( 0 && priority != 0 )
if ( 1 && priority != 0 )
printf("sendreq %s [%d:%d]\n",bits256_str(str,hash2),bp!=0?bp->bundleheight:-1,req->bundlei);
iguana_sendblockreqPT(coin,addr,req->bp,req->bundlei,hash2,0);
}

4
iguana/main.c

@ -1117,7 +1117,7 @@ void iguana_main(void *arg)
sleep(1);
char *str;
//iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}"));
if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":64,\"newcoin\":\"BTC\",\"active\":1,\"numhelpers\":1,\"poll\":1,\"startpend\":2,\"endpend\":2,\"cache\":0}"),0)) != 0 )
if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":1,\"startpend\":2,\"endpend\":2,\"cache\":0}"),0)) != 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0)) != 0 )
@ -1166,7 +1166,7 @@ void iguana_main(void *arg)
cJSON *argjson;
if ( (argjson= cJSON_Parse(arg)) != 0 )
{
printf("call argv JSON\n");
printf("call argv JSON.(%s)\n",(char *)arg);
SuperNET_JSON(&MYINFO,argjson,0);
free_json(argjson);
} else printf("error parsing.(%s)\n",(char *)arg);

Loading…
Cancel
Save