Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
581fee668a
  1. 2
      iguana/iguana777.c
  2. 4
      iguana/iguana777.h
  3. 2
      iguana/iguana_bundles.c
  4. 128
      iguana/iguana_unspents.c

2
iguana/iguana777.c

@ -459,7 +459,7 @@ void iguana_helper(void *arg)
if ( coin->polltimeout < polltimeout )
polltimeout = coin->polltimeout;
//printf("call spendvectors.%d\n",bp->hdrsi);
if ( (retval= iguana_spendvectors(coin,bp)) >= 0 )
if ( (retval= iguana_spendvectors(coin,bp,0)) >= 0 )
{
flag++;
if ( retval > 0 )

4
iguana/iguana777.h

@ -24,7 +24,6 @@ typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t
#define IGUANA_MAXSCRIPTSIZE 10001
#define IGUANA_SERIALIZE_SPENDVECTORGEN
#define IGUANA_SERIALIZE_BALANCEGEN
//#define IGUANA_DISABLEPEERS
#define _IGUANA_MAXSTUCKTIME 30
#define IGUANA_MAXITERATIONS 10000
@ -443,6 +442,7 @@ struct iguana_bundle
uint32_t issued[IGUANA_MAXBUNDLESIZE];
bits256 prevbundlehash2,hashes[IGUANA_MAXBUNDLESIZE+1],nextbundlehash2,allhash,*speculative;
struct iguana_ramchain ramchain; uint8_t red,green,blue;
struct iguana_spendvector *tmpspends; int32_t numtmpspends;
};
struct iguana_bundlereq
@ -801,7 +801,7 @@ uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8
int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *suffixp,uint8_t *vinscript,int32_t scriptlen);
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);
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,int32_t RTmode);
int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight);
int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp);
void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp);

2
iguana/iguana_bundles.c

