Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
10d8611baa
  1. 70
      deprecated/obsolete.h
  2. 4
      iguana/iguana777.h
  3. 4
      iguana/iguana_bundles.c
  4. 7
      iguana/iguana_msg.c
  5. 23
      iguana/iguana_ramchain.c
  6. 183
      iguana/iguana_recv.c
  7. 2
      iguana/ramchain_api.c

70
deprecated/obsolete.h

@ -14273,5 +14273,75 @@ len = 0;
}
counter = iguana_bundlekick(coin,bp,starti,max);
}
if ( req == 0 && 0 )
{
if ( 1 )//(rand() % 10) == 0 )
flag = iguana_neargap(coin,addr);
else if ( 0 && (bp= addr->bp) != 0 && bp->rank != 0 && addr->pendblocks < limit )
{
r = rand();
for (j=0; j<bp->n; j++)
{
i = (r + j) % bp->n;
if ( (block= bp->blocks[i]) != 0 && block->numrequests == bp->minrequests && block->fpipbits == 0 && block->queued == 0 )
{
printf("peer.%s BPranked.%d [%d:%d] pending.%d numreqs.%d\n",addr->ipaddr,bp->rank,bp->hdrsi,i,addr->pendblocks,block->numrequests);
block->numrequests++;
flag++;
iguana_sendblockreqPT(coin,addr,bp,i,block->RO.hash2,0);
break;
}
}
}
}
int32_t iguana_neargap(struct iguana_info *coin,struct iguana_peer *addr)
{
struct iguana_block *block,*bestblock = 0; struct iguana_bundle *bp,*bestbp = 0;
int32_t height,hdrsi,i,j,n,bundlei,gap,besti = -1; uint32_t r;
if ( addr->rank > 0 )
{
n = coin->peers.numranked * 2;
gap = addr->rank * (1 + n + coin->peers.numranked) + coin->peers.numranked;
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish == 0 )
break;
height = (i * coin->chain->bundlesize);
r = rand();
for (i=0; i<n; i++)
{
j = (gap + r + i) % n;
hdrsi = (height + j) / coin->chain->bundlesize;
if ( (bp= coin->bundles[hdrsi]) != 0 )
{
bundlei = (height + j) % coin->chain->bundlesize;
if ( (block= bp->blocks[bundlei]) != 0 && block->fpipbits == 0 && block->queued == 0 )
{
if ( block->numrequests == bp->minrequests )
{
bestblock = block;
bestbp = bp;
besti = bundlei;
break;
}
else if ( bestblock == 0 || block->numrequests < bestblock->numrequests )
{
bestblock = block;
bestbp = bp;
besti = bundlei;
}
}
}
}
if ( bestblock != 0 )
{
printf("near hwm.%d gap.%d peer.%s bpranked.%d [%d:%d] pending.%d numreqs.%d\n",height,j,addr->ipaddr,bestbp->rank,bestbp->hdrsi,besti,addr->pendblocks,bestblock->numrequests);
bestblock->numrequests++;
iguana_sendblockreqPT(coin,addr,bestbp,besti,bestblock->RO.hash2,0);
return(1);
}
}
return(0);
}
#endif

4
iguana/iguana777.h

@ -279,7 +279,7 @@ struct iguana_block
struct iguana_blockRO RO;
double PoW; // NOT consensus safe, for estimation purposes only
int32_t height; uint32_t fpipbits,numrequests,issued; long fpos;
uint16_t hdrsi,bundlei:12,mainchain:1,valid:1,queued:1,tbd:1,extra:8;
uint16_t hdrsi,bundlei:12,mainchain:1,valid:1,queued:1,txvalid:1,extra:8;
UT_hash_handle hh; bits256 *blockhashes;
};// __attribute__((packed));
@ -532,7 +532,7 @@ int32_t iguana_sethdr(struct iguana_msghdr *H,const uint8_t netmagic[4],char *co
int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices);
int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txblock,int32_t *lenp,uint8_t *data,int32_t datalen);
int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr);
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,char *hashstr);
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n);
// ramchain
int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acct,uint32_t pkind);

4
iguana/iguana_bundles.c

