Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
6492c6a4cd
  1. 126
      deprecated/obsolete.h
  2. 22
      iguana/iguana777.c
  3. 5
      iguana/iguana777.h
  4. 2
      iguana/iguana_blocks.c
  5. 7
      iguana/iguana_bundles.c
  6. 10
      iguana/iguana_peers.c
  7. 254
      iguana/iguana_recv.c
  8. 2
      iguana/main.c

126
deprecated/obsolete.h

@ -11219,4 +11219,130 @@ void iguana_dedicatedrecv(void *arg)
coin->savedblocks = (uint32_t)time(NULL); coin->savedblocks = (uint32_t)time(NULL);
} }
} }
/*struct iguana_block *iguana_blockrequest(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,uint32_t now,int32_t iamthreadsafe)
{
struct iguana_block *block = 0;
if( bp != 0 && bundlei >= 0 && bundlei < bp->n )
block = bp->blocks[bundlei];
if ( block == 0 && iamthreadsafe != 0 )
block = iguana_blockfind(coin,hash2);
if ( block != 0 )
{
//block->issued = now;
block->numrequests++;
}
return(block);
}*/
if ( 0 && addr->msgcounts.verack > 0 && coin->bundlescount > 0 && req == 0 && addr->pendblocks < limit )//&& now > addr->lastpoll )
{
if ( 1 )//strcmp("BTC",coin->symbol) != 0 )
{
int32_t bundlei;
incr = coin->peers.numranked == 0 ? coin->MAXPEERS : coin->peers.numranked;
if ( (rand() % 100) < 50 )
height = addr->rank * _IGUANA_MAXPENDING;
else if ( (rand() % 100) < 50 )
height = addr->addrind + (addr->rank * (coin->longestchain - coin->blocks.hwmchain.height) / (coin->peers.numranked+1));
else if ( (rand() % 100) < 50 )
{
height = (addr->lastheight + 1);
if ( height >= coin->longestchain-coin->chain->bundlesize )
height = addr->rank*incr*_IGUANA_MAXPENDING;
}
else
{
height = coin->longestchain - (rand() % incr) * 1000;
if ( height < 0 )
height = coin->blocks.hwmchain.height;
}
for (; height<coin->bundlescount*coin->chain->bundlesize; height+=incr)
{
if ( height > coin->longestchain )
height = addr->rank*incr*_IGUANA_MAXPENDING;
if ( height > addr->lastheight )
addr->lastheight = height;
if ( (bp= coin->bundles[height/coin->chain->bundlesize]) != 0 && bp->emitfinish == 0 )
{
bundlei = (height % coin->chain->bundlesize);
if ( bundlei < bp->n && bits256_nonz(bp->hashes[bundlei]) > 0 && (block= bp->blocks[bundlei]) != 0 && block->numrequests <= bp->minrequests && block->fpipbits == 0 && (bp->issued[bundlei] == 0 || now > bp->issued[bundlei]+13) )
{
block->numrequests++;
bp->issued[bundlei] = (uint32_t)time(NULL);;
//if ( 0 && (rand() % 100) == 0 )
printf("%s Send auto blockreq.%d [%d] minreq.%d\n",addr->ipaddr,bp->bundleheight+bundlei,block->numrequests,bp->minrequests);
iguana_sendblockreqPT(coin,addr,bp,bundlei,bp->hashes[bundlei],0);
return(1);
}
}
//if ( (rand() % 100) < 50 )
// break;
}
}
else
{
//printf("%s lastpoll.%u %u\n",addr->ipaddr,addr->lastpoll,now);
addr->lastpoll = now;
for (i=n=0; i<coin->bundlescount; i++)
if ( coin->bundles[i] != 0 && coin->bundles[i]->emitfinish == 0 )
n++;
if ( n >= coin->bundlescount-(coin->bundlescount>>3) || (addr->ipbits % 10) < 5 )
refbundlei = (addr->ipbits % coin->bundlescount);
else
{
if ( n*2 < coin->bundlescount )
{
for (i=refbundlei=0; i<IGUANA_MAXPEERS; i++)
{
if ( addr->usock == coin->peers.active[i].usock )
break;
if ( coin->peers.active[i].usock >= 0 )
refbundlei++;
}
//printf("half done\n");
} else refbundlei = ((addr->addrind*100) % coin->bundlescount);
}
for (i=0; i<coin->bundlescount; i++)
{
if ( (diff= (i - refbundlei)) < 0 )
diff = -diff;
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 )
{
metric = (1 + diff * ((addr->addrind&1) == 0 ? 1 : 1) * (1. + bp->metric));// / (i*((addr->addrind&1) != 0 ? 1 : i) + 1);
//printf("%f ",bp->metric);
if ( bestmetric < 0. || metric < bestmetric )
bestmetric = metric, bestbp = bp;
}
}
if ( bestbp != 0 && bp->emitfinish == 0 )
{
for (k=0; k<coin->bundlescount; k++)
{
i = (bestbp->hdrsi + k) % coin->bundlescount;
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish != 0 )
continue;
//printf("%.15f ref.%d addrind.%d bestbp.%d\n",bestmetric,refbundlei,addr->addrind,bp->hdrsi);
m = coin->chain->bundlesize;
if ( bp->n < m )
m = bp->n;
j = (addr->addrind*3 + 0) % m;
val = (bp->threshold / 1000.);
for (r=0; r<m; r++,j++)
{
if ( j >= m )
j = 0;
if ( (block= bp->blocks[j]) != 0 && block->fpipbits == 0 && block->queued == 0 && block->numrequests <= bp->minrequests )
{
block->numrequests++;
//block->issued = (uint32_t)time(NULL);;
//printf("%s Send auto blockreq.%d\n",addr->ipaddr,bp->bundleheight+j);
iguana_sendblockreqPT(coin,addr,bp,j,hash2,0);
return(1);
}
}
}
}
}
}
#endif #endif

