Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
befbe7eda1
  1. 5
      iguana/iguana777.h
  2. 9
      iguana/iguana_bundles.c
  3. 78
      iguana/iguana_init.c
  4. 18
      iguana/iguana_ramchain.c
  5. 1
      iguana/main.c

5
iguana/iguana777.h

@ -454,7 +454,7 @@ struct iguana_info
struct iguana_peers peers;
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,estsize,activebundles;
int32_t MAXPEERS,MAXPENDING,MAXBUNDLES,active,closestbundle,numemitted,lastsweep,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,balanceswritten;
int32_t MAXPEERS,MAXPENDING,MAXBUNDLES,active,closestbundle,numemitted,lastsweep,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,balanceswritten; bits256 balancehash;
uint32_t longestchain,lastsync,parsetime,numiAddrs,firstblock,lastpossible,bundlescount,savedblocks;
struct tai starttime; double startmillis;
struct iguana_chain *chain;
@ -474,7 +474,8 @@ struct iguana_info
double backstopmillis; bits256 backstophash2; int64_t spaceused;
int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes; bits256 reqtxids[64];
void *launched,*started;
uint64_t bloomsearches,bloomhits,bloomfalse,collisions; uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192],bundlebits[IGUANA_MAXBUNDLES/8+1]; struct OS_memspace blockMEM;
uint64_t bloomsearches,bloomhits,bloomfalse,collisions;
uint8_t blockspace[IGUANA_MAXPACKETSIZE + 8192]; struct OS_memspace blockMEM;
struct iguana_blocks blocks; bits256 APIblockhash,APItxid; char *APIblockstr;
struct iguana_waccount *wallet;
};

9
iguana/iguana_bundles.c

@ -761,7 +761,7 @@ 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;
struct iguana_bundle *prevbp; int32_t i,retval;
if ( (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)-1 )
return(0);
for (i=0; i<bp->hdrsi; i++)
@ -772,10 +772,15 @@ int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp)
if ( bp->startutxo == 0 )
{
bp->startutxo = (uint32_t)time(NULL);
if ( iguana_utxogen(coin,bp) >= 0 )
if ( (retval= iguana_utxogen(coin,bp)) >= 0 )
{
if ( retval > 0 )
{
printf("GENERATED UTXO.%d for ht.%d duration %d seconds\n",bp->hdrsi,bp->bundleheight,(uint32_t)time(NULL)-bp->startutxo);
bp->utxofinish = (uint32_t)time(NULL);
bp->balancefinish = 0;
}
if ( bp->balancefinish <= 1 )
iguana_balancesQ(coin,bp);
return(1);
} else printf("UTXO gen.[%d] utxo error\n",bp->hdrsi);

78
iguana/iguana_init.c

@ -184,6 +184,34 @@ int32_t iguana_savehdrs(struct iguana_info *coin)
return(retval);
}
void iguana_truncatebalances(struct iguana_info *coin)
{
int32_t i; struct iguana_bundle *bp; struct iguana_ramchain *ramchain;
for (i=0; i<coin->balanceswritten; i++)
{
if ( (bp= coin->bundles[i]) != 0 )
{
bp->balancefinish = 0;
ramchain = &bp->ramchain;
if ( ramchain->debitsfileptr != 0 )
{
munmap(ramchain->debitsfileptr,ramchain->debitsfilesize);
ramchain->debitsfileptr = 0;
ramchain->debitsfilesize = 0;
ramchain->A = 0;
}
if ( ramchain->lastspendsfileptr != 0 )
{
munmap(ramchain->lastspendsfileptr,ramchain->lastspendsfilesize);
ramchain->lastspendsfileptr = 0;
ramchain->lastspendsfilesize = 0;
ramchain->Uextras = 0;
}
}
}
coin->balanceswritten = 0;
}
void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
{
int32_t i,j,k,m,c,height,flag,bundlei; char checkstr[1024],line[1024];
@ -275,14 +303,6 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
bp->emitfinish = (uint32_t)time(NULL) + 1;
if ( coin->current != 0 && coin->current->hdrsi+1 == bp->hdrsi )
coin->current = bp;
//printf("LOADED bundle.%d %p current %p\n",bp->bundleheight,bp,coin->current);
//if ( bp->hdrsi == 0 || coin->bundles[bp->hdrsi-1]->emitfinish != 0 )
{
if ( 0 )
bp->validated = bp->balancefinish = bp->startutxo = bp->utxofinish = (uint32_t)time(NULL);
//printf("GENERATE UTXO, verify sigs, etc for ht.%d\n",bp->bundleheight);
iguana_bundleQ(coin,bp,1000);
}
}
else
{
@ -308,18 +328,46 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp)
}
if ( iter == 1 )
{
for (i=0; i<coin->bundlescount; i++)
if ( coin->bundles[i] == 0 )
if ( coin->balanceswritten > 0 )
{
for (i=0; i<coin->balanceswritten; i++)
if ( (bp= coin->bundles[i]) == 0 || bp->emitfinish <= 1 || bp->utxofinish <= 1 )
break;
printf("INIT bundles i.%d\n",i);
if ( 0 && i == coin->bundlescount && i > 1 )
if ( i != coin->balanceswritten )
{
bp = coin->bundles[coin->bundlescount - 2];
bp->emitfinish = bp->startutxo = bp->utxofinish = bp->balancefinish = 0;
iguana_bundleQ(coin,bp,1000);
printf("TRUNCATE balances written.%d -> %d\n",coin->balanceswritten,i);
iguana_truncatebalances(coin);
}
else
{
bits256 balancehash; struct iguana_utxo *Uptr; struct iguana_account *Aptr; struct sha256_vstate vstate; int32_t numpkinds,numunspents;
vupdate_sha256(balancehash.bytes,&vstate,0,0);
for (i=0; i<coin->balanceswritten; i++)
{
if ( (bp= coin->bundles[i]) != 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 )
{
vupdate_sha256(balancehash.bytes,&vstate,(void *)Aptr,sizeof(*Aptr)*numpkinds);
vupdate_sha256(balancehash.bytes,&vstate,(void *)Uptr,sizeof(*Uptr)*numunspents);
}
}
char str[65],str2[65]; printf("balancehash.(%s) vs (%s)\n",bits256_str(str,balancehash),bits256_str(str2,coin->balancehash));
if ( memcmp(balancehash.bytes,coin->balancehash.bytes,sizeof(balancehash)) != 0 )
{
printf("balancehash mismatch\n");
iguana_truncatebalances(coin);
} else printf("MATCHED balancehash numhdrsi.%d\n",coin->balanceswritten);
}
}
char buf[2048];
iguana_bundlestats(coin,buf);
if ( coin->balanceswritten < coin->bundlescount )
{
for (i=coin->balanceswritten; i<coin->bundlescount; i++)
{
if ( (bp= coin->bundles[i]) != 0 && bp->queued == 0 )
iguana_bundleQ(coin,bp,1000);
}
}
}
}

