Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
3f7d849de9
  1. 7
      iguana/SuperNET.c
  2. 45
      iguana/iguana777.c
  3. 36
      iguana/iguana777.h
  4. 72
      iguana/iguana_accept.c
  5. 40
      iguana/iguana_bundles.c
  6. 38
      iguana/iguana_init.c
  7. 82
      iguana/iguana_msg.c
  8. 42
      iguana/iguana_ramchain.c
  9. 49
      iguana/iguana_tx.c
  10. 218
      iguana/iguana_unspents.c
  11. 15
      iguana/main.c
  12. 9
      iguana/ramchain_api.c
  13. 2
      includes/iguana_apideclares.h

7
iguana/SuperNET.c

@ -1267,9 +1267,14 @@ STRING_ARG(SuperNET,wif2priv,wif)
return(jprint(retjson,1));
}
ZERO_ARGS(SuperNET,myipaddr)
STRING_ARG(SuperNET,myipaddr,ipaddr)
{
cJSON *retjson = cJSON_CreateObject();
if ( myinfo->ipaddr[0] == 0 )
{
if ( is_ipaddr(ipaddr) != 0 )
strcpy(myinfo->ipaddr,ipaddr);
}
jaddstr(retjson,"result",myinfo->ipaddr);
return(jprint(retjson,1));
}

45
iguana/iguana777.c

@ -376,17 +376,23 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
return(-1);
if ( coin->PREFETCHLAG > 0 )
iguana_ramchain_prefetch(coin,&bp->ramchain,0);
iguana_bundlevalidate(coin,bp,0);
if ( (retval= iguana_spendvectors(coin,bp,&bp->ramchain,0,bp->n,convertflag)) >= 0 )
if ( iguana_bundlevalidate(coin,bp,0) == bp->n )
{
if ( retval > 0 )
if ( (retval= iguana_spendvectors(coin,bp,&bp->ramchain,0,bp->n,convertflag)) >= 0 )
{
printf("GENERATED UTXO.%d for ht.%d duration %d seconds\n",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL) - bp->startutxo);
num++;
} // else printf("null retval from iguana_spendvectors.[%d]\n",bp->hdrsi);
bp->utxofinish = (uint32_t)time(NULL);
//iguana_balancesQ(coin,bp);
} else printf("UTXO gen.[%d] utxo error\n",bp->hdrsi);
if ( retval > 0 )
{
printf("GENERATED UTXO.%d for ht.%d duration %d seconds\n",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL) - bp->startutxo);
num++;
}
bp->utxofinish = (uint32_t)time(NULL);
} else printf("UTXO gen.[%d] utxo error\n",bp->hdrsi);
}
else
{
printf("validate.[%d] error. just refresh page or restart iguana\n",bp->hdrsi);
exit(-1);
}
}
while ( (n= iguana_utxofinished(coin)) < max )
{
@ -399,7 +405,13 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
{
if ( (bp= coin->bundles[hdrsi]) == 0 )
return(-1);
iguana_convert(coin,bp,0);
if ( bp != coin->current )
{
iguana_ramchain_prefetch(coin,&bp->ramchain,0);
bp->converted = 1;
iguana_convert(coin,helperid,bp,0,0);
bp->converted = (uint32_t)time(NULL);
}
}
}
if ( helperid == 0 )
@ -428,7 +440,10 @@ int32_t iguana_utxogen(struct iguana_info *coin,int32_t helperid,int32_t convert
printf("validated.%d of %d\n",n,max);
}
for (; hdrsi<max; hdrsi++,coin->balanceswritten++)
iguana_balancegen(coin,0,coin->bundles[hdrsi],0,coin->chain->bundlesize-1);
{
iguana_ramchain_prefetch(coin,&coin->bundles[hdrsi]->ramchain,0);
iguana_balancegen(coin,0,coin->bundles[hdrsi],0,coin->chain->bundlesize-1,0);
}
if ( iguana_balanceflush(coin,max) > 0 )
printf("balanceswritten.%d flushed bp->hdrsi %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,bp->hdrsi,coin->longestchain/coin->chain->bundlesize);
} else printf("error saving spendvectors\n");
@ -665,7 +680,7 @@ 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) ? 64 : 8;
mult = (strcmp("BTC",coin->symbol) != 0) ? 8 : 8;
maxval = IGUANA_MAXPENDBUNDLES;
coin->MAXMEM = juint(json,"RAM");
if ( jobj(json,"prefetchlag") != 0 )
@ -679,9 +694,9 @@ struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,
// maxval = (int32_t)coin->MAXMEM;
coin->MAXMEM *= (1024L * 1024 * 1024);
#ifdef __PNACL__
//maxval = 2 * (strcmp("BTC",coin->symbol) != 0) + 2;
if ( mult > 1 )
mult /= 2;
//maxval = 8;// * (strcmp("BTC",coin->symbol) != 0) + 8;
//if ( mult > 1 )
// mult /= 2;
#endif
if ( (coin->startPEND= juint(json,"startpend")) == 0 )
coin->startPEND = IGUANA_MAXPENDBUNDLES*mult;

36
iguana/iguana777.h

@ -26,11 +26,7 @@ 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 777
#else
#define IGUANA_MAXITERATIONS 3333
#endif
#define IGUANA_MAXITERATIONS 10000
#define IGUANA_DEFAULTLAG 30
#define IGUANA_MAXCOINS 64
@ -47,10 +43,14 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t
#define IGUANA_TAILPERCENTAGE 1.0
#define IGUANA_MAXPENDHDRS 1
#define IGUANA_MAXPENDINGREQUESTS 8
#define IGUANA_PENDINGREQUESTS 8
#define IGUANA_PENDINGREQUESTS 64
#define IGUANA_MINPENDBUNDLES 4
#define IGUANA_MAXPENDBUNDLES 32
#define IGUANA_MAXPENDBUNDLES 64
#ifdef __APPLE__
#define IGUANA_RPCPORT 7779
#else
#define IGUANA_RPCPORT 7778
#endif
#define IGUANA_MAXRAMCHAINSIZE ((uint64_t)1024L * 1024L * 1024L * 16)
#define IGUANA_MAPHASHTABLES 1
@ -80,7 +80,7 @@ struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpo
#define IGUANA_DEDICATED_THREADS
#ifdef IGUANA_DEDICATED_THREADS
#define IGUANA_MAXCONNTHREADS 16
#define IGUANA_MAXCONNTHREADS IGUANA_MINPEERS
#define IGUANA_MAXSENDTHREADS (IGUANA_MAXPEERS>>2)
#define IGUANA_MAXRECVTHREADS (IGUANA_MAXPEERS>>2)
#else
@ -89,6 +89,7 @@ struct iguana_txdatabits { uint64_t addrind:IGUANA_LOG2MAXPEERS,filecount:10,fpo
#define IGUANA_MAXRECVTHREADS 16
#endif
#define IGUANA_SUBDIRDIVISOR 28000
#ifdef __PNACL
void PNACL_message(const char* format, ...);
@ -343,7 +344,7 @@ struct iguana_txid { bits256 txid; uint32_t txidind:29,firstvout:28,firstvin:28,
struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos; uint16_t scriptlen,hdrsi; uint16_t fileid:11,type:5; int16_t vout; } __attribute__((packed));
struct iguana_spend { uint32_t spendtxidind,sequenceid,scriptpos; int16_t prevout; uint16_t fileid,scriptlen:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4
struct iguana_spend { uint32_t spendtxidind,sequenceid,scriptpos; int16_t prevout; uint16_t fileid,scriptlen:14,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4
struct iguana_pkhash { uint8_t rmd160[20]; uint32_t pkind; } __attribute__((packed)); //firstunspentind,pubkeyoffset
@ -405,8 +406,8 @@ struct iguana_peer
struct iguana_msgaddress A;
char ipaddr[64],lastcommand[16],coinstr[16],symbol[16];
uint64_t pingnonce,totalsent,totalrecv,ipbits; double pingtime,sendmillis,pingsum,getdatamillis;
uint32_t lastcontact,sendtime,ready,startsend,startrecv,pending,lastgotaddr,lastblockrecv,pendtime,lastflush,lastpoll,myipbits,persistent_peer;
int32_t supernet,dead,addrind,usock,lastheight,protover,relayflag,numpackets,numpings,ipv6,height,rank,pendhdrs,pendblocks,recvhdrs,lastlefti,validpub,othervalid,dirty[2],laggard;
uint32_t lastcontact,sendtime,ready,startsend,startrecv,pending,lastgotaddr,lastblockrecv,pendtime,lastflush,lastpoll,myipbits,persistent_peer,protover;
int32_t supernet,dead,addrind,usock,lastheight,relayflag,numpackets,numpings,ipv6,height,rank,pendhdrs,pendblocks,recvhdrs,lastlefti,validpub,othervalid,dirty[2],laggard;
double recvblocks,recvtotal;
int64_t allocated,freed;
bits256 RThashes[IGUANA_MAXBUNDLESIZE]; int32_t numRThashes;
@ -755,7 +756,7 @@ cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly);
int32_t btc_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype);
int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]);
int32_t iguana_launchcoin(char *symbol,cJSON *json);
bits256 iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1);
int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1);
int32_t iguana_jsonQ();
int32_t is_bitcoinrpc(struct supernet_info *myinfo,char *method,char *remoteaddr);
char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port);
@ -814,7 +815,7 @@ int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint3
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_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag);
int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight);
int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight,int32_t startemit);
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag);
void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp);
struct iguana_bloominds iguana_calcbloom(bits256 hash2);
@ -858,13 +859,10 @@ int32_t bitcoin_pubkeylen(const uint8_t *pubkey);
struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p,struct iguana_bundle *bp,int32_t i);
void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block);
int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block);
//void iguana_convertQ(struct iguana_info *coin,struct iguana_bundle *bp);
void iguana_convert(struct iguana_info *coin,struct iguana_bundle *bp,int32_t RTflag);//,struct iguana_ramchain *ramchain);
int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_bundle *bp,int32_t RTflag,int32_t starti);
int32_t iguana_bundleissuemissing(struct iguana_info *coin,struct iguana_bundle *bp,int32_t priority,double mult);
//int32_t iguana_blocksmissing(struct iguana_info *coin,int32_t *nonzp,uint8_t missings[IGUANA_MAXBUNDLESIZE/8+1],bits256 hashes[],double mult,struct iguana_bundle *bp,int32_t capacity);
FILE *myfopen(char *fname,char *mode);
int32_t myfclose(FILE *fp);
//void iguana_prefetch(struct iguana_info *coin,struct iguana_bundle *bp,int32_t width,int32_t flags);
int32_t iguana_walkchain(struct iguana_info *coin,int32_t skipflag);
struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight);
int32_t iguana_balancenormal(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight);
@ -875,9 +873,11 @@ int32_t iguana_utxofinished(struct iguana_info *coin);
int32_t iguana_balancefinished(struct iguana_info *coin);
int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain);
void iguana_allocvolatile(struct iguana_info *coin,struct iguana_ramchain *ramchain);
int32_t iguana_rwaddr(int32_t rwflag,uint8_t *serialized,struct iguana_msgaddress *addr,int32_t protover);
int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2);
int32_t iguana_peerinvdata(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max);
int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max);
int32_t iguana_peerinvrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max);
int32_t iguana_bundlefname(struct iguana_info *coin,struct iguana_bundle *bp,char *fname);
int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfiles);
int32_t iguana_voutsfname(struct iguana_info *coin,char *fname,int32_t slotid);

