Browse Source

test

release/v0.1
jl777 8 years ago
parent
commit
afce953d71
  1. 2
      iguana/iguana777.c
  2. 88
      iguana/iguana_realtime.c
  3. 8
      iguana/iguana_recv.c
  4. 10
      iguana/iguana_unspents.c
  5. 2
      includes/iguana_funcs.h

2
iguana/iguana777.c

@ -892,7 +892,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
if ( coin->MAXMEM == 0 ) if ( coin->MAXMEM == 0 )
coin->MAXMEM = IGUANA_DEFAULTRAM; coin->MAXMEM = IGUANA_DEFAULTRAM;
coin->MAXMEM *= (1024L * 1024 * 1024); coin->MAXMEM *= (1024L * 1024 * 1024);
coin->enableCACHE = (strcmp("BTCD",coin->symbol) == 0); coin->enableCACHE = 0;//(strcmp("BTCD",coin->symbol) == 0);
if ( jobj(json,"cache") != 0 ) if ( jobj(json,"cache") != 0 )
coin->enableCACHE = juint(json,"cache"); coin->enableCACHE = juint(json,"cache");
if ( (coin->polltimeout= juint(json,"poll")) <= 0 ) if ( (coin->polltimeout= juint(json,"poll")) <= 0 )

88
iguana/iguana_realtime.c