18
iguana/iguana_ramchain.c

@ -1305,7 +1305,7 @@ int32_t iguana_ramchain_free(struct iguana_ramchain *ramchain,int32_t deleteflag
int32_t iguana_ramchain_extras(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,int32_t extraflag)
{
RAMCHAIN_DECLARE; int32_t err=0,numhdrsi; char fname[1024]; //long filesize;
RAMCHAIN_DECLARE; int32_t err=0,numhdrsi; char fname[1024]; bits256 balancehash;
if ( ramchain->expanded != 0 )
{
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data);
@ -1324,22 +1324,27 @@ int32_t iguana_ramchain_extras(struct iguana_info *coin,struct iguana_ramchain *
if ( (ramchain->debitsfileptr= OS_mapfile(fname,&ramchain->debitsfilesize,0)) != 0 && ramchain->debitsfilesize == sizeof(int32_t) + sizeof(bits256) + sizeof(*ramchain->A) * ramchain->H.data->numpkinds )
{
numhdrsi = *(int32_t *)ramchain->debitsfileptr;
memcpy(balancehash.bytes,(void *)((long)ramchain->debitsfileptr + sizeof(numhdrsi)),sizeof(balancehash));
if ( coin->balanceswritten == 0 && numhdrsi > 0 && numhdrsi <= coin->bundlescount )
{
coin->balanceswritten = numhdrsi;
else if ( numhdrsi == coin->balanceswritten )
coin->balancehash = balancehash;
}
else if ( numhdrsi == coin->balanceswritten || memcmp(balancehash.bytes,coin->balancehash.bytes,sizeof(balancehash)) == 0 )
{
ramchain->A = (void *)((long)ramchain->debitsfileptr + sizeof(numhdrsi) + sizeof(bits256));
sprintf(fname,"DB/%s/accounts/lastspends.%d",coin->symbol,ramchain->H.data->height);
if ( (ramchain->lastspendsfileptr= OS_mapfile(fname,&ramchain->lastspendsfilesize,0)) != 0 && ramchain->lastspendsfilesize == sizeof(int32_t) + sizeof(bits256) + sizeof(*ramchain->Uextras) * ramchain->H.data->numunspents )
{
numhdrsi = *(int32_t *)ramchain->lastspendsfileptr;
if ( numhdrsi == coin->balanceswritten )
memcpy(balancehash.bytes,(void *)((long)ramchain->lastspendsfileptr + sizeof(numhdrsi)),sizeof(balancehash));
if ( numhdrsi == coin->balanceswritten || memcmp(balancehash.bytes,coin->balancehash.bytes,sizeof(balancehash)) == 0 )
{
ramchain->Uextras = (void *)((long)ramchain->lastspendsfileptr + sizeof(numhdrsi) + sizeof(bits256));
err = 0;
} else printf("ramchain map error2 balanceswritten %d vs %d hashes %x %x\n",coin->balanceswritten,numhdrsi,coin->balancehash.uints[0],balancehash.uints[0]);
}
}
} else printf("ramchain map error balanceswritten %d vs %d\n",coin->balanceswritten,numhdrsi);
} else printf("ramchain map error balanceswritten %d vs %d hashes %x %x\n",coin->balanceswritten,numhdrsi,coin->balancehash.uints[0],balancehash.uints[0]);
}
if ( err != 0 )
{
@ -1480,7 +1485,10 @@ struct iguana_ramchain *iguana_ramchain_map(struct iguana_info *coin,char *fname
if ( allocextras > 0 )
{
if ( iguana_ramchain_extras(coin,ramchain,ramchain->hashmem,allocextras) == 0 && bp != 0 )
{
bp->balancefinish = (uint32_t)time(NULL);
printf("found balances for %d\n",bp->hdrsi);
}
}
}
if ( B != 0 && bp != 0 )

1
iguana/main.c

@ -329,7 +329,6 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu
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;

Loading…
Cancel
Save