Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
2b215dd7d5
  1. 4
      iguana/iguana777.h
  2. 124
      iguana/iguana_bundles.c
  3. 17
      iguana/iguana_ramchain.c
  4. 2
      iguana/iguana_recv.c

4
iguana/iguana777.h

@ -477,7 +477,7 @@ struct iguana_info
struct iguana_bitmap screen;
//struct pollfd fds[IGUANA_MAXPEERS]; struct iguana_peer bindaddr; int32_t numsocks;
struct OS_memspace TXMEM;
struct OS_memspace TXMEM,HASHMEM,RAWMEM,MEM,MEMB[IGUANA_MAXBUNDLESIZE];
queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,cacheQ,recvQ;
double parsemillis,avetime; uint32_t Launched[8],Terminated[8];
portable_mutex_t peers_mutex,blocks_mutex;
@ -670,7 +670,7 @@ extern queue_t helperQ;
extern const char *Hardcoded_coins[][3];
void iguana_main(void *arg);
extern struct iguana_info *Coins[64];
int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,char *fname,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t numblocks);
int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,char *fname,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t numblocks,int32_t dispflag);
struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundleip,char *fname,struct OS_memspace *mem,uint32_t ipbits,bits256 hash2);
int32_t iguana_peerfile_exists(struct iguana_info *coin,struct iguana_peer *addr,char *dirname,char *fname,bits256 hash2,bits256 prevhash2,int32_t numblocks);
struct iguana_ramchain *iguana_ramchainset(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_txblock *txdata);

124
iguana/iguana_bundles.c