72
iguana/iguana_accept.c

@ -164,3 +164,75 @@ int32_t iguana_pendingaccept(struct iguana_info *coin)
}
return(0);
}*/
int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2)
{
struct iguana_txid *tx,T; int32_t len=0,i,height,retval=-1; struct iguana_block *block; struct iguana_msgblock msgB; uint8_t *serialized; bits256 checkhash2;
if ( (tx= iguana_txidfind(coin,&height,&T,hash2,coin->bundlescount-1)) != 0 )
{
serialized = calloc(coin->chain->bundlesize,sizeof(msgB));
for (i=0; i<coin->chain->bundlesize; i++)
{
if ( (block= iguana_blockptr("peerhdr",coin,height + i)) != 0 )
{
iguana_blockunconv(&msgB,block,1);
len += iguana_rwblock(1,&checkhash2,&serialized[sizeof(struct iguana_msghdr) + len],&msgB);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{
char str[65],str2[65];
printf("iguana_peerhdrrequest blockhash.%d error (%s) vs (%s)\n",height+i,bits256_str(str,checkhash2),bits256_str(str2,block->RO.hash2));
free(serialized);
return(-1);
}
}
}
if ( i == coin->chain->bundlesize || (i > 0 && height/coin->chain->bundlesize >= coin->blocks.hwmchain.height/coin->chain->bundlesize) )
retval = iguana_queue_send(coin,addr,0,serialized,"headers",len,0,0);
free(serialized);
}
return(retval);
}
int32_t iguana_peerinvrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max)
{
int32_t i,type,len = 0; uint64_t x; struct iguana_bundle *bp;
x = coin->bundlescount;
len += iguana_rwvarint(1,&space[sizeof(struct iguana_msghdr) + len],&x);
for (i=0; i<x; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
type = MSG_BLOCK;
len += iguana_rwnum(1,&space[sizeof(struct iguana_msghdr) + len],sizeof(uint32_t),&type);
len += iguana_rwbignum(1,&space[sizeof(struct iguana_msghdr) + len],sizeof(bits256),bp->hashes[0].bytes);
}
}
return(len);
}
int32_t iguana_peeraddrrequest(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t spacesize)
{
int32_t i,iter,n,max,sendlen; uint64_t x; struct iguana_msghdr H; struct iguana_msgaddress A; struct iguana_peer *tmpaddr;
sendlen = 0;
max = (IGUANA_MINPEERS + IGUANA_MAXPEERS) / 2;
if ( max > coin->peers.numranked )
max = coin->peers.numranked;
x = 0;
sendlen = iguana_rwvarint(1,&space[sizeof(H)],&x);
for (iter=0; iter<2; iter++)
{
for (i=n=0; i<max; i++)
{
memset(&A,0,sizeof(A));
if ( (tmpaddr= coin->peers.ranked[i]) != 0 && ((iter == 0 && tmpaddr->supernet != 0) || (iter == 1 && tmpaddr->supernet == 0)) )
{
sendlen += iguana_rwaddr(1,&space[sizeof(H) + sendlen],&tmpaddr->A,(int32_t)tmpaddr->protover);
x++;
}
}
}
sendlen = iguana_rwvarint(1,&space[sizeof(H)],&x);
printf("addrrequest: sendlen.%d x.%d\n",sendlen,(int32_t)x);
return(sendlen);
}

40
iguana/iguana_bundles.c

