From afce953d7168f76731ff3b0cc7c4bb424259d79f Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 18 Aug 2016 05:11:08 -0300 Subject: [PATCH] test --- iguana/iguana777.c | 2 +- iguana/iguana_realtime.c | 88 +++++++++++++++++++++++----------------- iguana/iguana_recv.c | 8 ++-- iguana/iguana_unspents.c | 10 ++--- includes/iguana_funcs.h | 2 +- 5 files changed, 62 insertions(+), 48 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index dfb5d7359..2a91251c9 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -892,7 +892,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, if ( coin->MAXMEM == 0 ) coin->MAXMEM = IGUANA_DEFAULTRAM; 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 ) coin->enableCACHE = juint(json,"cache"); if ( (coin->polltimeout= juint(json,"poll")) <= 0 ) diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 49da9afa7..a6155af08 100755 --- a/iguana/iguana_realtime.c +++ b/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)); } -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; sprintf(fname,"%s/%s/RT/%s.raw",GLOBAL_TMPDIR,coin->symbol,bits256_str(str,hash2)); OS_compatible_path(fname); - if ( *recvlenp > 0 ) + if ( *recvlenp == -1 ) + OS_removefile(fname,0); + else { - if ( coin->RTheight == 0 ) - { - printf("skip %s\n",bits256_str(str,hash2)); - return(0); - } - if ( (fp= fopen(fname,"rb")) != 0 ) + if ( (checkonly != 0 || *recvlenp > 0) && (fp= fopen(fname,"rb")) != 0 ) { fseek(fp,0,SEEK_END); filesize = ftell(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); - 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); } + //printf("len.%d filesize.%ld\n",len,filesize); 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 ) - 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 ( *recvlenp == 0 ) - { - if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 ) + if ( coin->RTheight == 0 ) + { + //printf("skip %s\n",bits256_str(str,hash2)); + return(0); + } + if ( (fp= fopen(fname,"wb")) != 0 ) + { + if ( fwrite(recvlenp,1,sizeof(*recvlenp),fp) != sizeof(*recvlenp) || fwrite(numtxp,1,sizeof(*numtxp),fp) != sizeof(*numtxp) || fwrite(data,1,*recvlenp,fp) != *recvlenp ) + 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)); - memcpy(&checknumtx,&ptr[sizeof(checklen)],sizeof(checknumtx)); - *numtxp = checknumtx; - if ( checklen == (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)) )//&& checknumtx == *numtxp ) + if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 ) { - for (i=nonz=0; iRTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 ) + struct iguana_txblock txdata; uint8_t *serialized; int32_t n,errs=0,numtx,len; uint32_t recvlen = 0; + if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 ) { 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]); - iguana_blockQ("RTiterate",coin,0,-1,block->RO.hash2,1); + //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]); + 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 ) { for (i=0; ipeers->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); 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]); memset(&txdata,0,sizeof(txdata)); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 4bff2e617..123d80ffa 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -80,9 +80,9 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr, { //char str[65]; 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); } //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; if ( block != 0 ) 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); } else printf("MSG_BLOCK null datalen.%d\n",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"); } 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; 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)); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 672832013..646f6d0d9 100755 --- a/iguana/iguana_unspents.c +++ b/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) { - 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; hdrsibundlescount-1; hdrsi++) { 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; iguana_RTreset(coin); iguana_RTpurge(coin,coin->firstRTheight); - if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) - iguana_RTnewblock(coin,block); + //if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + // iguana_RTnewblock(coin,block); return(coin->histbalance); } } @@ -1319,8 +1319,8 @@ continue; coin->firstRTheight = coin->RTheight = height; iguana_RTreset(coin); iguana_RTpurge(coin,coin->firstRTheight); - if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) - iguana_RTnewblock(coin,block); + //if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + // iguana_RTnewblock(coin,block); return(coin->histbalance); } } diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 71d097abc..866161b5f 100755 --- a/includes/iguana_funcs.h +++ b/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_RTpurge(struct iguana_info *coin,int32_t lastheight); 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_update_balances(struct iguana_info *coin); void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp);