diff --git a/iguana/confs/BTCD_hdrs.h b/iguana/confs/BTCD_hdrs.h index 239171b90..45f6ff412 100644 --- a/iguana/confs/BTCD_hdrs.h +++ b/iguana/confs/BTCD_hdrs.h @@ -2101,8 +2101,5 @@ char *BTCD_hdrs[][4] = { { "1049500", "450bc6a5f1b7d502c9a86ecb08ed3bf26c87149f6b6242deebf998ec1190dacb", "e496811cc6cab5c2b821d21ba29b71ca4256b228889e352e779a82aeea96df63", "64fd7f1d78833ec1260e9b39249e9957207845d99bab950ef921a3a5fafdda46"}, { "1050000", "a835e80973ca0240c06703a30433a139d200453a7296c24a22b62792d17ff2a1", "44c9a74b2ad97727ae4f419a77804a88f9a3cb31bb3ae65e2b372040c1eb273e", "95c578d836ef48bd93f58757d6c3b093acaa373f9654410f85dae1aefdd5d3fc"}, { "1050500", "631b74a56a6719158926aca09aa8ab8cd89b61e563a5b6386ec6de5e782e926a", "1e1c4fc04badc617cc382d6aadde8ae735277694e233a225634e2be077c97a2a", "fd4f6efdea193b035f4b5947404483b6930997bf8089d1661d9b9ef48c9887aa"}, -{ "1051000", "1ec8fcfb9b6d6c602e2775686f04f1d39a768064ee6aeb65930bfee5b1a94e19", "4f2f38f9f74bfd1ea8daf0ac5ffa8afb485436d5e4b35fd0742c454439b21488", "f6311a3834e71c30635c01e0c45aacfcb2241780e3aa13f2c834a84f5afda969"}, -{ "1051500", "73133e5c1408263f8053ed9a93ae7164dffc2381d3a7fa24cc78c29665b3bf39", "a47a6e2a98fef063017953ee09b4471622b986b7fe8dc6d52adda451db9c852e", "fb14519af510b672ace64d3d250549fad14d1ed623dd0544bc541b7e3710e38b"}, -{ "1052000", "20e08cce79f51cc9e5b0dd212f6cc3a0ad742244e58ce252600d286fe2415cc3", "edcb3b3a1aff133bac74770612727bf2f15cfafab7c63dfbfe6f2378debda004", "d47a434a2ba0524ee99b5664f66792b81fc9134f5ceb00e69efdf9a46f8142f4"}, -{ "1052500", "37e19650eba3eb3e2967c2585147cc37714d24ac681a8b78d11f946ceca3c083", "", ""}, +{ "1051000", "1ec8fcfb9b6d6c602e2775686f04f1d39a768064ee6aeb65930bfee5b1a94e19", "4f2f38f9f74bfd1ea8daf0ac5ffa8afb485436d5e4b35fd0742c454439b21488", "f6311a3834e71c30635c01e0c45aacfcb2241780e3aa13f2c834a84f5afda969"} }; diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 470e5d7ba..4ede231e5 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -208,11 +208,14 @@ void *iguana_kviAddriterator(struct iguana_info *coin,struct iguanakv *kv,struct uint32_t iguana_updatemetrics(struct iguana_info *coin) { - char fname[512],tmpfname[512],oldfname[512],ipaddr[64]; int32_t i,j; struct iguana_peer *addr,*tmpaddr; FILE *fp; + char fname[512],tmpfname[512],oldfname[512],ipaddr[64],*prefix = ""; int32_t i,j; struct iguana_peer *addr,*tmpaddr; FILE *fp; +#ifdef __PNACL__ + prefix = ""; +#endif 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,"%s/%s/peers.txt",GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); + sprintf(fname,"%sconfs/%s_peers.txt",prefix,coin->symbol), OS_compatible_path(fname); + sprintf(oldfname,"%sconfs/%s_oldpeers.txt",prefix,coin->symbol), OS_compatible_path(oldfname); + sprintf(tmpfname,"%s%s/%s/peers.txt",prefix,GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); if ( (fp= fopen(tmpfname,"w")) != 0 ) { for (i=0; ipeers.numranked; i++) @@ -576,7 +579,7 @@ void iguana_coinloop(void *arg) if ( strcmp(coin->symbol,"BTCD") == 0 ) { int32_t j; - char *ipaddrs[] = { "5.9.102.210", "89.248.160.236", "89.248.160.237", "89.248.160.238", "89.248.160.239", "89.248.160.240", "89.248.160.241", "89.248.160.242", "89.248.160.243", "89.248.160.244", "89.248.160.245", "78.47.58.62" }; + char *ipaddrs[] = { "5.9.102.210", "89.248.160.236", "89.248.160.237", "89.248.160.238", "89.248.160.239", "89.248.160.240", "89.248.160.241", "89.248.160.242", "89.248.160.243", "89.248.160.244", "89.248.160.245", "78.47.58.62", "67.212.70.88", "94.102.50.69", "50.179.58.158", "194.135.94.30", "109.236.85.42", "104.236.127.154", "68.45.147.145", "37.59.14.7", "78.47.115.250", "188.40.138.8", "62.75.143.120", "82.241.71.230", "217.23.6.2", "73.28.172.128", "45.55.149.34", "192.0.242.54", "81.181.155.53", "91.66.185.97", "85.25.217.233", "144.76.239.66", "95.80.9.112", "80.162.193.118", "173.65.129.85", "2.26.173.58", "78.14.250.69", "188.226.253.77", "58.107.67.39", "124.191.37.212", "176.226.137.238", "69.145.25.85", "24.168.14.28", "73.201.180.47", "76.188.171.53", "63.247.147.166", "121.108.241.247", "36.74.36.125", "106.186.119.171", "188.166.91.37", "223.134.228.208", "89.248.160.244", "178.33.209.212", "71.53.156.38", "88.198.10.165", "24.117.221.0", "74.14.104.57", "158.69.27.82", "110.174.129.213", "75.130.163.51" }; for (j=0; jlaunched = launched; @@ -670,8 +673,8 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, coin->myservices = services; coin->initialheight = initialheight; coin->mapflags = mapflags; - mult = (strcmp("BTC",coin->symbol) != 0) ? 4 : 1; - maxval = (strcmp("BTC",coin->symbol) != 0) ? IGUANA_MAXPENDBUNDLES : IGUANA_MAXPENDBUNDLES; + mult = (strcmp("BTC",coin->symbol) != 0) ? 16 : 1; + maxval = IGUANA_MAXPENDBUNDLES; coin->MAXMEM = juint(json,"RAM"); if ( jobj(json,"prefetchlag") != 0 ) coin->PREFETCHLAG = jint(json,"prefetchlag"); @@ -680,23 +683,25 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, coin->MAXSTUCKTIME = _IGUANA_MAXSTUCKTIME; if ( coin->MAXMEM == 0 ) coin->MAXMEM = IGUANA_DEFAULTRAM; - if ( strcmp("BTC",coin->symbol) == 0 && coin->MAXMEM < 4 ) - maxval = (int32_t)coin->MAXMEM; + //if ( strcmp("BTC",coin->symbol) == 0 && coin->MAXMEM < 4 ) + // maxval = (int32_t)coin->MAXMEM; coin->MAXMEM *= (1024L * 1024 * 1024); + prefix = ""; #ifdef __PNACL__ - maxval = 8; + //maxval = 16; + prefix = ""; #endif if ( (coin->startPEND= juint(json,"startpend")) == 0 ) - coin->startPEND = IGUANA_MAXPENDBUNDLES * mult; - if ( coin->startPEND > maxval * mult ) - coin->startPEND = maxval * mult; + coin->startPEND = IGUANA_MAXPENDBUNDLES*mult; + if ( coin->startPEND > maxval*mult ) + coin->startPEND = maxval*mult; else if ( coin->startPEND < 2 ) coin->startPEND = 2; coin->MAXBUNDLES = coin->startPEND; if ( (coin->endPEND= juint(json,"endpend")) == 0 ) - coin->endPEND = IGUANA_MINPENDBUNDLES * mult; - if ( coin->endPEND > maxval * mult ) - coin->endPEND = maxval * mult; + coin->endPEND = IGUANA_MINPENDBUNDLES*mult; + if ( coin->endPEND > maxval*mult ) + coin->endPEND = maxval*mult; else if ( coin->endPEND < 2 ) coin->endPEND = 2; coin->enableCACHE = (strcmp("BTC",coin->symbol) != 0); @@ -707,16 +712,17 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers, coin->active = juint(json,"active"); if ( (coin->minconfirms = minconfirms) == 0 ) coin->minconfirms = (strcmp(symbol,"BTC") == 0) ? 3 : 10; - printf("ensure directories\n"); - sprintf(dirname,"DB/ro/%s",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"DB/ro"), OS_ensure_directory(dirname); - sprintf(dirname,"DB/%s",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"DB/%s/validated",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"DB/%s/accounts",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"DB/%s/spends",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"DB/%s/vouts",symbol), OS_ensure_directory(dirname); - sprintf(dirname,"%s/%s",coin->VALIDATEDIR,symbol), OS_ensure_directory(dirname); - sprintf(dirname,"%s/%s",GLOBALTMPDIR,symbol), OS_ensure_directory(dirname); + printf("ensure directories maxval.%d mult.%d start.%d end.%d\n",maxval,mult,coin->startPEND,coin->endPEND); + sprintf(dirname,"%sDB/ro/%s",prefix,symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/ro",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/%s",prefix,symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/%s/validated",prefix,symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/%s/accounts",prefix,symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/%s/spends",prefix,symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/%s/vouts",prefix,symbol), OS_ensure_directory(dirname); + if ( coin->VALIDATEDIR[0] != 0 ) + sprintf(dirname,"%s%s/%s",prefix,coin->VALIDATEDIR,symbol), OS_ensure_directory(dirname); + sprintf(dirname,"%s%s/%s",prefix,GLOBALTMPDIR,symbol), OS_ensure_directory(dirname); if ( coin->chain == 0 && (coin->chain= iguana_createchain(json)) == 0 ) { printf("cant initialize chain.(%s)\n",jstr(json,0)); diff --git a/iguana/iguana777.h b/iguana/iguana777.h index c49bc5028..2720470f0 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -26,7 +26,11 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t #define IGUANA_SERIALIZE_SPENDVECTORGEN //#define IGUANA_DISABLEPEERS #define _IGUANA_MAXSTUCKTIME 10 +#ifdef __PNACL__ +#define IGUANA_MAXITERATIONS 77 +#else #define IGUANA_MAXITERATIONS 3333 +#endif #define IGUANA_DEFAULTLAG 30 #define IGUANA_MAXCOINS 64 @@ -43,7 +47,7 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t #define IGUANA_TAILPERCENTAGE 1.0 #define IGUANA_MAXPENDHDRS 1 #define IGUANA_MAXPENDINGREQUESTS 3 -#define IGUANA_PENDINGREQUESTS 256 +#define IGUANA_PENDINGREQUESTS 512 #define IGUANA_MINPENDBUNDLES 4 #define IGUANA_MAXPENDBUNDLES 16 #define IGUANA_RPCPORT 7778 @@ -660,7 +664,7 @@ void iguana_flushQ(struct iguana_info *coin,struct iguana_peer *addr); //struct iguana_txdatabits iguana_peerfilePT(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2,struct iguana_txdatabits txdatabits,int32_t recvlen); struct iguana_txdatabits iguana_calctxidbits(uint32_t addrind,uint32_t filecount,uint32_t fpos,uint32_t datalen); int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,uint32_t starttime); // helper thread -int32_t iguana_bundlemergeHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime); // helper thread +int32_t iguana_bundlemergeHT(char *fname,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime); // helper thread void iguana_peerfilename(struct iguana_info *coin,char *fname,uint32_t addrind,uint32_t filecount); @@ -828,12 +832,12 @@ int32_t iguana_volatilesmap(struct iguana_info *coin,struct iguana_ramchain *ram void iguana_volatilespurge(struct iguana_info *coin,struct iguana_ramchain *ramchain); int32_t iguana_volatilesinit(struct iguana_info *coin); void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle); -int64_t iguana_ramchainopen(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2); +int64_t iguana_ramchainopen(char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2); int32_t iguana_ramchain_free(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t deleteflag); void iguana_blocksetcounters(struct iguana_info *coin,struct iguana_block *block,struct iguana_ramchain * ramchain); int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int16_t bundlei); void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei); -int32_t iguana_mapchaininit(struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize); +int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize); void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp); void iguana_RTramchainfree(struct iguana_info *coin); void iguana_coinpurge(struct iguana_info *coin); diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index c246d9594..572585cbd 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -215,7 +215,9 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo if ( bits256_nonz(bp->hashes[bundlei]) != 0 && bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 ) { char str[65],str2[65]; - printf("bp->hashes[%d] mismatch %s != %s%s\n",bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str2,block->RO.hash2),block->mainchain?".main":""); + printf("bp.[%d]->hashes[%d] mismatch %s != %s%s\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str2,block->RO.hash2),block->mainchain?".main":""); + iguana_blockunmark(coin,block,bp,bundlei,1); + bp->blocks[bundlei] = 0; //if ( block->mainchain != 0 ) // bp->hashes[bundlei] = block->RO.hash2; @@ -310,7 +312,7 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bundleip,int32_t bundleheight,bits256 bundlehash2,bits256 allhash,int32_t issueflag) { - char str[65],dirname[1024]; struct iguana_bundle *prevbp,*bp = 0; + char str[65]; struct iguana_bundle *prevbp,*bp = 0; if ( bits256_nonz(bundlehash2) > 0 ) { bits256_str(str,bundlehash2); @@ -347,7 +349,7 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund } *bundleip = 0; bits256_str(str,bundlehash2); - sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname); + char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname); //sprintf(dirname,"DB/%s/%d",coin->symbol,bp->bundleheight), OS_ensure_directory(dirname); //printf("ht.%d alloc.[%d] new hdrs.%s\n",bp->bundleheight,coin->bundlescount,bits256_str(str,bp->hashes[0])); iguana_bundlehash2add(coin,0,bp,0,bundlehash2); @@ -413,7 +415,10 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp) { static const bits256 zero; - char fname[1024],dirname[1024]; FILE *fp; int32_t hdrsi,m,j; uint32_t ipbits; + char fname[1024],dirname[1024],*prefix = ""; FILE *fp; int32_t hdrsi,m,j; uint32_t ipbits; +#ifdef __PNACL__ + prefix = ""; +#endif if ( bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 ) { //printf("purged hdrsi.[%d] lag.%ld\n",bp->hdrsi,time(NULL) - bp->emitfinish); @@ -434,8 +439,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp) else printf("error removing.(%s)\n",fname); } } - sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight); - OS_remove_directory(dirname); + sprintf(dirname,"%s%s/%s/%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_remove_directory(dirname); bp->purgetime = (uint32_t)time(NULL); } } @@ -646,7 +650,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int prevhash2 = zero; if ( (ptr= iguana_bundlefile(coin,fname,&filesize,bp,i)) != 0 ) { - if ( iguana_mapchaininit(coin,&R,bp,i,block,ptr,filesize) > 0 ) + if ( iguana_mapchaininit(fname,coin,&R,bp,i,block,ptr,filesize) > 0 ) { B = (void *)(long)((long)R.H.data + R.H.data->Boffset); prevhash2 = B[0].prev_block; @@ -1206,8 +1210,8 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) if ( lastpending->hdrsi+done > coin->bundlescount-1 ) lastpending = coin->bundles[coin->bundlescount-1]; else lastpending = coin->bundles[lastpending->hdrsi+done]; - } - else coin->lastpending = coin->bundles[coin->bundlescount - 1]; + coin->lastpending = lastpending; + } else coin->lastpending = coin->bundles[coin->bundlescount - 1]; coin->numsaved = numsaved; coin->numemit = numemit; coin->spaceused = spaceused; diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index b1979726e..01bfbea8e 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -53,9 +53,12 @@ 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; char dirname[1024]; - sprintf(dirname,"%s/%s",GLOBALTMPDIR,coin->symbol), OS_portable_path(dirname); - sprintf(dirname,"tmp/%s",coin->symbol), OS_portable_path(dirname); + int32_t i; char dirname[1024],*prefix = ""; +#ifdef __PNACL__ + prefix = ""; +#endif + sprintf(dirname,"%s%s/%s",prefix,GLOBALTMPDIR,coin->symbol), OS_portable_path(dirname); + sprintf(dirname,"%stmp/%s",prefix,coin->symbol), OS_portable_path(dirname); portable_mutex_init(&coin->peers_mutex); portable_mutex_init(&coin->blocks_mutex); iguana_meminit(&coin->blockMEM,"blockMEM",coin->blockspace,sizeof(coin->blockspace),0); @@ -128,13 +131,16 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain) int32_t iguana_savehdrs(struct iguana_info *coin) { - char fname[512],shastr[65],tmpfname[512],tmpfname2[512],str2[65],str[65],oldfname[512]; + char fname[512],shastr[65],tmpfname[512],tmpfname2[512],str2[65],str[65],oldfname[512],*prefix=""; bits256 sha256all; FILE *fp,*fp2; struct iguana_bundle *bp; int32_t hdrsi,n,retval = 0; n = coin->blocks.hwmchain.height + 1; - sprintf(tmpfname,"%s/%s/hdrs.txt",GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); - sprintf(tmpfname2,"%s/%s/hdrs.h",GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); - sprintf(oldfname,"confs/%s_oldhdrs.txt",coin->symbol), OS_compatible_path(oldfname); - sprintf(fname,"confs/%s_hdrs.txt",coin->symbol), OS_compatible_path(fname); +#ifdef __PNACL__ + prefix = ""; +#endif + sprintf(tmpfname,"%s%s/%s/hdrs.txt",prefix,GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); + sprintf(tmpfname2,"%s%s/%s/hdrs.h",prefix,GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); + sprintf(oldfname,"%sconfs/%s_oldhdrs.txt",prefix,coin->symbol), OS_compatible_path(oldfname); + sprintf(fname,"%sconfs/%s_hdrs.txt",prefix,coin->symbol), OS_compatible_path(fname); if ( (fp= fopen(tmpfname,"w")) != 0 ) { if ( (fp2= fopen(tmpfname2,"w")) != 0 ) diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index fd4d965ba..498fea139 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -90,7 +90,10 @@ void iguana_blocksetcounters(struct iguana_info *coin,struct iguana_block *block 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; int32_t bundlei; char str[65]; + struct iguana_bundle *bp; int32_t bundlei; char str[65],*prefix = ""; +#ifdef __PNACL__ + prefix = ""; +#endif *hdrsip = -1; ipbits = 0; fname[0] = 0; //if ( ipbits == 0 ) @@ -111,7 +114,7 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname, if ( numblocks == 1 ) { if ( bits256_nonz(bp->hashes[bundlei]) != 0 ) - sprintf(fname,"%s/%s/%d/%s_%u.%d",dirname,coin->symbol,bp->bundleheight,bits256_str(str,bp->hashes[bundlei]),ipbits>1?ipbits:*hdrsip,bundlei); + sprintf(fname,"%s%s/%s/%d/%s_%u.%d",prefix,dirname,coin->symbol,bp->bundleheight,bits256_str(str,bp->hashes[bundlei]),ipbits>1?ipbits:*hdrsip,bundlei); else { printf("no hash for [%d:%d]\n",bp->hdrsi,bundlei); @@ -119,8 +122,8 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname, } } else if ( strncmp("DB",dirname,strlen("DB")) == 0 ) - sprintf(fname,"%s/%s/%s_%d.%u",dirname,coin->symbol,bits256_str(str,hash2),numblocks,ipbits>1?ipbits:*hdrsip); - else sprintf(fname,"%s/%s.%u",dirname,bits256_str(str,hash2),bp->bundleheight); + sprintf(fname,"%s%s/%s/%s_%d.%u",prefix,dirname,coin->symbol,bits256_str(str,hash2),numblocks,ipbits>1?ipbits:*hdrsip); + else sprintf(fname,"%s%s/%s.%u",prefix,dirname,bits256_str(str,hash2),bp->bundleheight); OS_compatible_path(fname); return(bundlei); } @@ -618,7 +621,7 @@ void *_iguana_ramchain_setptrs(RAMCHAIN_PTRPS,struct iguana_ramchaindata *rdata) return(rdata); } -void *iguana_ramchain_offset(void *dest,uint8_t *lhash,FILE *fp,uint64_t fpos,void *srcptr,uint64_t *offsetp,uint64_t len,uint64_t srcsize) +void *iguana_ramchain_offset(char *fname,void *dest,uint8_t *lhash,FILE *fp,uint64_t fpos,void *srcptr,uint64_t *offsetp,uint64_t len,uint64_t srcsize) { long err; void *destptr = (void *)(long)((long)dest + *offsetp); @@ -636,9 +639,9 @@ void *iguana_ramchain_offset(void *dest,uint8_t *lhash,FILE *fp,uint64_t fpos,vo { if ( (err= fwrite(srcptr,1,len,fp)) != len ) { - printf("iguana_ramchain_sizefunc: error.%ld writing len.%ld to fp.%p errno.%d\n",err,(long)len,fp,errno); + printf("iguana_ramchain_sizefunc.(%s): error.%ld writing len.%ld to fp.%p errno.%d\n",fname,err,(long)len,fp,errno); printf("probably out of disk space. please free up space\n"); - fprintf(stderr,"iguana_ramchain_sizefunc: error.%ld writing len.%ld to fp.%p errno.%d\n",err,(long)len,fp,errno); + fprintf(stderr,"iguana_ramchain_sizefunc.(%s): error.%ld writing len.%ld to fp.%p errno.%d\n",fname,err,(long)len,fp,errno); fprintf(stderr,"probably out of disk space. please free up space\n"); sleep(3); } @@ -715,7 +718,7 @@ int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain return(nonz); } -int64_t _iguana_rdata_action(FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],void *destptr,uint64_t fpos,uint32_t expanded,uint32_t numtxids,uint32_t numunspents,uint32_t numspends,uint32_t numpkinds,uint32_t numexternaltxids,uint32_t scriptspace,uint32_t txsparsebits,uint64_t numtxsparse,uint32_t pksparsebits,uint64_t numpksparse,uint64_t srcsize,RAMCHAIN_FUNC,int32_t numblocks) +int64_t _iguana_rdata_action(char *fname,FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],void *destptr,uint64_t fpos,uint32_t expanded,uint32_t numtxids,uint32_t numunspents,uint32_t numspends,uint32_t numpkinds,uint32_t numexternaltxids,uint32_t scriptspace,uint32_t txsparsebits,uint64_t numtxsparse,uint32_t pksparsebits,uint64_t numpksparse,uint64_t srcsize,RAMCHAIN_FUNC,int32_t numblocks) { #define RAMCHAIN_LARG(ind) ((lhashes == 0) ? 0 : lhashes[ind].bytes) FILE *fparg = 0; int32_t iter; uint64_t txbits,pkbits,offset = 0; struct iguana_ramchaindata *rdata = destptr; @@ -756,39 +759,39 @@ int64_t _iguana_rdata_action(FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],void *d char str[65]; //if ( fparg != 0 && numblocks > 1 ) // printf("%p B[0] %s -> ",B,bits256_str(str,B[0].hash2)); - B = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_BLOCKS),fparg,fpos,B,&offset,(sizeof(struct iguana_blockRO) * numblocks),srcsize); + B = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_BLOCKS),fparg,fpos,B,&offset,(sizeof(struct iguana_blockRO) * numblocks),srcsize); if ( 0 && fparg != 0 && numblocks > 1 ) { printf("%s %p\n",bits256_str(str,B[0].hash2),B); //if ( bits256_nonz(B[0].hash2) == 0 ) // getchar(); } - T = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_TXIDS),fparg,fpos,T,&offset,(sizeof(struct iguana_txid) * numtxids),srcsize); + T = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_TXIDS),fparg,fpos,T,&offset,(sizeof(struct iguana_txid) * numtxids),srcsize); if ( expanded != 0 ) { U = destptr, S = destptr; - Ux = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_UNSPENTS),fparg,fpos,Ux,&offset,(sizeof(struct iguana_unspent) * numunspents),srcsize); - Sx = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),fparg,fpos,Sx,&offset,(sizeof(struct iguana_spend) * numspends),srcsize); - P = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_PKHASHES),fparg,fpos,P,&offset,(sizeof(struct iguana_pkhash) * numpkinds),srcsize); - //U2 = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENTINDS),fparg,fpos,U2,&offset,(sizeof(struct iguana_Uextra) * numunspents),srcsize); - //P2 = 0;//iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_FIRSTSPENDS),fparg,fpos,P2,&offset,(sizeof(struct iguana_pkextra) * numpkinds),srcsize); - A = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_ACCOUNTS),fparg,fpos,A,&offset,(sizeof(struct iguana_account) * numpkinds),srcsize); + Ux = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_UNSPENTS),fparg,fpos,Ux,&offset,(sizeof(struct iguana_unspent) * numunspents),srcsize); + Sx = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),fparg,fpos,Sx,&offset,(sizeof(struct iguana_spend) * numspends),srcsize); + P = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_PKHASHES),fparg,fpos,P,&offset,(sizeof(struct iguana_pkhash) * numpkinds),srcsize); + //U2 = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENTINDS),fparg,fpos,U2,&offset,(sizeof(struct iguana_Uextra) * numunspents),srcsize); + //P2 = 0;//iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_FIRSTSPENDS),fparg,fpos,P2,&offset,(sizeof(struct iguana_pkextra) * numpkinds),srcsize); + A = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_ACCOUNTS),fparg,fpos,A,&offset,(sizeof(struct iguana_account) * numpkinds),srcsize); char str[65]; if ( 0 && X != 0 ) printf("%p X[1] -> %s\n",&X[1],bits256_str(str,X[1])); - X = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_EXTERNALS),fparg,fpos,X,&offset,(sizeof(bits256) * numexternaltxids),srcsize); - TXbits = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_TXBITS),fparg,fpos,TXbits,&offset,hconv_bitlen(txbits),srcsize); - PKbits = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_PKBITS),fparg,fpos,PKbits,&offset,hconv_bitlen(pkbits),srcsize); + X = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_EXTERNALS),fparg,fpos,X,&offset,(sizeof(bits256) * numexternaltxids),srcsize); + TXbits = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_TXBITS),fparg,fpos,TXbits,&offset,hconv_bitlen(txbits),srcsize); + PKbits = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_PKBITS),fparg,fpos,PKbits,&offset,hconv_bitlen(pkbits),srcsize); } else { Ux = destptr, Sx = destptr, P = destptr, A = destptr, X = destptr, TXbits = destptr, PKbits = destptr, Kspace = destptr; //U2 = destptr, P2 = destptr, - U = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_UNSPENTS),fparg,fpos,U,&offset,(sizeof(struct iguana_unspent20) * numunspents),srcsize); + U = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_UNSPENTS),fparg,fpos,U,&offset,(sizeof(struct iguana_unspent20) * numunspents),srcsize); if ( 0 && lhashes != 0 ) printf("iter.%d lhashes.%p offset.%ld destptr.%p len.%ld fparg.%p fpos.%ld srcsize.%ld\n",iter,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),(long)offset,destptr,(long)sizeof(struct iguana_spend256) * numspends,fparg,(long)fpos,(long)srcsize); - S = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),fparg,fpos,S,&offset,(sizeof(struct iguana_spend256) * numspends),srcsize); + S = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_SPENDS),fparg,fpos,S,&offset,(sizeof(struct iguana_spend256) * numspends),srcsize); } - Kspace = iguana_ramchain_offset(rdata,RAMCHAIN_LARG(IGUANA_LHASH_KSPACE),fparg,fpos,Kspace,&offset,scriptspace,srcsize); // at the end so it can be truncated + Kspace = iguana_ramchain_offset(fname,rdata,RAMCHAIN_LARG(IGUANA_LHASH_KSPACE),fparg,fpos,Kspace,&offset,scriptspace,srcsize); // at the end so it can be truncated if ( (fparg= fp) == 0 ) break; lhashes = 0; @@ -830,23 +833,23 @@ int64_t _iguana_rdata_action(FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],void *d #undef SPARSECOUNT } -int64_t iguana_ramchain_action(RAMCHAIN_FUNC,FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],struct iguana_ramchaindata *destdata,uint64_t fpos,struct iguana_ramchaindata *srcdata,int32_t numblocks,int32_t scriptspace) +int64_t iguana_ramchain_action(char *fname,RAMCHAIN_FUNC,FILE *fp,bits256 lhashes[IGUANA_NUMLHASHES],struct iguana_ramchaindata *destdata,uint64_t fpos,struct iguana_ramchaindata *srcdata,int32_t numblocks,int32_t scriptspace) { if ( 0 && ramchain->expanded == 0 ) printf("action.%p (%p %p %p) %ld allocated.%ld [%d:%d %d:%d]\n",srcdata,fp,lhashes,destdata,(long)fpos,(long)srcdata->allocsize,srcdata->txsparsebits,srcdata->numtxsparse,srcdata->pksparsebits,srcdata->numpksparse); - return(_iguana_rdata_action(fp,lhashes,destdata,fpos,ramchain->expanded,srcdata->numtxids,srcdata->numunspents,srcdata->numspends,srcdata->numpkinds,srcdata->numexternaltxids,scriptspace,srcdata->txsparsebits,srcdata->numtxsparse,srcdata->pksparsebits,srcdata->numpksparse,srcdata->allocsize,RAMCHAIN_ARG,numblocks)); + return(_iguana_rdata_action(fname,fp,lhashes,destdata,fpos,ramchain->expanded,srcdata->numtxids,srcdata->numunspents,srcdata->numspends,srcdata->numpkinds,srcdata->numexternaltxids,scriptspace,srcdata->txsparsebits,srcdata->numtxsparse,srcdata->pksparsebits,srcdata->numpksparse,srcdata->allocsize,RAMCHAIN_ARG,numblocks)); } -int64_t iguana_ramchain_size(RAMCHAIN_FUNC,int32_t numblocks,int32_t scriptspace) +int64_t iguana_ramchain_size(char *fname,RAMCHAIN_FUNC,int32_t numblocks,int32_t scriptspace) { int64_t allocsize; - allocsize = iguana_ramchain_action(RAMCHAIN_ARG,0,0,0,0,ramchain->H.data,numblocks,scriptspace); + allocsize = iguana_ramchain_action(fname,RAMCHAIN_ARG,0,0,0,0,ramchain->H.data,numblocks,scriptspace); if ( 0 && ramchain->expanded != 0 ) printf("%p iguana_ramchain_size.expanded.%d %u: Koffset.%u scriptoffset.%u stacksize.%u stackspace.%u [%u]\n",ramchain,ramchain->expanded,(int32_t)allocsize,(int32_t)ramchain->H.data->Koffset,(int32_t)ramchain->H.scriptoffset,(int32_t)ramchain->H.stacksize,(int32_t)ramchain->H.data->stackspace,scriptspace); return(allocsize); } -long iguana_ramchain_setsize(struct iguana_ramchain *ramchain,struct iguana_ramchaindata *srcdata,int32_t numblocks) +long iguana_ramchain_setsize(char *fname,struct iguana_ramchain *ramchain,struct iguana_ramchaindata *srcdata,int32_t numblocks) { RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; struct iguana_ramchaindata *rdata = ramchain->H.data; //B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0; //U2 = 0, P2 = 0, @@ -857,44 +860,44 @@ long iguana_ramchain_setsize(struct iguana_ramchain *ramchain,struct iguana_ramc rdata->numexternaltxids = ramchain->externalind; rdata->scriptspace = ramchain->H.scriptoffset; rdata->stackspace = ramchain->H.stacksize; - rdata->allocsize = iguana_ramchain_size(RAMCHAIN_ARG,numblocks,rdata->scriptspace); + rdata->allocsize = iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,rdata->scriptspace); if ( 0 && rdata->scriptspace != 0 ) printf("iguana_ramchain_setsize: Koffset.%d scriptspace.%d stackspace.%d (scriptoffset.%d stacksize.%d) allocsize.%d\n",(int32_t)rdata->Koffset,(int32_t)rdata->scriptspace,(int32_t)rdata->stackspace,(int32_t)ramchain->H.scriptoffset,(int32_t)ramchain->H.stacksize,(int32_t)rdata->allocsize); ramchain->datasize = rdata->allocsize; return((long)rdata->allocsize); } -int64_t iguana_ramchain_compact(RAMCHAIN_FUNC,struct iguana_ramchaindata *destdata,struct iguana_ramchaindata *srcdata,int32_t numblocks) +int64_t iguana_ramchain_compact(char *fname,RAMCHAIN_FUNC,struct iguana_ramchaindata *destdata,struct iguana_ramchaindata *srcdata,int32_t numblocks) { //iguana_ramchain_setsize(ramchain,srcdata); - return(iguana_ramchain_action(RAMCHAIN_ARG,0,0,destdata,0,srcdata,numblocks,ramchain->H.scriptoffset)); + return(iguana_ramchain_action(fname,RAMCHAIN_ARG,0,0,destdata,0,srcdata,numblocks,ramchain->H.scriptoffset)); } -bits256 iguana_ramchain_lhashes(RAMCHAIN_FUNC,struct iguana_ramchaindata *destdata,struct iguana_ramchaindata *srcdata,int32_t numblocks,int32_t scriptspace) +bits256 iguana_ramchain_lhashes(char *fname,RAMCHAIN_FUNC,struct iguana_ramchaindata *destdata,struct iguana_ramchaindata *srcdata,int32_t numblocks,int32_t scriptspace) { - iguana_ramchain_action(RAMCHAIN_ARG,0,destdata->lhashes,0,0,srcdata,numblocks,scriptspace); + iguana_ramchain_action(fname,RAMCHAIN_ARG,0,destdata->lhashes,0,0,srcdata,numblocks,scriptspace); memset(&destdata->sha256,0,sizeof(destdata->sha256)); vcalc_sha256(0,destdata->sha256.bytes,(void *)destdata,sizeof(*destdata)); return(destdata->sha256); } -int64_t iguana_ramchain_saveaction(RAMCHAIN_FUNC,FILE *fp,struct iguana_ramchaindata *rdata,int32_t numblocks,int32_t scriptspace) +int64_t iguana_ramchain_saveaction(char *fname,RAMCHAIN_FUNC,FILE *fp,struct iguana_ramchaindata *rdata,int32_t numblocks,int32_t scriptspace) { long before,after; before = ftell(fp); - iguana_ramchain_action(RAMCHAIN_ARG,fp,0,rdata,0,rdata,numblocks,scriptspace); + iguana_ramchain_action(fname,RAMCHAIN_ARG,fp,0,rdata,0,rdata,numblocks,scriptspace); after = ftell(fp); if ( 0 && ramchain->expanded == 0 ) { int32_t i; for (i=0; i size.%ld %ld vs %ld %u\n",(int32_t)rdata->Koffset,(long)Kspace-(long)rdata,sizeof(*rdata),rdata->numtxids,rdata->numunspents,rdata->numspends,rdata->numpkinds,rdata->numexternaltxids,(long)rdata->allocsize,(long)iguana_ramchain_size(RAMCHAIN_ARG,numblocks,scriptspace),after-before+sizeof(*rdata),scriptspace); + printf(" SAVEACTION: K.%d:%ld rdata.%ld DEST T.%d U.%d S.%d P.%d X.%d -> size.%ld %ld vs %ld %u\n",(int32_t)rdata->Koffset,(long)Kspace-(long)rdata,sizeof(*rdata),rdata->numtxids,rdata->numunspents,rdata->numspends,rdata->numpkinds,rdata->numexternaltxids,(long)rdata->allocsize,(long)iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace),after-before+sizeof(*rdata),scriptspace); } //printf("before.%ld after.%ld allocsize.%ld [%ld] %ld expanded.%d\n",before,after,(long)srcdata->allocsize,(long)ramchain->H.data->allocsize,(long)iguana_ramchain_size(ramchain),ramchain->expanded); return(after - before); } -int64_t iguana_ramchain_init(struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t firsti,int32_t numtxids,int32_t numunspents,int32_t numspends,int32_t numpkinds,int32_t numexternaltxids,int32_t scriptspace,int32_t expanded,int32_t numblocks) +int64_t iguana_ramchain_init(char *fname,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t firsti,int32_t numtxids,int32_t numunspents,int32_t numspends,int32_t numpkinds,int32_t numexternaltxids,int32_t scriptspace,int32_t expanded,int32_t numblocks) { RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; int64_t offset = 0; struct iguana_ramchaindata *rdata; //B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0; @@ -915,13 +918,13 @@ int64_t iguana_ramchain_init(struct iguana_ramchain *ramchain,struct OS_memspace numexternaltxids = numspends; if ( numpkinds == 0 ) numpkinds = numunspents; - _iguana_rdata_action(0,0,rdata,0,expanded,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks); + _iguana_rdata_action(fname,0,0,rdata,0,expanded,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks); offset += rdata->allocsize; if ( 0 && expanded != 0 ) printf("init T.%d U.%d S.%d P.%d X.%d -> %ld\n",numtxids,numunspents,numspends,numpkinds,numexternaltxids,(long)offset); - if ( rdata->allocsize != iguana_ramchain_size(RAMCHAIN_ARG,numblocks,scriptspace) ) + if ( rdata->allocsize != iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace) ) { - printf("offset.%ld scriptspace.%d allocsize.%ld vs memsize.%ld\n",(long)offset,scriptspace,(long)rdata->allocsize,(long)iguana_ramchain_size(RAMCHAIN_ARG,numblocks,scriptspace)); + printf("offset.%ld scriptspace.%d allocsize.%ld vs memsize.%ld\n",(long)offset,scriptspace,(long)rdata->allocsize,(long)iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace)); exit(-1); } if ( offset <= mem->totalsize ) @@ -929,7 +932,7 @@ int64_t iguana_ramchain_init(struct iguana_ramchain *ramchain,struct OS_memspace else { printf("offset.%ld vs memsize.%ld\n",(long)offset,(long)mem->totalsize); - printf("NEED %ld realloc for totalsize %ld\n",(long)offset,(long)iguana_ramchain_size(RAMCHAIN_ARG,numblocks,scriptspace)); + printf("NEED %ld realloc for totalsize %ld\n",(long)offset,(long)iguana_ramchain_size(fname,RAMCHAIN_ARG,numblocks,scriptspace)); getchar(); //exit(-1); iguana_mempurge(mem); @@ -943,13 +946,13 @@ int64_t iguana_ramchain_init(struct iguana_ramchain *ramchain,struct OS_memspace return(offset); } -int32_t iguana_ramchain_alloc(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,uint32_t numtxids,uint32_t numunspents,uint32_t numspends,uint32_t numpkinds,uint32_t numexternaltxids,uint32_t scriptspace,int32_t height,int32_t numblocks) +int32_t iguana_ramchain_alloc(char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,uint32_t numtxids,uint32_t numunspents,uint32_t numspends,uint32_t numpkinds,uint32_t numexternaltxids,uint32_t scriptspace,int32_t height,int32_t numblocks) { RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; int64_t hashsize,allocsize,x; //B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0; memset(ramchain,0,sizeof(*ramchain)); ramchain->height = height; - allocsize = _iguana_rdata_action(0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks); + allocsize = _iguana_rdata_action(fname,0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks); if ( 0 && ramchain->expanded != 0 ) printf("T.%d U.%d S.%d P.%d X.%d -> %ld\n",numtxids,numunspents,numspends,numpkinds,numexternaltxids,(long)allocsize); memset(mem,0,sizeof(*mem)); @@ -964,7 +967,7 @@ int32_t iguana_ramchain_alloc(struct iguana_info *coin,struct iguana_ramchain *r iguana_meminit(mem,"ramchain",0,allocsize + 65536,0); mem->alignflag = sizeof(uint32_t); hashmem->alignflag = sizeof(uint32_t); - if ( iguana_ramchain_init(ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks) == 0 ) + if ( iguana_ramchain_init(fname,ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks) == 0 ) return(-1); return(0); } @@ -983,7 +986,7 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits return(-1); } OS_compatible_path(fname); - if ( (fp= fopen(fname,"rb+")) == 0 ) + /*if ( (fp= fopen(fname,"rb+")) == 0 ) { if ( (fp= fopen(fname,"wb")) != 0 ) coin->peers.numfiles++; @@ -1005,22 +1008,32 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits printf("iguana_ramchain_save b: couldnt create.(%s)\n",fname); return(-1); } - } + }*/ +#ifdef __PNACL__ + static portable_mutex_t mutex; + portable_mutex_lock(&mutex); +#endif + if ( (fp= fopen(fname,"wb")) == 0 ) + printf("iguana_ramchain_save: couldnt create.(%s) errno.%d\n",fname,errno); + else coin->peers.numfiles++; if ( fp != 0 ) { fpos = ftell(fp); if ( ramchain->expanded != 0 ) - iguana_ramchain_lhashes(RAMCHAIN_ARG,rdata,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset); + iguana_ramchain_lhashes(fname,RAMCHAIN_ARG,rdata,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset); tmp = *rdata; - iguana_ramchain_compact(RAMCHAIN_ARG,&tmp,rdata,bp!=0?bp->n:1); + iguana_ramchain_compact(fname,RAMCHAIN_ARG,&tmp,rdata,bp!=0?bp->n:1); if ( 0 && ramchain->expanded != 0 ) - printf("compact: Koffset.%d scriptoffset.%d stacksize.%d allocsize.%d\n",(int32_t)ramchain->H.data->Koffset,ramchain->H.scriptoffset,ramchain->H.stacksize,(int32_t)ramchain->H.data->allocsize); + printf("compact.%s: Koffset.%d scriptoffset.%d stacksize.%d allocsize.%d\n",fname,(int32_t)ramchain->H.data->Koffset,ramchain->H.scriptoffset,ramchain->H.stacksize,(int32_t)ramchain->H.data->allocsize); fwrite(&tmp,1,sizeof(tmp),fp); - iguana_ramchain_saveaction(RAMCHAIN_ARG,fp,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset); + iguana_ramchain_saveaction(fname,RAMCHAIN_ARG,fp,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset); *rdata = tmp; fclose(fp); } - return(fpos); +#ifdef __PNACL__ + portable_mutex_unlock(&mutex); +#endif + return(fpos); } int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *ramchain) @@ -1375,9 +1388,9 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname } } _iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data); - if ( iguana_ramchain_size(RAMCHAIN_ARG,ramchain->numblocks,ramchain->H.data->scriptspace) != ramchain->H.data->allocsize || fpos+ramchain->H.data->allocsize > filesize ) + if ( iguana_ramchain_size(fname,RAMCHAIN_ARG,ramchain->numblocks,ramchain->H.data->scriptspace) != ramchain->H.data->allocsize || fpos+ramchain->H.data->allocsize > filesize ) { - printf("iguana_ramchain_map.(%s) size mismatch %ld vs %ld vs filesize.%ld numblocks.%d expanded.%d fpos.%d sum %ld\n",fname,(long)iguana_ramchain_size(RAMCHAIN_ARG,ramchain->numblocks,ramchain->H.data->scriptspace),(long)ramchain->H.data->allocsize,(long)filesize,ramchain->numblocks,expanded,(int32_t)fpos,(long)(fpos+ramchain->H.data->allocsize)); + printf("iguana_ramchain_map.(%s) size mismatch %ld vs %ld vs filesize.%ld numblocks.%d expanded.%d fpos.%d sum %ld\n",fname,(long)iguana_ramchain_size(fname,RAMCHAIN_ARG,ramchain->numblocks,ramchain->H.data->scriptspace),(long)ramchain->H.data->allocsize,(long)filesize,ramchain->numblocks,expanded,(int32_t)fpos,(long)(fpos+ramchain->H.data->allocsize)); //exit(-1); munmap(ramchain->fileptr,ramchain->filesize); OS_removefile(fname,0); @@ -1787,7 +1800,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru } sigsize = pubkeysize = 0; scriptspace = 1;//iguana_scriptspaceraw(coin,&scriptsize,&sigsize,&pubkeysize,txarray,txn_count); - if ( iguana_ramchain_init(ramchain,&addr->TXDATA,&addr->HASHMEM,1,txn_count,origtxdata->numunspents,origtxdata->numspends,0,0,(scriptspace+sigsize+pubkeysize)*1.1,0,1) == 0 ) + if ( iguana_ramchain_init(fname,ramchain,&addr->TXDATA,&addr->HASHMEM,1,txn_count,origtxdata->numunspents,origtxdata->numspends,0,0,(scriptspace+sigsize+pubkeysize)*1.1,0,1) == 0 ) { if ( block->fpipbits == 0 ) block->issued = block->RO.recvlen = 0, block->fpos = -1; @@ -1796,6 +1809,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru block->fpos = fpos = -1; iguana_ramchain_link(ramchain,block->RO.hash2,bp->hdrsi,bp->bundleheight+bundlei,bundlei,1,firsti,0); _iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data); + char dirname[1024]; sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_ensure_directory(dirname); //printf("Kspace.%p bp.[%d:%d] <- scriptspace.%d expanded.%d\n",Kspace,bp->hdrsi,bundlei,scriptspace,ramchain->expanded); if ( T == 0 || U == 0 || S == 0 || B == 0 ) { @@ -1829,7 +1843,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru ramchain->H.data->prevhash2 = block->RO.prev_block; ramchain->H.data->scriptspace = scriptspace = ramchain->H.scriptoffset; ramchain->H.data->stackspace = stackspace = ramchain->H.stacksize; - iguana_ramchain_setsize(ramchain,ramchain->H.data,1); + iguana_ramchain_setsize(fname,ramchain,ramchain->H.data,1); flag = 0; if ( ramchain->H.txidind != ramchain->H.data->numtxids || ramchain->H.unspentind != ramchain->H.data->numunspents || ramchain->H.spendind != ramchain->H.data->numspends ) { @@ -2112,7 +2126,7 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru ramchain->H.data->prevhash2 = block->RO.prev_block; ramchain->H.data->scriptspace = scriptoffset; ramchain->H.stacksize = ramchain->H.data->stackspace = stacksize; - iguana_ramchain_setsize(ramchain,ramchain->H.data,bp->n); + iguana_ramchain_setsize(fname,ramchain,ramchain->H.data,bp->n); //printf("Apresave T.%d U.%d S.%d P.%d X.%d -> size.%ld firsti.%d scriptoffset.%d stacksize.%d\n",ramchain->H.data->numtxids,ramchain->H.data->numunspents,ramchain->H.data->numspends,ramchain->H.data->numpkinds,ramchain->H.data->numexternaltxids,(long)ramchain->H.data->allocsize,firsti,ramchain->H.scriptoffset,ramchain->H.stacksize); *newchain = *ramchain; //memcpy(ramchain->roU2,ramchain->U2,sizeof(*ramchain->U2) * ramchain->H.data->numunspents); @@ -2230,7 +2244,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana return(mapchain); } -int64_t iguana_ramchainopen(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2) +int64_t iguana_ramchainopen(char *fname,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *mem,struct OS_memspace *hashmem,int32_t bundleheight,bits256 hash2) { RAMCHAIN_DECLARE; RAMCHAIN_ZEROES; int32_t i,numblocks = coin->chain->bundlesize; uint32_t numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int64_t hashsize,allocsize; //B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0; @@ -2258,7 +2272,7 @@ int64_t iguana_ramchainopen(struct iguana_info *coin,struct iguana_ramchain *ram numunspents *= 2.5, numspends *= 2.5, numpkinds *= 2.5; if ( mem->ptr == 0 ) { - while ( (allocsize= _iguana_rdata_action(0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks)) > 2*1024LL*1024L*1024L ) + while ( (allocsize= _iguana_rdata_action(fname,0,0,0,0,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,0,0,0,0,0,RAMCHAIN_ARG,numblocks)) > 2*1024LL*1024L*1024L ) { numtxids *= .9; numunspents *= .9; @@ -2273,7 +2287,7 @@ int64_t iguana_ramchainopen(struct iguana_info *coin,struct iguana_ramchain *ram hashsize = iguana_hashmemsize(numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace); iguana_meminit(hashmem,coin->symbol,0,hashsize + 65536*3,0); } - if ( iguana_ramchain_init(ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks) > 0 ) + if ( iguana_ramchain_init(fname,ramchain,mem,hashmem,1,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,1,numblocks) > 0 ) { iguana_ramchain_link(ramchain,hash2,bundleheight/coin->chain->bundlesize,bundleheight,0,0,1,0); ramchain->expanded = 1; @@ -2284,7 +2298,7 @@ int64_t iguana_ramchainopen(struct iguana_info *coin,struct iguana_ramchain *ram return(ramchain->H.data->allocsize); } -int32_t iguana_mapchaininit(struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize) +int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize) { int32_t firsti = 1; RAMCHAIN_DECLARE; memset(mapchain,0,sizeof(*mapchain)); @@ -2298,9 +2312,9 @@ int32_t iguana_mapchaininit(struct iguana_info *coin,struct iguana_ramchain *map return(-1); } _iguana_ramchain_setptrs(MAPCHAIN_PTRS,mapchain->H.data); - if ( block->fpos+mapchain->H.data->allocsize > filesize || iguana_ramchain_size(MAPCHAIN_ARG,1,mapchain->H.data->scriptspace) != mapchain->H.data->allocsize ) + if ( block->fpos+mapchain->H.data->allocsize > filesize || iguana_ramchain_size(fname,MAPCHAIN_ARG,1,mapchain->H.data->scriptspace) != mapchain->H.data->allocsize ) { - printf("iguana_mapchaininit.%d ipbits.%x size mismatch %ld vs %ld vs filesize.%ld fpos.%ld bundlei.%d expanded.%d soff.%d\n",bp->bundleheight,block->fpipbits,(long)iguana_ramchain_size(MAPCHAIN_ARG,1,mapchain->H.data->scriptspace),(long)mapchain->H.data->allocsize,(long)filesize,(long)block->fpos,bundlei,mapchain->expanded,mapchain->H.data->scriptspace); + printf("iguana_mapchaininit.%d ipbits.%x size mismatch %ld vs %ld vs filesize.%ld fpos.%ld bundlei.%d expanded.%d soff.%d\n",bp->bundleheight,block->fpipbits,(long)iguana_ramchain_size(fname,MAPCHAIN_ARG,1,mapchain->H.data->scriptspace),(long)mapchain->H.data->allocsize,(long)filesize,(long)block->fpos,bundlei,mapchain->expanded,mapchain->H.data->scriptspace); getchar(); return(-1); } @@ -2360,7 +2374,8 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str fpipbits = block->fpipbits, fpos = block->fpos; mapchain = &R[bundlei]; //printf("mapchain.[%d:%d] %p[%ld]\n",bp->hdrsi,bundlei,ptrs[bundlei],filesizes[bundlei]); - if ( iguana_mapchaininit(coin,mapchain,bp,bundlei,block,ptrs[bundlei],filesizes[bundlei]) < 0 ) + sprintf(fname,"save.%d",bp->hdrsi); + if ( iguana_mapchaininit(fname,coin,mapchain,bp,bundlei,block,ptrs[bundlei],filesizes[bundlei]) < 0 ) break; //printf("done mapchain.[%d:%d]\n",bp->hdrsi,bundlei); numtxids += (mapchain->H.data->numtxids - 1); @@ -2397,7 +2412,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str numexternaltxids = numspends; //printf("E.%d depth.%d start bundle ramchain %d at %u started.%u lag.%d\n",coin->numemitted,depth,bp->bundleheight,now,starttime,now-starttime); depth++; - if ( iguana_ramchain_alloc(coin,dest,mem,&HASHMEM,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace+sigspace,bp->bundleheight+starti,bp_n) < 0 ) + if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,numtxids,numunspents,numspends,numpkinds,numexternaltxids,scriptspace+sigspace,bp->bundleheight+starti,bp_n) < 0 ) { printf("error iguana_ramchain_alloc for bundleheight.%d\n",bp->bundleheight); iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi); @@ -2477,7 +2492,10 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi); if ( retval == 0 )//|| bp->generrs > 3 ) { - char dirname[1024]; + char dirname[1024],*prefix = ""; +#ifdef __PNACL__ + prefix = ""; +#endif //printf("delete %d files hdrs.%d retval.%d\n",num,bp->hdrsi,retval); if ( bp_n == bp->n && bp->n == coin->chain->bundlesize && bp->hdrsi < coin->bundlescount-3 ) { @@ -2487,7 +2505,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str coin->peers.numfiles -= OS_removefile(fname,0); else printf("error removing.(%s)\n",fname); } - sprintf(dirname,"%s/%s/%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_portable_rmdir(dirname,1); + sprintf(dirname,"%s%s/%s/%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight), OS_portable_rmdir(dirname,1); } sleep(1); iguana_bundleload(coin,&newchain,bp,0); @@ -2516,7 +2534,7 @@ void iguana_mergefree(struct iguana_info *coin,struct OS_memspace *mem,struct ig iguana_mempurge(hashmemB); } -int32_t iguana_bundlemergeHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime) +int32_t iguana_bundlemergeHT(char *fname,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime) { static int32_t depth; static const bits256 zero; RAMCHAIN_DESTDECLARE; struct OS_memspace HASHMEM,HASHMEMA,HASHMEMB; @@ -2545,7 +2563,7 @@ int32_t iguana_bundlemergeHT(struct iguana_info *coin,struct OS_memspace *mem,st } if ( A->H.data != 0 && B->H.data != 0 && B->height == A->height+A->numblocks ) { - if ( iguana_ramchain_alloc(coin,dest,mem,&HASHMEM,(A->H.data->numtxids+B->H.data->numtxids),(A->H.data->numunspents+B->H.data->numunspents),(A->H.data->numspends+B->H.data->numspends),(A->H.data->numpkinds+B->H.data->numpkinds),(A->H.data->numexternaltxids+B->H.data->numexternaltxids),A->H.data->scriptspace,A->height,A->numblocks + B->numblocks) < 0 ) + if ( iguana_ramchain_alloc(fname,coin,dest,mem,&HASHMEM,(A->H.data->numtxids+B->H.data->numtxids),(A->H.data->numunspents+B->H.data->numunspents),(A->H.data->numspends+B->H.data->numspends),(A->H.data->numpkinds+B->H.data->numpkinds),(A->H.data->numexternaltxids+B->H.data->numexternaltxids),A->H.data->scriptspace,A->height,A->numblocks + B->numblocks) < 0 ) { printf("depth.%d ht.%d fsize.%s ERROR alloc lag.%d elapsed.%ld\n",depth,dest->height,mbstr(str,dest->H.data->allocsize),now-starttime,time(NULL)-now); iguana_mergefree(coin,mem,A,B,&HASHMEM,&HASHMEMA,&HASHMEMB); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index ca42b9647..49743a8e4 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -833,7 +833,7 @@ void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp) struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct iguana_bundlereq *req,bits256 *blockhashes,int32_t num) { - int32_t bundlei,i,len,starti; struct iguana_bundle *bp; bits256 allhash,zero; uint8_t serialized[512]; struct iguana_peer *addr; struct iguana_block *block; char str[65],str2[65]; + int32_t bundlei,i,starti; struct iguana_bundle *bp; bits256 allhash,zero; struct iguana_peer *addr; struct iguana_block *block; char str[65],str2[65]; // uint8_t serialized[512]; memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); @@ -846,7 +846,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct bp->dirty++; bp->hdrtime = (uint32_t)time(NULL); blockhashes[0] = bp->hashes[0]; - iguana_blockQ("recvhash0",coin,bp,0,blockhashes[0],1); + //iguana_blockQ("recvhash0",coin,bp,0,blockhashes[0],1); if ( num >= coin->chain->bundlesize ) { if ( bits256_nonz(bp->nextbundlehash2) == 0 && num > coin->chain->bundlesize ) @@ -913,8 +913,8 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct if ( iguana_allhashcmp(coin,bp,blockhashes,coin->chain->bundlesize) > 0 ) { bp->hdrtime = (uint32_t)time(NULL); - iguana_blockQ("recvhash2",coin,bp,1,blockhashes[1],1); - iguana_blockQ("recvhash3",coin,bp,0,blockhashes[0],1); + //iguana_blockQ("recvhash2",coin,bp,1,blockhashes[1],1); + //iguana_blockQ("recvhash3",coin,bp,0,blockhashes[0],1); //iguana_blockQ("recvhash4",coin,bp,coin->chain->bundlesize-1,blockhashes[coin->chain->bundlesize-1],0); //printf("matched bundle.%d\n",bp->bundleheight); return(req); @@ -929,14 +929,14 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct //block->blockhashes = blockhashes, req->hashes = 0; //printf("set block->blockhashes[%d]\n",num); } - if ( (addr= coin->peers.ranked[0]) != 0 ) + /*if ( (addr= coin->peers.ranked[0]) != 0 ) { if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&blockhashes[1],1)) > 0 ) { iguana_send(coin,addr,serialized,len); //char str[65]; printf("REQ.%s\n",bits256_str(str,blockhashes[1])); } - } + }*/ iguana_blockQ("hdr1",coin,0,-1,blockhashes[1],1); } else @@ -944,8 +944,8 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct if ( (block= iguana_blockfind("recvhashes2",coin,blockhashes[1])) == 0 ) { iguana_blockhashset("recvhashes3",coin,-1,blockhashes[1],1); - if ( (block= iguana_blockfind("recvhashes4",coin,blockhashes[1])) != 0 ) - iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],1); // should be RT block + //if ( (block= iguana_blockfind("recvhashes4",coin,blockhashes[1])) != 0 ) + // iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],1); // should be RT block } block->newtx = 1; iguana_blockQ("RTblock",coin,0,-7,blockhashes[1],1); // should be RT block @@ -1451,8 +1451,8 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr) flag++; } //else printf("skip hdrreq.%s m.%d z.%d bp.%p longest.%d queued.%d\n",hashstr,m,z,bp,bp->coin->longestchain,bp->queued); } - free_queueitem(hashstr); - return(flag); + //free_queueitem(hashstr); + //return(flag); } else printf("datalen.%d from gethdrs\n",datalen); free_queueitem(hashstr); hashstr = 0; @@ -1518,20 +1518,26 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded char str[2000]; hwmheight = coin->blocks.hwmchain.height; coin->RTramchain_busy = 1; + //printf("recvQ\n"); flag += iguana_processrecvQ(coin,&newhwm); + //printf("reqhdrs\n"); flag += iguana_reqhdrs(coin); if ( coin->RTheight != 0 ) { if ( time(NULL) > coin->laststats+5 ) { + //printf("reqblocks\n"); flag += iguana_reqblocks(coin); + //printf("bundlestats\n"); iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); coin->laststats = (uint32_t)time(NULL); } } else { + //printf("reqblocks\n"); flag += iguana_reqblocks(coin); + //printf("bundlestats\n"); iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); } //printf("call _iguana_chainlink\n"); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 6f34b4b76..247caafc2 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -1373,8 +1373,11 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle) int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi) { int32_t hdrsi,numpkinds,iter,numhdrsi,i,numunspents,err; struct iguana_bundle *bp; - char fname[1024],fname2[1024],destfname[1024]; bits256 balancehash,allbundles; FILE *fp,*fp2; + char fname[1024],fname2[1024],destfname[1024],*prefix=""; bits256 balancehash,allbundles; FILE *fp,*fp2; struct iguana_utxo *Uptr; struct iguana_account *Aptr; struct sha256_vstate vstate,bstate; +#ifdef __PNACL__ + prefix = ""; +#endif vupdate_sha256(balancehash.bytes,&vstate,0,0); /*for (hdrsi=0; hdrsibundlescount; hdrsi++) if ( (bp= coin->bundles[hdrsi]) == 0 || bp->balancefinish <= 1 || bp->ramchain.H.data == 0 || bp->ramchain.A == 0 || bp->ramchain.Uextras == 0 ) @@ -1393,8 +1396,8 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi) numunspents = numpkinds = 0; if ( (bp= coin->bundles[hdrsi]) != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (numunspents= bp->ramchain.H.data->numunspents) > 0 && (Aptr= bp->ramchain.A) != 0 && (Uptr= bp->ramchain.Uextras) != 0 ) { - sprintf(fname,"%s/%s/%d/debits.N%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight,numhdrsi); - sprintf(fname2,"%s/%s/%d/lastspends.N%d",GLOBALTMPDIR,coin->symbol,bp->bundleheight,numhdrsi); + sprintf(fname,"%s%s/%s/%d/debits.N%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight,numhdrsi); + sprintf(fname2,"%s%s/%s/%d/lastspends.N%d",prefix,GLOBALTMPDIR,coin->symbol,bp->bundleheight,numhdrsi); if ( iter == 0 ) { vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr)*numpkinds); @@ -1641,7 +1644,7 @@ void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest, char fname[1024]; long filesize; int32_t err; void *ptr; if ( block == bp->blocks[bundlei] && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 ) { - if ( iguana_mapchaininit(coin,R,bp,bundlei,block,ptr,filesize) == 0 ) + if ( iguana_mapchaininit(fname,coin,R,bp,bundlei,block,ptr,filesize) == 0 ) { if ( dest != 0 ) err = iguana_ramchain_iterate(coin,dest,R,bp,bundlei); @@ -1659,7 +1662,7 @@ void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest, return(0); } -void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp) +void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp) { uint32_t i,changed = 0; struct iguana_ramchain *dest = &coin->RTramchain; struct iguana_blockRO *B; if ( dest->H.data != 0 ) @@ -1688,7 +1691,7 @@ void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp) if ( coin->RTramchain.H.data == 0 ) { printf("ALLOC RTramchain\n"); - iguana_ramchainopen(coin,dest,&coin->RTmem,&coin->RThashmem,bp->bundleheight,bp->hashes[0]); + iguana_ramchainopen(fname,coin,dest,&coin->RTmem,&coin->RThashmem,bp->bundleheight,bp->hashes[0]); dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti; dest->externalind = dest->H.stacksize = 0; dest->H.scriptoffset = 1; @@ -1799,7 +1802,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin) printf("RTheaders %s\n",coin->symbol); } bp->lastRT = (uint32_t)time(NULL); - iguana_RTramchainalloc(coin,bp); + iguana_RTramchainalloc("RTbundle",coin,bp); bp->isRT = 1; while ( (rdata= coin->RTramchain.H.data) != 0 && coin->RTheight <= coin->blocks.hwmchain.height ) { diff --git a/iguana/main.c b/iguana/main.c index ed6e6e239..7cf28d9e3 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -58,13 +58,14 @@ int32_t Showmode,Autofold,PANGEA_MAXTHREADS = 1; struct category_info *Categories; struct iguana_info *Coins[IGUANA_MAXCOINS]; -char Userhome[512],GLOBALTMPDIR[512] = "tmp"; +char Userhome[512]; int32_t USE_JAY,FIRST_EXTERNAL,IGUANA_disableNXT,Debuglevel,BIGENDIAN; uint32_t prices777_NXTBLOCK,MAX_DEPTH = 100; queue_t helperQ,jsonQ,finishedQ,bundlesQ,validateQ,emitQ,TerminateQ; struct supernet_info MYINFO,**MYINFOS; static int32_t initflag; int32_t HDRnet,netBLOCKS; +char GLOBALTMPDIR[512] = "tmp"; cJSON *API_json; #ifdef __linux__ int32_t IGUANA_NUMHELPERS = 8; @@ -1197,15 +1198,19 @@ void iguana_commandline(struct supernet_info *myinfo,char *arg) void iguana_ensuredirs() { - OS_ensure_directory("help"); - OS_ensure_directory("confs"); - OS_ensure_directory("DB"); - OS_ensure_directory("DB/ECB"); - OS_ensure_directory("tmp"); - OS_ensure_directory("purgeable"); - OS_ensure_directory("purgeable/BTC"); - OS_ensure_directory("purgeable/BTCD"); - OS_ensure_directory(GLOBALTMPDIR); + char dirname[512],*prefix = ""; +#ifdef __PNACL__ + prefix = ""; +#endif + sprintf(dirname,"%shelp",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%sconfs",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%sDB/ECB",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%stmp",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%spurgeable",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%spurgeable/BTC",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%spurgeable/BTCD",prefix), OS_ensure_directory(dirname); + sprintf(dirname,"%s%s",prefix,GLOBALTMPDIR), OS_ensure_directory(dirname); } void iguana_Qinit() diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index c671f20c5..2d9cc263d 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -40,28 +40,31 @@ STRING_ARG(iguana,validate,activecoin) STRING_ARG(iguana,removecoin,activecoin) { - struct iguana_bundle *bp; int32_t i; char fname[1024]; + struct iguana_bundle *bp; int32_t i; char fname[1024],*prefix = ""; +#ifdef __PNACL__ + prefix = "/"; +#endif if ( (coin= iguana_coinfind(activecoin)) != 0 ) { coin->active = 0; coin->started = 0; for (i=0; isymbol,i), OS_removefile(fname,0); - sprintf(fname,"purgeable/%s/%04d.vins",coin->symbol,i), OS_removefile(fname,0); + sprintf(fname,"%sDB/%s/vouts/%04d.vouts",prefix,coin->symbol,i), OS_removefile(fname,0); + sprintf(fname,"%spurgeable/%s/%04d.vins",prefix,coin->symbol,i), OS_removefile(fname,0); } - sprintf(fname,"DB/%s/vouts/*",coin->symbol), OS_removefile(fname,0); - sprintf(fname,"purgeable/%s/*",coin->symbol), OS_removefile(fname,0); + sprintf(fname,"%sDB/%s/vouts/*",prefix,coin->symbol), OS_removefile(fname,0); + sprintf(fname,"%s%s/%s/*",prefix,coin->VALIDATEDIR,coin->symbol), OS_removefile(fname,0); for (i=0; ibundlescount; i++) { - sprintf(fname,"DB/%s/balancecrc.%d",coin->symbol,i), OS_removefile(fname,0); + sprintf(fname,"%sDB/%s/balancecrc.%d",prefix,coin->symbol,i), OS_removefile(fname,0); if ( (bp= coin->bundles[i]) != 0 ) { iguana_bundlepurgefiles(coin,bp); iguana_bundleremove(coin,bp->hdrsi); } } - sprintf(fname,"DB/%s/*",coin->symbol), OS_removefile(fname,0); + sprintf(fname,"%sDB/%s/*",prefix,coin->symbol), OS_removefile(fname,0); } return(clonestr("{\"error\":\"no active coin\"}")); }