Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
1b3a623c42
  1. 2
      iguana/iguana777.h
  2. 8
      iguana/iguana_bundles.c
  3. 2
      iguana/iguana_peers.c
  4. 4
      iguana/iguana_recv.c
  5. 92
      iguana/main.c

2
iguana/iguana777.h

@ -788,7 +788,7 @@ int32_t iguana_bloomfind(struct iguana_info *coin,struct iguana_bloom16 *bloom,i
struct iguana_bloominds iguana_bloomset(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit);
int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp);
void iguana_balancesQ(struct iguana_info *coin,struct iguana_bundle *bp);
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi);
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist);
int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti,int32_t max);
void iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp);
int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe);

8
iguana/iguana_bundles.c

@ -496,7 +496,7 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int
{
if ( peercounts[i] > threshold && (addr= coin->peers.ranked[i]) != 0 && now > bp->currenttime+lag && addr->dead == 0 )
{
if ( numpeers > 64 || addr->laggard++ > 777 )
if ( numpeers > 64 || addr->laggard++ > 13 )
addr->dead = (uint32_t)time(NULL);
for (j=0; j<bp->n; j++)
{
@ -762,8 +762,8 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp)
int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp)
{
struct iguana_bundle *prevbp; int32_t i;
if ( (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)-1 )
return(0);
//if ( (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)-1 )
// return(0);
for (i=0; i<bp->hdrsi; i++)
if ( (prevbp= coin->bundles[i]) == 0 || prevbp->emitfinish < coin->startutc )
break;
@ -829,7 +829,7 @@ int32_t iguana_bundleiters(struct iguana_info *coin,struct OS_memspace *mem,stru
{
if ( iguana_bundleready(coin,bp) == bp->n )
{
printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT bundle.%d | 1st.%d h.%d s.[%d] maxbundles.%d NET.(h%d b%d)\n",bp->bundleheight,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,netBLOCKS);
printf(">>>>>>>>>>>>>>>>>>>>>>> EMIT.%s bundle.%d | 1st.%d h.%d s.[%d] maxbundles.%d NET.(h%d b%d)\n",coin->symbol,bp->bundleheight,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,netBLOCKS);
bp->emitfinish = 1;
iguana_bundletweak(coin,bp);
sleep(1); // just in case data isnt totally sync'ed to HDD

2
iguana/iguana_peers.c

@ -1085,7 +1085,7 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
addr->dead = 1;
}
}
printf(">>>>>>>>>>>>>> finish dedicatedloop.%s\n",addr->ipaddr);
printf(">>>>>>>>>>>>>> finish %s dedicatedloop.%s\n",coin->symbol,addr->ipaddr);
if ( addr->vinsfp != 0 )
fclose(addr->vinsfp);
if ( addr->voutsfp != 0 )

4
iguana/iguana_recv.c

@ -620,7 +620,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
}
if ( bp != 0 && (bp->speculative == 0 || num > bp->numspec) && bp->emitfinish == 0 )
{
printf("FOUND speculative.%s BLOCKHASHES[%d] ht.%d\n",bits256_str(str,blockhashes[1]),num,bp->bundleheight);
//printf("FOUND speculative.%s BLOCKHASHES[%d] ht.%d\n",bits256_str(str,blockhashes[1]),num,bp->bundleheight);
if ( bp->speculative == 0 )
bp->speculative = mycalloc('s',bp->n+1,sizeof(*bp->speculative));
for (i=bp->numspec; i<num&&i<=bp->n; i++)
@ -1006,7 +1006,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
flag++;
char str[65];
if ( 1 && (rand() % 1000) == 0 || bp->bundleheight > coin->longestchain-coin->chain->bundlesize )
printf("%s MAINCHAIN.%d threshold %.3f %.3f lag %.3f\n",bits256_str(str,hash2),coin->blocks.hwmchain.height+1,threshold,coin->backstopmillis,lag);
printf("%s %s MAINCHAIN.%d threshold %.3f %.3f lag %.3f\n",coin->symbol,bits256_str(str,hash2),coin->blocks.hwmchain.height+1,threshold,coin->backstopmillis,lag);
}
else if ( bp != 0 && bundlei < bp->n-1 && (bits256_nonz(bp->hashes[bundlei+1]) != 0 || (bp->speculative != 0 && bits256_nonz(bp->speculative[bundlei+1]) != 0)) )
{

92
iguana/main.c

@ -323,54 +323,90 @@ void sigalarm_func() { printf("\nSIGALRM\n"); signal(SIGALRM,sigalarm_func); }
void sigcontinue_func() { printf("\nSIGCONT\n"); signal(SIGCONT,sigcontinue_func); }
#endif
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi)
int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t purgedist)
{
int32_t hdrsi,numpkinds; struct iguana_bundle *bp; char fname[1024],fname2[1024]; struct iguana_utxo *Uptr; struct iguana_account *Aptr;
int32_t hdrsi,numpkinds,iter,numhdrsi,numunspents,err; 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);
memset(coin->bundlebits,0,sizeof(coin->bundlebits));
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;
if ( hdrsi <= coin->balanceswritten || hdrsi < refhdrsi )
return(0);
refhdrsi = hdrsi;
for (hdrsi=0; hdrsi<refhdrsi; hdrsi++)
numhdrsi = hdrsi+1;
vupdate_sha256(balancehash.bytes,&vstate,0,0);
for (iter=0; iter<3; iter++)
{
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (Aptr= bp->ramchain.A) != 0 && (Uptr= bp->ramchain.Uextras) != 0 )
for (hdrsi=0; hdrsi<numhdrsi; hdrsi++)
{
if ( 1 )//forceflag == 0 )
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->ramchain.H.data != 0 && (numpkinds= bp->ramchain.H.data->numpkinds) > 0 && (numunspents= bp->ramchain.H.data->numunspents) > 0 && (Aptr= bp->ramchain.A) != 0 && (Uptr= bp->ramchain.Uextras) != 0 )
{
sprintf(fname,"accounts/%s/debits.%d",coin->symbol,bp->bundleheight);
sprintf(fname2,"accounts/%s/lastspends.%d",coin->symbol,bp->bundleheight);
}
else
{
sprintf(fname,"DB/%s/accounts/debits_%d.%d",coin->symbol,coin->bundlescount,bp->bundleheight);
sprintf(fname2,"DB/%s/accounts/lastspends_%d.%d",coin->symbol,coin->bundlescount,bp->bundleheight);
}
//printf("save (%s) and (%s) %p %p\n",fname,fname2,bp,bp->ramchain.H.data);//,bp->ramchain.H.data->numpkinds,bp->ramchain.H.data->numunspents);
/* if ( (fp= fopen(fname,"wb")) != 0 && (fp2= fopen(fname2,"wb")) != 0 )
{
if ( fwrite(&coin->bundlescount,1,sizeof(coin->bundlescount),fp) == sizeof(coin->bundlescount) && fwrite(&coin->bundlescount,1,sizeof(coin->bundlescount),fp2) == sizeof(coin->bundlescount) && fwrite(coin->bundlebits,1,blen,fp) == blen && fwrite(coin->bundlebits,1,blen,fp2) == blen )
if ( iter == 0 )
{
if ( fwrite(bp->ramchain.A,sizeof(*bp->ramchain.A),bp->ramchain.H.data->numpkinds,fp) == bp->ramchain.H.data->numpkinds )
vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr)*numpkinds);
vupdate_sha256(balancehash.bytes,&vstate,(void *)Uptr,sizeof(*Uptr)*numunspents);
}
else if ( iter == 1 )
{
if ( (fp= fopen(fname,"wb")) != 0 && (fp2= fopen(fname2,"wb")) != 0 )
{
if ( fwrite(bp->ramchain.Uextras,sizeof(*bp->ramchain.Uextras),bp->ramchain.H.data->numunspents,fp2) == bp->ramchain.H.data->numunspents )
err = -1;
if ( fwrite(&numhdrsi,1,sizeof(numhdrsi),fp) == sizeof(numhdrsi) && fwrite(&numhdrsi,1,sizeof(numhdrsi),fp2) == sizeof(numhdrsi) && fwrite(balancehash.bytes,1,sizeof(balancehash),fp) == sizeof(balancehash) && fwrite(balancehash.bytes,1,sizeof(balancehash),fp2) == sizeof(balancehash) )
{
bp->dirty = 0;
printf("saved (%s) and (%s)\n",fname,fname2);
if ( fwrite(Aptr,sizeof(*Aptr),numpkinds,fp) == numpkinds )
{
if ( fwrite(Uptr,sizeof(*Uptr),numunspents,fp2) == numunspents )
{
bp->dirty = 0;
err = 0;
//printf("saved (%s) and (%s)\n",fname,fname2);
}
}
}
if ( err != 0 )
{
printf("balanceflush.%s error iter.%d hdrsi.%d\n",coin->symbol,iter,hdrsi);
fclose(fp);
fclose(fp2);
return(-1);
}
fclose(fp), fclose(fp2);
}
else if ( fp != 0 )
fclose(fp);
}
else if ( iter == 2 )
{
sprintf(destfname,"DB/%s/accounts/debits_%d.%d",coin->symbol,numhdrsi,bp->bundleheight);
if ( OS_copyfile(fname,destfname,1) < 0 )
{
printf("balances error copying (%s) -> (%s)\n",fname,destfname);
return(-1);
}
sprintf(destfname,"DB/%s/accounts/lastspends_%d.%d",coin->symbol,numhdrsi,bp->bundleheight);
if ( OS_copyfile(fname2,destfname,1) < 0 )
{
printf("balances error copying (%s) -> (%s)\n",fname2,destfname);
return(-1);
}
if ( hdrsi > numhdrsi-purgedist && numhdrsi >= purgedist )
{
sprintf(destfname,"DB/%s/accounts/debits_%d.%d",coin->symbol,numhdrsi-purgedist,bp->bundleheight);
OS_removefile(destfname,0);
sprintf(destfname,"DB/%s/accounts/lastspends_%d.%d",coin->symbol,numhdrsi-purgedist,bp->bundleheight);
OS_removefile(destfname,0);
}
continue;
}
fclose(fp), fclose(fp2);
if ( bp->dirty != 0 )
printf("error writing %s\n",fname);
}
else if ( fp != 0 )
fclose(fp);*/
}
else return(-1);
}
coin->balanceswritten = refhdrsi + 1;
coin->balanceswritten = numhdrsi;
printf("BALANCES WRITTEN for %d bundles\n",coin->balanceswritten);
return(coin->balanceswritten);
}
@ -400,7 +436,7 @@ void mainloop(struct supernet_info *myinfo)
//printf("hdrsi.%d start balances.%d\n",bp->hdrsi,bp->bundleheight);
iguana_balancecalc(ptr->coin,bp);
bp->queued = 0;
iguana_balanceflush(ptr->coin,bp->hdrsi);
iguana_balanceflush(ptr->coin,bp->hdrsi,3);
printf("flushed bp->hdrsi %d vs %d coin->longestchain/coin->chain->bundlesize\n",bp->hdrsi,coin->longestchain/coin->chain->bundlesize);
}
else

Loading…
Cancel
Save