Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
feac4c11fa
  1. 41
      deprecated/obsolete.h
  2. 5
      iguana/iguana777.h
  3. 10
      iguana/iguana_blocks.c
  4. 107
      iguana/iguana_bundles.c
  5. 15
      iguana/iguana_init.c
  6. 4
      iguana/iguana_ramchain.c
  7. 234
      iguana/iguana_recv.c
  8. 67
      iguana/iguana_unspents.c

41
deprecated/obsolete.h

@ -14515,5 +14515,46 @@ len = 0;
printf("j.%d num.%d bundlei.%d\n",j,num,bundlei);
break;
}*/
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,origblock->RO.prev_block)) != 0 )
{
printf("iguana_recvblock got prev block [%d:%d]\n",bp->hdrsi,bundlei);
if ( bundlei < bp->n-1 )
bundlei++;
else bp = 0, bundlei = -2;
/*if ( bits256_cmp(prev->RO.hash2,block->RO.prev_block) == 0 && bundlei < bp->n-1 )
{
bundlei++;
iguana_bundlehash2add(coin,&tmpblock,bp,bundlei,block->RO.hash2);
if ( tmpblock == block )
{
printf("[%d:%d] speculative block.%p\n",bp->hdrsi,bundlei,block);
bp->blocks[bundlei] = block;
bp->hashes[bundlei] = block->RO.hash2;
block->bundlei = bundlei;
block->hdrsi = bp->hdrsi;
block->mainchain = prev->mainchain;
} else printf("error adding speculative prev [%d:%d]\n",bp->hdrsi,bundlei);
}*/
}
/*for (i=coin->bundlescount-1; i>=0; i--)
{
//if ( coin->bundles[i] != 0 )
// printf("compare vs %s\n",bits256_str(str,coin->bundles[i]->hashes[0]));
if ( coin->bundles[i] != 0 && bits256_cmp(origblock->RO.prev_block,coin->bundles[i]->hashes[0]) == 0 )
{
bp = coin->bundles[i];
bundlei = 1;
iguana_bundlehash2add(coin,&block,bp,bundlei,origblock->RO.hash2);
printf("iguana_recvblock [%d] bundlehashadd set.%d block.%p\n",i,bundlei,block);
if ( block != 0 )
{
bp->blocks[bundlei] = block;
block->bundlei = bundlei;
block->hdrsi = bp->hdrsi;
}
break;
}
}*/
//printf("i.%d ref prev.(%s)\n",i,bits256_str(str,origblock->RO.prev_block));
#endif

5
iguana/iguana777.h

@ -437,7 +437,9 @@ struct iguana_bundle
int32_t numhashes,numrecv,numsaved,numcached,generrs,checkedtmp,currentflag;
int32_t minrequests,n,hdrsi,bundleheight,numtxids,numspends,numunspents,numspec,isRT;
double avetime,threshold,metric; uint64_t datasize,estsize;
struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE]; uint32_t issued[IGUANA_MAXBUNDLESIZE];
struct iguana_block *blocks[IGUANA_MAXBUNDLESIZE];
uint8_t *speculativecache[IGUANA_MAXBUNDLESIZE];
uint32_t issued[IGUANA_MAXBUNDLESIZE];
bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative;
struct iguana_ramchain ramchain; uint8_t red,green,blue;
};
@ -831,6 +833,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp);
uint32_t iguana_sparseaddtx(uint8_t *bits,int32_t width,uint32_t tablesize,bits256 txid,struct iguana_txid *T,uint32_t txidind,struct iguana_ramchain *ramchain);
void iguana_launchpeer(struct iguana_info *coin,char *ipaddr);
void iguana_spendvectorsQ(struct iguana_info *coin,struct iguana_bundle *bp);
int8_t iguana_blockstatus(struct iguana_info *coin,struct iguana_block *block);
extern int32_t HDRnet,netBLOCKS;

10
iguana/iguana_blocks.c