@ -345,7 +345,7 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl
int32_t hdrsi,iter; int64_t Toffset; char fname[1024]; FILE *fp; struct iguana_ramchaindata rdata;
for (iter=0; iter<2; iter++)
{
iguana_peerfname(coin,&hdrsi,iter==0?"DB/ro":"DB",fname,0,bp->hashes[0],zero,bp->n);
iguana_peerfname(coin,&hdrsi,iter==0?"DB/ro":"DB",fname,0,bp->hashes[0],zero,bp->n,1);
if ( (fp= fopen(fname,"rb")) != 0 )
{
fseek(fp,(long)&rdata.Toffset - (long)&rdata,SEEK_SET);
@ -375,7 +375,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
{
if ( (ipbits= (uint32_t)coin->peers.active[j].ipbits) != 0 )
{
if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,bp->hashes[0],zero,1) >= 0 )
if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,bp->hashes[0],zero,1,1) >= 0 )
{
if ( OS_removefile(fname,0) > 0 )
coin->peers.numfiles--, m++;
@ -637,7 +637,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp)
if ( iguana_blockvalidate(coin,&valid,block,1) < 0 || block->fpipbits == 0 || block->fpos < 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) )
{
fname[0] = 0;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1)) != i )
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1,1)) != i )
printf("checki.%d vs %d mismatch?\n",checki,i);
if ( fname[0] != 0 )
OS_removefile(fname,0);
@ -860,6 +860,36 @@ int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp)
return(0);
}
int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB)
{
if ( iguana_bundleready(coin,bp) == bp->n )
{
printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT.%s bundle.%d | 1st.%d h.%d s.[%d] maxbundles.%d NET.(h%d b%d)\n",coin->symbol,bp->bundleheight,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,netBLOCKS);
if ( bp->emitfinish != 0 )
{
printf("already EMIT for bundle.%d\n",bp->hdrsi);
return(0);
}
bp->emitfinish = 1;
iguana_bundletweak(coin,bp);
sleep(1); // just in case data isnt totally sync'ed to HDD
coin->emitbusy++;
if ( iguana_bundlesaveHT(coin,mem,memB,bp,(uint32_t)time(NULL)) == 0 )
{
//fprintf(stderr,"emitQ done coin.%p bp.[%d] ht.%d\n",coin,bp->hdrsi,bp->bundleheight);
bp->emitfinish = (uint32_t)time(NULL) + 1;
coin->numemitted++;
}
else
{
fprintf(stderr,"emitQ done coin.%p bp.[%d] ht.%d error\n",coin,bp->hdrsi,bp->bundleheight);
bp->emitfinish = 0;
}
coin->emitbusy--;
}
return(1);
}
int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,int32_t timelimit)
{
int32_t range,starti,lasti,i,n,len,retval=0,max,counter = 0; struct iguana_block *block; struct iguana_bundle *currentbp,*lastbp; uint8_t serialized[512]; struct iguana_peer *addr; long lag; struct iguana_blockreq *breq;
@ -913,31 +943,8 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
}
else if ( bp->numsaved >= bp->n )//&& (bp->isRT == 0 || coin->RTheight > bp->bundleheight+bp->n+coin->minconfirms) )
{
if ( iguana_bundleready(coin,bp) == bp->n )
{
printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT.%s bundle.%d | 1st.%d h.%d s.[%d] maxbundles.%d NET.(h%d b%d)\n",coin->symbol,bp->bundleheight,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,netBLOCKS);
if ( bp->emitfinish != 0 )
{
printf("already EMIT for bundle.%d\n",bp->hdrsi);
return(0);
}
bp->emitfinish = 1;
iguana_bundletweak(coin,bp);
sleep(1); // just in case data isnt totally sync'ed to HDD
coin->emitbusy++;
if ( iguana_bundlesaveHT(coin,mem,memB,bp,(uint32_t)time(NULL)) == 0 )
{
//fprintf(stderr,"emitQ done coin.%p bp.[%d] ht.%d\n",coin,bp->hdrsi,bp->bundleheight);
bp->emitfinish = (uint32_t)time(NULL) + 1;
coin->numemitted++;
}
else
{
fprintf(stderr,"emitQ done coin.%p bp.[%d] ht.%d error\n",coin,bp->hdrsi,bp->bundleheight);
bp->emitfinish = 0;
}
coin->emitbusy--;
}
if ( iguana_bundlefinalize(coin,bp,mem,memB) == 0 )
return(0);
retval = 1;
}
else if ( bp->hdrsi == starti || (bits256_nonz(bp->allhash) != 0 && bp->hdrsi >= starti && bp->hdrsi <= starti+range) )
@ -1089,45 +1096,70 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
} // else break;
}
}
int32_t checki,hdrsi,havefile,missing,recvlen; char fname[1024]; FILE *fp; struct iguana_msghdr H; static bits256 zero;
if ( bp == coin->current )
{
int32_t checki,hdrsi,havefile; char fname[1024]; FILE *fp; static bits256 zero;
now = (int32_t)time(NULL);
for (j=havefile=0; j<bp->n; j++)
for (j=havefile=missing=0; j<bp->n; j++)
{
if ( bits256_nonz(bp->hashes[j]) != 0 )
hash2 = bp->hashes[j];
else if ( bp->speculative != 0 )
hash2 = bp->speculative[j];
if ( bits256_nonz(hash2) == 0 )
{
missing++;
continue;
checki = iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,hash2,zero,1);
}
checki = iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,hash2,zero,1,0);
if ( (fp= fopen(fname,"rb")) != 0 )
{
havefile++;
fclose(fp);
continue;
}
/*if ( (block= bp->blocks[j]) != 0 && block->fpipbits != 0 && block->fpos >= 0 && block->RO.recvlen > 0 && bits256_nonz(block->RO.prev_block) != 0 )
continue;
//if ( (block= bp->blocks[j]) != 0 && block->fpipbits != 0 && block->fpos >= 0 && block->RO.recvlen > 0 && bits256_nonz(block->RO.prev_block) != 0 )
// continue;
missing++;
if ( bp->speculativecache[j] != 0 )
{
if ( bp->speculativecache[j] != 0 && (block= iguana_blockfind(coin,bp->speculative[j])) != 0 )
{
block->bundlei = j;
block->hdrsi = bp->hdrsi;
bp->blocks[j] = block;
printf("bundlehashadd set.%d recvlen.%d\n",j,recvlen);
iguana_bundlehash2add(coin,0,bp,j,bp->speculative[j]);
recvlen = *(int32_t *)bp->speculativecache[j];
memset(&H,0,sizeof(H));
iguana_sethdr(&H,coin->chain->netmagic,"block",&bp->speculativecache[j][sizeof(recvlen)],recvlen);
if ( coin->RAWMEM.ptr == 0 )
iguana_meminit(&coin->RAWMEM,"cache",0,IGUANA_MAXPACKETSIZE + 65536*3,0);
if ( coin->TXMEM.ptr == 0 )
iguana_meminit(&coin->TXMEM,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0);
if ( coin->HASHMEM.ptr == 0 )
iguana_meminit(&coin->HASHMEM,"HASHPTRS",0,256,0);
if ( iguana_msgparser(coin,0,&coin->RAWMEM,&coin->TXMEM,&coin->HASHMEM,&H,&bp->speculativecache[j][sizeof(recvlen)],recvlen) < 0 )
printf("error parsing speculativecache.[%d:%d]\n",bp->hdrsi,j);
myfree(bp->speculativecache[j],recvlen + sizeof(recvlen));
bp->speculativecache[j] = 0;
}
continue;
}
fprintf(stderr,"-[%d:%d].%d ",bp->hdrsi,j,now-bp->issued[j]);
if ( now > bp->issued[j]+30 )//|| bp->numcached >= bp->n-2 )
if ( now > bp->issued[j]+30 || (rand() % 10) == 0 )
{
struct iguana_peer *addr; int32_t r;
if ( (rand() % 10) == 0 && (r= coin->peers.numranked) != 0 && (addr= coin->peers.ranked[rand() % r]) != 0 && addr->dead == 0 && addr->usock >= 0 )
iguana_sendblockreqPT(coin,addr,bp,j,hash2,0), printf("%s ",addr->ipaddr);
fprintf(stderr,"currentstop [%d:%d]\n",bp->hdrsi,j);
iguana_blockQ("currentstop",coin,bp,j,hash2,now > bp->issued[j]+30);
iguana_blockQ("currentstop",coin,bp,j,hash2,1);
bp->issued[j] = now;
}*/
}
}
fprintf(stderr,"[%d] check numcached.%d numhashes.%d numsaved.%d havefile.%d\n",bp->hdrsi,bp->numcached,bp->numhashes,bp->numsaved,havefile);
fprintf(stderr,"[%d] check numcached.%d numhashes.%d numsaved.%d havefile.%d missing.%d\n",bp->hdrsi,bp->numcached,bp->numhashes,bp->numsaved,havefile,missing);
}
if ( bp->speculative != 0 && (bp->numsaved + bp->numcached) == bp->n )
if ( bp->speculative != 0 && missing == 0 )
{
hash2 = bp->hashes[0];
for (i=1; i<bp->n; i++)
@ -1137,10 +1169,18 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
else if ( bits256_nonz(bp->hashes[i]) != 0 )
block = iguana_blockfind(coin,bp->hashes[i]);
if ( block == 0 || bits256_cmp(block->RO.prev_block,hash2) != 0 )
{
printf("error with speculative prev at i.%d\n",i);
break;
}
hash2 = block->RO.prev_block;
}
if ( i == bp->n )
iguana_bundlefinalize(coin,bp,&coin->MEM,coin->MEMB);
}
/*if ( bp->speculative != 0 && missing == 0 )
{
if ( i == bp->n )
{
printf("have complete speculative bundle!\n");
for (i=1; i<bp->n; i++)
@ -1152,13 +1192,13 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
block->bundlei = i;
block->hdrsi = bp->hdrsi;
bp->blocks[i] = block;
//printf("bundlehashadd set.%d\n",bundlei);
printf("bundlehashadd set.%d\n",i);
iguana_bundlehash2add(coin,0,bp,i,bp->speculative[i]);
}
}
}
}
}
}*/
//bp->rank = 0;
estsize += bp->estsize;//iguana_bundlecalcs(coin,bp,done);
//bp->metric = bp->numhashes;