22
iguana/iguana777.c

@ -247,6 +247,20 @@ void iguana_mergeQ(struct iguana_info *coin,struct iguana_bundle *bp,struct igua
queue_enqueue("helperQ",&helperQ,&ptr->DL,0); queue_enqueue("helperQ",&helperQ,&ptr->DL,0);
} }
void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp)
{
struct iguana_helper *ptr;
ptr = mycalloc('i',1,sizeof(*ptr));
ptr->allocsize = sizeof(*ptr);
ptr->coin = coin;
ptr->bp = bp, ptr->hdrsi = bp->hdrsi;
ptr->type = 'B';
ptr->starttime = (uint32_t)time(NULL);
coin->numbundlesQ++;
//printf("%s bundle.%d[%d] emitfinish.%u\n",coin->symbol,ptr->hdrsi,bp->n,bp->emitfinish);
queue_enqueue("helperQ",&helperQ,&ptr->DL,0);
}
int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_helper *ptr) int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_helper *ptr)
{ {
struct iguana_info *coin; struct iguana_peer *addr; struct iguana_bundle *bp,*nextbp; struct iguana_info *coin; struct iguana_peer *addr; struct iguana_bundle *bp,*nextbp;
@ -315,17 +329,9 @@ void iguana_helper(void *arg)
} }
flag++; flag++;
} }
if ( flag == 0 )
{
/*for (i=0; i<sizeof(Coins)/sizeof(*Coins); i++)
{
if ( (coin= Coins[i]) != 0 && coin->launched != 0 )
flag += iguana_rpctest(coin);
}*/
if ( flag == 0 ) if ( flag == 0 )
usleep(10000); usleep(10000);
} }
}
} }
void iguana_coinloop(void *arg) void iguana_coinloop(void *arg)

5
iguana/iguana777.h

@ -387,7 +387,7 @@ struct iguana_bundle
{ {
struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp; struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp;
struct iguana_bloom16 bloom; struct iguana_bloom16 bloom;
uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime; uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued;
int32_t numhashes,numrecv,numsaved,numcached; int32_t numhashes,numrecv,numsaved,numcached;
int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents; int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents;
double avetime,threshold,metric; uint64_t datasize,estsize; double avetime,threshold,metric; uint64_t datasize,estsize;
@ -439,7 +439,7 @@ struct iguana_info
portable_mutex_t peers_mutex,blocks_mutex; portable_mutex_t peers_mutex,blocks_mutex;
struct iguana_bundle *bundles[IGUANA_MAXBUNDLES]; struct iguana_bundle *bundles[IGUANA_MAXBUNDLES];
double rankedbps[IGUANA_MAXBUNDLES][2]; double rankedbps[IGUANA_MAXBUNDLES][2];
int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle; uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent; int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle; uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ;
double backstopmillis; bits256 backstophash2; double backstopmillis; bits256 backstophash2;
int32_t initialheight,mapflags,minconfirms,numrecv,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids; bits256 reqtxids[64]; int32_t initialheight,mapflags,minconfirms,numrecv,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids; bits256 reqtxids[64];
void *launched,*started; void *launched,*started;
@ -685,6 +685,7 @@ int32_t iguana_jsonQ();
int32_t is_bitcoinrpc(char *method); int32_t is_bitcoinrpc(char *method);
char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr); char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr);
cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr); cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr);
void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp);
#include "../includes/iguana_api.h" #include "../includes/iguana_api.h"

2
iguana/iguana_blocks.c