@ -506,58 +506,65 @@ void iguana_RTunmap(uint8_t *ptr,uint32_t len)
OS_releasemap(&ptr[-2*sizeof(len)],len+2*sizeof(len)); OS_releasemap(&ptr[-2*sizeof(len)],len+2*sizeof(len));
} }
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t fromcache) void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t checkonly)
{ {
FILE *fp; char fname[1024],str[65]; long filesize; int32_t len; uint8_t *ptr; uint32_t i,nonz,checknumtx,checklen; FILE *fp; char fname[1024],str[65]; long filesize; int32_t len; uint8_t *ptr; uint32_t i,nonz,checknumtx,checklen;
sprintf(fname,"%s/%s/RT/%s.raw",GLOBAL_TMPDIR,coin->symbol,bits256_str(str,hash2)); sprintf(fname,"%s/%s/RT/%s.raw",GLOBAL_TMPDIR,coin->symbol,bits256_str(str,hash2));
OS_compatible_path(fname); OS_compatible_path(fname);
if ( *recvlenp > 0 ) if ( *recvlenp == -1 )
OS_removefile(fname,0);
else
{ {
if ( coin->RTheight == 0 ) if ( (checkonly != 0 || *recvlenp > 0) && (fp= fopen(fname,"rb")) != 0 )
{
printf("skip %s\n",bits256_str(str,hash2));
return(0);
}
if ( (fp= fopen(fname,"rb")) != 0 )
{ {
fseek(fp,0,SEEK_END); fseek(fp,0,SEEK_END);
filesize = ftell(fp); filesize = ftell(fp);
rewind(fp); rewind(fp);
if ( fread(&len,1,sizeof(len),fp) == sizeof(len) && len == filesize+sizeof(int32_t)*2 ) if ( fread(&len,1,sizeof(len),fp) == sizeof(len) && len == filesize-sizeof(int32_t)*2 )
{ {
fclose(fp); fclose(fp);
printf("already have %s\n",bits256_str(str,hash2)); //printf("already have %s\n",bits256_str(str,hash2));
*recvlenp = 0;
if ( checkonly != 0 )
return((void *)"already have rawdata");
return(0); return(0);
} }
//printf("len.%d filesize.%ld\n",len,filesize);
fclose(fp); fclose(fp);
} }
if ( (fp= fopen(fname,"wb")) != 0 ) if ( *recvlenp > 0 )
{ {
if ( fwrite(recvlenp,1,sizeof(*recvlenp),fp) != sizeof(*recvlenp) || fwrite(numtxp,1,sizeof(*numtxp),fp) != sizeof(*numtxp) || fwrite(data,1,*recvlenp,fp) != *recvlenp ) if ( coin->RTheight == 0 )
printf("error writing %s len.%d numtx.%d\n",bits256_str(str,hash2),*recvlenp,*numtxp); {
fclose(fp); //printf("skip %s\n",bits256_str(str,hash2));
printf("numtx.%d len.%d %s\n",*numtxp,*recvlenp,fname); return(0);
} else printf("couldnt create %s\n",fname); }
} if ( (fp= fopen(fname,"wb")) != 0 )
else if ( *recvlenp == 0 ) {
{ if ( fwrite(recvlenp,1,sizeof(*recvlenp),fp) != sizeof(*recvlenp) || fwrite(numtxp,1,sizeof(*numtxp),fp) != sizeof(*numtxp) || fwrite(data,1,*recvlenp,fp) != *recvlenp )
if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 ) printf("error writing %s len.%d numtx.%d\n",bits256_str(str,hash2),*recvlenp,*numtxp);
fclose(fp);
//printf("numtx.%d len.%d %s\n",*numtxp,*recvlenp,fname);
} else printf("couldnt create %s\n",fname);
}
else if ( checkonly == 0 )
{ {
memcpy(&checklen,ptr,sizeof(checklen)); if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 )
memcpy(&checknumtx,&ptr[sizeof(checklen)],sizeof(checknumtx));
*numtxp = checknumtx;
if ( checklen == (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)) )//&& checknumtx == *numtxp )
{ {
for (i=nonz=0; i<checklen; i++) memcpy(&checklen,ptr,sizeof(checklen));
if ( ptr[2*sizeof(checklen) + i] != 0 ) memcpy(&checknumtx,&ptr[sizeof(checklen)],sizeof(checknumtx));
nonz++; *numtxp = checknumtx;
*recvlenp = (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)); if ( checklen == (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)) )//&& checknumtx == *numtxp )
return(&ptr[sizeof(*recvlenp) + sizeof(checknumtx)]); {
} else printf("checklen.%d vs %d, checknumtx %d vs %d\n",checklen,(int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)),checknumtx,*numtxp); for (i=nonz=0; i<checklen; i++)
if ( ptr[2*sizeof(checklen) + i] != 0 )
nonz++;
*recvlenp = (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx));
return(&ptr[sizeof(*recvlenp) + sizeof(checknumtx)]);
} else printf("checklen.%d vs %d, checknumtx %d vs %d\n",checklen,(int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)),checknumtx,*numtxp);
}
} }
} }
else if ( *recvlenp == -1 )
OS_removefile(fname,0);
return(0); return(0);
} }
@ -579,12 +586,19 @@ void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight)
int32_t iguana_RTiterate(struct iguana_info *coin,int32_t offset,struct iguana_block *block,int64_t polarity) int32_t iguana_RTiterate(struct iguana_info *coin,int32_t offset,struct iguana_block *block,int64_t polarity)
{ {
struct iguana_txblock txdata; struct iguana_peer *addr; uint8_t *serialized; int32_t i,n,errs=0,numtx,len; uint32_t recvlen = 0; struct iguana_txblock txdata; uint8_t *serialized; int32_t n,errs=0,numtx,len; uint32_t recvlen = 0;
while ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 ) if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
{ {
char str[65]; char str[65];
printf("errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]); //printf("errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
iguana_blockQ("RTiterate",coin,0,-1,block->RO.hash2,1); coin->RTrawdata[offset] = iguana_RTrawdata(coin,block->RO.hash2,0,&coin->RTrecvlens[offset],&coin->RTnumtx[offset],0);
if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
{
printf("B errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
return(0);
}
/*struct iguana_peer *addr;
iguana_blockQ("RTiterate",coin,0,-1,block->RO.hash2,1);
if ( coin->peers != 0 && coin->peers->numranked > 0 ) if ( coin->peers != 0 && coin->peers->numranked > 0 )
{ {
for (i=0; i<coin->peers->numranked&&i<8; i++) for (i=0; i<coin->peers->numranked&&i<8; i++)
@ -596,7 +610,7 @@ int32_t iguana_RTiterate(struct iguana_info *coin,int32_t offset,struct iguana_b
{ {
iguana_RTreset(coin); iguana_RTreset(coin);
return(-1); return(-1);
} }*/
} }
printf("%s RTiterate.%lld offset.%d numtx.%d len.%d\n",coin->symbol,(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset]); printf("%s RTiterate.%lld offset.%d numtx.%d len.%d\n",coin->symbol,(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset]);
memset(&txdata,0,sizeof(txdata)); memset(&txdata,0,sizeof(txdata));

8
iguana/iguana_recv.c

@ -80,9 +80,9 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
{ {
//char str[65]; //char str[65];
recvlen = numtx = 0; recvlen = numtx = 0;
if ( iguana_RTrawdata(coin,hash2,0,&recvlen,&numtx,0) != 0 ) if ( iguana_RTrawdata(coin,hash2,0,&recvlen,&numtx,1) != 0 )
{ {
printf("found valid [%d:%d] in blockreqPT\n",checkbp->hdrsi,j); //printf("found valid [%d:%d] in blockreqPT\n",checkbp->hdrsi,j);
return(0); return(0);
} //else printf("no RTrawdata for %s\n",bits256_str(str,hash2)); } //else printf("no RTrawdata for %s\n",bits256_str(str,hash2));
} }
@ -121,7 +121,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
bp->issued[bundlei] = addr->pendtime; bp->issued[bundlei] = addr->pendtime;
if ( block != 0 ) if ( block != 0 )
block->issued = addr->pendtime; block->issued = addr->pendtime;
//if ( 0 && coin->current == bp ) if ( 0 && coin->current == bp )
printf("REQ.(%s) [%d:%d] %s\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr); printf("REQ.(%s) [%d:%d] %s\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr);
} else printf("MSG_BLOCK null datalen.%d\n",len); } else printf("MSG_BLOCK null datalen.%d\n",len);
return(len); return(len);
@ -504,7 +504,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
} //else printf("cant save block\n"); } //else printf("cant save block\n");
} }
numtx = origtxdata->zblock.RO.txn_count; numtx = origtxdata->zblock.RO.txn_count;
iguana_RTrawdata(coin,txdata->zblock.RO.hash2,data,&recvlen,&numtx,fromcache); iguana_RTrawdata(coin,txdata->zblock.RO.hash2,data,&recvlen,&numtx,0);
req->zblock = txdata->zblock; req->zblock = txdata->zblock;
if ( coin->virtualchain != 0 ) if ( coin->virtualchain != 0 )
printf("%s recvlen.%d ipbits.%x prev.(%s)\n",coin->symbol,req->zblock.RO.recvlen,req->zblock.fpipbits,bits256_str(str,txdata->zblock.RO.prev_block)); printf("%s recvlen.%d ipbits.%x prev.(%s)\n",coin->symbol,req->zblock.RO.recvlen,req->zblock.fpipbits,bits256_str(str,txdata->zblock.RO.prev_block));