@ -751,13 +751,17 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int
}
else
//#endif
iguana_blockunmark(coin,block,bp,i,0);
iguana_blockunmark(coin,block,bp,i,1);
}
}
else if ( bp->queued != 0 )
else
{
printf("error getting block (%d:%d) %p\n",bp->hdrsi,i,block);
return(-1);
iguana_blockunmark(coin,block,bp,i,0);
if ( bp->queued != 0 )
{
printf("error getting block (%d:%d) %p\n",bp->hdrsi,i,block);
return(-1);
}
}
}
return(ready);
@ -880,12 +884,12 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int
}
/*int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp)
{
struct iguana_bundle *prevbp; int32_t i;
#ifdef IGUANA_SERIALIZE_SPENDVECTORGEN
if ( ((prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)) || coin->numemit < prevbp->hdrsi )
return(0);
#endif
{
struct iguana_bundle *prevbp; int32_t i;
#ifdef IGUANA_SERIALIZE_SPENDVECTORGEN
if ( ((prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)) || coin->numemit < prevbp->hdrsi )
return(0);
#endif
for (i=0; i<bp->hdrsi; i++)
if ( (prevbp= coin->bundles[i]) == 0 || prevbp->emitfinish <= 1 || (prevbp->utxofinish == 0 && prevbp->tmpspends == 0) )
break;
@ -921,9 +925,10 @@ int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp,
return(0);
}
bp->emitfinish = 1;
sleep(2); // make sure new incoming packet didnt overwrite
sleep(1); // make sure new incoming packet didnt overwrite
if ( iguana_bundleready(coin,bp,1) == bp->n )
{
sleep(1); // make sure new incoming packet didnt overwrite
coin->emitbusy++;
if ( iguana_bundlesaveHT(coin,mem,memB,bp,(uint32_t)time(NULL)) == 0 )
{
@ -950,8 +955,14 @@ int32_t iguana_bundlefinalize(struct iguana_info *coin,struct iguana_bundle *bp,
bp->emitfinish = 0;
printf("interloper! [%d] save interupted, will retry next iteration\n",bp->hdrsi);
}
return(1);
}
else
{
printf("bundlefinalize.[%d] not ready\n",bp->hdrsi);
iguana_bundleremove(coin,bp->hdrsi,1);
}
return(1);
return(0);
}
int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,int32_t timelimit,int32_t lag)
@ -976,13 +987,14 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
iguana_autoextend(coin,bp);
if ( 0 && bp->hdrsi == 0 )
printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->utxofinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount);
bp->nexttime = (uint32_t)time(NULL) + cbrt(bp->hdrsi - starti)/10;
bp->nexttime = (uint32_t)time(NULL) + ((bp->hdrsi > starti) ? cbrt(bp->hdrsi - starti)/10 : 0);
if ( bp->hdrsi == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->bundleheight < coin->longestchain-coin->chain->bundlesize) )
iguana_bundlehdr(coin,bp,starti);
else if ( bp->emitfinish == 0 && bp->numsaved >= bp->n )
{
if ( iguana_bundlefinalize(coin,bp,mem,memB) >= 0 )
if ( iguana_bundlefinalize(coin,bp,mem,memB) > 0 )
return(0);
else printf("bundlefinalize not done.[%d]\n",bp->hdrsi);
retval = 1;
}
else if ( bp->hdrsi == starti || (bp->hdrsi >= starti && bp->hdrsi <= starti+range) )

38
iguana/iguana_init.c

@ -191,7 +191,7 @@ int32_t iguana_savehdrs(struct iguana_info *coin)
return(retval);
}
bits256 iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1)
int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1)
{
char str[65]; struct iguana_block *block;
bp->bundleheight = height;
@ -212,6 +212,7 @@ bits256 iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,i
{
if ( coin->current != 0 && coin->current->hdrsi+1 == bp->hdrsi )
coin->current = bp;
return(0);
}
else
{
@ -220,13 +221,14 @@ bits256 iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,i
iguana_blockQ("init",coin,bp,0,hash2,1);
//printf("init reqhdrs.%d\n",bp->bundleheight);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(str),1);
memset(&hash2,0,sizeof(hash2));
return(-1);
}
return(hash2);
}
void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
{
int32_t j,k,m,c,height,flag,bundlei; char checkstr[1024],line[1024];
int32_t j,k,m,c,flag,bundlei,lastheight,height = -1; char checkstr[1024],line[1024];
struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,hash1,zero,lastbundle;
memset(&zero,0,sizeof(zero));
lastbundle = zero;
@ -282,6 +284,9 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
}
else
{
lastheight = height = -1;
if ( coin->bundlescount > 0 && (bp= coin->bundles[coin->bundlescount - 1]) != 0 )
lastheight = bp->bundleheight, lastbundle = bp->hashes[0];
for (k=height=0; k<j-1; k++)
{
if ( (c= line[k]) == ' ' )
@ -323,7 +328,11 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
printf("mismatched allhash.[%d]\n",bp->hdrsi);
bp->allhash = allhash;
}
lastbundle = iguana_bundleinitmap(coin,bp,height,hash2,hash1);
if ( height > lastheight )
{
if ( iguana_bundleinitmap(coin,bp,height,hash2,hash1) == 0 )
lastbundle = hash2, lastheight = height;
}
}
}
}
@ -332,7 +341,10 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
memset(line,0,sizeof(line));
}
if ( iter == 1 && bits256_nonz(lastbundle) != 0 )
{
printf("parseline ht.%d\n",lastheight);
iguana_initfinal(coin,lastbundle);
}
}
void iguana_ramchainpurge(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain)
@ -483,7 +495,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
for (j=0; j<num; j++)
{
//printf("%s ",ipaddrs[j]);
if ( j < IGUANA_MINPEERS )
if ( 0 && j < IGUANA_MINPEERS )
iguana_launchpeer(coin,ipaddrs[j]);
else iguana_possible_peer(coin,ipaddrs[j]);
}
@ -494,8 +506,8 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
#include "confs/BTCD_hdrs.h"
if ( strcmp(coin->symbol,"BTCD") == 0 )
{
bits256 hash2,allhash,hash1; int32_t bundlei,i,height; struct iguana_bundle *bp;
for (i=0; i<sizeof(BTCD_hdrs)/sizeof(*BTCD_hdrs); i++)
bits256 hash2,allhash,hash1; int32_t bundlei,i,nonz,height; struct iguana_bundle *bp;
for (i=nonz=0; i<sizeof(BTCD_hdrs)/sizeof(*BTCD_hdrs); i++)
{
height = atoi(BTCD_hdrs[i][0]);
if ( height > (coin->blocks.maxbits - 1000) )
@ -506,11 +518,15 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
if ( BTCD_hdrs[i][3][0] != 0 )
hash1 = bits256_conv(BTCD_hdrs[i][3]);
if ( (bp= iguana_bundlecreate(coin,&bundlei,height,hash2,allhash,0)) != 0 )
lastbundle = iguana_bundleinitmap(coin,bp,height,hash2,hash1);
{
if ( iguana_bundleinitmap(coin,bp,height,hash2,hash1) == 0 )
lastbundle = hash2, nonz++;
}
}
if ( bits256_nonz(lastbundle) != 0 )
iguana_initfinal(coin,lastbundle);
break;
printf("H file.[%d] nonz.%d\n",i,nonz);
//if ( bits256_nonz(lastbundle) != 0 )
// iguana_initfinal(coin,lastbundle);
//break;
}
}
#endif

82
iguana/iguana_msg.c

@ -191,7 +191,7 @@ int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,ui
msg.nServices = myservices;
msg.nTime = (int64_t)time(NULL);
msg.nonce = coin->instance_nonce;
sprintf(msg.strSubVer,"/Satoshi:0.12.0/");
sprintf(msg.strSubVer,"/Satoshi:0.10.0/");
msg.nStartingHeight = coin->blocks.hwmchain.height;
iguana_gotdata(coin,addr,msg.nStartingHeight);
len = iguana_rwversion(1,&serialized[sizeof(struct iguana_msghdr)],&msg,addr->ipaddr,0);
@ -242,14 +242,15 @@ void iguana_gotaddr(struct iguana_info *coin,struct iguana_peer *addr,struct igu
void iguana_gotping(struct iguana_info *coin,struct iguana_peer *addr,uint64_t nonce,uint8_t *data)
{
int32_t len; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(nonce)];
int32_t len; char myipaddr[64]; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(nonce)];
len = iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr)],sizeof(uint64_t),&nonce);
if ( memcmp(data,&serialized[sizeof(struct iguana_msghdr)],sizeof(nonce)) != 0 )
printf("ping ser error %llx != %llx\n",(long long)nonce,*(long long *)data);
iguana_queue_send(coin,addr,0,serialized,"pong",len,0,0);
if ( addr->supernet != 0 )
{
printf("send getpeers to %s\n",addr->ipaddr);
expand_ipbits(myipaddr,(uint32_t)nonce);
printf("send getpeers to %s, myipaddr.(%s)\n",addr->ipaddr,myipaddr);
iguana_send_supernet(coin,addr,SUPERNET_GETPEERSTR,0);
}
}
@ -260,10 +261,10 @@ int32_t iguana_send_ping(struct iguana_info *coin,struct iguana_peer *addr)
if ( (nonce= addr->pingnonce) == 0 )
{
OS_randombytes((uint8_t *)&nonce,sizeof(nonce));
addr->pingnonce = nonce;
addr->pingnonce = ((nonce & 0xffffffff) << 32) | ((uint32_t)addr->ipbits & 0xffffffff);
addr->pingtime = (uint32_t)time(NULL);
}
printf("pingnonce.%llx\n",(long long)nonce);
//printf("pingnonce.%llx\n",(long long)nonce);
len = iguana_rwnum(1,&serialized[sizeof(struct iguana_msghdr)],sizeof(uint64_t),&nonce);
if ( addr->supernet != 0 )
iguana_send_supernet(coin,addr,SUPERNET_GETPEERSTR,0);
@ -540,7 +541,19 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
}
retval = 0;
//printf("iguana_msgparser %s parse.(%s)\n",addr->ipaddr,H->command);
if ( (ishost= (strcmp(H->command,"getblocks") == 0)) || strcmp(H->command,"block") == 0 )
if ( strncmp(H->command,"SuperNET",strlen("SuperNET")) == 0 )
{
addr->supernet = 1;
addr->msgcounts.verack++;
len = recvlen;
if ( (retstr= SuperNET_p2p(coin,addr,&delay,addr->ipaddr,data,recvlen,H->command[strlen("SuperNET")]=='b')) != 0 )
{
iguana_send_supernet(coin,addr,retstr,delay);
free(retstr);
}
//printf("GOT.(%s) [%s] len.%d from %s -> (%s)\n",H->command,data,recvlen,addr->ipaddr,retstr==0?"null":retstr);
}
else if ( (ishost= (strcmp(H->command,"getblocks") == 0)) || strcmp(H->command,"block") == 0 )
{
struct iguana_txblock txdata;
if ( addr != 0 )
@ -569,7 +582,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
}
}
}
if ( (ishost= (strcmp(H->command,"data") == 0)) || strcmp(H->command,"inv") == 0 )
else if ( (ishost= (strcmp(H->command,"data") == 0)) || strcmp(H->command,"inv") == 0 )
{
if ( addr != 0 )
{
@ -579,8 +592,8 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
printf("%s SERVER getdata\n",addr->ipaddr);
intvectors = srvmsg = 'D';
// generate intvectors data, create new type for shahdrs!
if ( (sendlen= iguana_peerinvdata(coin,addr,addr->blockspace,sizeof(addr->blockspace))) > 0 )
iguana_queue_send(coin,addr,0,addr->blockspace,"inv",0,0,0);
if ( (sendlen= iguana_peerinvrequest(coin,addr,addr->blockspace,sizeof(addr->blockspace))) > 0 )
iguana_queue_send(coin,addr,0,addr->blockspace,"inv",sendlen,0,0);
}
else
{
@ -589,29 +602,6 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
}
}
}
else if ( strcmp(H->command,"notfound") == 0 )
{
printf("%s SERVER notfound\n",addr->ipaddr);
intvectors = 'N', addr->msgcounts.notfound++;
len = iguana_intvectors(coin,addr,1,data,recvlen);
}
else if ( strcmp(H->command,"mempool") == 0 )
{
printf("%s SERVER mempool\n",addr->ipaddr);
srvmsg = 'M', addr->msgcounts.mempool++;
}
else if ( strncmp(H->command,"SuperNET",strlen("SuperNET")) == 0 )
{
addr->supernet = 1;
addr->msgcounts.verack++;
len = recvlen;
if ( (retstr= SuperNET_p2p(coin,addr,&delay,addr->ipaddr,data,recvlen,H->command[strlen("SuperNET")]=='b')) != 0 )
{
iguana_send_supernet(coin,addr,retstr,delay);
free(retstr);
}
//printf("GOT.(%s) [%s] len.%d from %s -> (%s)\n",H->command,data,recvlen,addr->ipaddr,retstr==0?"null":retstr);
}
else if ( (ishost= (strcmp(H->command,"getheaders") == 0)) || strcmp(H->command,"headers") == 0 )
{
struct iguana_msgblock msg; struct iguana_block *blocks; uint32_t n;
@ -713,26 +703,24 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
}
else
{
struct iguana_peer *tmpaddr;
len = 0;
x = coin->peers.numranked;
if ( x > (sizeof(serialized)-sizeof(*H)-sizeof(uint64_t))/sizeof(A) )
x = (sizeof(serialized)-sizeof(*H)-sizeof(uint64_t))/sizeof(A);
sendlen = iguana_rwvarint(1,&serialized[sizeof(*H)+sendlen],&x);
for (i=0; i<x; i++)
{
memset(&A,0,sizeof(A));
if ( (tmpaddr= coin->peers.ranked[i]) != 0 )
{
sendlen += iguana_rwaddr(1,&serialized[sizeof(*H)+sendlen],&tmpaddr->A,(int32_t)tmpaddr->protover);
}
}
retval = iguana_queue_send(coin,addr,0,serialized,"addr",sendlen,0,0);
if ( (sendlen= iguana_peeraddrrequest(coin,addr,addr->blockspace,sizeof(addr->blockspace))) > 0 )
retval = iguana_queue_send(coin,addr,0,addr->blockspace,"addr",sendlen,0,0);
addr->msgcounts.getaddr++;
}
}
//printf("%s -> addr recvlen.%d num.%d\n",addr->ipaddr,recvlen,(int32_t)x);
}
else if ( strcmp(H->command,"notfound") == 0 )
{
printf("%s SERVER notfound\n",addr->ipaddr);
intvectors = 'N', addr->msgcounts.notfound++;
len = iguana_intvectors(coin,addr,1,data,recvlen);
}
else if ( strcmp(H->command,"mempool") == 0 )
{
printf("%s SERVER mempool\n",addr->ipaddr);
srvmsg = 'M', addr->msgcounts.mempool++;
}
else if ( strcmp(H->command,"tx") == 0 )
{
struct iguana_msgtx *tx;

42
iguana/iguana_ramchain.c

@ -90,7 +90,7 @@ 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,subdir; char str[65];
*hdrsip = -1; ipbits = 0;
fname[0] = 0;
//if ( ipbits == 0 )
@ -119,7 +119,14 @@ int32_t iguana_peerfname(struct iguana_info *coin,int32_t *hdrsip,char *dirname,
}
}
else if ( strncmp(GLOBAL_DBDIR,dirname,strlen(GLOBAL_DBDIR)) == 0 )
sprintf(fname,"%s/%s/%s_%d.%u",dirname,coin->symbol,bits256_str(str,hash2),numblocks,ipbits>1?ipbits:*hdrsip);
{
subdir = bp->bundleheight / IGUANA_SUBDIRDIVISOR;
sprintf(fname,"%s/%s/%d",dirname,coin->symbol,subdir), OS_ensure_directory(fname);
sprintf(fname,"%s/%s/%d/%s_%d.%u",dirname,coin->symbol,subdir,bits256_str(str,hash2),numblocks,ipbits>1?ipbits:*hdrsip);
//#ifndef __PNACL__
// sprintf(fname,"%s/%s/%s_%d.%u",dirname,coin->symbol,bits256_str(str,hash2),numblocks,ipbits>1?ipbits:*hdrsip);
//#endif
}
else sprintf(fname,"%s/%s.%u",dirname,bits256_str(str,hash2),bp->bundleheight);
OS_compatible_path(fname);
return(bundlei);
@ -638,11 +645,13 @@ void *iguana_ramchain_offset(char *fname,void *dest,uint8_t *lhash,FILE *fp,uint
{
if ( (err= fwrite(srcptr,1,len,fp)) != len )
{
printf("iguana_ramchain_sizefunc.(%s): error.%ld writing len.%ld to fp.%p errno.%d\n",fname,err,(long)len,fp,errno);
printf("iguana_ramchain_offset.(%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.(%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);
fseek(fp,0,SEEK_SET);
len = 0;
fpos = 0;
}
//else printf("fp.(%ld <- %d) ",ftell(fp),(int32_t)len);
}
@ -1024,8 +1033,11 @@ long iguana_ramchain_save(struct iguana_info *coin,RAMCHAIN_FUNC,uint32_t ipbits
iguana_ramchain_compact(fname,RAMCHAIN_ARG,&tmp,rdata,bp!=0?bp->n:1);
if ( 0 && ramchain->expanded != 0 )
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(fname,RAMCHAIN_ARG,fp,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset);
if ( fwrite(&tmp,1,sizeof(tmp),fp) != sizeof(tmp) )
{
printf("ramchain_save error writing header.%s\n",fname);
fpos = -1;
} else iguana_ramchain_saveaction(fname,RAMCHAIN_ARG,fp,rdata,bp!=0?bp->n:1,ramchain->H.scriptoffset);
*rdata = tmp;
fclose(fp);
}
@ -1240,7 +1252,7 @@ int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfi
struct iguana_bundle *bp; char fname[1024],str[65];
if ( hdrsi >= 0 && hdrsi < coin->bundlescount && (bp= coin->bundles[hdrsi]) != 0 )
{
printf("delete bundle.[%d]\n",hdrsi);
//printf("delete bundle.[%d]\n",hdrsi);
iguana_ramchain_free(coin,&bp->ramchain,0);
if ( iguana_bundlefname(coin,bp,fname) == 0 )
OS_removefile(fname,0);
@ -1303,7 +1315,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
munmap(ptr,filesize);
ramchain->Xspendinds = 0;
}
} //else if ( iter == 1 ) printf("no Xspendfile.(%s)\n",fname);
} else if ( iter == 1 ) printf("no Xspendfile.(%s)\n",fname);
}
}
return(ramchain->numXspends);
@ -1982,7 +1994,8 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru
}
if ( deletefile != 0 )
{
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,block->RO.hash2,zero,1,1)) != i )
fname[0] = 0;
if ( block != 0 && (checki= iguana_peerfname(coin,&hdrsi,GLOBAL_TMPDIR,fname,0,block->RO.hash2,zero,1,1)) != i )
{
printf("checki.%d vs %d mismatch? %s\n",checki,i,fname);
}
@ -2150,7 +2163,10 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru
ramchain->H.data->scriptspace = scriptoffset;
ramchain->H.stacksize = ramchain->H.data->stackspace = stacksize;
if ( iguana_ramchain_save(coin,RAMCHAIN_ARG,0,firsthash2,zero,0,bp) < 0 )
printf("ERROR saving ramchain hdrsi.%d\n",hdrsi);
{
printf("ERROR saving ramchain hdrsi.%d, deleting and will regenerate\n",hdrsi);
iguana_mempurge(hashmem);
}
else
{
//printf("DEST T.%d U.%d S.%d P.%d X.%d -> size.%ld Xoffset.%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,(int32_t)ramchain->H.data->Xoffset);
@ -2183,6 +2199,11 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru
}
iguana_mempurge(hashmem);
}
if ( retval < 0 )
{
printf("remove unmappable bundle.[%d]\n",bp->hdrsi);
iguana_bundleremove(coin,bp->hdrsi,0);
}
return(retval);
}
@ -2237,6 +2258,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
{
//printf("couldnt load bundle.%d\n",bp->bundleheight);
memset(&bp->ramchain,0,sizeof(bp->ramchain));
iguana_bundleremove(coin,bp->hdrsi,0);
}
if ( mapchain != 0 )
coin->newramchain++;

49
iguana/iguana_tx.c

@ -163,8 +163,8 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
*txidp = bits256_doublesha256(txidstr,serialized,len);
if ( memcmp(txidp,tx->txid.bytes,sizeof(*txidp)) != 0 )
{
for (i=0; i<len; i++)
printf("%02x",serialized[i]);
//for (i=0; i<len; i++)
// printf("%02x",serialized[i]);
char str[65],str2[65]; printf("\nrw.%d numvins.%d numvouts.%d error generating txbytes txid %s vs %s\n",rwflag,numvins,numvouts,bits256_str(str,*txidp),bits256_str(str2,tx->txid));
return(len);
}
@ -241,51 +241,6 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
return(-1);
}
int32_t iguana_peerhdrrequest(struct iguana_info *coin,struct iguana_peer *addr,bits256 hash2)
{
struct iguana_txid *tx,T; int32_t len=0,i,height,retval=-1; struct iguana_block *block; struct iguana_msgblock msgB; uint8_t *serialized; bits256 checkhash2;
if ( (tx= iguana_txidfind(coin,&height,&T,hash2,coin->bundlescount-1)) != 0 )
{
serialized = calloc(coin->chain->bundlesize,sizeof(msgB));
for (i=0; i<coin->chain->bundlesize; i++)
{
if ( (block= iguana_blockptr("peerhdr",coin,height + i)) != 0 )
{
iguana_blockunconv(&msgB,block,1);
len += iguana_rwblock(1,&checkhash2,&serialized[sizeof(struct iguana_msghdr) + len],&msgB);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{
char str[65],str2[65];
printf("iguana_peerhdrrequest blockhash.%d error (%s) vs (%s)\n",height+i,bits256_str(str,checkhash2),bits256_str(str2,block->RO.hash2));
free(serialized);
return(-1);
}
}
}
if ( i == coin->chain->bundlesize || (i > 0 && height/coin->chain->bundlesize >= coin->blocks.hwmchain.height/coin->chain->bundlesize) )
retval = iguana_queue_send(coin,addr,0,serialized,"headers",len,0,0);
free(serialized);
}
return(retval);
}
int32_t iguana_peerinvdata(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *space,int32_t max)
{
int32_t i,type,len = 0; uint64_t x; struct iguana_bundle *bp;
x = coin->bundlescount;
len += iguana_rwvarint(1,&space[sizeof(struct iguana_msghdr) + len],&x);
for (i=0; i<x; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
type = MSG_BLOCK;
len += iguana_rwnum(1,&space[sizeof(struct iguana_msghdr) + len],sizeof(uint32_t),&type);
len += iguana_rwbignum(1,&space[sizeof(struct iguana_msghdr) + len],sizeof(bits256),bp->hashes[0].bytes);
}
}
return(len);
}
cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag)
{
char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgblock msg;

218
iguana/iguana_unspents.c

@ -280,6 +280,8 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
utxo = &spentchain->Uextras[spent_unspentind];
if ( utxo->spentflag == 0 )
{
if ( fromheight/coin->chain->bundlesize >= coin->current->hdrsi )
printf("iguana_volatileupdate.%d: [%d] spent.(u%u %.8f pkind.%d) fromht.%d [%d] spendind.%d\n",incremental,spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind);
utxo->prevunspentind = A2[spent_pkind].lastunspentind;
utxo->spentflag = 1;
utxo->fromheight = fromheight;
@ -289,7 +291,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
}
else
{
printf("spent_unspentind[%d] in hdrs.[%d] is spent fromht.%d %.8f\n",spent_unspentind,spent_hdrsi,utxo->fromheight,dstr(spent_value));
printf("from.%d spent_unspentind[%d] in hdrs.[%d] is spent fromht.%d %.8f\n",fromheight,spent_unspentind,spent_hdrsi,utxo->fromheight,dstr(spent_value));
}
} else printf("null ptrs.[%d] u.%u p.%u %.8f from ht.%d s.%u\n",spent_hdrsi,spent_unspentind,spent_pkind,dstr(spent_value),fromheight,spendind);
}
@ -304,7 +306,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
return(0);
}
}
printf("iguana_volatileupdate: [%d] spent.(u%u %.8f pkind.%d) double spend? at ht.%d [%d] spendind.%d\n",spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind);
printf("iguana_volatileupdate.%d: [%d] spent.(u%u %.8f pkind.%d) double spend? at ht.%d [%d] spendind.%d\n",incremental,spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind);
iguana_bundleremove(coin,spent_hdrsi,0);
iguana_bundleremove(coin,fromheight/coin->chain->bundlesize,0);
exit(-1);
@ -836,7 +838,7 @@ void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON
free(rmdarray);
}
static inline int32_t _iguana_spendvectorconv(struct iguana_spendvector *ptr,struct iguana_unspent *u,int32_t numpkinds)
static inline int32_t _iguana_spendvectorconv(struct iguana_spendvector *ptr,struct iguana_unspent *u,int32_t numpkinds,int32_t hdrsi,uint32_t unspentind)
{
uint32_t spent_pkind = 0;
if ( (spent_pkind= u->pkind) != 0 && spent_pkind < numpkinds )
@ -845,7 +847,7 @@ static inline int32_t _iguana_spendvectorconv(struct iguana_spendvector *ptr,str
ptr->value = u->value;
ptr->tmpflag = 0;
return(spent_pkind);
}
} else printf("spendvectorconv [%d] u%d pkind.%u/num %u\n",hdrsi,unspentind,u->pkind,numpkinds);
return(0);
}
@ -861,7 +863,7 @@ uint32_t iguana_spendvectorconv(struct iguana_info *coin,struct iguana_spendvect
if ( ptr->hdrsi >= 0 && ptr->hdrsi < coin->bundlescount && (spentbp= coin->bundles[ptr->hdrsi]) != 0 )
{
spentU = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Uoffset);
if ( (spent_pkind= _iguana_spendvectorconv(ptr,&spentU[ptr->unspentind],spentbp->ramchain.H.data->numpkinds)) != 0 )
if ( (spent_pkind= _iguana_spendvectorconv(ptr,&spentU[ptr->unspentind],spentbp->ramchain.H.data->numpkinds,ptr->hdrsi,ptr->unspentind)) != 0 )
converted++;
else printf("illegal [%d].u%u pkind.%u vs %u\n",ptr->hdrsi,ptr->unspentind,spent_pkind,spentbp->ramchain.H.data->numpkinds);
} else printf("illegal [%d].u%u\n",ptr->hdrsi,ptr->unspentind);
@ -945,9 +947,8 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,st
ptr = mycalloc('x',sizeof(*ptr),n);
total += n;
startmillis = OS_milliseconds();
if ( 0 && strcmp(coin->symbol,"BTC") == 0 )
//if ( 0 && strcmp(coin->symbol,"BTC") == 0 )
printf("start UTXOGEN.%d max.%d ptr.%p millis.%.3f\n",bp->bundleheight,n,ptr,startmillis);
//txidind = spendind = rdata->firsti;
starttime = (uint32_t)time(NULL);
txidind = B[starti].firsttxidind;
spendind = B[starti].firstvin;
@ -1029,7 +1030,8 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,st
ptr[emit].unspentind = spent_unspentind;
ptr[emit].fromheight = bp->bundleheight + i;
ptr[emit].tmpflag = 1;
//printf("ht.%d [%d] TMPVECTOR u%d\n",ptr[emit].fromheight,ptr[emit].hdrsi,ptr[emit].unspentind);
if ( 0 && bp == coin->current )
printf("ht.%d spends [%d] TMPVECTOR u%d\n",ptr[emit].fromheight,ptr[emit].hdrsi,ptr[emit].unspentind);
emit++;
}
}
@ -1060,21 +1062,23 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,st
{
if ( bp->tmpspends != 0 )
{
if ( bp->tmpspends != ramchain->Xspendinds )
if ( bp->tmpspends != ramchain->Xspendinds && emit > 0 )
{
//printf("spendvectors: unexpected tmpspends? or RT [%d] numtmpspends.%d vs emit.%d\n",bp->hdrsi,bp->numtmpspends,emit);
printf("spendvectors: RT [%d] numtmpspends.%d vs emit.%d\n",bp->hdrsi,bp->numtmpspends,emit);
bp->tmpspends = myrealloc('x',bp->tmpspends,sizeof(*ptr)*bp->numtmpspends,sizeof(*ptr)*(bp->numtmpspends+emit));
memcpy(&bp->tmpspends[bp->numtmpspends],ptr,sizeof(*ptr)*emit);
bp->numtmpspends += emit;
}
}
else
else if ( emit > 0 )
{
bp->tmpspends = myrealloc('x',ptr,sizeof(*ptr)*n,sizeof(*ptr)*emit);
bp->numtmpspends = emit;
//printf("ALLOC tmpspends.[%d]\n",bp->hdrsi);
ptr = 0;
}
if ( bp == coin->current )
printf("spendvectors.[%d]: tmpspends.%p[%d] after += emit.%d X.%p\n",bp->hdrsi,bp->tmpspends,bp->numtmpspends,emit,bp->ramchain.Xspendinds);
} else errs = -iguana_spendvectorsave(coin,bp,ramchain,ptr!=0?ptr:bp->tmpspends,emit,n);
}
if ( ptr != 0 )
@ -1085,31 +1089,39 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,st
return(-errs);
}
int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight)
int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t starti,int32_t endheight,int32_t startemit)
{
uint32_t spent_unspentind,spent_pkind,txidind,h,i,j,k,now; uint64_t spent_value;
uint32_t spent_unspentind,spent_pkind,txidind,h,i,j,endi,k,now; uint64_t spent_value;
struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata;
struct iguana_spendvector *spend; struct iguana_unspent *spentU,*u;
struct iguana_spendvector *spend; struct iguana_unspent *spentU,*u; struct iguana_spendvector *Xspendinds;
struct iguana_txid *T; struct iguana_blockRO *B; struct iguana_bundle *spentbp;
int32_t spent_hdrsi,spendind,n,errs=0,emit=0; struct iguana_spend *S,*s;
ramchain = &bp->ramchain;
int32_t spent_hdrsi,spendind,n,numXspends,errs=0,emit=0; struct iguana_spend *S,*s;
ramchain = &bp->ramchain; //(bp == coin->current) ? &coin->RTramchain : &bp->ramchain;
if ( (rdata= ramchain->H.data) == 0 || (n= ramchain->H.data->numspends) < 1 )
return(-1);
S = (void *)(long)((long)rdata + rdata->Soffset);
B = (void *)(long)((long)rdata + rdata->Boffset);
T = (void *)(long)((long)rdata + rdata->Toffset);
if ( ramchain->Xspendinds == 0 && bp->hdrsi > 0 )
numXspends = ramchain->numXspends;
if ( (Xspendinds= ramchain->Xspendinds) == 0 )
{
printf("iguana_balancegen.%d: no Xspendinds[%d]\n",bp->hdrsi,ramchain->numXspends);
return(-1);
numXspends = bp->numtmpspends;
if ( (Xspendinds= bp->tmpspends) == 0 )
{
//printf("iguana_balancegen.%d: no Xspendinds[%d]\n",bp->hdrsi,numXspends);
//return(-1);
}
}
iguana_ramchain_prefetch(coin,ramchain,0);
fprintf(stderr,"BALANCEGEN.[%d] ",bp->hdrsi);
txidind = spendind = rdata->firsti;
for (i=0; i<bp->n; i++)
endi = (endheight % bp->n);
txidind = B[starti].firsttxidind;
spendind = B[starti].firstvin;
emit = startemit;
fprintf(stderr,"BALANCEGEN.[%d] %p[%d] starti.%d s%d <-> endi.%d s%d startemit.%d\n",bp->hdrsi,Xspendinds,numXspends,starti,spendind,endi,B[endi].firstvin+B[endi].numvins,startemit);
for (i=starti; i<=endi; i++)
{
now = (uint32_t)time(NULL);
//printf("hdrs.[%d] B[%d] 1st txidind.%d txn_count.%d firstvin.%d firstvout.%d\n",bp->hdrsi,i,B[i].firsttxidind,B[i].txn_count,B[i].firstvin,B[i].firstvout);
if ( bp == coin->current )
printf("hdrs.[%d] B[%d] 1st txidind.%d txn_count.%d firstvin.%d firstvout.%d\n",bp->hdrsi,i,B[i].firsttxidind,B[i].txn_count,B[i].firstvin,B[i].firstvout);
if ( txidind != B[i].firsttxidind || spendind != B[i].firstvin )
{
printf("balancegen: txidind %u != %u B[%d].firsttxidind || spendind %u != %u B[%d].firstvin errs.%d\n",txidind,B[i].firsttxidind,i,spendind,B[i].firstvin,i,errs);
@ -1123,7 +1135,8 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
printf("balancegen: txidind %u != %u T[txidind].firsttxidind || spendind %u != %u T[txidind].firstvin errs.%d\n",txidind,T[txidind].txidind,spendind,T[txidind].firstvin,errs);
return(-1);
}
//printf("txidind.%d txi.%d numvins.%d spendind.%d\n",txidind,j,T[txidind].numvins,spendind);
if ( bp == coin->current )
printf("starti.%d txidind.%d txi.%d numvins.%d spendind.%d\n",i,txidind,j,T[txidind].numvins,spendind);
for (k=0; k<T[txidind].numvins && errs==0; k++,spendind++)
{
s = &S[spendind];
@ -1132,18 +1145,19 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
spent_unspentind = spent_pkind = 0;
if ( s->external != 0 && s->prevout >= 0 )
{
if ( emit >= ramchain->numXspends )
if ( emit >= numXspends )
errs++;
else
else if ( Xspendinds != 0 )
{
spend = &ramchain->Xspendinds[emit];
spend = &Xspendinds[emit++];
spent_unspentind = spend->unspentind;
spent_value = spend->value;
spent_pkind = spend->pkind;
spent_unspentind = spend->unspentind;
spent_hdrsi = spend->hdrsi;
h = spend->fromheight;//bundlei + (spent_hdrsi * coin->chain->bundlesize);
emit++;
h = spend->fromheight;
}
if ( bp == coin->current )
printf("external prevout.%d (emit.%d numX.%d) %p u%d p%d errs.%d spent_hdrsi.%d s%u\n",s->prevout,emit,numXspends,Xspendinds,spent_unspentind,spent_pkind,errs,spent_hdrsi,spendind);
}
else if ( s->prevout >= 0 )
{
@ -1156,42 +1170,45 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig
u = &spentU[spent_unspentind];
if ( (spent_pkind= u->pkind) != 0 && spent_pkind < rdata->numpkinds )
spent_value = u->value;
//printf("txidind.%d 1st.%d prevout.%d\n",txidind,T[txidind].firstvout,s->prevout);
if ( bp == coin->current )
printf("internal spend.%d txidind.%d 1st.%d prevout.%d\n",spendind,txidind,T[txidind].firstvout,s->prevout);
}
else
else if ( i > 0 || j > 0 || k > 0 )
{
printf("iguana_balancegen [%d] txidind overflow %u vs %u\n",bp->hdrsi,s->spendtxidind,rdata->numtxids);
printf("iguana_balancegen [%d] txidind overflow %u vs %u (%d %d %d)\n",bp->hdrsi,s->spendtxidind,rdata->numtxids,i,j,k);
errs++;
}
}
else continue;
spentbp = 0;
if ( spent_unspentind > 0 && spent_pkind > 0 && (spentbp= coin->bundles[spent_hdrsi]) != 0 )
if ( (spentbp= coin->bundles[spent_hdrsi]) != 0 && spent_unspentind > 0 && spent_pkind > 0 )
{
if ( bp == coin->current )
printf("[%d] spendind.%u -> [%d] u%d\n",bp->hdrsi,spendind,spent_hdrsi,spent_unspentind);
if ( iguana_volatileupdate(coin,0,&spentbp->ramchain,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,h) < 0 )
errs++;
}
else
else if ( Xspendinds != 0 )
{
errs++;
printf("iguana_balancegen: error spentbp.%p with unspentind.%d [%d]\n",spentbp,spent_unspentind,spent_hdrsi);
printf("iguana_balancegen: error spentbp.%p with unspentind.%d [%d] (%d %d %d)\n",spentbp,spent_unspentind,spent_hdrsi,i,j,k);
}
}
}
}
if ( txidind != bp->ramchain.H.data->numtxids )
if ( txidind != bp->ramchain.H.data->numtxids && (bp != coin->current || txidind != ramchain->H.txidind) )
{
printf("numtxid.%d != bp numtxids %d\n",txidind,bp->ramchain.H.data->numtxids);
printf("numtxid.%d != bp numtxids %d/%d\n",txidind,bp->ramchain.H.txidind,bp->ramchain.H.data->numtxids);
errs++;
}
if ( spendind != bp->ramchain.H.data->numspends )
if ( spendind != ramchain->H.data->numspends && (bp != coin->current || spendind != ramchain->H.spendind) )
{
printf("spendind.%d != bp numspends %d\n",spendind,bp->ramchain.H.data->numspends);
printf("spendind.%d != bp numspends %d/%d\n",spendind,bp->ramchain.H.spendind,bp->ramchain.H.data->numspends);
errs++;
}
if ( emit != ramchain->numXspends )
if ( emit != numXspends )
{
printf("iguana_balancegen: emit %d != %d ramchain->numXspends\n",emit,ramchain->numXspends);
printf("iguana_balancegen: emit %d != %d ramchain->numXspends\n",emit,numXspends);
errs++;
}
//printf(">>>>>>>> balances.%d done errs.%d spendind.%d\n",bp->hdrsi,errs,n);
@ -1321,10 +1338,13 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle)
printf("req lastbundle.(%s)\n",hashstr);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
}
for (i=0; i<coin->bundlescount-1; i++)
for (i=1; i<coin->bundlescount-1; i++)
{
if ( coin->bundles[i] == 0 || coin->bundles[i]->utxofinish <= 1 )
if ( (bp= coin->bundles[i]) == 0 || bp->utxofinish <= 1 )
{
printf("initfinal break: bp.%p or utxofinish.%u\n",bp,bp!=0?bp->utxofinish:-1);
break;
}
}
if ( i < coin->bundlescount-1 )
{
@ -1412,7 +1432,7 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
if ( fwrite(Uptr,sizeof(*Uptr),numunspents,fp2) == numunspents )
{
err = 0;
printf("[%d] of %d saved (%s) and (%s)\n",hdrsi,numhdrsi,fname,fname2);
//printf("[%d] of %d saved (%s) and (%s)\n",hdrsi,numhdrsi,fname,fname2);
}
}
}
@ -1446,7 +1466,7 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
printf("balances error copying (%s) -> (%s)\n",fname2,destfname);
return(-1);
}
printf("%s -> %s\n",fname,destfname);
//printf("%s -> %s\n",fname,destfname);
OS_removefile(fname,0);
OS_removefile(fname2,0);
}
@ -1524,7 +1544,7 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin)
{
if ( iter == 0 )
{
if ( bp->tmpspends != 0 && bp->converted != 0 )
if ( bp->tmpspends != 0 )//&& bp->converted != 0 )
{
for (j=0; j<bp->numtmpspends; j++)
if ( bp->tmpspends[j].tmpflag != 0 )
@ -1536,7 +1556,7 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin)
}
else if ( iguana_spendvectorsave(coin,bp,&bp->ramchain,bp->tmpspends,bp->numtmpspends,bp->ramchain.H.data->numspends) == 0 )
{
if ( bp->tmpspends != 0 && bp->tmpspends != bp->ramchain.Xspendinds )
if ( bp->tmpspends != 0 && bp->numtmpspends > 0 && bp->tmpspends != bp->ramchain.Xspendinds )
myfree(bp->tmpspends,sizeof(*bp->tmpspends) * bp->numtmpspends);
bp->numtmpspends = 0;
bp->tmpspends = 0;
@ -1548,23 +1568,22 @@ int32_t iguana_spendvectorsaves(struct iguana_info *coin)
return(0);
}
int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *spentbp)
int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *spentbp,int32_t starti)
{
struct iguana_bundle *bp; int16_t spent_hdrsi; uint32_t numpkinds; struct iguana_unspent *spentU; struct iguana_spendvector *vec; int32_t i,converted,j,n = coin->bundlescount; struct iguana_ramchain *ramchain;
if ( spentbp->converted != 0 )
struct iguana_bundle *bp; int16_t spent_hdrsi; uint32_t numpkinds; struct iguana_unspent *spentU; struct iguana_spendvector *vec; int32_t i,converted,j,n = coin->bundlescount; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata = 0;
if ( (rdata= spentbp->ramchain.H.data) == 0 )
{
//printf("[%d] already converted.%u\n",spentbp->hdrsi,spentbp->converted);
//if ( spentbp == coin->current )
printf("iguana_spendvectorconvs: [%d] null rdata.%p\n",spentbp->hdrsi,rdata);
return(-1);
}
spentbp->converted = 1;
spent_hdrsi = spentbp->hdrsi;
ramchain = &spentbp->ramchain;
numpkinds = ramchain->H.data->numpkinds;
iguana_ramchain_prefetch(coin,ramchain,0);
spentU = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Uoffset);
for (i=converted=0; i<n; i++)
numpkinds = rdata->numpkinds;
spentU = (void *)(long)((long)rdata + rdata->Uoffset);
for (i=starti,converted=0; i<n; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bp->tmpspends != 0 && bp->numtmpspends > 0 )
if ( (bp= coin->bundles[i]) != 0 && bp->tmpspends != 0 )
{
for (j=0; j<bp->numtmpspends; j++)
{
@ -1573,40 +1592,50 @@ int32_t iguana_spendvectorconvs(struct iguana_info *coin,struct iguana_bundle *s
{
if ( vec->tmpflag == 0 )
{
if ( bp->tmpspends != bp->ramchain.Xspendinds )
if ( bp->tmpspends != bp->ramchain.Xspendinds && bp != coin->current )
printf("unexpected null tmpflag [%d] j.%d spentbp.[%d]\n",bp->hdrsi,j,spentbp->hdrsi);
}
else
{
if ( _iguana_spendvectorconv(vec,&spentU[vec->unspentind],numpkinds) != 0 )
/*if ( vec->fromheight >= coin->current->bundleheight )
{
printf("inside [%d] RT.%d spends vec.([%d] u%d p%d) tmp.%d\n",spentbp->hdrsi,vec->fromheight,vec->hdrsi,vec->unspentind,vec->pkind,vec->tmpflag);
}*/
if ( _iguana_spendvectorconv(vec,&spentU[vec->unspentind],numpkinds,vec->hdrsi,vec->unspentind) != 0 )
converted++;
else
{
printf("iguana_spendvectorconv.[%d] error [%d] at %d of %d/%d\n",spentbp->hdrsi,bp->hdrsi,j,bp->numtmpspends,n);
printf("iguana_spendvectorconv.[%d] error [%d] at %d of T[%d/%d] [%d] u%u p%u\n",spentbp->hdrsi,bp->hdrsi,j,bp->numtmpspends,n,vec->hdrsi,vec->unspentind,spentU[vec->unspentind].pkind);
return(-1);
}
}
/*if ( vec->fromheight >= coin->current->bundleheight )
{
printf("outside [%d] RT.%d spends vec.([%d] u%d p%d) tmp.%d\n",spentbp->hdrsi,vec->fromheight,vec->hdrsi,vec->unspentind,vec->pkind,vec->tmpflag);
}*/
}
}
}
else if ( bp->hdrsi > 0 && bp->hdrsi < coin->bundlescount-1 )
else if ( bp->hdrsi < coin->bundlescount-1 )
{
//printf("iguana_spendvectorconvs: [%d] null bp.%p or null tmpspends\n",i,bp);
//printf("iguana_spendvectorconvs: [%d] null bp.%p\n",i,bp);
}
}
spentbp->converted = (uint32_t)time(NULL);
//spentbp->converted = (uint32_t)time(NULL);
//printf("spendvectorconvs.[%d] converted.%d\n",refbp->hdrsi,converted);
return(converted);
}
void iguana_convert(struct iguana_info *coin,struct iguana_bundle *bp,int32_t RTflag)
int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_bundle *bp,int32_t RTflag,int32_t starti)
{
static int64_t total,depth;
int32_t i,n,m,converted; int64_t total_tmpspends; double startmillis = OS_milliseconds();
static int64_t total[256],depth;
int32_t i,n,m,max,converted; int64_t total_tmpspends,sum; double startmillis = OS_milliseconds();
depth++;
//printf("iguana_convert.[%d] depth.%d %u\n",bp->hdrsi,(int32_t)depth,bp->converted);
if ( (converted= iguana_spendvectorconvs(coin,bp)) < 0 )
printf("error ram balancecalc.[%d]\n",bp->hdrsi);
if ( (converted= iguana_spendvectorconvs(coin,bp,starti)) < 0 )
{
printf("error iguana_convert.[%d]\n",bp->hdrsi);
return(0);
}
else
{
n = coin->bundlescount;
@ -1619,10 +1648,15 @@ void iguana_convert(struct iguana_info *coin,struct iguana_bundle *bp,int32_t RT
m++;
}
}
total += converted;
printf("[%4d] millis %7.3f converted.%-7d balance calc.%-4d of %4d | total.%llu of %llu depth.%d\n",bp->hdrsi,OS_milliseconds()-startmillis,converted,m,n,(long long)total,(long long)total_tmpspends,(int32_t)depth);
max = (int32_t)(sizeof(total) / sizeof(*total));
total[helperid % max] += converted;
for (i=sum=0; i<max; i++)
sum += total[i];
if ( converted != 0 )
printf("[%4d] millis %7.3f converted.%-7d balance calc.%-4d of %4d | total.%llu of %llu depth.%d\n",bp->hdrsi,OS_milliseconds()-startmillis,converted,m,n,(long long)sum,(long long)total_tmpspends,(int32_t)depth);
}
depth--;
return(converted);
}
void iguana_RTramchainfree(struct iguana_info *coin)
@ -1637,7 +1671,7 @@ void iguana_RTramchainfree(struct iguana_info *coin)
void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block)
{
char fname[1024]; long filesize; int32_t err; void *ptr;
char fname[1024]; long filesize; int32_t err; void *ptr=0;
if ( block == bp->blocks[bundlei] && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 )
{
if ( iguana_mapchaininit(fname,coin,R,bp,bundlei,block,ptr,filesize) == 0 )
@ -1652,9 +1686,9 @@ void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,
printf("mapped.%s\n",bits256_str(str,R->H.data->firsthash2));
} else return(ptr);
iguana_blockunmark(coin,block,bp,bundlei,1);
}
} else printf("ramchainfile ptr.%p block.%p mapchaininit error\n",ptr,block);
iguana_ramchain_free(coin,R,1);
}
} else printf("ramchainfile ptr.%p block.%p\n",ptr,block);
return(0);
}
@ -1704,6 +1738,7 @@ void iguana_rdataset(struct iguana_ramchain *dest,struct iguana_ramchaindata *rd
rdest->numtxids = src->H.txidind;
rdest->numunspents = src->H.unspentind;
rdest->numspends = src->H.spendind;
printf("RT set numtxids.%u numspends.%u\n",rdest->numtxids,rdest->numspends);
}
void iguana_rdatarestore(struct iguana_ramchain *dest,struct iguana_ramchaindata *rdest,struct iguana_ramchain *src)
@ -1715,6 +1750,7 @@ void iguana_rdatarestore(struct iguana_ramchain *dest,struct iguana_ramchaindata
src->H.txidind = rdest->numtxids;
src->H.unspentind = rdest->numunspents;
src->H.spendind = rdest->numspends;
printf("RT restore numtxids.%u numspends.%u\n",rdest->numtxids,rdest->numspends);
}
void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t numaddrs)
@ -1733,12 +1769,13 @@ void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t num
void iguana_RTspendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
{
int32_t lasti; struct iguana_ramchain R; struct iguana_ramchaindata RDATA;
int32_t lasti,hdrsi,orignumemit; struct iguana_ramchain R; struct iguana_ramchaindata RDATA;
bp->ramchain = coin->RTramchain;
iguana_rdataset(&R,&RDATA,&coin->RTramchain);
iguana_ramchain_prefetch(coin,&coin->RTramchain,0);
//iguana_ramchain_prefetch(coin,&coin->RTramchain,0);
if ( (lasti= (coin->RTheight - ((coin->RTheight/bp->n)*bp->n))) >= bp->n-1 )
lasti = bp->n - 1;
orignumemit = bp->numtmpspends;
if ( iguana_spendvectors(coin,bp,&coin->RTramchain,coin->RTstarti,lasti,0) < 0 )
{
printf("RTutxo error -> RTramchainfree\n");
@ -1748,10 +1785,12 @@ void iguana_RTspendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
else
{
//printf("spendvectors calculated to %d\n",coin->RTheight);
bp->converted = 0;
iguana_convert(coin,bp,1);
bp->converted = 1;
for (hdrsi=0; hdrsi<bp->hdrsi; hdrsi++)
iguana_convert(coin,IGUANA_NUMHELPERS,coin->bundles[hdrsi],1,orignumemit);
//printf("spendvectors converted to %d\n",coin->RTheight);
iguana_balancegen(coin,0,bp,coin->RTstarti,coin->RTheight-1);
bp->converted = (uint32_t)time(NULL);
iguana_balancegen(coin,0,bp,coin->RTstarti,coin->RTheight-1,orignumemit);
printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,(coin->RTheight-1)%bp->n);
coin->RTstarti = (coin->RTheight % bp->n);
}
@ -1795,7 +1834,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
//printf("%d ",addr->numRThashes);
}
}
printf("RTheaders %s\n",coin->symbol);
//printf("RTheaders %s\n",coin->symbol);
}
bp->lastRT = (uint32_t)time(NULL);
iguana_RTramchainalloc("RTbundle",coin,bp);
@ -1805,8 +1844,8 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
dest = &coin->RTramchain;
B = (void *)(long)((long)rdata + rdata->Boffset);
bundlei = (coin->RTheight % coin->chain->bundlesize);
block = iguana_bundleblock(coin,&hash2,bp,bundlei);
iguana_bundlehashadd(coin,bp,bundlei,block);
if ( (block= iguana_bundleblock(coin,&hash2,bp,bundlei)) != 0 )
iguana_bundlehashadd(coin,bp,bundlei,block);
//printf("RT.%d vs hwm.%d starti.%d bp->n %d block.%p/%p ramchain.%p\n",coin->RTheight,coin->blocks.hwmchain.height,coin->RTstarti,bp->n,block,bp->blocks[bundlei],dest->H.data);
if ( block != 0 && bits256_nonz(block->RO.prev_block) != 0 )
{
@ -1857,7 +1896,12 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
printf("RTgenesis verified\n");
coin->RTgenesis = (uint32_t)time(NULL);
iguana_RTspendvectors(coin,bp);
} else printf("RTgenesis failed to verify n.%d vs %d\n",n,coin->RTheight);
}
else
{
printf("RTgenesis failed to verify n.%d vs %d\n",n,coin->RTheight);
iguana_RTramchainfree(coin);
}
}
if ( dest != 0 && flag != 0 )
printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize);
@ -1914,8 +1958,8 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,
}
if ( errs != 0 )
{
//printf("would have removed.[%d]\n",bp->hdrsi);
iguana_bundleremove(coin,bp->hdrsi,0);
printf("remove.[%d]\n",bp->hdrsi);
iguana_bundleremove(coin,bp->hdrsi,1);
}
return(bp->n - errs);
}