@ -338,9 +338,17 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
coin->longestchain = block->height+1;
if ( 0 && (block->height % 1000) == 0 )
printf("EXTENDMAIN %s %d <- (%s) n.%u max.%u PoW %f numtx.%d valid.%d\n",str,block->height,str2,hwmchain->height+1,coin->blocks.maxblocks,block->PoW,block->RO.txn_count,block->valid);
struct iguana_bundle *bp;
struct iguana_bundle *bp; int32_t hdrsi;
if ( (block->height % coin->chain->bundlesize) == 0 )
{
if ( (hdrsi= block->height/coin->chain->bundlesize) < coin->bundlescount )
{
if ( (bp= coin->bundles[hdrsi]) != 0 && bits256_cmp(block->RO.hash2,bp->hashes[0]) != 0 )
{
printf(">>>>>>>>>>>>>> interloper bundle.[%d] ht.%d %s != %s\n",hdrsi,block->height,bits256_str(str,bp->hashes[0]),bits256_str(str2,block->RO.hash2));
coin->bundles[hdrsi] = 0;
}
}
bp = iguana_bundlecreate(coin,&bundlei,block->height,block->RO.hash2,zero,0);
if ( bp != 0 && bp->hdrsi == coin->bundlescount-1 )
{

107
iguana/iguana_bundles.c

@ -533,7 +533,7 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int
}
for (i=0; i<bp->n; i++)
{
if ( (block= bp->blocks[i]) != 0 && (bits256_nonz(block->RO.prev_block) == 0 || block->RO.recvlen == 0 || block->fpipbits == 0 || block->fpos < 0) )
if ( (block= bp->blocks[i]) != 0 && iguana_blockstatus(coin,block) == 0 && bp->speculativecache[i] == 0 )
{
if ( now > block->issued+lag )
{
@ -566,9 +566,9 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int
}
for (i=0; i<bp->n; i++)
{
if ( (block= bp->blocks[i]) != 0 )
if ( (block= bp->blocks[i]) != 0 && bp->speculativecache[i] == 0 )
{
if ( block->fpipbits == 0 || block->RO.recvlen == 0 || block->fpos < 0 || ((bp->hdrsi != 0 || i > 0) && bits256_nonz(block->RO.prev_block) == 0) )
if ( (iguana_blockstatus(coin,block)&7) != 7 || ((bp->hdrsi != 0 || i > 0) && bits256_nonz(block->RO.prev_block) == 0) )
{
if ( block->issued == 0 || now > block->issued+lag )
{
@ -611,7 +611,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp)
if ( (block= bp->blocks[i]) != 0 )
{
//printf("(%x:%x) ",(uint32_t)block->RO.hash2.ulongs[3],(uint32_t)bp->hashes[i].ulongs[3]);
if ( iguana_blockvalidate(coin,&valid,block,1) < 0 || block->fpipbits == 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) )
if ( iguana_blockvalidate(coin,&valid,block,1) < 0 || (iguana_blockstatus(coin,block)&7) != 7 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) )
{
fname[0] = 0;
if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1)) != i )
@ -636,27 +636,36 @@ int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32
int32_t i; uint32_t now; struct iguana_block *block;
if ( bp->isRT == 0 && (bp->hdrsi == coin->bundlescount-1 || bp == coin->current) )
printf("hdr ITERATE.%d bundle.%d vs %d: h.%d n.%d r.%d s.%d c.%d finished.%d spec.%p[%d]\n",bp->hdrsi,bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->numcached,bp->emitfinish,bp->speculative,bp->numspec);
if ( coin->enableCACHE != 0 && bp->numhashes < bp->n )
if ( coin->enableCACHE != 0 && bp->numhashes < bp->n && (bp->speculative == 0 || bp->hdrsi >= coin->longestchain/bp->n) )
{
char str[64];
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
if ( bp->hdrsi == coin->bundlescount-1 && bp->speculative != 0 && bits256_nonz(bp->nextbundlehash2) == 0 )
{
if ( time(NULL) > bp->issued[1]+10 )
{
iguana_blockQ("getnexthdr",coin,0,-1,bp->speculative[1],1);
bp->issued[1] = (uint32_t)time(NULL);
}
}
if ( bp->speculative != 0 && bp == coin->current )
{
now = (uint32_t)time(NULL);
for (i=0; i<bp->numspec&&i<bp->n; i++)
for (i=1; i<bp->numspec&&i<bp->n; i++)
{
if ( bits256_nonz(bp->hashes[i]) == 0 && bits256_nonz(bp->speculative[i]) != 0 )
{
if ( now > bp->issued[i]+60 && ((block= iguana_blockfind(coin,bp->speculative[i])) == 0 || block->req == 0) )
if ( (block= bp->blocks[i]) == 0 && bp->speculativecache[i] == 0 )
{
bp->issued[i] = now;
printf("speculative.[%d:%d]\n",bp->hdrsi,i);
iguana_blockQ("speculative",coin,0,-1,bp->speculative[i],0);
iguana_blockQ("speculative",coin,bp,-i,bp->speculative[i],now > bp->issued[i]+60);
bp->issued[i] = now;
continue;
}
}
//else if ( bp->blocks[i] == 0 )
// break;
else if ( (block= bp->blocks[i]) != 0 && bp->speculativecache[i] == 0 && iguana_blockstatus(coin,block) == 0 && now > bp->issued[i]+60 )
iguana_blockQ("speculativeB",coin,bp,i,block->RO.hash2,1);
}
}
return(counter);
@ -749,7 +758,7 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp)
datasize += block->RO.recvlen;
}
}
else if ( bp == coin->current )
else if ( 0 && bp == coin->current && bp->speculativecache[bundlei] == 0 )
{
char str[65]; printf("missing prev_block [%d:%d] %s\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]));
if ( block != 0 )
@ -769,8 +778,8 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp)
bp->issued[bundlei] = 0;
bp->blocks[bundlei] = 0;
memset(bp->hashes[bundlei].bytes,0,sizeof(bp->hashes[bundlei]));
OS_removefile(fname,0);
}*/
OS_removefile(fname,0);
}*/
numhashes++;
bp->checkedtmp++;
}
@ -778,18 +787,21 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp)
{
if ( bp->speculative != 0 && bits256_nonz(bp->speculative[bundlei]) != 0 )
{
if ( (block= iguana_blockfind(coin,bp->speculative[bundlei])) == 0 || block->req == 0 )
if ( bp->speculativecache[bundlei] == 0 )
{
if ( bits256_nonz(bp->hashes[bundlei]) == 0 )
if ( (block= bp->blocks[bundlei]) == 0 || iguana_blockstatus(coin,block) == 0 )
{
if ( time(NULL) > bp->issued[bundlei]+60 )
if ( bits256_nonz(bp->hashes[bundlei]) == 0 )
{
//char str[65]; printf(" mismatched [%d:%d] %s block.%p\n",bp->hdrsi,bundlei,bits256_str(str,bp->speculative[bundlei]),block);
iguana_blockQ("missing",coin,0,-1,bp->speculative[bundlei],0);
bp->issued[bundlei] = (uint32_t)time(NULL);
}
} else if ( (block= bp->blocks[bundlei]) != 0 && ((block->fpipbits != 0 && block->fpos >= 0 && block->RO.recvlen != 0) || block->queued != 0) )
numcached++;
if ( 0 && time(NULL) > bp->issued[bundlei]+60 )
{
//char str[65]; printf(" mismatched [%d:%d] %s block.%p\n",bp->hdrsi,bundlei,bits256_str(str,bp->speculative[bundlei]),block);
iguana_blockQ("missing",coin,0,-1,bp->speculative[bundlei],0);
bp->issued[bundlei] = (uint32_t)time(NULL);
}
} else if ( (block= bp->blocks[bundlei]) != 0 && iguana_blockstatus(coin,block) != 0 )
numcached++;
} else numcached++;
} else numcached++;
}
}
@ -917,7 +929,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
}
retval = 1;
}
else if ( bp->hdrsi >= starti && bp->hdrsi <= starti+range )
else if ( bp->hdrsi == starti || (bits256_nonz(bp->allhash) != 0 && bp->hdrsi >= starti && bp->hdrsi <= starti+range) )
{
max = bp->n;
counter = iguana_bundleissue(coin,bp,max,timelimit);
@ -930,7 +942,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
if ( coin->stucktime != 0 )
{
lag = time(NULL)-coin->stucktime;
if ( ((lag/coin->MAXSTUCKTIME)>>1) > coin->stuckiters )//|| lag > coin->MAXSTUCKTIME )
if ( ((lag/coin->MAXSTUCKTIME)>>1) > coin->stuckiters )
{
coin->stuckiters = (int32_t)lag/60;
if ( lag > coin->MAXSTUCKTIME )
@ -947,23 +959,20 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
if ( bits256_nonz(bp->hashes[i]) != 0 )
iguana_blockQ("stuck",coin,bp,i,bp->hashes[i],0);
}
if ( (block= bp->blocks[i]) != 0 && (block->RO.recvlen == 0 || block->fpos < 0 || block->fpipbits == 0 || bits256_nonz(block->RO.prev_block) == 0) )
if ( (block= bp->blocks[i]) != 0 && (iguana_blockstatus(coin,block)&0xf) != 0xf )
{
//if ( time(NULL) > block->issued+10 )
printf("[%d:%d] ",bp->hdrsi,i);
iguana_blockQ("stuck",coin,bp,i,block->RO.hash2,0);
//iguana_blockQ("stuck",coin,bp,i,block->RO.hash2,1);
if ( coin->peers.numranked > 8 && (addr= coin->peers.ranked[n % 8]) != 0 && addr->usock >= 0 && addr->dead == 0 && addr->msgcounts.verack != 0 )
{
printf("[%d:%d] ",bp->hdrsi,i);
iguana_blockQ("stuck",coin,bp,i,block->RO.hash2,0);
//iguana_blockQ("stuck",coin,bp,i,block->RO.hash2,1);
if ( coin->peers.numranked > 8 && (addr= coin->peers.ranked[n % 8]) != 0 && addr->usock >= 0 && addr->dead == 0 && addr->msgcounts.verack != 0 )
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&block->RO.hash2,1)) > 0 )
{
if ( (len= iguana_getdata(coin,serialized,MSG_BLOCK,&block->RO.hash2,1)) > 0 )
{
printf("%s, ",addr->ipaddr);
iguana_send(coin,addr,serialized,len);
}
printf("%s, ",addr->ipaddr);
iguana_send(coin,addr,serialized,len);
}
block->issued = (uint32_t)time(NULL);
}
block->issued = (uint32_t)time(NULL);
n++;
}
}
@ -972,7 +981,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
}
}
}
} else bp->nexttime += 10;
} else bp->nexttime += 3;
//printf("done hdrs.%d\n",bp->hdrsi);
iguana_bundleQ(coin,bp,1000);
return(retval);
@ -999,8 +1008,8 @@ static int32_t revsortds(double *buf,uint32_t num,int32_t size)
void iguana_bundlestats(struct iguana_info *coin,char *str)
{
int32_t i,n,m,j,numv,r,count,pending,dispflag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit;
int64_t spaceused=0,estsize = 0; struct iguana_bundle *bp,*lastpending = 0,*firstgap = 0; struct iguana_block *block,*prev; uint32_t now; struct iguana_peer *addr; bits256 hash2;
int32_t i,n,m,j,numv,count,pending,dispflag,numutxo,numbalances,numrecv,done,numhashes,numcached,numsaved,numemit;
int64_t spaceused=0,estsize = 0; struct iguana_bundle *bp,*lastpending = 0,*firstgap = 0; struct iguana_block *block,*prev; uint32_t now; bits256 hash2;
now = (uint32_t)time(NULL);
dispflag = 1;//(rand() % 1000) == 0;
numrecv = numhashes = numcached = numsaved = numemit = done = numutxo = numbalances = 0;
@ -1013,8 +1022,12 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
if ( bp->emitfinish > 1 )
{
for (j=0; j<bp->n; j++)
{
if ( bp->blocks[j] == 0 )
bp->blocks[j] = iguana_blockfind(coin,bp->hashes[j]);
if ( bp->speculativecache[j] != 0 && (block= bp->blocks[j]) != 0 && iguana_blockstatus(coin,block) != 0 )
numcached++;
}
}
//if ( iguana_blockfind(coin,bp->hashes[0]) == 0 )
// printf("UNEXPECTED null block for bundlehash.%d\n",bp->hdrsi);
@ -1035,14 +1048,14 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
block = iguana_blockhashset(coin,-1,bp->speculative[j],1);
}
}
else if ( bits256_nonz(block->RO.prev_block) != 0 && block->fpipbits != 0 )
else if ( bits256_nonz(block->RO.prev_block) != 0 && iguana_blockstatus(coin,block) != 0 )
continue;
prev = bp->blocks[j-1];
//printf("[%d:%d] prev.%p nonz.%d speculative.%d block.%p\n",bp->hdrsi,j,bp->blocks[j-1],bits256_nonz(bp->hashes[j]),bits256_nonz(bp->speculative[j]),bp->blocks[j]);
if ( block != 0 && bp->blocks[j] == 0 ) //prev != 0 &&
{
//char str2[65]; printf("[%d:%d] prev.%p nonz.%d speculative.%d prev.%s vs %s ipbits.%x q.%d\n",bp->hdrsi,j,bp->blocks[j-1],bits256_nonz(bp->hashes[j]),bits256_nonz(bp->speculative[j]),bits256_str(str,prev->RO.hash2),bits256_str(str2,block->RO.prev_block),block->fpipbits,block->queued);
if ( block->fpipbits == 0 && block->queued == 0 )
if ( iguana_blockstatus(coin,block) == 0 && bp->speculativecache[j] == 0 )
{
if ( block->req != 0 )
{
@ -1061,7 +1074,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
} // else break;
}
}
else if ( 0 && bp == coin->current )
/*else if ( 0 && bp == coin->current )
{
for (j=0; j<bp->n; j++)
if ( (block= bp->blocks[j]) != 0 && (block->RO.recvlen == 0 || block->fpipbits == 0 || block->fpos < 0) && time(NULL) > block->issued+3 && (rand() % 10) == 0 )
@ -1073,7 +1086,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
block->issued = (uint32_t)time(NULL);
break;
}
}
}*/
if ( bp->speculative != 0 && numcached == bp->n )
{
hash2 = bp->hashes[0];
@ -1101,12 +1114,6 @@ void iguana_bundlestats(struct iguana_info *coin,char *str)
bp->blocks[i] = block;
//printf("bundlehashadd set.%d\n",bundlei);
iguana_bundlehash2add(coin,0,bp,i,bp->speculative[i]);
if ( block->req != 0 )
{
queue_enqueue("cacheQ",&coin->cacheQ,&block->req->DL,0);
block->req = 0;
block->queued = 1;
}
}
}
}

