Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
cdde8ce426
  1. 61
      iguana/iguana_ramchain.c

61
iguana/iguana_ramchain.c

@ -1758,7 +1758,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
int32_t j,metalen,hdrsi,prevout,scriptlen; uint32_t sequenceid,destspendind=0,desttxidind=0;
bits256 prevhash; uint64_t value; uint8_t type,_script[IGUANA_MAXSCRIPTSIZE]; struct iguana_unspent *u; struct scriptdata *script;
struct iguana_txid *tx; struct iguana_ramchaindata *rdata; uint8_t *rmd160,*scriptdata;
printf("iterate ramchain.%p rdata.%p dest.%p ht.%d/%d txids.%p\n",ramchain,ramchain->H.data,dest,bp->bundleheight,bp->n,ramchain->txids);
//printf("iterate ramchain.%p rdata.%p dest.%p ht.%d/%d txids.%p\n",ramchain,ramchain->H.data,dest,bp->bundleheight,bp->n,ramchain->txids);
if ( (rdata= ramchain->H.data) == 0 )
{
printf("iguana_ramchain_iterate cant iterate without data\n");
@ -1766,7 +1766,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
}
if ( dest != 0 )
_iguana_ramchain_setptrs(RAMCHAIN_DESTPTRS,dest->H.data);
else fprintf(stderr,"iterate %d/%d dest.%p ramchain.%p rdata.%p\n",bp->bundleheight,bp->n,dest,ramchain,rdata);
//else fprintf(stderr,"iterate %d/%d dest.%p ramchain.%p rdata.%p\n",bp->bundleheight,bp->n,dest,ramchain,rdata);
_iguana_ramchain_setptrs(RAMCHAIN_PTRS,ramchain->H.data);
ramchain->H.ROflag = 1;
ramchain->H.unspentind = ramchain->H.spendind = ramchain->pkind = rdata->firsti;
@ -1776,10 +1776,9 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
desttxidind = dest->H.txidind;
destspendind = dest->H.spendind;
}
printf("txid loop\n");
for (ramchain->H.txidind=rdata->firsti; ramchain->H.txidind<rdata->numtxids; ramchain->H.txidind++)
{
if ( 1 && ramchain->expanded == 0 && dest != 0 )
if ( 0 && ramchain->expanded == 0 && dest != 0 )
printf("ITER TXID.%d -> dest.%p desttxid.%d dest->hashmem.%p numtxids.%d\n",ramchain->H.txidind,dest,dest!=0?dest->H.txidind:0,dest!=0?dest->hashmem:0,rdata->numtxids);
tx = &T[ramchain->H.txidind];
if ( iguana_ramchain_addtxid(coin,RAMCHAIN_ARG,tx->txid,tx->numvouts,tx->numvins,tx->locktime,tx->version,tx->timestamp) == 0 )
@ -1787,12 +1786,11 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
if ( dest != 0 )
{
char str[65];
if ( 1 && ramchain->expanded == 0 )
if ( 0 && ramchain->expanded == 0 )
printf("add hdrsi.%d dest.%p txidind.%d %s\n",dest->H.hdrsi,ramchain,dest->H.txidind,bits256_str(str,tx->txid));
if ( iguana_ramchain_addtxid(coin,RAMCHAIN_DESTARG,tx->txid,tx->numvouts,tx->numvins,tx->locktime,tx->version,tx->timestamp) == 0 )
return(-2);
}
else printf("txid added\n");
for (j=0; j<tx->numvouts; j++)
{
script = 0;
@ -1803,7 +1801,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
if ( ramchain->expanded != 0 )
{
u = &Ux[ramchain->H.unspentind];
if ( 1 && ramchain->expanded == 0 && dest != 0 )
if ( 0 && ramchain->expanded == 0 && dest != 0 )
fprintf(stderr,"unspentind.%d pkind.%d Ux.%p scriptoffset.%d pubkeyoffset.%d\n",ramchain->H.unspentind,Ux[ramchain->H.unspentind].pkind,Ux,u->scriptoffset,P[u->pkind].pubkeyoffset);
value = u->value;
hdrsi = u->hdrsi;
@ -1830,12 +1828,12 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
scriptdata = U[ramchain->H.unspentind].scriptptr;
scriptlen = U[ramchain->H.unspentind].scriptlen;
//scriptdata = iguana_scriptptr(coin,&scriptlen,_script,U[ramchain->H.unspentind].scriptfpos,U[ramchain->H.unspentind].scriptptr,U[ramchain->H.unspentind].scriptlen,sizeof(U[ramchain->H.unspentind].scriptptr),0);
if ( scriptdata != 0 && scriptlen > 0 )
/*if ( scriptdata != 0 && scriptlen > 0 )
{
int32_t i; for (i=0; i<scriptlen; i++)
printf("%02x",scriptdata[i]);
fprintf(stderr," raw unspent script type.%d U%d\n",type,ramchain->H.unspentind);
} else printf("no script\n");
} else printf("no script\n");*/
//for (i=0; i<20; i++)
// printf("%02x",rmd160[i]);
//printf(" raw rmd160\n");
@ -1846,7 +1844,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
{
if ( iguana_ramchain_addunspent(coin,RAMCHAIN_DESTARG,value,hdrsi,rmd160,j,type,scriptdata,scriptlen) == 0 )
return(-5);
} else printf("addunspent20 done\n");
} //else printf("addunspent20 done\n");
} else return(-6);
}
ramchain->H.spendind += tx->numvins;
@ -1854,13 +1852,13 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
{
dest->H.txidind++;
dest->H.spendind += tx->numvins;
} else printf("iter scriptoffset.%u/%u stacksize.%u/%u\n",ramchain->H.scriptoffset,ramchain->H.data->scriptspace,ramchain->H.stacksize,ramchain->H.data->stackspace);
} //else printf("iter scriptoffset.%u/%u stacksize.%u/%u\n",ramchain->H.scriptoffset,ramchain->H.data->scriptspace,ramchain->H.stacksize,ramchain->H.data->stackspace);
}
if ( dest != 0 )
{
dest->H.txidind = desttxidind;
dest->H.spendind = destspendind;
} else printf("Start VINs\n");
} //else printf("Start VINs\n");
ramchain->H.txidind = ramchain->H.spendind = rdata->firsti;
for (ramchain->H.txidind=rdata->firsti; ramchain->H.txidind<rdata->numtxids; ramchain->H.txidind++)
{
@ -1872,7 +1870,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
scriptlen = 0;
if ( ramchain->expanded != 0 )
{
fprintf(stderr,"spendind.%d txidind.%d vin.%d call vinscriptdecode scriptspace.%d\n",ramchain->H.spendind,ramchain->H.txidind,j,ramchain->H.data->scriptspace);
//fprintf(stderr,"spendind.%d txidind.%d vin.%d call vinscriptdecode scriptspace.%d\n",ramchain->H.spendind,ramchain->H.txidind,j,ramchain->H.data->scriptspace);
scriptlen = iguana_vinscriptdecode(coin,&metalen,&sequenceid,_script,&Kspace[ramchain->H.data->scriptspace],Kspace,&Sx[ramchain->H.spendind]);
scriptdata = _script;
prevout = iguana_ramchain_txid(coin,RAMCHAIN_ARG,&prevhash,&Sx[ramchain->H.spendind]);
@ -1897,12 +1895,12 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
scriptdata = S[ramchain->H.spendind].vinscriptptr;
scriptlen = S[ramchain->H.spendind].vinscriptlen;
//scriptdata = iguana_scriptptr(coin,&scriptlen,_script,S[ramchain->H.spendind].scriptfpos,S[ramchain->H.spendind].vinscriptptr,S[ramchain->H.spendind].vinscriptlen,sizeof(S[ramchain->H.spendind].vinscriptptr),1);
if ( scriptdata != 0 && scriptlen > 0 )
/*if ( scriptdata != 0 && scriptlen > 0 )
{
int32_t i; for (i=0; i<scriptlen; i++)
printf("%02x",scriptdata[i]);
printf(" spendind.%d vinscript\n",ramchain->H.spendind);
}
}*/
if ( iguana_ramchain_addspend256(coin,RAMCHAIN_ARG,prevhash,prevout,scriptdata,scriptlen,sequenceid,bp) == 0 )
return(-8);
}
@ -1996,16 +1994,16 @@ int32_t iguana_ramchain_scriptspace(struct iguana_info *coin,int32_t *sigspacep,
sigspace += sigsize;
pubkeyspace += pubkeysize;
sigspace += suffixlen;
fprintf(stderr,"(%d %d %d %d).%d ",sigsize,pubkeysize,p2shsize,suffixlen,scriptlen);
} else fprintf(stderr,"(none)" );
//fprintf(stderr,"(%d %d %d %d).%d ",sigsize,pubkeysize,p2shsize,suffixlen,scriptlen);
} //else fprintf(stderr,"(none)" );
}
}
altspace += tx->numvins * 16 + 128; // for metascripts
scriptspace += tx->numvins * 16 + 128; // for metascripts
fprintf(stderr,"scriptspace.%u altspace.%u, ",scriptspace,altspace);
//fprintf(stderr,"scriptspace.%u altspace.%u, ",scriptspace,altspace);
}
*sigspacep = sigspace, *pubkeyspacep = pubkeyspace;
printf("altspace.%d numvouts.%d numvins.%d scriptspace.%d p2shspace.%d sigspace.%d pubkeyspace.%d\n",altspace,tx->numvouts,tx->numvins,scriptspace,p2shspace,sigspace,pubkeyspace);
//printf("altspace.%d numvouts.%d numvins.%d scriptspace.%d p2shspace.%d sigspace.%d pubkeyspace.%d\n",altspace,tx->numvouts,tx->numvins,scriptspace,p2shspace,sigspace,pubkeyspace);
return(scriptspace + p2shspace);
}
@ -2252,11 +2250,6 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru
uint8_t *destoffset,*srcoffset;
firsthash2 = ramchain->H.data->firsthash2, lasthash2 = ramchain->H.data->lasthash2;
height = ramchain->height, firsti = ramchain->H.data->firsti, hdrsi = ramchain->H.hdrsi, numblocks = ramchain->numblocks;
if ( bp->bundleheight == 32000 || bp->bundleheight == 150000 || bp->bundleheight == 116000 || bp->bundleheight == 166000 || bp->bundleheight == 130000 || bp->bundleheight == 180000 || bp->bundleheight == 140000 || bp->bundleheight == 90000 || bp->bundleheight == 176000 || bp->bundleheight == 340000 || bp->bundleheight == 374000 || bp->bundleheight == 180000 )
{
// printf("skip ht.%d for now\n",bp->bundleheight);
// return(-1);
}
//printf("B[] %p\n",B);
if ( 1 && ramchain->expanded != 0 )
{
@ -2281,12 +2274,12 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru
memcpy(ramchain->roA,ramchain->A,sizeof(*ramchain->A) * ramchain->H.data->numpkinds);
memset(ramchain->A,0,sizeof(*ramchain->A) * ramchain->H.data->numpkinds);
//printf("presave T.%d U.%d S.%d P.%d X.%d -> size.%ld firsti.%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,firsti);
printf("0 preSAVE: Koffset.%d scriptoffset.%d stacksize.%d allocsize.%d\n",(int32_t)ramchain->H.data->Koffset,ramchain->H.scriptoffset,ramchain->H.stacksize,(int32_t)ramchain->H.data->allocsize);
//printf("0 preSAVE: Koffset.%d scriptoffset.%d stacksize.%d allocsize.%d\n",(int32_t)ramchain->H.data->Koffset,ramchain->H.scriptoffset,ramchain->H.stacksize,(int32_t)ramchain->H.data->allocsize);
if ( (err= iguana_ramchain_iterate(coin,0,ramchain,bp)) != 0 )
printf("ERROR.%d iterating presave ramchain hdrsi.%d\n",err,hdrsi);
else
{
printf("Bpresave T.%d U.%d S.%d P.%d X.%d -> size.%ld firsti.%d scriptoffset.%d stacksize.%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,firsti,ramchain->H.scriptoffset,ramchain->H.stacksize);
//printf("Bpresave T.%d U.%d S.%d P.%d X.%d -> size.%ld firsti.%d scriptoffset.%d stacksize.%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,firsti,ramchain->H.scriptoffset,ramchain->H.stacksize);
if ( (err= iguana_ramchain_verify(coin,ramchain)) != 0 )
printf("ERROR.%d verifying presave ramchain hdrsi.%d\n",err,hdrsi);
else retval = 0;
@ -2391,9 +2384,9 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str
struct iguana_ramchain *R,*mapchain,*dest,newchain; uint32_t fpipbits,now = (uint32_t)time(NULL);
int32_t i,numtxids,valid,sigspace,sigsize,pubkeysize,pubkeyspace,numunspents,numspends,numpkinds,numexternaltxids,scriptspace,fpos; struct iguana_block *block;
struct OS_memspace HASHMEM; int32_t err,j,num,hdrsi,bundlei,firsti= 1,retval = -1;
if ( bp->bundleheight != 32000 )
return(0);
B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0;//U2 = 0, P2 = 0,
//if ( bp->bundleheight != 32000 )
// return(0);
B = 0, Ux = 0, Sx = 0, P = 0, A = 0, X = 0, Kspace = TXbits = PKbits = 0, U = 0, S = 0, T = 0;
R = mycalloc('s',bp->n,sizeof(*R));
ptrs = mycalloc('w',bp->n,sizeof(*ptrs));
ipbits = mycalloc('w',bp->n,sizeof(*ipbits));
@ -2487,12 +2480,9 @@ if ( bp->bundleheight != 32000 )
iguana_bundlemapfree(mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,bp->n);
return(-1);
}
printf("link ramchain\n");
iguana_ramchain_link(dest,bp->hashes[0],bp->hashes[bp->n-1],bp->hdrsi,bp->bundleheight,0,bp->n,firsti,0);
dest->expanded = 1;
printf("_iguana_ramchain_setptrs\n");
_iguana_ramchain_setptrs(RAMCHAIN_DESTPTRS,dest->H.data);
printf("iguana_ramchain_extras\n");
iguana_ramchain_extras(dest,&HASHMEM);
for (i=0; i<bp->n; i++)
{
@ -2511,17 +2501,14 @@ if ( bp->bundleheight != 32000 )
}
dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti;
dest->externalind = dest->H.scriptoffset = dest->H.stacksize = 0;
//printf("\n");
printf("start iterations\n");
for (bundlei=0; bundlei<bp->n; bundlei++)
{
if ( (block= bp->blocks[bundlei]) != 0 )
{
printf("blocksetcounters dest->txids %p\n",dest->txids);
iguana_blocksetcounters(coin,block,dest);
coin->blocks.RO[bp->bundleheight+bundlei] = block->RO;
destB[bundlei] = block->RO;
fprintf(stderr,"(%d %d).%d ",R[bundlei].H.data->numtxids,dest->H.txidind,bundlei);
//fprintf(stderr,"(%d %d).%d ",R[bundlei].H.data->numtxids,dest->H.txidind,bundlei);
if ( (err= iguana_ramchain_iterate(coin,dest,&R[bundlei],bp)) != 0 )
{
printf("error ramchain_iterate hdrs.%d bundlei.%d\n",bp->hdrsi,bundlei);
@ -2539,7 +2526,7 @@ if ( bp->bundleheight != 32000 )
printf("bundlesave: stack smashed %d+%d > %d\n",dest->H.scriptoffset,dest->H.stacksize,dest->H.data->scriptspace);
bundlei = -1;
}
printf("GETCHAR! about to save dest scriptoffset.%d stacksize.%d data scriptspace.%d\n",dest->H.scriptoffset,dest->H.stacksize,dest->H.data->scriptspace), getchar();
//printf("GETCHAR! about to save dest scriptoffset.%d stacksize.%d data scriptspace.%d\n",dest->H.scriptoffset,dest->H.stacksize,dest->H.data->scriptspace), getchar();
depth--;
if ( bundlei == bp->n && iguana_ramchain_expandedsave(coin,RAMCHAIN_DESTARG,&newchain,&HASHMEM,0,bp) == 0 )
{

Loading…
Cancel
Save