@ -329,7 +329,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
printf("EXTENDMAIN %s %d <- (%s) n.%u max.%u PoW %f numtx.%d valid.%d\n",str,block->height,str2,hwmchain->height+1,coin->blocks.maxblocks,block->PoW,block->RO.txn_count,block->valid); printf("EXTENDMAIN %s %d <- (%s) n.%u max.%u PoW %f numtx.%d valid.%d\n",str,block->height,str2,hwmchain->height+1,coin->blocks.maxblocks,block->PoW,block->RO.txn_count,block->valid);
struct iguana_bundle *bp; struct iguana_bundle *bp;
if ( (block->height % coin->chain->bundlesize) == 0 ) if ( (block->height % coin->chain->bundlesize) == 0 )
bp = iguana_bundlecreate(coin,&bundlei,block->height,block->RO.hash2,zero,1); bp = iguana_bundlecreate(coin,&bundlei,block->height,block->RO.hash2,zero,0);
else else
{ {
if ( (bp= coin->bundles[block->height / coin->chain->bundlesize]) != 0 ) if ( (bp= coin->bundles[block->height / coin->chain->bundlesize]) != 0 )

7
iguana/iguana_bundles.c

@ -279,11 +279,6 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund
bp->allhash = allhash; bp->allhash = allhash;
if ( bp->bundleheight >= 0 && bp->bundleheight != (bundleheight - *bundleip) ) if ( bp->bundleheight >= 0 && bp->bundleheight != (bundleheight - *bundleip) )
printf("bundlecreate warning: bp->bundleheight %d != %d (bundleheight %d - %d bundlei)\n",bp->bundleheight,(bundleheight - *bundleip),bundleheight,*bundleip); printf("bundlecreate warning: bp->bundleheight %d != %d (bundleheight %d - %d bundlei)\n",bp->bundleheight,(bundleheight - *bundleip),bundleheight,*bundleip);
if ( *bundleip == 0 && iguana_bundlehash2add(coin,0,bp,0,bundlehash2) == 0 )
{
//if ( bp->numhashes < bp->n )
// queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
}
return(bp); return(bp);
} }
bp = mycalloc('b',1,sizeof(*bp)); bp = mycalloc('b',1,sizeof(*bp));
@ -552,7 +547,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
tmp = (difft.millis * 1000000); tmp = (difft.millis * 1000000);
tmp %= 1000000000; tmp %= 1000000000;
difft.millis = ((double)tmp / 1000000.); difft.millis = ((double)tmp / 1000000.);
sprintf(str,"N[%d] h.%d r.%d c.%d:%d:%d s.%d d.%d E.%d:%d M.%d L.%d est.%d %s %d:%02d:%02d %03.3f peers.%d/%d",coin->bundlescount,numhashes,coin->blocksrecv,coin->numcached,numcached,coin->cachefreed,numsaved,done,numemit,coin->numreqsent,coin->blocks.hwmchain.height,coin->longestchain,coin->MAXBUNDLES,mbstr(str2,estsize),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,difft.millis,p,coin->MAXPEERS); sprintf(str,"N[%d] Q.%d h.%d r.%d c.%d:%d:%d s.%d d.%d E.%d:%d M.%d L.%d est.%d %s %d:%02d:%02d %03.3f peers.%d/%d",coin->bundlescount,coin->numbundlesQ,numhashes,coin->blocksrecv,coin->numcached,numcached,coin->cachefreed,numsaved,done,numemit,coin->numreqsent,coin->blocks.hwmchain.height,coin->longestchain,coin->MAXBUNDLES,mbstr(str2,estsize),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,difft.millis,p,coin->MAXPEERS);
//sprintf(str+strlen(str),"%s.%-2d %s time %.2f files.%d Q.%d %d\n",coin->symbol,flag,str,(double)(time(NULL)-coin->starttime)/60.,coin->peers.numfiles,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ)); //sprintf(str+strlen(str),"%s.%-2d %s time %.2f files.%d Q.%d %d\n",coin->symbol,flag,str,(double)(time(NULL)-coin->starttime)/60.,coin->peers.numfiles,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ));
//if ( (rand() % 100) == 0 ) //if ( (rand() % 100) == 0 )
static uint32_t lastdisp; static uint32_t lastdisp;

10
iguana/iguana_peers.c