@ -510,16 +510,18 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp)
{
block->RO.recvlen = (uint32_t)ftell(fp);
block->fpipbits = 1;
block->fpos = 0;
//printf("[%d:%d] len.%d\n",hdrsi,bundlei,block->RO.recvlen);
}
fclose(fp);
}
bp->blocks[bundlei] = block;
block->hdrsi = bp->hdrsi, block->bundlei = bundlei;
if ( bp->minrequests == 0 || (block->numrequests > 0 && block->numrequests < bp->minrequests) )
bp->minrequests = block->numrequests;
if ( bits256_nonz(block->RO.prev_block) > 0 )
{
if ( block->fpipbits != 0 )
if ( block->fpos >= 0 )
bp->numsaved++;
if ( block->RO.recvlen != 0 )
{

7
iguana/iguana_msg.c

@ -302,15 +302,14 @@ int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,ch
return(iguana_sethdr((void *)serialized,coin->chain->netmagic,cmd,&serialized[sizeof(struct iguana_msghdr)],len));
}
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,char *hashstr)
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n)
{
uint32_t len,i,n=1; bits256 hash2;
decode_hex(hash2.bytes,sizeof(hash2),hashstr);
uint32_t len,i; //bits256 hash2;
len = iguana_rwvarint32(1,&serialized[sizeof(struct iguana_msghdr)],(uint32_t *)&n);
for (i=0; i<n; i++)
{
len += iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(uint32_t),&type);
len += iguana_rwbignum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(bits256),hash2.bytes);
len += iguana_rwbignum(1,&serialized[sizeof(struct iguana_msghdr) + len],sizeof(bits256),hashes[i].bytes);
}
return(iguana_sethdr((void *)serialized,coin->chain->netmagic,"getdata",&serialized[sizeof(struct iguana_msghdr)],len));
}

23
iguana/iguana_ramchain.c