15
iguana/main.c

@ -70,10 +70,10 @@ cJSON *API_json;
#ifdef __PNACL__
char GLOBAL_TMPDIR[512] = "/tmp";
char GLOBAL_DBDIR[512] = "/DB";
char GLOBAL_HELPDIR[512] = "help";
char GLOBAL_VALIDATEDIR[512] = "purgeable";
char GLOBAL_CONFSDIR[512] = "confs";
int32_t IGUANA_NUMHELPERS = 4;
char GLOBAL_HELPDIR[512] = "/DB/help";
char GLOBAL_VALIDATEDIR[512] = "/DB/purgeable";
char GLOBAL_CONFSDIR[512] = "/DB/confs";
int32_t IGUANA_NUMHELPERS = 1;
#else
char GLOBAL_TMPDIR[512] = "tmp";
char GLOBAL_HELPDIR[512] = "help";
@ -1133,7 +1133,7 @@ void iguana_appletests(struct supernet_info *myinfo)
exit(-1);
}
sleep(1);*/
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"VALIDATE\":1,\"prefetchlag\":13,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":2048,\"endpend\":1,\"services\":0,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0,myinfo->rpcport)) != 0 )
if ( 1 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"prefetchlag\":13,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":500,\"endpend\":500,\"services\":129,\"maxpeers\":64,\"newcoin\":\"BTCD\",\"active\":1,\"numhelpers\":4,\"poll\":1}"),0,myinfo->rpcport)) != 0 )
{
free(str);
if ( 0 && (str= SuperNET_JSON(myinfo,cJSON_Parse("{\"userhome\":\"/Users/jimbolaptop/Library/Application Support\",\"agent\":\"iguana\",\"method\":\"addcoin\",\"services\":1024,\"maxpeers\":256,\"newcoin\":\"BTCD\",\"active\":1}"),0,myinfo->rpcport)) != 0 )
@ -1209,12 +1209,11 @@ void iguana_ensuredirs()
sprintf(dirname,"%s",GLOBAL_HELPDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_CONFSDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/ECB",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_TMPDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/ECB",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/BTC",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/BTCD",GLOBAL_VALIDATEDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s",GLOBAL_TMPDIR), OS_ensure_directory(dirname);
}
void iguana_Qinit()
@ -1322,7 +1321,7 @@ void iguana_main(void *arg)
iguana_helpinit(myinfo);
iguana_commandline(myinfo,arg);
#ifdef __APPLE__
//iguana_appletests(myinfo);
iguana_appletests(myinfo);
#endif
iguana_launchdaemons(myinfo);
}