15
iguana/iguana_init.c

@ -324,19 +324,28 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
void iguana_ramchainpurge(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain)
{
iguana_ramchain_free(coin,ramchain,1);
}
void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp)
{
static bits256 zero;
int32_t i; static bits256 zero;
iguana_ramchainpurge(coin,bp,&bp->ramchain);
if ( bp->speculative != 0 )
{
for (i=0; i<bp->n; i++)
if ( bp->speculativecache[i] != 0 )
{
myfree(bp->speculativecache[i],*(int32_t *)bp->speculativecache[i]);
bp->speculativecache[i] = 0;
}
myfree(bp->speculative,sizeof(*bp->speculative) * bp->numspec);
}
bp->numspec = 0;
bp->speculative = 0;
memset(bp->hashes,0,sizeof(bp->hashes));
memset(bp->issued,0,sizeof(bp->issued));
bp->prevbundlehash2 = bp->nextbundlehash2 = bp->allhash = zero;
iguana_ramchain_free(coin,&bp->ramchain,1);
}
void iguana_blockpurge(struct iguana_info *coin,struct iguana_block *block)
@ -352,7 +361,7 @@ void iguana_blockpurge(struct iguana_info *coin,struct iguana_block *block)
void iguana_blockspurge(struct iguana_info *coin)
{
struct iguana_block *block,*tmp;
if ( 0 && coin->blocks.hash != 0 )
if ( 1 && coin->blocks.hash != 0 )
{
HASH_ITER(hh,coin->blocks.hash,block,tmp)
{

4
iguana/iguana_ramchain.c

@ -1127,7 +1127,6 @@ int32_t iguana_ramchain_free(struct iguana_info *coin,struct iguana_ramchain *ra
if ( ramchain->hashmem == 0 )
myfree(item,sizeof(*item));
}
ramchain->txids = 0;
}
if ( ramchain->pkhashes != 0 )
{
@ -1137,9 +1136,10 @@ int32_t iguana_ramchain_free(struct iguana_info *coin,struct iguana_ramchain *ra
if ( ramchain->hashmem == 0 )
myfree(item,sizeof(*item));
}
ramchain->pkhashes = 0;
}
}
ramchain->txids = 0;
ramchain->pkhashes = 0;
if ( ramchain->hashmem != 0 )
iguana_mempurge(ramchain->hashmem), ramchain->hashmem = 0;
if ( ramchain->filesize != 0 )

234
iguana/iguana_recv.c

@ -157,9 +157,52 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl
}
#endif
int32_t iguana_speculativefind(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_block *block,uint8_t *data,int32_t recvlen)
{
int32_t i,j,numcached; uint8_t *tmp; char str[65];
for (i=1; i<bp->n; i++)
{
if ( bits256_cmp(bp->speculative[i],block->RO.hash2) == 0 )
{
if ( (tmp= bp->speculativecache[i]) != 0 )
{
if ( memcmp(&recvlen,tmp,sizeof(recvlen)) != 0 || memcmp(&tmp[sizeof(recvlen)],data,recvlen) != 0 )
printf("ERROR ");
printf("[%d:%d] already has recvlen.%d for %s\n",bp->hdrsi,i,recvlen,bits256_str(str,block->RO.hash2));
return(0);
}
bp->speculativecache[i] = mycalloc('p',1,recvlen + sizeof(recvlen));
memcpy(bp->speculativecache[i],&recvlen,sizeof(recvlen));
memcpy(&bp->speculativecache[i][sizeof(recvlen)],data,recvlen);
for (j=numcached=0; j<bp->n; j++)
if ( bp->speculativecache[j] != 0 )
numcached++;
printf("cache %s [%d:%d] h.%d s.%d c.%d -> %d\n",bits256_str(str,block->RO.hash2),bp->hdrsi,i,bp->numhashes,bp->numsaved,bp->numcached,numcached);
return(i);
}
}
return(0);
}
int8_t iguana_blockstatus(struct iguana_info *coin,struct iguana_block *block)
{
int32_t status = 0;
if ( block->RO.recvlen != 0 )
status |= 1;
if ( block->fpipbits != 0 )
status |= 2;
if ( block->fpos >= 0 )
status |= 4;
if ( bits256_nonz(block->RO.prev_block) != 0 )
status |= 8;
if ( block->queued != 0 )
status |= 0xc0; // force negative, 0x80 can be +128
return(status);
}
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
{
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,i,j,bundlei,copyflag;
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,speculative=0,i,j,bundlei,copyflag; struct iguana_block *block;
struct iguana_bundle *bp;
if ( 0 )
{
@ -207,59 +250,50 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
}
else if ( 0 && coin->enableCACHE != 0 )
printf("cache.%d validated.(%s)\n",coin->enableCACHE,bits256_str(str,origtxdata->block.RO.hash2));
if ( (bp= coin->current) != 0 )
copyflag = (coin->enableCACHE != 0) && (strcmp(coin->symbol,"BTC") != 0);
bp = 0, bundlei = -2;
bp = iguana_bundlefind(coin,&bp,&bundlei,origtxdata->block.RO.hash2);
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
{
if ( bp->emitfinish != 0 )
{
printf("got [%d:%d] with emitfinish.%u\n",bp->hdrsi,bundlei,bp->emitfinish);
return;
}
bp->dirty++;
if ( bundlei >= 0 && (block= bp->blocks[bundlei]) != 0 )
{
if ( iguana_blockstatus(coin,block) != 0 && block->txvalid != 0 )
{
if ( bits256_cmp(origtxdata->block.RO.hash2,block->RO.hash2) == 0 )
return;
else printf("mismatched tx received? mainchain.%d\n",block->mainchain);
if ( block->mainchain != 0 )
return;
}
block->RO = origtxdata->block.RO;
//printf("update prev for [%d:%d]\n",bp->hdrsi,bundlei);
}
}
else
{
while ( bp != 0 && bp->hdrsi < coin->bundlescount )
if ( (bp= coin->current) != 0 && bp->speculative != 0 )
{
//struct iguana_block *block;
if ( bp->speculative != 0 )
for (i=bp->hdrsi; i<coin->bundlescount; i++)
{
for (i=1; i<bp->n; i++)
if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 && bp->speculative != 0 && bp->numhashes < bp->n )
{
if ( bits256_cmp(bp->speculative[i],origtxdata->block.RO.hash2) == 0 )
if ( iguana_speculativefind(coin,bp,&origtxdata->block,data,recvlen) >= 0 )
{
if ( bits256_cmp(bp->hashes[i-1],origtxdata->block.RO.prev_block) == 0 )
{
//block->bundlei = i;
//block->hdrsi = bp->hdrsi;
//bp->blocks[i] = block;
//printf("cache bundlehashadd set.%d\n",i);
iguana_bundlehash2add(coin,0,bp,i,origtxdata->block.RO.hash2);
//if ( block->req != 0 )
{
//printf("cacheQ ");
//queue_enqueue("cacheQ",&coin->cacheQ,&req->DL,0);
//block->req = 0;
}
}
//printf("speculative recv.[%d:%d] numcached.%d\n",bp->hdrsi,i,bp->numcached);
bp = 0;
copyflag = 0;
speculative = 1;
break;
}
}
}
if ( bp != 0 )
{
if ( bp->hdrsi < coin->bundlescount-1 )
bp = coin->bundles[bp->hdrsi + 1];
else bp = 0;
}
}
bp = 0;
}
copyflag = coin->enableCACHE;
bp = 0, bundlei = -2;
bp = iguana_bundlefind(coin,&bp,&bundlei,origtxdata->block.RO.hash2);
if ( bp != 0 )
{
if ( bp->emitfinish != 0 )
{
//printf("got [%d:%d] with emitfinish.%u\n",bp->hdrsi,bundlei,bp->emitfinish);
return;
}
bp->dirty++;
}
if ( copyflag != 0 && recvlen != 0 && (bp == 0 || (bp->blocks[bundlei] != 0 && bp->blocks[bundlei]->fpipbits == 0)) )
if ( copyflag != 0 && recvlen != 0 && (bp == 0 || bundlei < 0 || ((block= bp->blocks[bundlei]) != 0 && iguana_blockstatus(coin,block) == 0)) )
{
req = iguana_bundlereq(coin,addr,'B',copyflag * recvlen);
req->copyflag = 1;
@ -271,19 +305,6 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
copyflag = 0;
req = iguana_bundlereq(coin,addr,'B',0);
}
if ( bp != 0 && bundlei >= 0 && bp->blocks[bundlei] != 0 )//&& bits256_cmp(bp->blocks[bundlei]->RO.prev_block,origtxdata->block.RO.prev_block) != 0 )
{
if ( bp->blocks[bundlei]->fpos >= 0 && bp->blocks[bundlei]->fpipbits != 0 && bp->blocks[bundlei]->txvalid != 0 )
{
if ( bits256_cmp(origtxdata->block.RO.hash2,bp->blocks[bundlei]->RO.hash2) == 0 )
return;
else printf("mismatched tx received? mainchain.%d\n",bp->blocks[bundlei]->mainchain);
if ( bp->blocks[bundlei]->mainchain != 0 )
return;
}
bp->blocks[bundlei]->RO = origtxdata->block.RO;
//printf("update prev for [%d:%d]\n",bp->hdrsi,bundlei);
}
req->recvlen = recvlen;
req->H = *H;
if ( bits256_cmp(origtxdata->block.RO.hash2,coin->APIblockhash) == 0 )
@ -300,7 +321,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
addr->lastblockrecv = (uint32_t)time(NULL);
addr->recvblocks += 1.;
addr->recvtotal += recvlen;
if ( iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->block.RO.txn_count,data,recvlen) > 0 )
if ( speculative == 0 && iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->block.RO.txn_count,data,recvlen) > 0 )
{
txdata->block.fpipbits = (uint32_t)addr->ipbits;
txdata->block.RO.recvlen = recvlen;
@ -545,7 +566,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
}
else if ( bp->hdrsi > 0 && (bp= coin->bundles[bp->hdrsi-1]) != 0 )
iguana_bundlehash2add(coin,0,bp,coin->chain->bundlesize-1,prevhash2);
if ( coin->enableCACHE != 0 )
if ( 0 && coin->enableCACHE != 0 )
iguana_bundlespeculate(coin,bp,bundlei,hash2,1);
}
prevbp = 0, prevbundlei = -2;
@ -568,7 +589,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
//printf("bundlehash2add next %d\n",prevbundlei);
iguana_bundlehash2add(coin,0,prevbp,prevbundlei+1,hash2);
}
if ( coin->enableCACHE != 0 )
if ( 0 && coin->enableCACHE != 0 )
iguana_bundlespeculate(coin,prevbp,prevbundlei,prevhash2,2);
}
}
@ -580,7 +601,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl
void iguana_checklongestchain(struct iguana_info *coin,struct iguana_bundle *bp,int32_t num)
{
int32_t i; struct iguana_peer *addr;
if ( num > 10 && num < bp->n )
if ( num > 3 && num < bp->n )
{
if ( coin->longestchain > bp->bundleheight+num+3 )
{
@ -685,10 +706,11 @@ void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp)
if ( bp->hdrsi == coin->bundlescount-1 && bits256_nonz(bp->nextbundlehash2) != 0 )
{
init_hexbytes_noT(hashstr,bp->nextbundlehash2.bytes,sizeof(bits256));
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
newbp = iguana_bundlecreate(coin,&bundlei,bp->bundleheight+coin->chain->bundlesize,bp->nextbundlehash2,zero,1);
if ( newbp != 0 )
{
if ( newbp->speculative == 0 )
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1);
printf("EXTEND last bundle %s/%s ht.%d\n",bits256_str(str,newbp->hashes[0]),bits256_str(str2,bp->nextbundlehash2),newbp->bundleheight);
if ( newbp->queued == 0 )
iguana_bundleQ(coin,newbp,1000);
@ -799,65 +821,21 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundlereq *req,struct iguana_block *origblock,int32_t numtx,int32_t datalen,int32_t recvlen,int32_t *newhwmp)
{
struct iguana_bundle *bp=0; int32_t width,numsaved=0,bundlei = -2; struct iguana_block *block,*tmpblock,*prev; char str[65];
if ( (bp= iguana_bundleset(coin,&block,&bundlei,origblock)) == 0 )
{
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,origblock->RO.prev_block)) != 0 )
{
printf("iguana_recvblock got prev block [%d:%d]\n",bp->hdrsi,bundlei);
if ( bundlei < bp->n-1 )
bundlei++;
else bp = 0, bundlei = -2;
/*if ( bits256_cmp(prev->RO.hash2,block->RO.prev_block) == 0 && bundlei < bp->n-1 )
{
bundlei++;
iguana_bundlehash2add(coin,&tmpblock,bp,bundlei,block->RO.hash2);
if ( tmpblock == block )
{
printf("[%d:%d] speculative block.%p\n",bp->hdrsi,bundlei,block);
bp->blocks[bundlei] = block;
bp->hashes[bundlei] = block->RO.hash2;
block->bundlei = bundlei;
block->hdrsi = bp->hdrsi;
block->mainchain = prev->mainchain;
} else printf("error adding speculative prev [%d:%d]\n",bp->hdrsi,bundlei);
}*/
}
/*for (i=coin->bundlescount-1; i>=0; i--)
{
//if ( coin->bundles[i] != 0 )
// printf("compare vs %s\n",bits256_str(str,coin->bundles[i]->hashes[0]));
if ( coin->bundles[i] != 0 && bits256_cmp(origblock->RO.prev_block,coin->bundles[i]->hashes[0]) == 0 )
{
bp = coin->bundles[i];
bundlei = 1;
iguana_bundlehash2add(coin,&block,bp,bundlei,origblock->RO.hash2);
printf("iguana_recvblock [%d] bundlehashadd set.%d block.%p\n",i,bundlei,block);
if ( block != 0 )
{
bp->blocks[bundlei] = block;
block->bundlei = bundlei;
block->hdrsi = bp->hdrsi;
}
break;
}
}*/
//printf("i.%d ref prev.(%s)\n",i,bits256_str(str,origblock->RO.prev_block));
}
if ( bp == coin->current && bp != 0 && block != 0 && bp->speculative != 0 && bundlei >= 0 )
if ( (bp= iguana_bundleset(coin,&block,&bundlei,origblock)) != 0 && bp == coin->current && block != 0 && bp->speculative != 0 && bundlei >= 0 )
{
if ( bp->speculative != 0 && bp->numspec <= bundlei )
{
bp->speculative[bundlei] = block->RO.hash2;
bp->numspec = bundlei+1;
}
if ( block != 0 && bundlei > 0 && (prev= iguana_blockfind(coin,block->RO.prev_block)) != 0 )
/*if ( block != 0 && bundlei > 0 && (prev= iguana_blockfind(coin,block->RO.prev_block)) != 0 )
{
if ( bp->bundleheight+bundlei-1 >= coin->blocks.hwmchain.height )
{
printf("prev issue.%s\n",bits256_str(str,prev->RO.hash2));
iguana_blockQ("previssue",coin,bp,bundlei-1,prev->RO.hash2,0);
}
}
}*/
}
if ( bp != 0 )
bp->dirty++;
@ -873,7 +851,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
}
fprintf(stderr,"%s [%d:%d] block.%x | s.%d r.%d copy.%d\n",bits256_str(str,origblock->RO.hash2),bp!=0?bp->hdrsi:-1,bundlei,block->fpipbits,numsaved,numrecv,req->copyflag);
}
if ( 1 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && coin->enableCACHE != 0 )
if ( 0 && bundlei == 1 && bp != 0 && bp->numhashes < bp->n && coin->enableCACHE != 0 && bp->speculative == 0 )
{
//printf("reissue hdrs request for [%d]\n",bp->hdrsi);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
@ -882,7 +860,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
{
if ( block != origblock )
iguana_blockcopy(coin,block,origblock);
if ( block->newtx != 0 )
if ( 0 && block->newtx != 0 )
{
if ( (prev= iguana_blockfind(coin,block->RO.prev_block)) == 0 )
prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1);
@ -917,7 +895,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana
{
if ( block->queued == 0 && bp != 0 )
{
//char str[65]; fprintf(stderr,"req.%p %s copyflag.%d %d data %d %d\n",req,bits256_str(str,block->RO.hash2),req->copyflag,block->height,req->recvlen,recvlen);
char str[65]; fprintf(stderr,"req.%p %s copyflag.%d %d data %d %d\n",req,bits256_str(str,block->RO.hash2),req->copyflag,block->height,req->recvlen,recvlen);
coin->numcached++;
block->queued = 1;
queue_enqueue("cacheQ",&coin->cacheQ,&req->DL,0);
@ -1149,7 +1127,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
}
}
}
else if ( bp != 0 && time(NULL) > bp->hdrtime+10 )
else if ( 0 && bp != 0 && time(NULL) > bp->hdrtime+10 && bp->speculative == 0 )
{
char str[65];
//printf("MAINCHAIN gethdr %d %s\n",bp->bundleheight,bits256_str(str,bp->hashes[0]));
@ -1225,7 +1203,7 @@ int32_t iguana_reqhdrs(struct iguana_info *coin)
{
for (i=0; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 && (bp->hdrsi == coin->longestchain/coin->chain->bundlesize || i == coin->bundlescount-1 || bp->numhashes < bp->n) )
if ( (bp= coin->bundles[i]) != 0 && (bp->hdrsi == coin->longestchain/coin->chain->bundlesize || i == coin->bundlescount-1 || (bp->numhashes < bp->n && bp->speculative == 0)) )
{
if ( bp == coin->current )
lag = 13;
@ -1268,13 +1246,26 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
return(-1);
}
block = iguana_blockfind(coin,hash2);
if ( priority != 0 || block == 0 || (block->queued == 0 && block->fpipbits == 0) )
if ( priority != 0 || block == 0 || iguana_blockstatus(coin,block) == 0 )
{
if ( bp != 0 && bundlei >= 0 && bundlei < bp->n )
if ( bp != 0 )
{
if ( block == 0 )
block = bp->blocks[bundlei];
height = bp->bundleheight + bundlei;
if ( bundlei >= 0 && bundlei < bp->n )
{
if ( block == 0 )
block = bp->blocks[bundlei];
height = bp->bundleheight + bundlei;
}
else
{
if ( priority == 0 && -bundlei >= 0 && -bundlei < bp->n && bp->speculative != 0 )
{
if ( bp->speculativecache[-bundlei] != 0 )
return(0);
}
bp = 0;
bundlei = -1;
}
}
if ( block != 0 )
{
@ -1308,6 +1299,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle
req->height = height;
req->bundlei = bundlei;
char str2[65];
//printf("%s %s %s [%d:%d] %d %s %d numranked.%d qsize.%d\n",coin->symbol,argstr,str,bp!=0?bp->hdrsi:-1,bundlei,req->height,bits256_str(str2,hash2),coin->blocks.recvblocks,coin->peers.numranked,queue_size(Q));
if ( Q == &coin->blocksQ )
{
if ( (n= queue_size(Q)) > 100000 )
@ -1362,13 +1354,13 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr)
else if ( bp->numhashes < bp->n )
z = 1;
}
if ( bp == 0 || z != 0 || bp == coin->current )
if ( bp == 0 || bp->speculative == 0 || bp == coin->current )
{
//printf("%s request HDR.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp!=0?bp->numhashes:0);
printf("%s request HDR.(%s) numhashes.%d\n",addr!=0?addr->ipaddr:"local",hashstr,bp!=0?bp->numhashes:0);
iguana_send(coin,addr,serialized,datalen);
addr->pendhdrs++;
flag++;
} 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);
} //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);

67
iguana/iguana_unspents.c

@ -406,14 +406,14 @@ struct iguana_txid *iguana_txidfind(struct iguana_info *coin,int32_t *heightp,st
return(0);
}
struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spend_hdrsi,struct iguana_spend *s)
struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spent_hdrsi,struct iguana_spend *s)
{
int32_t prev_vout,height,hdrsi; uint32_t sequenceid,unspentind; char str[65];
struct iguana_bundle *spentbp=0; struct iguana_txid *T,TX,*tp; bits256 *X; bits256 prev_hash;
X = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Xoffset);
T = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset);
sequenceid = s->sequenceid;
hdrsi = spend_hdrsi;
hdrsi = spent_hdrsi;
*unspentindp = 0;
memset(prevhashp,0,sizeof(*prevhashp));
if ( s->prevout < 0 )
@ -431,7 +431,7 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
*unspentindp = unspentind;
if ( unspentind == 0 )
{
if ( (tp= iguana_txidfind(coin,&height,&TX,prev_hash,spend_hdrsi-1)) != 0 )
if ( (tp= iguana_txidfind(coin,&height,&TX,prev_hash,spent_hdrsi-1)) != 0 )
{
*unspentindp = unspentind = TX.firstvout + ((prev_vout > 0) ? prev_vout : 0);
hdrsi = height / coin->chain->bundlesize;
@ -439,12 +439,12 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
}
else
{
printf("cant find prev_hash.(%s) for bp.[%d]\n",bits256_str(str,prev_hash),spend_hdrsi);
printf("cant find prev_hash.(%s) for bp.[%d]\n",bits256_str(str,prev_hash),spent_hdrsi);
}
}
} else printf("external spent unexpected nonz unspentind [%d]\n",spent_hdrsi);
}
if ( hdrsi > spend_hdrsi || (spentbp= coin->bundles[hdrsi]) == 0 )
printf("illegal hdrsi.%d when [%d] spentbp.%p\n",hdrsi,spend_hdrsi,spentbp);//, getchar();
if ( hdrsi > spent_hdrsi || (spentbp= coin->bundles[hdrsi]) == 0 )
printf("illegal hdrsi.%d when [%d] spentbp.%p\n",hdrsi,spent_hdrsi,spentbp);//, getchar();
//else if ( spentbp->ramchain.spents[unspentind].ind != 0 || hdrsi < 0 )
// printf("DOUBLE SPEND? U%d %p bp.[%d] unspentind.%u already has %u, no room\n",unspentind,&spentbp->ramchain.spents[unspentind],hdrsi,unspentind,spentbp->ramchain.spents[unspentind].ind);//, getchar();
else if ( unspentind == 0 || unspentind >= spentbp->ramchain.H.data->numunspents )
@ -637,6 +637,24 @@ void iguana_unspents(struct supernet_info *myinfo,struct iguana_info *coin,cJSON
free(rmdarray);
}
void iguana_prefetch(struct iguana_info *coin,struct iguana_bundle *bp)
{
int32_t i; struct iguana_bundle *spentbp; uint32_t starttime = (uint32_t)time(NULL);
if ( bp->hdrsi > 30 )
{
printf("start prefetch for [%d]\n",bp->hdrsi);
for (i=1; i<30; i++)
{
if ( (spentbp= coin->bundles[bp->hdrsi - i]) != 0 )
{
iguana_ramchain_prefetch(coin,&spentbp->ramchain);
spentbp->lastprefetch = starttime;
}
}
printf("end prefetch for [%d] elapsed %d\n",bp->hdrsi,(uint32_t)time(NULL)-starttime);
}
}
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
{
static uint64_t total,emitted;
@ -657,23 +675,13 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
//printf("iguana_spendvectors: already have Xspendinds[%d]\n",ramchain->numXspends);
return(0);
}
starttime = (uint32_t)time(NULL);
ptr = mycalloc('x',sizeof(*ptr),n);
total += n;
//printf("start UTXOGEN.%d max.%d ptr.%p\n",bp->bundleheight,n,ptr);
txidind = spendind = rdata->firsti;
iguana_ramchain_prefetch(coin,ramchain);
if ( bp->hdrsi > 5 )
{
for (i=1; i<5; i++)
{
if ( (spentbp= coin->bundles[bp->hdrsi - i]) != 0 )
{
iguana_ramchain_prefetch(coin,&spentbp->ramchain);
spentbp->lastprefetch = starttime;
}
}
}
iguana_prefetch(coin,bp);
starttime = (uint32_t)time(NULL);
for (i=0; i<bp->n; i++)
{
if ( txidind != B[i].firsttxidind || spendind != B[i].firstvin )
@ -693,7 +701,7 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
}
for (k=0; k<T[txidind].numvins && errs==0; k++,spendind++)
{
if ( (spendind % 100000) == 0 )
if ( (spendind % 1000000) == 0 )
printf("spendvectors elapsed.%-3d [%-3d:%4d] spendind.%d\n",(uint32_t)time(NULL)-starttime,bp->hdrsi,i,spendind);
s = &S[spendind];
u = 0;
@ -1214,6 +1222,7 @@ void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp)
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;
iguana_prefetch(coin,bp);
}
}
@ -1322,10 +1331,11 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist)
{
int32_t hdrsi,numpkinds,iter,numhdrsi,numunspents,err; struct iguana_bundle *bp;
int32_t hdrsi,numpkinds,iter,numhdrsi,numunspents,err,origcount; struct iguana_bundle *bp;
char fname[1024],fname2[1024],destfname[1024]; bits256 balancehash; FILE *fp,*fp2;
struct iguana_utxo *Uptr; struct iguana_account *Aptr; struct sha256_vstate vstate;
vupdate_sha256(balancehash.bytes,&vstate,0,0);
origcount = coin->balanceswritten;
for (hdrsi=0; hdrsi<coin->bundlescount; hdrsi++)
if ( (bp= coin->bundles[hdrsi]) == 0 || bp->balancefinish <= 1 || bp->ramchain.H.data == 0 || bp->ramchain.A == 0 || bp->ramchain.Uextras == 0 )
break;
@ -1438,7 +1448,20 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu
}
char str[65]; printf("BALANCES WRITTEN for %d bundles %s\n",coin->balanceswritten,bits256_str(str,coin->balancehash));
iguana_coinpurge(coin);
//exit(-1);
if ( strcmp(coin->symbol,"BTC") == 0 && coin->balanceswritten > origcount+10 )
{
int32_t i;
coin->active = 0;
coin->started = 0;
for (i=0; i<IGUANA_MAXPEERS; i++)
coin->peers.active[i].dead = (uint32_t)time(NULL);
for (i=0; i<100; i++)
{
printf("need to exit, please restart after shutdown in %d seconds, or just ctrl-C\n",100-i);
sleep(1);
}
exit(-1);
}
//coin->balanceswritten = iguana_volatileinit(coin);
//iguana_RTramchainfree(coin);
return(coin->balanceswritten);

Loading…
Cancel
Save