17
iguana/iguana_ramchain.c

@ -88,7 +88,7 @@ void iguana_blocksetcounters(struct iguana_info *coin,struct iguana_block *block
block->RO.firstexternalind = ramchain->externalind;
}
int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,char *fname,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t numblocks)
int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,char *fname,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t numblocks,int32_t dispflag)
{
struct iguana_bundle *bp = 0; int32_t bundlei = -2; char str[65];
*hdrsip = -1; ipbits = 0;
@ -99,7 +99,8 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,
{
if ( bits256_nonz(prevhash2) == 0 || (bp= iguana_bundlefind(coin,&bp,&bundlei,prevhash2)) == 0 || bundlei >= coin->chain->bundlesize-1 )
{
printf("iguana_peerfname error finding.(%s) spec.%p bp.%p\n",bits256_str(str,hash2),bp!=0?bp->speculative:0,bp);
if ( dispflag != 0 )
printf("iguana_peerfname error finding.(%s) spec.%p bp.%p\n",bits256_str(str,hash2),bp!=0?bp->speculative:0,bp);
return(-2);
}
else bundlei++;
@ -125,7 +126,7 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,
int32_t iguana_peerfile_exists(struct iguana_info *coin,struct iguana_peer *addr,char *dirname,char *fname,bits256 hash2,bits256 prevhash2,int32_t numblocks)
{
FILE *fp; int32_t bundlei,hdrsi;
if ( (bundlei= iguana_peerfname(coin,&hdrsi,dirname,fname,addr!=0?(uint32_t)addr->ipbits:0,hash2,prevhash2,numblocks)) >= 0 )
if ( (bundlei= iguana_peerfname(coin,&hdrsi,dirname,fname,addr!=0?(uint32_t)addr->ipbits:0,hash2,prevhash2,numblocks,1)) >= 0 )
{
OS_compatible_path(fname);
if ( (fp= fopen(fname,"rb")) == 0 )
@ -925,7 +926,7 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
printf("ramchainsave no data ptr\n");
return(-1);
}
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?"DB":GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,ramchain->numblocks)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?"DB":GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,ramchain->numblocks,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf(" wont save.(%s) bundlei.%d != checki.%d\n",fname,bundlei,checki);
return(-1);
@ -1235,7 +1236,7 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname
for (iter=0; iter<2; iter++)
{
dirstr = (iter == 0) ? "DB/ro" : "DB";
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?dirstr:GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,numblocks)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?dirstr:GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,numblocks,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf("iguana_ramchain_map.(%s) illegal hdrsi.%d bundlei.%d %s\n",fname,hdrsi,bundlei,bits256_str(str,hash2));
continue;
@ -1901,7 +1902,7 @@ int32_t iguana_oldbundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **p
if ( j == num )
{
ipbits[num] = fpipbits;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,fpipbits,bp->hashes[bundlei],zero,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,fpipbits,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf("B iguana_ramchain_map.(%s) illegal hdrsi.%d bundlei.%d checki.%d\n",fname,hdrsi,bundlei,checki);
return(0);
@ -1925,7 +1926,7 @@ void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,str
{
int32_t checki,hdrsi; void *ptr = 0; static bits256 zero;
*filesizep = 0;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,bp->hashes[bundlei],zero,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize )
{
printf("B iguana_ramchain_map.(%s) illegal hdrsi.%d bundlei.%d checki.%d\n",fname,hdrsi,bundlei,checki);
return(0);
@ -2366,7 +2367,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str
{
for (j=starti; j<=endi; j++)
{
if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,1,bp->hashes[j],zero,1) >= 0 ) // ipbits[j]
if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,1,bp->hashes[j],zero,1,1) >= 0 ) // ipbits[j]
coin->peers.numfiles -= OS_removefile(fname,0);
else printf("error removing.(%s)\n",fname);
}

2
iguana/iguana_recv.c

@ -1303,7 +1303,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
req->height = height;
req->bundlei = bundlei;
char str2[65];
printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q));
//printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q));
if ( Q == &coin->blocksQ )
{
if ( (n= queue_size(Q)) > 100000 )

Loading…
Cancel
Save