9
iguana/ramchain_api.c

@ -40,7 +40,7 @@ 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,height; char fname[1024];
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
coin->active = 0;
@ -61,7 +61,12 @@ STRING_ARG(iguana,removecoin,activecoin)
iguana_bundleremove(coin,bp->hdrsi,1);
}
}
sprintf(fname,"%s/%s/*",GLOBAL_DBDIR,coin->symbol), OS_removefile(fname,0);
for (height=0; height<coin->longestchain; height+=IGUANA_SUBDIRDIVISOR)
{
sprintf(fname,"%s/%s/%d",GLOBAL_DBDIR,coin->symbol,height/IGUANA_SUBDIRDIVISOR);
OS_remove_directory(fname);
}
sprintf(fname,"%s/%s/*",GLOBAL_DBDIR,coin->symbol), OS_remove_directory(fname);
}
return(clonestr("{\"error\":\"no active coin\"}"));
}

2
includes/iguana_apideclares.h

@ -14,7 +14,7 @@
******************************************************************************/
STRING_ARG(SuperNET,bitcoinrpc,setcoin);
ZERO_ARGS(SuperNET,myipaddr);
STRING_ARG(SuperNET,myipaddr,ipaddr);
STRING_ARG(SuperNET,setmyipaddr,ipaddr);
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,minaccept,base,rel,minprice,basevolume);
TWO_STRINGS_AND_TWO_DOUBLES(InstantDEX,maxaccept,base,rel,maxprice,basevolume);

Loading…
Cancel
Save