@ -925,8 +925,6 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
bufsize = IGUANA_MAXPACKETSIZE; bufsize = IGUANA_MAXPACKETSIZE;
buf = mycalloc('r',1,bufsize); buf = mycalloc('r',1,bufsize);
printf("send version myservices.%llu to (%s)\n",(long long)coin->myservices,addr->ipaddr); printf("send version myservices.%llu to (%s)\n",(long long)coin->myservices,addr->ipaddr);
//if ( addr->supernet != 0 )
// iguana_send_supernet(coin,addr,"{\"agent\":\"SuperNET\",\"method\":\"getpeers\"}",0);
iguana_send_version(coin,addr,coin->myservices); iguana_send_version(coin,addr,coin->myservices);
sleep(1+(rand()%5)); sleep(1+(rand()%5));
iguana_queue_send(coin,addr,0,serialized,"getaddr",0,0,0); iguana_queue_send(coin,addr,0,serialized,"getaddr",0,0,0);
@ -970,14 +968,6 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
} }
if ( flag == 0 ) if ( flag == 0 )
{ {
/*if ( 0 && time(NULL) > addr->pendtime+30 )
{
if ( addr->pendblocks > 0 )
addr->pendblocks--;
if ( addr->pendhdrs > 0 )
addr->pendhdrs--;
addr->pendtime = 0;
}*/
if ( coin->active != 0 && (fds.revents & POLLOUT) != 0 ) if ( coin->active != 0 && (fds.revents & POLLOUT) != 0 )
{ {
if ( iguana_pollQsPT(coin,addr) > 0 ) if ( iguana_pollQsPT(coin,addr) > 0 )

254
iguana/iguana_recv.c

@ -30,22 +30,7 @@ struct iguana_bundlereq *iguana_bundlereq(struct iguana_info *coin,struct iguana
return(req); return(req);
} }
/*struct iguana_block *iguana_blockrequest(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,uint32_t now,int32_t iamthreadsafe) int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe)
{
struct iguana_block *block = 0;
if( bp != 0 && bundlei >= 0 && bundlei < bp->n )
block = bp->blocks[bundlei];
if ( block == 0 && iamthreadsafe != 0 )
block = iguana_blockfind(coin,hash2);
if ( block != 0 )
{
//block->issued = now;
block->numrequests++;
}
return(block);
}*/
int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe)
{ {
int32_t len; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; int32_t len; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)];
char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2)); char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
@ -60,8 +45,7 @@ int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,st
coin->numreqsent++; coin->numreqsent++;
addr->pendblocks++; addr->pendblocks++;
addr->pendtime = (uint32_t)time(NULL); addr->pendtime = (uint32_t)time(NULL);
//iguana_blockrequest(coin,bp,bundlei,hash2,addr->pendtime,iamthreadsafe); printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1);
//printf("REQ.%s bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1);
} else printf("MSG_BLOCK null datalen.%d\n",len); } else printf("MSG_BLOCK null datalen.%d\n",len);
return(len); return(len);
} }
@ -295,29 +279,42 @@ void iguana_patch(struct iguana_info *coin,struct iguana_block *block)
} }
} }
int32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bits256 *blockhashes,int32_t num) uint32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bits256 *blockhashes,int32_t num)
{ {
bits256 allhash; int32_t err,i,n; struct iguana_block *block; bits256 allhash; int32_t err,i,n; struct iguana_block *block,*prev;
if ( bits256_nonz(bp->allhash) > 0 && num >= coin->chain->bundlesize ) if ( bits256_nonz(bp->allhash) > 0 && num >= coin->chain->bundlesize )
{ {
for (i=0; i<bp->n; i++)
if ( bits256_nonz(blockhashes[i]) == 0 )
blockhashes[i] = bp->hashes[i];
vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes)); vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes));
if ( memcmp(allhash.bytes,bp->allhash.bytes,sizeof(allhash)) == 0 ) if ( memcmp(allhash.bytes,bp->allhash.bytes,sizeof(allhash)) == 0 && bp->queued == 0 )
{ {
if ( bp->bundleheight > 0 )
prev = iguana_blockfind(coin,iguana_blockhash(coin,bp->bundleheight-1));
else prev = 0;
for (i=n=0; i<coin->chain->bundlesize&&i<bp->n; i++) for (i=n=0; i<coin->chain->bundlesize&&i<bp->n; i++)
{ {
if ( (err= iguana_bundlehash2add(coin,0,bp,i,blockhashes[i])) < 0 ) if ( (err= iguana_bundlehash2add(coin,&block,bp,i,blockhashes[i])) < 0 )
return(err); return(err);
if ( 1 && bp->emitfinish == 0 && (block= bp->blocks[i]) != 0 && (block->queued == 0 && block->fpipbits == 0) && block->numrequests <= bp->minrequests+10 ) if ( block != 0 && block == bp->blocks[i] )
iguana_blockQ(coin,bp,i,block->RO.hash2,1), n++; {
block->height = bp->bundleheight + i;
block->mainchain = 1;
if ( prev != 0 )
{
prev->hh.next = block;
block->hh.prev = prev;
} }
printf("ALLHASHES FOUND! %d requested.%d\n",bp->bundleheight,n);
return(i);
} }
prev = block;
//if ( 1 && bp->emitfinish == 0 && (block= bp->blocks[i]) != 0 && (block->queued == 0 && block->fpipbits == 0) && block->numrequests <= bp->minrequests+10 )
// iguana_blockQ(coin,bp,i,block->RO.hash2,1), n++;
} }
return(-1); //printf("ALLHASHES FOUND! %d requested.%d\n",bp->bundleheight,n);
bp->queued = (uint32_t)time(NULL);
iguana_bundleQ(coin,bp);
return(bp->queued);
}
}
return(0);
} }
// main context, ie single threaded // main context, ie single threaded
@ -334,7 +331,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
if ( block != origblock ) if ( block != origblock )
iguana_blockcopy(coin,block,origblock); iguana_blockcopy(coin,block,origblock);
*blockp = block; *blockp = block;
if ( 0 && bits256_nonz(block->RO.prev_block) > 0 ) if ( 1 && bits256_nonz(block->RO.prev_block) > 0 )
iguana_patch(coin,block); iguana_patch(coin,block);
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,block->RO.hash2)) != 0 ) if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,block->RO.hash2)) != 0 )
{ {
@ -362,16 +359,16 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
//if ( coin->bundlescount < bp->hdrsi+1 ) //if ( coin->bundlescount < bp->hdrsi+1 )
{ {
//char str[65]; printf("autoextend CREATE.%d new bundle.%s\n",bp->bundleheight + coin->chain->bundlesize,bits256_str(str,block->RO.hash2)); //char str[65]; printf("autoextend CREATE.%d new bundle.%s\n",bp->bundleheight + coin->chain->bundlesize,bits256_str(str,block->RO.hash2));
iguana_bundlecreate(coin,&bundlei,bp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,1); iguana_bundlecreate(coin,&bundlei,bp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,0);
} }
} }
else if ( bundlei < coin->chain->bundlesize-1 ) else if ( bundlei < coin->chain->bundlesize-1 )
{ {
iguana_bundlehash2add(coin,0,bp,bundlei+1,block->RO.hash2); iguana_bundlehash2add(coin,0,bp,bundlei+1,block->RO.hash2);
if ( bundlei == 0 ) if ( bundlei == 0 && bp->numhashes < bp->n )
{ {
char str[65]; bits256_str(str,block->RO.prev_block); char str[65]; bits256_str(str,block->RO.prev_block);
//printf("found block -> hdr.%s\n",str); printf("found block -> hdr.%s\n",str);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
} }
} }
@ -408,54 +405,48 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig
struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *blockhashes,int32_t num) struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *blockhashes,int32_t num)
{ {
int32_t bundlei,i,n = 0; struct iguana_block *block; struct iguana_bundle *bp;// char str[65]; int32_t bundlei,i; struct iguana_bundle *bp;
bp = 0, bundlei = -2, iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); bp = 0, bundlei = -2, iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]);
//char str[65]; printf("blockhashes[%d] %s bp.%d[%d]\n",num,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei);
if ( bp != 0 ) if ( bp != 0 )
{ {
bp->hdrtime = (uint32_t)time(NULL);
blockhashes[0] = bp->hashes[0]; blockhashes[0] = bp->hashes[0];
if ( num >= coin->chain->bundlesize ) if ( num >= coin->chain->bundlesize )
{ {
bp->hdrtime = (uint32_t)time(NULL); if ( iguana_allhashcmp(coin,bp,blockhashes,num) > 0 )
if ( iguana_allhashcmp(coin,bp,blockhashes,num) == 0 )
return(req); return(req);
} }
for (i=0; i<num; i++) if ( bp->hdrsi == coin->bundlescount-1 )
{
if ( bits256_nonz(blockhashes[i]) > 0 && (block= iguana_blockhashset(coin,-1,blockhashes[i],1)) != 0 )
{ {
if ( block->hdrsi == bp->hdrsi && block->bundlei == i ) for (i=0; i<num; i++)
n++; iguana_blockQ(coin,0,-1,blockhashes[i],0);
}
} }
//printf("got [%d] num.%d matched hashes\n",n,num);
} }
else else if ( num >= coin->chain->bundlesize )
{ {
//char str[65]; printf("blockhashes[%d] %s\n",num,bits256_str(str,blockhashes[1])); for (i=0; i<coin->bundlescount; i++)
iguana_blockQ(coin,0,-1,blockhashes[1],1);
for (i=coin->chain->bundlesize; i<num; i++)
{ {
if ( i >= coin->chain->bundlesize && (i % coin->chain->bundlesize) < 2 && bits256_nonz(blockhashes[i]) > 0 ) if ( (bp= coin->bundles[i]) != 0 && bp->queued == 0 && bits256_nonz(bp->hashes[0]) > 0 )
iguana_blockQ(coin,0,-1,blockhashes[i],0);
}
}
/*if ( (block= iguana_blockhashset(coin,-1,blockhashes[1],1)) != 0 && num > 2 )
{ {
if ( block->rawdata != 0 ) blockhashes[0] = bp->hashes[0];
if ( iguana_allhashcmp(coin,bp,blockhashes,coin->chain->bundlesize) > 0 )
{ {
if ( block->copyflag != 0 ) bp->hdrtime = (uint32_t)time(NULL);
myfree(block->rawdata,block->RO.recvlen), block->copyflag = 0; iguana_blockQ(coin,bp,0,blockhashes[0],0);
else myfree(block->rawdata,block->numhashes * sizeof(bits256)); iguana_blockQ(coin,bp,1,blockhashes[1],0);
iguana_blockQ(coin,bp,coin->chain->bundlesize-1,blockhashes[coin->chain->bundlesize],0);
if ( num > coin->chain->bundlesize )
iguana_blockQ(coin,0,-1,blockhashes[coin->chain->bundlesize],0);
//printf("matched bundle.%d\n",bp->bundleheight);
return(req);
} }
//char str[65]; printf("got %d unmatched hashes %d:%d %s\n",num,bp==0?-1:bp->bundleheight,bundlei,bits256_str(str,blockhashes[1]));
block->rawdata = blockhashes, block->numhashes = num, block->havehashes = 1;
req->hashes = 0;
} }
if ( 0 && num >= coin->chain->bundlesize+1 ) }
{ printf("issue block1\n");
char str[65]; bits256_str(str,blockhashes[coin->chain->bundlesize]); iguana_blockQ(coin,0,-1,blockhashes[1],1);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); }
}*/ else iguana_blockQ(coin,0,-1,blockhashes[1],0); // should be RT block
return(req); return(req);
} }
@ -464,8 +455,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
struct iguana_bundle *prevbp=0,*bp=0; int32_t prevbundlei=-2,bundlei = -2; struct iguana_block *prevblock,*block; struct iguana_bundle *prevbp=0,*bp=0; int32_t prevbundlei=-2,bundlei = -2; struct iguana_block *prevblock,*block;
bp = iguana_bundleset(coin,&block,&bundlei,origblock); bp = iguana_bundleset(coin,&block,&bundlei,origblock);
//usleep(1000); static int total; char str[65]; printf("RECV %s [%d:%d] block.%08x | %d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,total++);
//static int total; char str[65]; printf("RECV %s [%d:%d] block.%08x | %d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,total++);
iguana_bundlefind(coin,&prevbp,&prevbundlei,origblock->RO.prev_block); iguana_bundlefind(coin,&prevbp,&prevbundlei,origblock->RO.prev_block);
if ( prevbp != 0 && prevbundlei >= 0 && (prevblock= iguana_blockfind(coin,origblock->RO.prev_block)) != 0 ) if ( prevbp != 0 && prevbundlei >= 0 && (prevblock= iguana_blockfind(coin,origblock->RO.prev_block)) != 0 )
{ {
@ -478,7 +468,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
//if ( coin->bundlescount < bp->hdrsi+1 ) //if ( coin->bundlescount < bp->hdrsi+1 )
{ {
//char str[65]; printf("autoextend CREATE.%d new bundle.%s\n",bp->bundleheight + coin->chain->bundlesize,bits256_str(str,block->RO.hash2)); //char str[65]; printf("autoextend CREATE.%d new bundle.%s\n",bp->bundleheight + coin->chain->bundlesize,bits256_str(str,block->RO.hash2));
iguana_bundlecreate(coin,&prevbundlei,prevbp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,1); iguana_bundlecreate(coin,&prevbundlei,prevbp->bundleheight + coin->chain->bundlesize,block->RO.hash2,zero,0);
} }
} }
else else
@ -489,7 +479,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
if ( prevbp->numhashes < prevbp->n && prevbundlei == 0 ) if ( prevbp->numhashes < prevbp->n && prevbundlei == 0 )
{ {
char str[65]; bits256_str(str,prevbp->hashes[0]); char str[65]; bits256_str(str,prevbp->hashes[0]);
//printf("Afound block -> %d hdr.%s\n",prevbp->bundleheight,str); printf("Afound block -> %d hdr.%s\n",prevbp->bundleheight,str);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
} }
//char str[65]; printf("PREV %s prevbp.%p[%d] h.%d\n",bits256_str(str,origblock->RO.prev_block),prevbp,prevbundlei,prevbp->numhashes); //char str[65]; printf("PREV %s prevbp.%p[%d] h.%d\n",bits256_str(str,origblock->RO.prev_block),prevbp,prevbundlei,prevbp->numhashes);
@ -683,8 +673,8 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
{ {
uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)];
char *hashstr=0; bits256 hash2; uint32_t now; struct iguana_block *block; struct iguana_blockreq *req=0; char *hashstr=0; bits256 hash2; uint32_t now; struct iguana_block *block; struct iguana_blockreq *req=0;
int32_t i,r,diff,j,k,n,m,z; double metric,bestmetric = -1.; struct iguana_bundle *bp,*bestbp = 0; int32_t m,z; struct iguana_bundle *bp;
int32_t limit,refbundlei,height=-1,incr,bundlei,datalen,flag = 0; double val; int32_t limit,height=-1,bundlei,datalen,flag = 0;
if ( addr->msgcounts.verack == 0 ) if ( addr->msgcounts.verack == 0 )
return(0); return(0);
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);
@ -701,7 +691,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
bp = 0, bundlei = -2; bp = 0, bundlei = -2;
bp = iguana_bundlefind(coin,&bp,&bundlei,hash2); bp = iguana_bundlefind(coin,&bp,&bundlei,hash2);
z = 0; z = 0;
if ( bp != 0 ) if ( bp != 0 && bp->queued == 0 )
{ {
if ( bp->bundleheight+coin->chain->bundlesize < coin->longestchain ) if ( bp->bundleheight+coin->chain->bundlesize < coin->longestchain )
{ {
@ -714,7 +704,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
} }
if ( bp == 0 || z != 0 ) if ( bp == 0 || z != 0 )
{ {
//printf("%s request hdr.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp->numhashes); printf("%s request hdr.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp->numhashes);
iguana_send(coin,addr,serialized,datalen); iguana_send(coin,addr,serialized,datalen);
addr->pendhdrs++; addr->pendhdrs++;
flag++; flag++;
@ -734,118 +724,8 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
//if ( addr->pendblocks >= limit ) //if ( addr->pendblocks >= limit )
// printf("%s %d overlimit.%d\n",addr->ipaddr,addr->pendblocks,limit); // printf("%s %d overlimit.%d\n",addr->ipaddr,addr->pendblocks,limit);
req = queue_dequeue(&coin->priorityQ,0); req = queue_dequeue(&coin->priorityQ,0);
if ( 0 && addr->msgcounts.verack > 0 && coin->bundlescount > 0 && req == 0 && addr->pendblocks < limit )//&& now > addr->lastpoll )
{
if ( 1 )//strcmp("BTC",coin->symbol) != 0 )
{
int32_t bundlei;
incr = coin->peers.numranked == 0 ? coin->MAXPEERS : coin->peers.numranked;
if ( (rand() % 100) < 50 )
height = addr->rank * _IGUANA_MAXPENDING;
else if ( (rand() % 100) < 50 )
height = addr->addrind + (addr->rank * (coin->longestchain - coin->blocks.hwmchain.height) / (coin->peers.numranked+1));
else if ( (rand() % 100) < 50 )
{
height = (addr->lastheight + 1);
if ( height >= coin->longestchain-coin->chain->bundlesize )
height = addr->rank*incr*_IGUANA_MAXPENDING;
}
else
{
height = coin->longestchain - (rand() % incr) * 1000;
if ( height < 0 )
height = coin->blocks.hwmchain.height;
}
for (; height<coin->bundlescount*coin->chain->bundlesize; height+=incr)
{
if ( height > coin->longestchain )
height = addr->rank*incr*_IGUANA_MAXPENDING;
if ( height > addr->lastheight )
addr->lastheight = height;
if ( (bp= coin->bundles[height/coin->chain->bundlesize]) != 0 && bp->emitfinish == 0 )
{
bundlei = (height % coin->chain->bundlesize);
if ( bundlei < bp->n && bits256_nonz(bp->hashes[bundlei]) > 0 && (block= bp->blocks[bundlei]) != 0 && block->numrequests <= bp->minrequests && block->fpipbits == 0 && (bp->issued[bundlei] == 0 || now > bp->issued[bundlei]+13) )
{
block->numrequests++;
bp->issued[bundlei] = (uint32_t)time(NULL);;
//if ( 0 && (rand() % 100) == 0 )
printf("%s Send auto blockreq.%d [%d] minreq.%d\n",addr->ipaddr,bp->bundleheight+bundlei,block->numrequests,bp->minrequests);
iguana_sendblockreq(coin,addr,bp,bundlei,bp->hashes[bundlei],0);
return(1);
}
}
//if ( (rand() % 100) < 50 )
// break;
}
}
else
{
//printf("%s lastpoll.%u %u\n",addr->ipaddr,addr->lastpoll,now);
addr->lastpoll = now;
for (i=n=0; i<coin->bundlescount; i++)
if ( coin->bundles[i] != 0 && coin->bundles[i]->emitfinish == 0 )
n++;
if ( n >= coin->bundlescount-(coin->bundlescount>>3) || (addr->ipbits % 10) < 5 )
refbundlei = (addr->ipbits % coin->bundlescount);
else
{
if ( n*2 < coin->bundlescount )
{
for (i=refbundlei=0; i<IGUANA_MAXPEERS; i++)
{
if ( addr->usock == coin->peers.active[i].usock )
break;
if ( coin->peers.active[i].usock >= 0 )
refbundlei++;
}
//printf("half done\n");
} else refbundlei = ((addr->addrind*100) % coin->bundlescount);
}
for (i=0; i<coin->bundlescount; i++)
{
if ( (diff= (i - refbundlei)) < 0 )
diff = -diff;
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 )
{
metric = (1 + diff * ((addr->addrind&1) == 0 ? 1 : 1) * (1. + bp->metric));// / (i*((addr->addrind&1) != 0 ? 1 : i) + 1);
//printf("%f ",bp->metric);
if ( bestmetric < 0. || metric < bestmetric )
bestmetric = metric, bestbp = bp;
}
}
if ( bestbp != 0 && bp->emitfinish == 0 )
{
for (k=0; k<coin->bundlescount; k++)
{
i = (bestbp->hdrsi + k) % coin->bundlescount;
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish != 0 )
continue;
//printf("%.15f ref.%d addrind.%d bestbp.%d\n",bestmetric,refbundlei,addr->addrind,bp->hdrsi);
m = coin->chain->bundlesize;
if ( bp->n < m )
m = bp->n;
j = (addr->addrind*3 + 0) % m;
val = (bp->threshold / 1000.);
for (r=0; r<m; r++,j++)
{
if ( j >= m )
j = 0;
if ( (block= bp->blocks[j]) != 0 && block->fpipbits == 0 && block->queued == 0 && block->numrequests <= bp->minrequests )
{
block->numrequests++;
//block->issued = (uint32_t)time(NULL);;
//printf("%s Send auto blockreq.%d\n",addr->ipaddr,bp->bundleheight+j);
iguana_sendblockreq(coin,addr,bp,j,hash2,0);
return(1);
}
}
}
}
}
}
int32_t priority; int32_t priority;
if ( addr->rank != 1 && req == 0 ) if ( addr->rank != 1 && req == 0 && addr->pendblocks < limit )
{ {
priority = 0; priority = 0;
req = queue_dequeue(&coin->blocksQ,0); req = queue_dequeue(&coin->blocksQ,0);
@ -867,7 +747,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
// printf(" issue.%s\n",bits256_str(str,hash2)); // printf(" issue.%s\n",bits256_str(str,hash2));
if ( block != 0 ) if ( block != 0 )
block->numrequests++; block->numrequests++;
iguana_sendblockreq(coin,addr,req->bp,req->bundlei,hash2,0); iguana_sendblockreqPT(coin,addr,req->bp,req->bundlei,hash2,0);
} }
flag++; flag++;
myfree(req,sizeof(*req)); myfree(req,sizeof(*req));
@ -900,7 +780,7 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded
lflag++; lflag++;
//else printf("chainlink error for %d\n",coin->blocks.hwmchain.height+1); //else printf("chainlink error for %d\n",coin->blocks.hwmchain.height+1);
} }
if ( 1 ) if ( 0 )
{ {
double threshold,lag = OS_milliseconds() - coin->backstopmillis; double threshold,lag = OS_milliseconds() - coin->backstopmillis;
threshold = (10 + coin->longestchain - coin->blocksrecv); threshold = (10 + coin->longestchain - coin->blocksrecv);
@ -911,7 +791,7 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded
else threshold = coin->avetime; else threshold = coin->avetime;
threshold *= 100. * sqrt(threshold) * .000777; threshold *= 100. * sqrt(threshold) * .000777;
if ( strcmp(coin->symbol,"BTC") != 0 ) if ( strcmp(coin->symbol,"BTC") != 0 )
threshold = 400; threshold = 33;
else threshold = 1000; else threshold = 1000;
if ( coin->blocks.hwmchain.height < coin->longestchain && (coin->backstop != coin->blocks.hwmchain.height+1 || lag > threshold) ) if ( coin->blocks.hwmchain.height < coin->longestchain && (coin->backstop != coin->blocks.hwmchain.height+1 || lag > threshold) )
{ {

2
iguana/main.c

@ -318,7 +318,7 @@ void iguana_main(void *arg)
#ifdef __APPLE__ #ifdef __APPLE__
sleep(1); sleep(1);
char *str; char *str;
if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":64,\"coin\":\"BTCD\",\"active\":1}"),0)) != 0 ) if ( (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":0,\"maxpeers\":128,\"coin\":\"BTCD\",\"active\":1}"),0)) != 0 )
{ {
printf("got.(%s)\n",str); printf("got.(%s)\n",str);
free(str); free(str);

Loading…
Cancel
Save