@ -720,7 +720,7 @@ int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp)
{
struct iguana_bundle *prevbp; int32_t i;
#ifdef IGUANA_SERIALIZE_SPENDVECTORGEN
if ( coin->PREFETCHLAG != 0 && (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)-0*coin->MAXBUNDLES )
if ( (prevbp= coin->current) != 0 && prevbp->hdrsi < (coin->longestchain / coin->chain->bundlesize)-0*coin->MAXBUNDLES )
return(0);
#endif
for (i=0; i<bp->hdrsi; i++)

128
iguana/iguana_unspents.c

@ -690,13 +690,44 @@ void iguana_prefetch(struct iguana_info *coin,struct iguana_bundle *bp,int32_t w
}
}
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
int32_t iguana_spendvectorsave(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,struct iguana_spendvector *ptr,int32_t emit,int32_t n)
{
int32_t retval = -1; FILE *fp; char fname[1024],str[65]; long fsize; bits256 zero,sha256;
memset(zero.bytes,0,sizeof(zero));
sprintf(fname,"DB/%s/spends/%s.%d",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight);
vcalc_sha256(0,sha256.bytes,(void *)ptr,(int32_t)(sizeof(*ptr) * emit));
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(sha256.bytes,1,sizeof(sha256),fp) != sizeof(sha256) )
printf("error writing hash for %ld -> (%s)\n",sizeof(*ptr) * emit,fname);
else if ( fwrite(ptr,sizeof(*ptr),emit,fp) != emit )
printf("error writing %d of %d -> (%s)\n",emit,n,fname);
else
{
retval = 0;
fsize = ftell(fp);
fclose(fp), fp = 0;
if ( iguana_Xspendmap(coin,ramchain,bp) < 0 )
printf("error mapping Xspendmap.(%s)\n",fname);
else retval = 0;
}
if ( fp != 0 )
fclose(fp);
//int32_t i; for (i=0; i<ramchain->numXspends; i++)
// printf("(%d u%d) ",ramchain->Xspendinds[i].hdrsi,ramchain->Xspendinds[i].ind);
//printf("filesize %ld Xspendptr.%p %p num.%d\n",fsize,ramchain->Xspendptr,ramchain->Xspendinds,ramchain->numXspends);
}
else printf("iguana_spendvectors: Error creating.(%s)\n",fname);
return(retval);
}
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,int32_t RTmode)
{
static uint64_t total,emitted;
int32_t spendind,n,txidind,errs=0,emit=0,i,j,k,retval = -1; long fsize;
int32_t spendind,n,txidind,errs=0,emit=0,i,j,k;
uint32_t spent_unspentind,spent_pkind,now,starttime; struct iguana_ramchaindata *rdata;
struct iguana_bundle *spentbp; struct iguana_blockRO *B; FILE *fp; char fname[1024],str[65];
bits256 prevhash,zero,sha256; struct iguana_unspent *u,*spentU; struct iguana_txid *T;
struct iguana_bundle *spentbp; struct iguana_blockRO *B; char str[65];
bits256 prevhash; struct iguana_unspent *u,*spentU; struct iguana_txid *T;
struct iguana_spend *S,*s; struct iguana_spendvector *ptr; struct iguana_ramchain *ramchain;
ramchain = &bp->ramchain;
//printf("iguana_spendvectors.[%d] gen.%d ramchain data.%p\n",bp->hdrsi,bp->bundleheight,ramchain->H.data);
@ -760,33 +791,45 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
iguana_ramchain_prefetch(coin,&spentbp->ramchain);
spentbp->lastprefetch = now;
}*/
spentU = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Uoffset);
u = &spentU[spent_unspentind];
if ( (spent_pkind= u->pkind) != 0 && spent_pkind < spentbp->ramchain.H.data->numpkinds )
if ( RTmode != 0 )
{
if ( (ptr[emit].unspentind= spent_unspentind) != 0 && spentbp->hdrsi < bp->hdrsi )
spentU = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Uoffset);
u = &spentU[spent_unspentind];
if ( (spent_pkind= u->pkind) != 0 && spent_pkind < spentbp->ramchain.H.data->numpkinds )
{
ptr[emit].hdrsi = spentbp->hdrsi;
ptr[emit].pkind = spent_pkind;
ptr[emit].value = u->value;
ptr[emit].bundlei = i;
//ptr[emit].txi = j;
//printf("(%d u%d).%d ",spentbp->hdrsi,unspentind,emit);
emit++;
if ( (ptr[emit].unspentind= spent_unspentind) != 0 && spentbp->hdrsi < bp->hdrsi )
{
ptr[emit].hdrsi = spentbp->hdrsi;
ptr[emit].pkind = spent_pkind;
ptr[emit].value = u->value;
ptr[emit].bundlei = i;
//ptr[emit].txi = j;
//printf("(%d u%d).%d ",spentbp->hdrsi,unspentind,emit);
emit++;
}
else
{
printf("spendvectors: null unspentind for spendind.%d hdrsi.%d [%d]\n",spendind,spentbp->hdrsi,bp->hdrsi);
errs++;
break;
}
}
else
{
printf("spendvectors: null unspentind for spendind.%d hdrsi.%d [%d]\n",spendind,spentbp->hdrsi,bp->hdrsi);
errs++;
printf("spendvectors: unresolved spendind.%d hdrsi.%d\n",spendind,bp->hdrsi);
break;
}
}
else
{
errs++;
printf("spendvectors: unresolved spendind.%d hdrsi.%d\n",spendind,bp->hdrsi);
break;
ptr[emit].hdrsi = spentbp->hdrsi;
ptr[emit].pkind = spent_unspentind; // temp overload
ptr[emit].bundlei = i;
//ptr[emit].txi = j;
//printf("(%d u%d).%d ",spentbp->hdrsi,unspentind,emit);
emit++;
}
}
else
@ -812,32 +855,15 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
if ( errs == 0 && emit >= 0 )
{
emitted += emit;
memset(zero.bytes,0,sizeof(zero));
sprintf(fname,"DB/%s/spends/%s.%d",coin->symbol,bits256_str(str,bp->hashes[0]),bp->bundleheight);
vcalc_sha256(0,sha256.bytes,(void *)ptr,(int32_t)(sizeof(*ptr) * emit));
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(sha256.bytes,1,sizeof(sha256),fp) != sizeof(sha256) )
printf("error writing hash for %ld -> (%s)\n",sizeof(*ptr) * emit,fname);
else if ( fwrite(ptr,sizeof(*ptr),emit,fp) != emit )
printf("error writing %d of %d -> (%s)\n",emit,n,fname);
else retval = 0;
fsize = ftell(fp);
fclose(fp);
if ( iguana_Xspendmap(coin,ramchain,bp) < 0 )
{
printf("error mapping Xspendmap.(%s)\n",fname);
retval = -1;
}
//int32_t i; for (i=0; i<ramchain->numXspends; i++)
// printf("(%d u%d) ",ramchain->Xspendinds[i].hdrsi,ramchain->Xspendinds[i].ind);
//printf("filesize %ld Xspendptr.%p %p num.%d\n",fsize,ramchain->Xspendptr,ramchain->Xspendinds,ramchain->numXspends);
}
if ( RTmode != 0 )
iguana_spendvectorsave(coin,bp,ramchain,ptr,emit,n);
else
{
printf("iguana_spendvectors: Error creating.(%s)\n",fname);
retval = -1;
if ( bp->tmpspends != 0 )
printf("unexpected tmpspends? [%d] numtmpspends.%d vs emit.%d\n",bp->hdrsi,bp->numtmpspends,emit);
bp->tmpspends = myrealloc('x',ptr,sizeof(*ptr)*n,sizeof(*ptr)*emit);
}
bp->numtmpspends = emit;
}
if ( ptr != 0 )
myfree(ptr,sizeof(*ptr) * n);
@ -1542,7 +1568,7 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi,int32_t pu
int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight)
{
uint32_t starttime,j=0,flag = 0; struct iguana_bundle *prevbp;
uint32_t starttime; int32_t j=0,flag = 0; struct iguana_bundle *prevbp;
if ( bp->balancefinish > 1 )
{
printf("make sure DB files have this bp.%d\n",bp->hdrsi);
@ -1552,17 +1578,15 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int
bp->nexttime = (uint32_t)time(NULL);
if ( bp != 0 && coin != 0 && (bp->hdrsi == 0 || (prevbp= coin->bundles[bp->hdrsi-1]) != 0) )
{
#ifdef IGUANA_SERIALIZE_BALANCEGEN
for (j=0; j<coin->bundlescount-1; j++)
{
if ( (prevbp= coin->bundles[j]) == 0 || prevbp->utxofinish <= 1 )
if ( (prevbp= coin->bundles[j]) == 0 || prevbp->utxofinish <= 1 || prevbp->tmpspends == 0 )
{
j = -1;
break;
}
}
#endif
if ( j != -1 )
/*if ( j != -1 )
{
for (j=0; j<bp->hdrsi; j++)
{
@ -1572,9 +1596,9 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int
break;
}
}
}
}*/
//printf("B [%d] j.%d u.%u b.%u\n",bp->hdrsi,j,bp->utxofinish,bp->balancefinish);
if ( bp->bundleheight+bp->n <= coin->blocks.hwmchain.height && bp->utxofinish > 1 && bp->balancefinish <= 1 && (bp->hdrsi == 0 || bp->hdrsi == j) )
if ( j >= 0 && bp->bundleheight+bp->n <= coin->blocks.hwmchain.height && bp->utxofinish > 1 && bp->balancefinish <= 1 )//&& (bp->hdrsi == 0 || bp->hdrsi == j) )
{
if ( bp->hdrsi >= coin->balanceswritten )
{
@ -1592,7 +1616,7 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int
}
bp->balancefinish = (uint32_t)time(NULL);
bp->queued = 0;
if ( bp->hdrsi >= coin->blocks.hwmchain.height/coin->chain->bundlesize-1 && bp->hdrsi >= coin->longestchain/coin->chain->bundlesize-3 )
if ( bp->hdrsi >= coin->blocks.hwmchain.height/coin->chain->bundlesize-1 && bp->hdrsi >= coin->longestchain/coin->chain->bundlesize-1 )
{
printf("TRIGGER FLUSH %d vs %d\n",bp->hdrsi,coin->blocks.hwmchain.height/coin->chain->bundlesize);
sleep(1);
@ -1608,7 +1632,7 @@ int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int
else
{
//printf("third case.%d utxo.%u balance.%u prev.%u\n",bp->hdrsi,bp->utxofinish,bp->balancefinish,prevbp!=0?prevbp->utxofinish:-1);
coin->pendbalances--;
//coin->pendbalances--;
iguana_balancesQ(coin,bp);
}
}

Loading…
Cancel
Save