10
iguana/iguana_unspents.c

@ -1173,7 +1173,7 @@ int32_t iguana_utxoaddr_validate(struct supernet_info *myinfo,struct iguana_info
int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight) int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight)
{ {
char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t checkbalance=0,balance = 0; struct iguana_block *block; char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t checkbalance=0,balance = 0;
for (hdrsi=0; hdrsi<coin->bundlescount-1; hdrsi++) for (hdrsi=0; hdrsi<coin->bundlescount-1; hdrsi++)
{ {
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight ) if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight )
@ -1190,8 +1190,8 @@ int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coi
coin->firstRTheight = coin->RTheight = height; coin->firstRTheight = coin->RTheight = height;
iguana_RTreset(coin); iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight); iguana_RTpurge(coin,coin->firstRTheight);
if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) //if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
iguana_RTnewblock(coin,block); // iguana_RTnewblock(coin,block);
return(coin->histbalance); return(coin->histbalance);
} }
} }
@ -1319,8 +1319,8 @@ continue;
coin->firstRTheight = coin->RTheight = height; coin->firstRTheight = coin->RTheight = height;
iguana_RTreset(coin); iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight); iguana_RTpurge(coin,coin->firstRTheight);
if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) //if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
iguana_RTnewblock(coin,block); // iguana_RTnewblock(coin,block);
return(coin->histbalance); return(coin->histbalance);
} }
} }

2
includes/iguana_funcs.h

@ -546,7 +546,7 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_block *block,int64_
void iguana_RTreset(struct iguana_info *coin); void iguana_RTreset(struct iguana_info *coin);
void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight); void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight);
void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block); void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block);
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t fromcache); void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t checkonly);
void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp); void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp);
void iguana_update_balances(struct iguana_info *coin); void iguana_update_balances(struct iguana_info *coin);
void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp); void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp);

Loading…
Cancel
Save