@ -1770,7 +1770,6 @@ bits256 iguana_merkle(struct iguana_info *coin,bits256 *tree,struct iguana_msgtx
n += txn_count;
for (i=0; i<txn_count; i+=2)
{
//printf("prev.%d n.%d txn_count.%d dest.%d src2.%d\n",prev,n,txn_count,n+(i>>1),prev+i);
iguana_rwbignum(1,serialized,sizeof(*tree),tree[prev + i].bytes);
iguana_rwbignum(1,&serialized[sizeof(*tree)],sizeof(*tree),tree[prev + i + 1].bytes);
tree[n + (i >> 1)] = bits256_doublesha256(0,serialized,sizeof(serialized));
@ -1830,6 +1829,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
printf("%d:%d has no block ptr.%p %s or wrong hash\n",bp->hdrsi,bundlei,block,bits256_str(str,origtxdata->block.RO.hash2));
return(-1);
}
block->txvalid = 1;
if ( block->fpipbits != 0 )
{
static int32_t numredundant; static double redundantsize; static uint32_t lastdisp;
@ -1861,6 +1861,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
printf("fatal error getting txdataptrs %p %p %p %p\n",T,U,S,B);
return(-1);
}
block->fpipbits = 1;
for (i=0; i<txn_count; i++,ramchain->H.txidind++)
{
tx = &txarray[i];
@ -1889,6 +1890,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
if ( ramchain->H.txidind != ramchain->H.data->numtxids || ramchain->H.unspentind != ramchain->H.data->numunspents || ramchain->H.spendind != ramchain->H.data->numspends )
{
printf("error creating PT ramchain.[%d:%d] ramchain->txidind %d != %d ramchain->data->numtxids || ramchain->unspentind %d != %d ramchain->data->numunspents || ramchain->spendind %d != %d ramchain->data->numspends space.(%d v %d)\n",bp->hdrsi,bp->bundleheight,ramchain->H.txidind,ramchain->H.data->numtxids,ramchain->H.unspentind,ramchain->H.data->numunspents,ramchain->H.spendind,ramchain->H.data->numspends,ramchain->H.scriptoffset,ramchain->H.data->scriptspace);
block->fpipbits = 0;
block->issued = 0;
block->RO.recvlen = 0;
}
@ -1920,13 +1922,16 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
if ( 1 ) // unix issues?
{
if ( (err= iguana_ramchain_cmp(ramchain,mapchain,0)) != 0 )
printf("error.%d comparing ramchains\n",err);
ptr = mapchain->fileptr; fsize = mapchain->filesize;
mapchain->fileptr = 0, mapchain->filesize = 0;
iguana_ramchain_free(mapchain,1);
memset(&R,0,sizeof(R));
R.H.data = (void *)(long)((long)ptr + fpos), R.filesize = fsize;
iguana_ramchain_link(&R,block->RO.hash2,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
fpos = -1, printf("error.%d comparing ramchains\n",err);
else
{
ptr = mapchain->fileptr; fsize = mapchain->filesize;
mapchain->fileptr = 0, mapchain->filesize = 0;
iguana_ramchain_free(mapchain,1);
memset(&R,0,sizeof(R));
R.H.data = (void *)(long)((long)ptr + fpos), R.filesize = fsize;
iguana_ramchain_link(&R,block->RO.hash2,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,1);
}
}
if ( (err= iguana_ramchain_cmp(ramchain,&R,0)) != 0 )
{
@ -1960,6 +1965,8 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru
}
} else printf("ramchain verification error.%d hdrsi.%d bundlei.%d\n",err,bp->hdrsi,bundlei);
}
if ( fpos < 0 )
block->fpos = -1, block->fpipbits = block->RO.recvlen = 0;
//fprintf(stderr,"finished with hdrsi.%d ht.%d scripts.%u:%u\n",bp->hdrsi,bp->bundleheight,ramchain->H.scriptoffset,ramchain->H.data->scriptspace);
ramchain->H.ROflag = 0;
iguana_ramchain_free(ramchain,0);

183
iguana/iguana_recv.c

@ -37,7 +37,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
if ( addr == 0 || memcmp(lastreq.bytes,hash2.bytes,sizeof(hash2)) == 0 || memcmp(lastreq2.bytes,hash2.bytes,sizeof(hash2)) == 0 )
{
//printf("duplicate req %s or null addr.%p\n",bits256_str(hexstr,hash2),addr);
printf("duplicate req %s or null addr.%p\n",bits256_str(hexstr,hash2),addr);
//return(0);
}
if ( addr->msgcounts.verack == 0 )
@ -47,7 +47,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
}
lastreq2 = lastreq;
lastreq = hash2;
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,hexstr)) > 0 )
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&hash2,1)) > 0 )
{
iguana_send(coin,addr,serialized,len);
coin->numreqsent++;
@ -62,8 +62,8 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
int32_t iguana_sendtxidreq(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2)
{
uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)];
int32_t len,i,r,j; char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
if ( (len= iguana_getdata(coin,serialized,MSG_TX,hexstr)) > 0 )
int32_t len,i,r,j; //char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
if ( (len= iguana_getdata(coin,serialized,MSG_TX,&hash2,1)) > 0 )
{
if ( addr == 0 )
{
@ -157,7 +157,7 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
{
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,i,j,bundlei,copyflag; char fname[1024];
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,i,j,bundlei,copyflag;
struct iguana_bundle *bp;
if ( 0 )
{
@ -191,20 +191,33 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
return;
} //else printf("validated.%s\n",bits256_str(str,origtxdata->block.RO.hash2));
copyflag = 1 * (strcmp(coin->symbol,"BTC") != 0);
req = iguana_bundlereq(coin,addr,'B',copyflag * recvlen);
req->recvlen = recvlen;
req->H = *H;
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)) )
{
req = iguana_bundlereq(coin,addr,'B',copyflag * recvlen);
//printf("copy %p serialized[%d]\n",req,req->recvlen);
memcpy(req->serialized,data,recvlen), req->copyflag = 1;
memcpy(req->serialized,data,recvlen);
}
else
{
copyflag = 0;
req = iguana_bundlereq(coin,addr,'B',0);
}
if ( bp != 0 && bundlei >= 0 && bp->blocks[bundlei] != 0 )//&& bits256_cmp(bp->blocks[bundlei]->RO.prev_block,origtxdata->block.RO.prev_block) != 0 )
{
if ( bp->blocks[bundlei]->fpos >= 0 && bp->blocks[bundlei]->fpipbits != 0 && bp->blocks[bundlei]->txvalid != 0 )
{
if ( bits256_cmp(origtxdata->block.RO.hash2,bp->blocks[bundlei]->RO.hash2) == 0 )
return;
else printf("mismatched tx received? mainchain.%d\n",bp->blocks[bundlei]->mainchain);
if ( bp->blocks[bundlei]->mainchain != 0 )
return;
}
bp->blocks[bundlei]->RO = origtxdata->block.RO;
//printf("update prev for [%d:%d]\n",bp->hdrsi,bundlei);
}
req->recvlen = recvlen;
req->H = *H;
if ( bits256_cmp(origtxdata->block.RO.hash2,coin->APIblockhash) == 0 )
{
printf("MATCHED APIblockhash\n");
@ -225,7 +238,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
txdata->block.fpipbits = recvlen;
req->datalen = txdata->datalen;
req->ipbits = txdata->block.fpipbits;
if ( 0 )
/*if ( 0 )
{
struct iguana_txblock *checktxdata; struct OS_memspace checkmem; int32_t checkbundlei;
memset(&checkmem,0,sizeof(checkmem));
@ -235,7 +248,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
printf("check datalen.%d bundlei.%d T.%d U.%d S.%d P.%d X.%d\n",checktxdata->datalen,checkbundlei,checktxdata->numtxids,checktxdata->numunspents,checktxdata->numspends,checktxdata->numpkinds,checktxdata->numexternaltxids);
}
iguana_mempurge(&checkmem);
}
}*/
}
}
//printf("recvlen.%d\n",req->recvlen);
@ -289,7 +302,7 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
}
void iguana_patch(struct iguana_info *coin,struct iguana_block *block)
/*void iguana_patch(struct iguana_info *coin,struct iguana_block *block)
{
int32_t i,j,origheight,height; struct iguana_block *prev,*next; struct iguana_bundle *bp;
prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1);
@ -343,7 +356,7 @@ void iguana_patch(struct iguana_info *coin,struct iguana_block *block)
}
}
}
}
}*/
uint32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bits256 *blockhashes,int32_t num)
{
@ -397,10 +410,10 @@ 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 bundlei.%d offset.%d\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str,bundlei,offset);
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 )
/*else if ( bp->speculative != 0 && bundlei < bp->numspec && memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)) == 0 )
{
bundlei += offset;
if ( bundlei < bp->n && bundlei < bp->numspec )
@ -408,7 +421,7 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in
//char str[65]; printf("speculative req[%d] %s\n",bundlei,bits256_str(str,bp->speculative[bundlei]));
//iguana_blockQ(coin,0,-1,bp->speculative[bundlei],0);
}
} //else printf("speculative.%p %d vs %d cmp.%d\n",bp->speculative,bundlei,bp->numspec,bp->speculative!=0?memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)):-1);
} //else printf("speculative.%p %d vs %d cmp.%d\n",bp->speculative,bundlei,bp->numspec,bp->speculative!=0?memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)):-1);*/
}
@ -433,8 +446,8 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
}
*blockp = block;
prevhash2 = origblock->RO.prev_block;
if ( 0 && bits256_nonz(prevhash2) > 0 )
iguana_patch(coin,block);
//if ( 0 && bits256_nonz(prevhash2) > 0 )
// iguana_patch(coin,block);
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei < coin->chain->bundlesize )
{
//fprintf(stderr,"bundle found %d:%d\n",bp->hdrsi,bundlei);
@ -675,8 +688,8 @@ struct iguana_bundlereq *iguana_recvunconfirmed(struct iguana_info *coin,struct
int32_t iguana_reqblocks(struct iguana_info *coin)
{
int32_t hdrsi,lflag,n,numissued,bundlei,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp; struct iguana_peer *addr;
if ( 0 && (bp= coin->current) != 0 && bp->numsaved < bp->n ) // queue_size(&coin->priorityQ) == 0 &&
int32_t hdrsi,lflag,bundlei,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp;
/*if ( 0 && (bp= coin->current) != 0 && bp->numsaved < bp->n )
{
for (hdrsi=numissued=0; hdrsi<coin->MAXBUNDLES && coin->current->hdrsi+hdrsi<coin->bundlescount && numissued<100; hdrsi++)
{
@ -687,19 +700,13 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
for (bundlei=n=flag=0; bundlei<bp->n; bundlei++)
if ( (block= bp->blocks[bundlei]) != 0 )
{
if ( bits256_nonz(block->RO.hash2) > 0 && block->fpipbits != 0 )
if ( bits256_nonz(block->RO.hash2) > 0 && block->fpos >= 0 )
n++;
else if ( time(NULL) > block->issued+60 ) //bp->numsaved > bp->n*.9 &&
else if ( block->fpipbits == 0 || time(NULL) > block->issued+60 )
{
//char str[65];
//printf("%d ",bundlei);
/*block->fpipbits = 0;
block->queued = 0;
block->issued = 0;
bp->issued[bundlei] = 0;*/
block->issued = (uint32_t)time(NULL);
iguana_sendblockreqPT(coin,addr,bp,bundlei,block->RO.hash2,0);
//iguana_blockQ(coin,bp,bundlei,block->RO.hash2,1);
//iguana_sendblockreqPT(coin,addr,bp,bundlei,block->RO.hash2,0);
iguana_blockQ("reqblocks",coin,bp,bundlei,block->RO.hash2,0);
flag++;
if ( ++numissued > 100 )
break;
@ -708,7 +715,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
if ( 0 && flag != 0 )
printf("issued %d priority blocks for %d current.[%d] have %d blocks emit.%u\n",flag,hdrsi,bp->hdrsi,n,bp->emitfinish);
}
}
}*/
hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize;
if ( (bp= coin->bundles[hdrsi]) != 0 )
{
@ -723,14 +730,14 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
iguana_blockQ("reqblocks",coin,bp,bundlei,next->RO.hash2,0);
}
}
else if ( iguana_blockfind(coin,bp->hashes[bundlei]) == 0 )
/*else if ( iguana_blockfind(coin,bp->hashes[bundlei]) == 0 )
{
/*if ( bits256_nonz(bp->hashes[bundlei]) > 0 )
{
printf("next %d\n",coin->blocks.hwmchain.height+1);
iguana_blockQ(coin,bp,bundlei,bp->hashes[bundlei],0);
}
else*/ if ( bp->speculative != 0 && (bits256_cmp(bp->hashes[bundlei],bp->speculative[bundlei]) != 0 || (rand() % 100) == 0) )
//if ( bits256_nonz(bp->hashes[bundlei]) > 0 )
// {
// printf("next %d\n",coin->blocks.hwmchain.height+1);
// iguana_blockQ(coin,bp,bundlei,bp->hashes[bundlei],0);
// }
// else if ( bp->speculative != 0 && (bits256_cmp(bp->hashes[bundlei],bp->speculative[bundlei]) != 0 || (rand() % 100) == 0) )
{
if ( time(NULL) > bp->issued[bundlei]+30 && iguana_blockfind(coin,bp->speculative[bundlei]) == 0 )
{
@ -743,13 +750,13 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
bp->issued[bundlei] = (uint32_t)time(NULL);
}
}
}
}*/
}
else if ( 0 && (bp= coin->bundles[--hdrsi]) != 0 )
/*else if ( 0 && (bp= coin->bundles[--hdrsi]) != 0 )
{
char str[65];
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
}*/
lflag = 1;
while ( lflag != 0 )
{
@ -772,7 +779,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
}
else if ( bp != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 && time(NULL) > bp->issued[bundlei]+60 )
{
bp->issued[bundlei] = (uint32_t)time(NULL);
printf("reqblock [%d:%d]\n",bp->hdrsi,bundlei);
iguana_blockQ("reqblocks1",coin,bp,bundlei,bp->hashes[bundlei],0);
}
if ( next != 0 )
@ -890,23 +897,14 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
{
for (i=0; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 && (bp->numhashes < bp->n || i == coin->bundlescount-1) )//bp->emitfinish < coin->startutc )
if ( (bp= coin->bundles[i]) != 0 && (bp->numhashes < bp->n || i == coin->bundlescount-1) )
{
if ( i == coin->bundlescount-1 )
lag = 30;
else lag = 30 + (rand() % 30);
lag = 30;
//if ( i < coin->bundlescount-1 && (bp->numhashes >= (rand() % bp->n) || time(NULL) < bp->hdrtime+lag) )
// continue;
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);
if ( bp->issuetime == 0 )
coin->numpendings++;
//char str[65];
//bits256_str(str,bp->hashes[0]);
//printf("(%s %d).%d ",str,bp->bundleheight,i);
//printf("%d ",bp->bundleheight);
init_hexbytes_noT(hashstr,bp->hashes[0].bytes,sizeof(bits256));
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
//printf("hdrsi.%d reqHDR.(%s) numhashes.%d\n",bp->hdrsi,hashstr,bp->numhashes);
@ -965,7 +963,10 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
req = mycalloc('y',1,sizeof(*req));
req->hash2 = hash2;
if ( (req->bp= bp) != 0 && bundlei >= 0 )
{
height = bp->bundleheight + bundlei;
bp->issued[bundlei] = (uint32_t)time(NULL);
}
req->height = height;
req->bundlei = bundlei;
char str2[65];
@ -983,60 +984,11 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
return(0);
}
int32_t iguana_neargap(struct iguana_info *coin,struct iguana_peer *addr)
{
struct iguana_block *block,*bestblock = 0; struct iguana_bundle *bp,*bestbp = 0;
int32_t height,hdrsi,i,j,n,bundlei,gap,besti = -1; uint32_t r;
if ( addr->rank > 0 )
{
n = coin->peers.numranked * 2;
gap = addr->rank * (1 + n + coin->peers.numranked) + coin->peers.numranked;
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish == 0 )
break;
height = (i * coin->chain->bundlesize);
r = rand();
for (i=0; i<n; i++)
{
j = (gap + r + i) % n;
hdrsi = (height + j) / coin->chain->bundlesize;
if ( (bp= coin->bundles[hdrsi]) != 0 )
{
bundlei = (height + j) % coin->chain->bundlesize;
if ( (block= bp->blocks[bundlei]) != 0 && block->fpipbits == 0 && block->queued == 0 )
{
if ( block->numrequests == bp->minrequests )
{
bestblock = block;
bestbp = bp;
besti = bundlei;
break;
}
else if ( bestblock == 0 || block->numrequests < bestblock->numrequests )
{
bestblock = block;
bestbp = bp;
besti = bundlei;
}
}
}
}
if ( bestblock != 0 )
{
printf("near hwm.%d gap.%d peer.%s bpranked.%d [%d:%d] pending.%d numreqs.%d\n",height,j,addr->ipaddr,bestbp->rank,bestbp->hdrsi,besti,addr->pendblocks,bestblock->numrequests);
bestblock->numrequests++;
iguana_sendblockreqPT(coin,addr,bestbp,besti,bestblock->RO.hash2,0);
return(1);
}
}
return(0);
}
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)];
struct iguana_block *block; struct iguana_blockreq *req=0; char *hashstr=0; bits256 hash2;
int32_t j,bundlei,priority,i,m,z,pend,limit,height=-1,datalen,flag = 0; uint32_t r;
int32_t bundlei,priority,i,m,z,pend,limit,height=-1,datalen,flag = 0;
uint32_t now; struct iguana_bundle *bp; struct iguana_peer *ptr;
if ( addr->msgcounts.verack == 0 )
return(0);
@ -1054,7 +1006,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
bp = 0, bundlei = -2;
bp = iguana_bundlefind(coin,&bp,&bundlei,hash2);
z = m = 0;
if ( bp != 0 )//&& bp->queued == 0 )
if ( bp != 0 )
{
if ( bp->bundleheight+coin->chain->bundlesize < coin->longestchain )
{
@ -1080,8 +1032,8 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
hashstr = 0;
}
}
if ( netBLOCKS > coin->MAXPEERS*coin->MAXPENDING )
usleep(netBLOCKS);
//if ( netBLOCKS > coin->MAXPEERS*coin->MAXPENDING )
// usleep(netBLOCKS);
if ( (limit= addr->recvblocks) > coin->MAXPENDING )
limit = coin->MAXPENDING;
if ( limit < 1 )
@ -1104,27 +1056,6 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
if ( pend < coin->MAXPENDING*m )
req = queue_dequeue(&coin->blocksQ,0);
}
if ( req == 0 && 0 )
{
if ( 1 )//(rand() % 10) == 0 )
flag = iguana_neargap(coin,addr);
else if ( 0 && (bp= addr->bp) != 0 && bp->rank != 0 && addr->pendblocks < limit )
{
r = rand();
for (j=0; j<bp->n; j++)
{
i = (r + j) % bp->n;
if ( (block= bp->blocks[i]) != 0 && block->numrequests == bp->minrequests && block->fpipbits == 0 && block->queued == 0 )
{
printf("peer.%s BPranked.%d [%d:%d] pending.%d numreqs.%d\n",addr->ipaddr,bp->rank,bp->hdrsi,i,addr->pendblocks,block->numrequests);
block->numrequests++;
flag++;
iguana_sendblockreqPT(coin,addr,bp,i,block->RO.hash2,0);
break;
}
}
}
}
if ( req != 0 )
{
hash2 = req->hash2;

2
iguana/ramchain_api.c

@ -22,7 +22,7 @@ char *iguana_APIrequest(struct iguana_info *coin,bits256 blockhash,bits256 txid,
coin->APIblockhash = blockhash;
coin->APItxid = txid;
printf("request block.(%s) txid.%llx\n",bits256_str(str,blockhash),(long long)txid.txid);
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,bits256_str(str,blockhash))) > 0 )
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhash,1)) > 0 )
{
for (i=0; i<seconds; i++)
{

Loading…
Cancel
Save