From a4b10b346a8b7a80cdd7ea5b75397fc1a57ed920 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 13 Mar 2016 15:52:28 -0300 Subject: [PATCH] test --- iguana/iguana777.c | 49 ++++++++++++----- iguana/iguana777.h | 11 ++-- iguana/iguana_bundles.c | 6 +-- iguana/iguana_init.c | 11 ++-- iguana/iguana_ramchain.c | 10 ++-- iguana/iguana_recv.c | 110 +++++++++++++++++++++++---------------- iguana/iguana_unspents.c | 18 +++++++ iguana/main.c | 35 ++++++++----- 8 files changed, 164 insertions(+), 86 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index cf39ef7f7..0bac07235 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -212,7 +212,7 @@ uint32_t iguana_updatemetrics(struct iguana_info *coin) iguana_peermetrics(coin); sprintf(fname,"confs/%s_peers.txt",coin->symbol), OS_compatible_path(fname); sprintf(oldfname,"confs/%s_oldpeers.txt",coin->symbol), OS_compatible_path(oldfname); - sprintf(tmpfname,"tmp/%s/peers.txt",coin->symbol), OS_compatible_path(tmpfname); + sprintf(tmpfname,"%s/%s/peers.txt",GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); if ( (fp= fopen(tmpfname,"w")) != 0 ) { for (i=0; ipeers.numranked; i++) @@ -272,6 +272,20 @@ void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t ti queue_enqueue("bundlesQ",&bundlesQ,&ptr->DL,0); } +void iguana_validateQ(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 = 'V'; + ptr->starttime = (uint32_t)time(NULL); + ptr->timelimit = 0; + printf("VALIDATE Q %s bundle.%d[%d] utxofinish.%u balancefinish.%u\n",coin->symbol,ptr->hdrsi,bp->n,bp->utxofinish,bp->balancefinish); + queue_enqueue("validateQ",&validateQ,&ptr->DL,0); +} + 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; @@ -300,8 +314,7 @@ int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *m { bp->emitfinish = (uint32_t)time(NULL); coin->numemitted++; - } - else bp->emitfinish = 0; + } else bp->emitfinish = 0; } } else printf("no bundle in helperrequest\n"); } else printf("no coin in helperrequest\n"); @@ -310,7 +323,7 @@ int32_t iguana_helpertask(FILE *fp,struct OS_memspace *mem,struct OS_memspace *m void iguana_helper(void *arg) { - FILE *fp = 0; char fname[512],name[64],*helpername = 0; cJSON *argjson=0; int32_t flag; + FILE *fp = 0; char fname[512],name[64],*helpername = 0; cJSON *argjson=0; int32_t flag,idle=0; struct iguana_helper *ptr; struct iguana_info *coin; struct OS_memspace MEM,*MEMB; if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) helpername = jstr(argjson,"name"); @@ -319,7 +332,7 @@ void iguana_helper(void *arg) sprintf(name,"helper.%d",rand()); helpername = name; } - sprintf(fname,"tmp/%s",helpername); + sprintf(fname,"%s/%s",GLOBALTMPDIR,helpername); OS_compatible_path(fname); fp = fopen(fname,"wb"); if ( argjson != 0 ) @@ -332,10 +345,11 @@ void iguana_helper(void *arg) flag = 0; if ( (ptr= queue_dequeue(&helperQ,0)) != 0 ) { - if ( (coin= ptr->coin) != 0 && 0 )//myallocated(0,-1) > coin->MAXMEM ) + if ( (coin= ptr->coin) != 0 && 0 ) queue_enqueue("reQ",&helperQ,&ptr->DL,0); else { + idle = 0; coin->helperdepth++; iguana_helpertask(fp,&MEM,MEMB,ptr); coin->helperdepth--; @@ -343,17 +357,28 @@ void iguana_helper(void *arg) } flag++; } - else + else if ( (ptr= queue_dequeue(&bundlesQ,0)) != 0 ) + { + idle = 0; + if ( ptr->bp != 0 && ptr->coin != 0 ) + flag += iguana_bundleiters(ptr->coin,ptr->bp,ptr->timelimit); + else printf("helper missing param? %p %p %u\n",ptr->coin,ptr->bp,ptr->timelimit); + myfree(ptr,ptr->allocsize); + flag++; + } + else if ( idle++ > 100 ) { - if ( (ptr= queue_dequeue(&bundlesQ,0)) != 0 ) + if ( (ptr= queue_dequeue(&validateQ,0)) != 0 ) { if ( ptr->bp != 0 && ptr->coin != 0 ) - flag += iguana_bundleiters(ptr->coin,ptr->bp,ptr->timelimit); + flag += iguana_bundlevalidate(ptr->coin,ptr->bp); + else printf("helper validate missing param? %p %p\n",ptr->coin,ptr->bp); myfree(ptr,ptr->allocsize); + flag++; } } if ( flag == 0 ) - usleep(100000); + usleep(10000); } } @@ -454,7 +479,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, coin = iguana_coinadd(symbol,json); coin->launched = launched; if ( (coin->MAXPEERS= maxpeers) <= 0 ) - coin->MAXPEERS = (strcmp(symbol,"BTC") == 0) ? 64 : 32; + coin->MAXPEERS = (strcmp(symbol,"BTC") == 0) ? 128 : 64; if ( (coin->MAXRECVCACHE= maxrecvcache) == 0 ) coin->MAXRECVCACHE = IGUANA_MAXRECVCACHE; if ( (coin->MAXPENDING= maxpending) <= 0 ) @@ -465,7 +490,7 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, sprintf(dirname,"DB/%s",symbol), OS_ensure_directory(dirname); sprintf(dirname,"vouts/%s",symbol), OS_ensure_directory(dirname); sprintf(dirname,"vins/%s",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"tmp/%s",symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%s/%s",GLOBALTMPDIR,symbol), OS_ensure_directory(dirname); coin->initialheight = initialheight; coin->mapflags = mapflags; coin->MAXMEM = juint(json,"RAM"); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index 5b1a7c623..1085c4409 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -418,7 +418,7 @@ struct iguana_bundle { struct queueitem DL; struct iguana_info *coin; struct iguana_bundle *nextbp; struct iguana_bloom16 bloom; uint32_t rawscriptspace; - uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish; + uint32_t issuetime,hdrtime,emitfinish,mergefinish,purgetime,queued,startutxo,utxofinish,balancefinish,validated,lastspeculative; int32_t numhashes,numrecv,numsaved,numcached,rank,generrs,checkedtmp; int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec; double avetime,threshold,metric; uint64_t datasize,estsize; @@ -467,7 +467,7 @@ struct iguana_info struct iguana_bitmap screen; //struct pollfd fds[IGUANA_MAXPEERS]; struct iguana_peer bindaddr; int32_t numsocks; struct OS_memspace TXMEM; - queue_t acceptQ,bundlesQ,hdrsQ,blocksQ,priorityQ,possibleQ,TerminateQ,cacheQ; + queue_t acceptQ,hdrsQ,blocksQ,priorityQ,possibleQ,TerminateQ,cacheQ,recvQ; double parsemillis,avetime; uint32_t Launched[8],Terminated[8]; portable_mutex_t peers_mutex,blocks_mutex; portable_mutex_t scripts_mutex[2]; FILE *scriptsfp[2]; void *scriptsptr[2]; long scriptsfilesize[2]; @@ -785,8 +785,13 @@ uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8 int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *suffixp,uint8_t *vinscript,int32_t scriptlen); void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len); int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp); +int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp); +int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp); +int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp); +void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp); -extern queue_t bundlesQ; +extern queue_t bundlesQ,validateQ; +extern char GLOBALTMPDIR[]; #include "../includes/iguana_api.h" diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index d39c0b909..7736eb6cd 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -298,7 +298,7 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund coin->bundles[coin->bundlescount-1]->nextbp = bp; *bundleip = 0; bits256_str(str,bundlehash2); - sprintf(dirname,"tmp/%s/%d",coin->symbol,bp->bundleheight), OS_ensure_directory(dirname); + sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname); //printf("ht.%d alloc.[%d] new hdrs.%s %s\n",bp->bundleheight,coin->bundlescount,str,bits256_str(str2,allhash)); iguana_bundlehash2add(coin,0,bp,0,bundlehash2); if ( issueflag != 0 ) @@ -352,7 +352,7 @@ void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp) { if ( (ipbits= (uint32_t)coin->peers.active[j].ipbits) != 0 ) { - if ( iguana_peerfname(coin,&hdrsi,"tmp",fname,ipbits,bp->hashes[0],zero,1) >= 0 ) + if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,bp->hashes[0],zero,1) >= 0 ) { if ( OS_removefile(fname,0) > 0 ) coin->peers.numfiles--, m++; @@ -380,7 +380,7 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int { if ( block == iguana_blockfind(coin,bp->hashes[bundlei]) ) { - if ( (checki= iguana_peerfname(coin,&hdrsi,"tmp",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)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize ) { printf("iguana_bundlecalcs.(%s) illegal hdrsi.%d bundlei.%d checki.%d\n",fname,hdrsi,bundlei,checki); continue; diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index fc90b0db9..cde1421ed 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -27,13 +27,13 @@ void iguana_initQs(struct iguana_info *coin) { int32_t i; iguana_initQ(&coin->acceptQ,"acceptQ"); - iguana_initQ(&coin->bundlesQ,"bundlesQ"); iguana_initQ(&coin->hdrsQ,"hdrsQ"); iguana_initQ(&coin->blocksQ,"blocksQ"); iguana_initQ(&coin->priorityQ,"priorityQ"); iguana_initQ(&coin->possibleQ,"possibleQ"); iguana_initQ(&coin->cacheQ,"cacheQ"); iguana_initQ(&coin->TerminateQ,"TerminateQ"); + iguana_initQ(&coin->recvQ,"recvQ"); for (i=0; ipeers.active[i].sendQ,"addrsendQ"); } @@ -53,7 +53,7 @@ void iguana_initpeer(struct iguana_info *coin,struct iguana_peer *addr,uint64_t void iguana_initcoin(struct iguana_info *coin,cJSON *argjson) { int32_t i; - //sprintf(dirname,"tmp/%s",coin->symbol), OS_portable_path(dirname); + //sprintf(dirname,"%s/%s",GLOBALTMPDIR,coin->symbol), OS_portable_path(dirname); //OS_portable_rmdir(dirname,0); portable_mutex_init(&coin->peers_mutex); portable_mutex_init(&coin->blocks_mutex); @@ -135,7 +135,7 @@ int32_t iguana_savehdrs(struct iguana_info *coin) n = coin->blocks.hwmchain.height + 1; hashes = mycalloc('h',coin->chain->bundlesize,sizeof(*hashes)); sprintf(oldfname,"confs/%s_oldhdrs.txt",coin->symbol), OS_compatible_path(oldfname); - sprintf(tmpfname,"tmp/%s/hdrs.txt",coin->symbol), OS_compatible_path(tmpfname); + sprintf(tmpfname,"%s/%s/hdrs.txt",GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); sprintf(fname,"confs/%s_hdrs.txt",coin->symbol), OS_compatible_path(fname); if ( (fp= fopen(tmpfname,"w")) != 0 ) { @@ -273,9 +273,9 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) { bp->emitfinish = (uint32_t)time(NULL) + 1; //printf("LOADED bundle.%d\n",bp->bundleheight); - if ( bp->hdrsi == 0 || coin->bundles[bp->hdrsi-1]->emitfinish != 0 ) + //if ( bp->hdrsi == 0 || coin->bundles[bp->hdrsi-1]->emitfinish != 0 ) { - bp->startutxo = (uint32_t)time(NULL); + //bp->startutxo = (uint32_t)time(NULL); printf("GENERATE UTXO, verify sigs, etc for ht.%d\n",bp->bundleheight); iguana_bundleQ(coin,bp,1000); } @@ -286,6 +286,7 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) init_hexbytes_noT(str,hash2.bytes,sizeof(hash2)); bp->emitfinish = 0; iguana_blockQ(coin,bp,0,hash2,1); + printf("init reqhdrs.%d\n",bp->bundleheight); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1); } } diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 5c69869d0..efa183f87 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -1151,7 +1151,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":"tmp",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)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize ) { printf(" wont save.(%s) bundlei.%d != checki.%d\n",fname,bundlei,checki); return(-1); @@ -1405,7 +1405,7 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname }*/ if ( ramchain->fileptr == 0 || ramchain->filesize <= 0 ) { - if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?"DB":"tmp",fname,ipbits,hash2,prevhash2,numblocks)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize ) + if ( (checki= iguana_peerfname(coin,&hdrsi,ipbits==0?"DB":GLOBALTMPDIR,fname,ipbits,hash2,prevhash2,numblocks)) != 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)); return(0); @@ -1997,7 +1997,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,"tmp",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)) != 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); @@ -2022,7 +2022,7 @@ int32_t iguana_bundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **ptrs int32_t bundlei,checki,hdrsi,num = 0; char fname[1024]; static bits256 zero; for (bundlei=0; bundlein; bundlei++) { - if ( (checki= iguana_peerfname(coin,&hdrsi,"tmp",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)) != 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); @@ -2407,7 +2407,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str //printf("delete %d files hdrs.%d retval.%d\n",num,bp->hdrsi,retval); for (j=0; jhashes[j],zero,1) >= 0 ) // ipbits[j] + if ( iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,1,bp->hashes[j],zero,1) >= 0 ) // ipbits[j] coin->peers.numfiles -= OS_removefile(fname,0); else printf("error removing.(%s)\n",fname); } diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 12b0fce98..cd965b071 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -107,7 +107,7 @@ void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,st req->datalen = datalen; req->txid = tx->txid; memcpy(req->serialized,data,datalen); - queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); } #ifdef later @@ -115,7 +115,7 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl { int32_t bundlei,datalen,checki,hdrsi,fpos; char str[65],str2[65]; FILE *fp; bits256 checkhash2; struct iguana_txblock *txdata = 0; static bits256 zero; - if ( (bundlei= iguana_peerfname(coin,&hdrsi,"tmp",fname,ipbits,hash2,zero,1)) >= 0 ) + if ( (bundlei= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,hash2,zero,1)) >= 0 ) //if ( (bundlei= iguana_peerfname(coin,&hdrsi,fname,ipbits,hash2)) >= 0 ) { if ( (fp= fopen(fname,"rb")) != 0 ) @@ -245,7 +245,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i coin->recvtime = (uint32_t)time(NULL); req->addr = addr; netBLOCKS++; - queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); } void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n) @@ -254,7 +254,7 @@ void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 //printf("got %d txids from %s\n",n,addr->ipaddr); req = iguana_bundlereq(coin,addr,'T',0); req->hashes = txids, req->n = n; - queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); } static int32_t HDRnet; @@ -272,7 +272,7 @@ void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct req->blocks = blocks, req->n = n; HDRnet++; //char str[65]; printf("PTblockhdrs.%s net.%d blocks.%d\n",bits256_str(str,blocks[0].RO.hash2),HDRnet,netBLOCKS); - queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); } void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *blockhashes,int32_t n) @@ -287,7 +287,7 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi req = iguana_bundlereq(coin,addr,'S',0); req->hashes = blockhashes, req->n = n; //printf("bundlesQ blockhashes.%p[%d]\n",blockhashes,n); - queue_enqueue("bundlesQ",&coin->bundlesQ,&req->DL,0); + queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); } void iguana_patch(struct iguana_info *coin,struct iguana_block *block) @@ -398,16 +398,16 @@ 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\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str); + fprintf(stderr,"Afound block -> %d %d hdr.%s bundlei.%d offset.%d\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,str,bundlei,offset); 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 ) { bundlei += offset; + //char str[65]; printf("speculative req[%d] %s\n",bundlei,bits256_str(str,bp->speculative[bundlei])); if ( bundlei < bp->n && bundlei < bp->numspec ) { - //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); + 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); } @@ -452,47 +452,60 @@ int32_t iguana_bundlekick(struct iguana_info *coin,struct iguana_bundle *bp,int3 int32_t iguana_bundleiters(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit) { - int32_t i,range,starti,issued,valid,max,counter = 0; struct iguana_block *block; double endmillis,width; + int32_t i,range,starti,numhashes,issued,valid,max,counter = 0; struct iguana_block *block; double endmillis,width; struct iguana_bundle *prevbp; uint32_t starttime; coin->numbundlesQ--; - if ( bp->numhashes < bp->n && bp->bundleheight < coin->longestchain-coin->chain->bundlesize ) + for (i=numhashes=0; in; i++) + numhashes += bits256_nonz(bp->hashes[i]); + if ( numhashes < bp->n && bp->bundleheight < coin->longestchain-coin->chain->bundlesize ) { + //if ( bp->speculative != 0 ) + // printf("hdr ITERATE bundle.%d vs %d: h.%d n.%d r.%d s.%d finished.%d speculative.%p\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->emitfinish,bp->speculative); if ( strcmp(coin->symbol,"BTC") != 0 && bp->speculative == 0 && bp->numhashes < 3 ) { char str[64]; - //printf("hdr ITERATE bundle.%d vs %d: h.%d n.%d r.%d s.%d finished.%d speculative.%p\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->emitfinish,bp->speculative); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); } - /*else - { - for (i=1; in; i++) - if ( bits256_nonz(bp->hashes[i]) == 0 && bits256_nonz(bp->speculative[i]) > 0 ) - { - iguana_blockQ(coin,0,-1,bp->speculative[i],0); - break; - } - }*/ - usleep(100); + else if ( time(NULL) > bp->lastspeculative+60 ) + { + for (i=1,counter=0; in; i++) + if ( bits256_nonz(bp->hashes[i]) == 0 && bits256_nonz(bp->speculative[i]) > 0 ) + iguana_blockQ(coin,0,-1,bp->speculative[i],0), counter++; + if ( counter != 0 ) + printf("SPECULATIVE issue.%d bp.[%d]\n",counter,bp->hdrsi); + bp->lastspeculative = (uint32_t)time(NULL); + } iguana_bundleQ(coin,bp,bp->n*5); return(0); } if ( bp->emitfinish != 0 ) { - if ( bp->emitfinish > coin->startutc ) + if ( bp->emitfinish >= coin->startutc && (bp->hdrsi == 0 || ((prevbp= coin->bundles[bp->hdrsi-1]) != 0 && prevbp->emitfinish >= coin->startutc)) ) { if ( bp->startutxo == 0 ) { - if ( bp->hdrsi == 0 || coin->bundles[bp->hdrsi-1]->emitfinish != 0 ) + bp->startutxo = (uint32_t)time(NULL); + if ( iguana_utxogen(coin,bp) < 0 ) { - bp->startutxo = (uint32_t)time(NULL); - printf("GENERATE UTXO, verify sigs, etc for ht.%d\n",bp->bundleheight); + printf("GENERATE UTXO ERROR ht.%d\n",bp->bundleheight); + exit(-1); } - iguana_bundleQ(coin,bp,1000); + printf("GENERATED UTXO for ht.%d duration %d seconds\n",bp->bundleheight,(uint32_t)time(NULL)-bp->startutxo); + bp->utxofinish = (uint32_t)time(NULL); } - else if ( bp->utxofinish == 0 ) + if ( bp->balancefinish == 0 && (bp->hdrsi == 0 || (prevbp != 0 && prevbp->utxofinish != 0)) ) { - printf("UTXO FINISHED ht.%d\n",bp->bundleheight); + starttime = (uint32_t)time(NULL); + if ( iguana_balancegen(coin,bp) < 0 ) + { + printf("GENERATE BALANCES ERROR ht.%d\n",bp->bundleheight); + exit(-1); + } + bp->balancefinish = (uint32_t)time(NULL); + printf("GENERATED BALANCES for ht.%d duration %d seconds\n",bp->bundleheight,(uint32_t)starttime - bp->balancefinish); + iguana_validateQ(coin,bp); } } + iguana_bundleQ(coin,bp,1000); return(0); } //printf("BUNDLEITERS.%d\n",bp->hdrsi); @@ -630,7 +643,11 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl if ( prevbundlei < coin->chain->bundlesize ) { if ( prevbp->hdrsi+1 == coin->bundlescount && prevbundlei == coin->chain->bundlesize-1 ) - iguana_bundlecreate(coin,&prevbundlei,prevbp->bundleheight + coin->chain->bundlesize,hash2,zero,0); + { + printf("AUTOCREATE.%d\n",prevbp->bundleheight + coin->chain->bundlesize); + bp = iguana_bundlecreate(coin,bundleip,prevbp->bundleheight + coin->chain->bundlesize,hash2,zero,0); + iguana_bundleQ(coin,bp,1000); + } if ( prevbundlei < coin->chain->bundlesize-1 ) { //printf("bundlehash2add next %d\n",prevbundlei); @@ -713,8 +730,8 @@ 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) { - static bits256 zero; - int32_t bundlei,i; struct iguana_bundle *bp; bits256 allhash; char hashstr[65];// struct iguana_block *block; + int32_t bundlei,i; struct iguana_bundle *bp; bits256 allhash,zero; char hashstr[65]; + memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; if ( num < 2 ) return(req); @@ -722,7 +739,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct iguana_blockQ(coin,0,-1,blockhashes[1],0); iguana_blockQ(coin,0,-1,blockhashes[1],1); char str[65]; - if ( bp != 0 && bp->hdrsi == 0 ) + //if ( bp != 0 && bp->hdrsi == 0 ) printf("blockhashes[%d] %d of %d %s bp.%d[%d]\n",num,bp==0?-1:bp->hdrsi,coin->bundlescount,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei); if ( bp != 0 ) { @@ -737,16 +754,17 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct { init_hexbytes_noT(hashstr,blockhashes[coin->chain->bundlesize].bytes,sizeof(bits256)); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1); - iguana_bundlecreate(coin,&bundlei,bp->bundleheight+coin->chain->bundlesize,blockhashes[coin->chain->bundlesize],zero,0); + bp = iguana_bundlecreate(coin,&bundlei,bp->bundleheight+coin->chain->bundlesize,blockhashes[coin->chain->bundlesize],zero,1); printf("EXTEND last bundle %s ht.%d\n",hashstr,bp->bundleheight+coin->chain->bundlesize); + iguana_bundleQ(coin,bp,1000); } - if ( iguana_allhashcmp(coin,bp,blockhashes,num) > 0 ) + else if ( iguana_allhashcmp(coin,bp,blockhashes,num) > 0 ) return(req); //printf("done allhashes\n"); } if ( (bp->speculative == 0 || num > bp->numspec) && bp->emitfinish == 0 ) { - //printf("FOUND speculative.%p BLOCKHASHES[%d] ht.%d\n",bp->speculative,num,bp->bundleheight); + printf("FOUND speculative.%p BLOCKHASHES[%d] ht.%d\n",bp->speculative,num,bp->bundleheight); if ( bp->speculative != 0 ) myfree(bp->speculative,sizeof(*bp->speculative) * bp->numspec); bp->speculative = blockhashes; @@ -860,13 +878,13 @@ struct iguana_bundlereq *iguana_recvunconfirmed(struct iguana_info *coin,struct return(req); } -int32_t iguana_processbundlesQ(struct iguana_info *coin,int32_t *newhwmp) // single threaded +int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single threaded { int32_t flag = 0; struct iguana_bundlereq *req; *newhwmp = 0; - while ( (req= queue_dequeue(&coin->bundlesQ,0)) != 0 ) + while ( (req= queue_dequeue(&coin->recvQ,0)) != 0 ) { - //fprintf(stderr,"%s bundlesQ.%p type.%c n.%d\n",req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n); + //fprintf(stderr,"%s recvQ.%p type.%c n.%d\n",req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n); if ( req->type == 'B' ) // one block with all txdata { netBLOCKS--; @@ -894,8 +912,8 @@ int32_t iguana_processbundlesQ(struct iguana_info *coin,int32_t *newhwmp) // sin if ( (req= iguana_recvtxids(coin,req,req->hashes,req->n)) != 0 ) myfree(req->hashes,(req->n+1) * sizeof(*req->hashes)), req->hashes = 0; } - else printf("iguana_updatebundles unknown type.%c\n",req->type); - //fprintf(stderr,"finished bundlesQ\n"); + else printf("iguana_updatebundles unknown type.%c\n",req->type), getchar(); + //fprintf(stderr,"finished coin->recvQ\n"); if ( req != 0 ) myfree(req,req->allocsize), req = 0; if ( flag >= IGUANA_BUNDLELOOP ) @@ -920,7 +938,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin) { for (i=0; ibundlescount; i++) { - if ( (bp= coin->bundles[i]) != 0 && bp->numhashes < bp->n )//bp->emitfinish < coin->startutc ) + if ( (bp= coin->bundles[i]) != 0 && (bp->numhashes < bp->n || i == coin->bundlescount-1) )//bp->emitfinish < coin->startutc ) { if ( i == coin->bundlescount-1 ) lag = 30; @@ -930,7 +948,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin) // 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); + 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]; @@ -1100,7 +1118,7 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) } 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!=0?bp->numhashes:0); iguana_send(coin,addr,serialized,datalen); addr->pendhdrs++; flag++; @@ -1318,8 +1336,8 @@ int32_t iguana_reqblocks(struct iguana_info *coin) int32_t iguana_processrecv(struct iguana_info *coin) // single threaded { int32_t newhwm = 0,flag = 0; - //fprintf(stderr,"process bundlesQ\n"); - flag += iguana_processbundlesQ(coin,&newhwm); + //fprintf(stderr,"process coin->recvQ\n"); + flag += iguana_processrecvQ(coin,&newhwm); //fprintf(stderr,"iguana_reqhdrs\n"); flag += iguana_reqhdrs(coin); //fprintf(stderr,"iguana_reqblocks\n"); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 663fa8793..7db61654e 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -318,3 +318,21 @@ uint8_t *iguana_rmdarray(struct iguana_info *coin,int32_t *numrmdsp,cJSON *array } return(rmdarray); } + +int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp) +{ + printf("UTXOGEN.%d\n",bp->bundleheight); + return(0); +} + +int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp) +{ + printf("BALANCEGEN.%d\n",bp->bundleheight); + return(0); +} + +int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp) +{ + printf("VALIDATE.%d\n",bp->bundleheight); + return(0); +} \ No newline at end of file diff --git a/iguana/main.c b/iguana/main.c index 99efd7de0..b93ccda3b 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -35,10 +35,10 @@ int32_t Showmode,Autofold,PANGEA_MAXTHREADS = 1; struct category_info *Categories; struct iguana_info *Coins[IGUANA_MAXCOINS]; -char Userhome[512]; +char Userhome[512],GLOBALTMPDIR[512] = "tmp"; int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel; uint32_t prices777_NXTBLOCK,MAX_DEPTH = 100; -queue_t helperQ,jsonQ,finishedQ,bundlesQ; +queue_t helperQ,jsonQ,finishedQ,bundlesQ,validateQ; struct supernet_info MYINFO,**MYINFOS; static int32_t initflag; cJSON *API_json; @@ -324,20 +324,21 @@ void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func void mainloop(struct supernet_info *myinfo) { - struct iguana_helper *ptr; int32_t flag; + int32_t flag; while ( 1 ) { flag = 0; iguana_jsonQ(); if ( flag == 0 ) { - if ( (ptr= queue_dequeue(&bundlesQ,0)) != 0 ) + /*if ( (ptr= queue_dequeue(&bundlesQ,0)) != 0 ) { if ( ptr->bp != 0 && ptr->coin != 0 ) flag += iguana_bundleiters(ptr->coin,ptr->bp,ptr->timelimit); myfree(ptr,ptr->allocsize); } - else pangea_queues(SuperNET_MYINFO(0)); + else*/ + pangea_queues(SuperNET_MYINFO(0)); } if ( flag == 0 ) { @@ -1083,19 +1084,29 @@ void iguana_main(void *arg) //iguana_chaingenesis(genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC iguana_initQ(&helperQ,"helperQ"); + iguana_initQ(&jsonQ,"jsonQ"); + iguana_initQ(&finishedQ,"finishedQ"); + iguana_initQ(&bundlesQ,"bundlesQ"); + iguana_initQ(&validateQ,"validateQ"); + if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) + { + safecopy(Userhome,jstr(argjson,"userhome"),sizeof(Userhome)); + if ( jstr(argjson,"tmpdir") != 0 ) + { + safecopy(GLOBALTMPDIR,jstr(argjson,"tmpdir"),sizeof(GLOBALTMPDIR)); + printf("GLOBAL tmpdir.(%s)\n",GLOBALTMPDIR); + } + free_json(argjson); + } OS_ensure_directory("help"); OS_ensure_directory("confs"); OS_ensure_directory("DB"), OS_ensure_directory("DB/ECB"); OS_ensure_directory("tmp"); + OS_ensure_directory(GLOBALTMPDIR); OS_ensure_directory("vins"); OS_ensure_directory("vouts"); iguana_coinadd("BTC",0); iguana_coinadd("BTCD",0); - if ( arg != 0 && (argjson= cJSON_Parse(arg)) != 0 ) - { - safecopy(Userhome,jstr(argjson,"userhome"),sizeof(Userhome)); - free_json(argjson); - } if ( (tmpstr= SuperNET_JSON(myinfo,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"help\"}"),0)) != 0 ) { if ( (API_json= cJSON_Parse(tmpstr)) != 0 && (API_json= jobj(API_json,"result")) != 0 ) @@ -1120,10 +1131,10 @@ void iguana_main(void *arg) sleep(1); char *str; //iguana_launchcoin(MYINFO.rpcsymbol,cJSON_Parse("{}")); - if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":1}"),0)) != 0 ) + if ( 1 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":1,\"poll\":1}"),0)) != 0 ) { free(str); - if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":128,\"maxpeers\":128,\"newcoin\":\"BTCD\",\"active\":1}"),0)) != 0 ) + if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":256,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0)) != 0 ) { free(str); if ( 0 && (str= SuperNET_JSON(&MYINFO,cJSON_Parse("{\"agent\":\"SuperNET\",\"method\":\"login\",\"handle\":\"alice\",\"password\":\"alice\",\"passphrase\":\"alice\"}"),0)) != 0 )