Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
86565e605c
  1. 21
      iguana/iguana777.h
  2. 2
      iguana/iguana_bundles.c
  3. 10
      iguana/iguana_peers.c
  4. 48
      iguana/iguana_ramchain.c
  5. 328
      iguana/iguana_unspents.c

21
iguana/iguana777.h

@ -325,26 +325,27 @@ struct iguana_ledger
//struct iguana_account accounts[];
} __attribute__((packed));
// ramchain append only structs -> canonical 32bit inds and ledgerhashes
struct iguana_unspent20 { uint64_t value; uint32_t scriptpos,txidind:28,type:4; uint16_t scriptlen,ipbits; uint8_t rmd160[20]; } __attribute__((packed));
struct iguana_spend256 { bits256 prevhash2; uint32_t sequenceid,scriptpos; int16_t prevout; uint16_t vinscriptlen,spendind,ipbits; } __attribute__((packed));
// ramchain temp file structures
struct iguana_unspent20 { uint64_t value; uint32_t scriptpos,txidind:28,type:4; uint16_t scriptlen,fileid; uint8_t rmd160[20]; } __attribute__((packed));
struct iguana_spend256 { bits256 prevhash2; uint32_t sequenceid,scriptpos; int16_t prevout; uint16_t vinscriptlen,spendind,fileid; } __attribute__((packed));
// permanent readonly structs
struct iguana_txid { bits256 txid; uint32_t txidind,firstvout,firstvin,locktime,version,timestamp,extraoffset; uint16_t numvouts,numvins; } __attribute__((packed));
struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos,ipbits; uint16_t hdrsi,type:4,scriptlen:14; int16_t vout; } __attribute__((packed));
struct iguana_unspent { uint64_t value; uint32_t txidind,pkind,prevunspentind,scriptpos; uint16_t fileid,scriptlen; uint16_t hdrsi:11,type:5; int16_t vout; } __attribute__((packed));
struct iguana_spend { uint32_t spendtxidind,sequenceid,scriptpos,ipbits; int16_t prevout; uint16_t scriptlen:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4
struct iguana_spend { uint32_t spendtxidind,sequenceid,scriptpos; int16_t prevout; uint16_t fileid,scriptlen:15,external:1; } __attribute__((packed)); // numsigs:4,numpubkeys:4,p2sh:1,sighash:4
struct iguana_pkhash { uint8_t rmd160[20]; uint32_t pkind; } __attribute__((packed)); //firstunspentind,pubkeyoffset
// dynamic
struct iguana_account { int64_t total; uint32_t lastind; } __attribute__((packed));
struct iguana_utxo { uint64_t prevunspentind:26,height:24,spentflag:1,tbd:13; } __attribute__((packed));
struct iguana_account { int64_t total; uint32_t lastunspentind; } __attribute__((packed));
struct iguana_utxo { uint32_t fromheight,prevunspentind:31,spentflag:1; } __attribute__((packed));
struct iguana_hhaccount { UT_hash_handle hh; uint8_t buf[6]; struct iguana_account a; } __attribute__((packed));
struct iguana_hhutxo { UT_hash_handle hh; uint8_t buf[6]; struct iguana_utxo u; } __attribute__((packed));
// GLOBAL one zero to non-zero write (unless reorg)
struct iguana_spendvector { uint64_t hdrsi:14,ind:26,height:24; } __attribute__((packed)); // unspentind
struct iguana_spendvector { uint64_t value; uint32_t pkind,unspentind; uint16_t hdrsi,bundlei; } __attribute__((packed)); // unspentind
//struct iguana_pkextra { uint32_t firstspendind; } __attribute__((packed)); // pkind
struct iguana_txblock
@ -475,7 +476,7 @@ struct iguana_info
struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending;
struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem;
int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified;
uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp;
uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis;
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;
@ -788,7 +789,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_utxogen(struct iguana_info *coin,struct iguana_bundle *bp);
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp);
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

@ -784,7 +784,7 @@ int32_t iguana_bundlefinish(struct iguana_info *coin,struct iguana_bundle *bp)
if ( bp->startutxo == 0 )
{
bp->startutxo = (uint32_t)time(NULL);
if ( (retval= iguana_utxogen(coin,bp)) >= 0 )
if ( (retval= iguana_spendvectors(coin,bp)) >= 0 )
{
if ( retval > 0 )
{

10
iguana/iguana_peers.c

@ -959,8 +959,8 @@ int64_t iguana_peerallocated(struct iguana_info *coin,struct iguana_peer *addr)
void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
{
static uint32_t lastping;
struct pollfd fds; struct iguana_bundlereq *req; char fname[1024]; uint8_t *buf;//,serialized[64];
uint32_t ipbits; int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout;
struct pollfd fds; struct iguana_bundlereq *req; char fname[1024]; uint8_t *buf; uint32_t ipbits;
int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout;
#ifdef IGUANA_PEERALLOC
int32_t i; int64_t remaining; struct OS_memspace *mem[sizeof(addr->SEROUT)/sizeof(*addr->SEROUT)];
for (i=0; i<sizeof(addr->SEROUT)/sizeof(*addr->SEROUT); i++)
@ -976,19 +976,19 @@ void iguana_dedicatedloop(struct iguana_info *coin,struct iguana_peer *addr)
}
#endif
addr->addrind = (int32_t)(((long)addr - (long)&coin->peers.active[0]) / sizeof(*addr));
ipbits = (uint32_t)addr->ipbits;
sprintf(fname,"DB/%s/vouts/%08x.vouts",coin->symbol,ipbits);
sprintf(fname,"DB/%s/vouts/%04d.vouts",coin->symbol,addr->addrind);
if ( (addr->voutsfp= fopen(fname,"rb+")) != 0 )
fseek(addr->voutsfp,0,SEEK_END);
else addr->voutsfp = fopen(fname,"wb+");
if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
{
sprintf(fname,"purgeable/%s/%08x.vins",coin->symbol,ipbits);
sprintf(fname,"purgeable/%s/%04d.vins",coin->symbol,addr->addrind);
if ( (addr->vinsfp= fopen(fname,"rb+")) != 0 )
fseek(addr->vinsfp,0,SEEK_END);
else addr->vinsfp = fopen(fname,"wb+");
}
//addr->pubkey = GENESIS_PUBKEY;
ipbits = (uint32_t)addr->ipbits;
vcalc_sha256(0,addr->iphash.bytes,(uint8_t *)&ipbits,sizeof(ipbits));
//char str[65]; printf("start dedicatedloop.%s addrind.%d %s\n",addr->ipaddr,addr->addrind,bits256_str(str,addr->iphash));
addr->maxfilehash2 = IGUANA_MAXFILEITEMS;

48
iguana/iguana_ramchain.c

@ -461,7 +461,7 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
V.spendlen = iguana_scriptgen(coin,&V.M,&V.N,V.coinaddr,V.spendscript,asmstr,u->rmd160,type,(const struct vin_info *)&V,vout);
if ( (V.spendlen != scriptlen || memcmp(V.spendscript,script,scriptlen) != 0) && addr != 0 && addr->voutsfp != 0 )
{
u->ipbits = (uint32_t)addr->ipbits;
u->fileid = (uint32_t)addr->addrind;
u->scriptpos = (uint32_t)ftell(addr->voutsfp);
if ( fwrite(script,1,scriptlen,addr->voutsfp) != scriptlen )
printf("error writing scriptlen.%d\n",scriptlen);
@ -470,7 +470,7 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
else
{
u->scriptpos = 0;
u->ipbits = 0;
u->fileid = 0;
}
} else u->scriptpos = 0;
u->txidind = ramchain->H.txidind;
@ -478,7 +478,7 @@ uint32_t iguana_ramchain_addunspent20(struct iguana_info *coin,struct iguana_pee
return(unspentind);
}
uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint64_t value,uint16_t hdrsi,uint8_t *rmd160,uint16_t vout,uint8_t type,uint32_t ipbits,uint32_t fpos,int32_t scriptlen)
uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint64_t value,uint16_t hdrsi,uint8_t *rmd160,uint16_t vout,uint8_t type,uint16_t fileid,uint32_t fpos,int32_t scriptlen)
{
uint32_t unspentind; struct iguana_unspent *u; struct iguana_kvitem *ptr; int32_t pkind;//,checklen,metalen; uint8_t _script[IGUANA_MAXSCRIPTSIZE],*checkscript;
unspentind = ramchain->H.unspentind++;
@ -502,9 +502,9 @@ uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint6
printf("script mismatch len.%d vs %d or cmp error.%d\n",scriptlen,checklen,(checkscript != 0 && script != 0) ? memcmp(checkscript,script,scriptlen):0);
} //else printf("RO spendscript match.%d\n",scriptlen);
}*/
if ( u->ipbits != ipbits || u->scriptpos != fpos || u->scriptlen != scriptlen || u->value != value || u->pkind != pkind || u->value != value || u->txidind != ramchain->H.txidind || (pkind != 0 && u->prevunspentind != A[pkind].lastind) || u->vout != vout || u->hdrsi != hdrsi )
if ( u->fileid != fileid || u->scriptpos != fpos || u->scriptlen != scriptlen || u->value != value || u->pkind != pkind || u->value != value || u->txidind != ramchain->H.txidind || (pkind != 0 && u->prevunspentind != A[pkind].lastunspentind) || u->vout != vout || u->hdrsi != hdrsi )
{
printf("iguana_ramchain_addunspent: (%d %d %d) vs (%d %d %d) mismatched values.(%d %.8f %d %d %d %d) vs (%d %.8f %d %d %d %d)\n",u->ipbits,u->scriptpos,u->scriptlen,ipbits,fpos,scriptlen,u->pkind,dstr(u->value),u->txidind,u->prevunspentind,u->vout,u->hdrsi,pkind,dstr(value),ramchain->H.txidind,A[pkind].lastind,vout,hdrsi);
printf("iguana_ramchain_addunspent: (%d %d %d) vs (%d %d %d) mismatched values.(%d %.8f %d %d %d %d) vs (%d %.8f %d %d %d %d)\n",u->fileid,u->scriptpos,u->scriptlen,fileid,fpos,scriptlen,u->pkind,dstr(u->value),u->txidind,u->prevunspentind,u->vout,u->hdrsi,pkind,dstr(value),ramchain->H.txidind,A[pkind].lastunspentind,vout,hdrsi);
exit(-1);
return(0);
}
@ -517,15 +517,15 @@ uint32_t iguana_ramchain_addunspent(struct iguana_info *coin,RAMCHAIN_FUNC,uint6
//else pubkeyoffset = 0;
u->vout = vout, u->hdrsi = hdrsi;
u->txidind = ramchain->H.txidind, u->pkind = pkind;
u->prevunspentind = A[pkind].lastind;
u->ipbits = ipbits;
u->prevunspentind = A[pkind].lastunspentind;
u->fileid = fileid;
u->scriptlen = scriptlen;
u->scriptpos = fpos;
u->type = type;
}
//printf("%p A[%d] last <- U%d\n",&A[pkind],pkind,unspentind);
A[pkind].total += value;
A[pkind].lastind = unspentind;
A[pkind].lastunspentind = unspentind;
return(unspentind);
}
@ -579,7 +579,7 @@ int32_t iguana_ramchain_txid(struct iguana_info *coin,RAMCHAIN_FUNC,bits256 *txi
return(-2);
}
uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256 prev_hash,int32_t prev_vout,uint32_t sequence,int32_t hdrsi,uint32_t ipbits,uint32_t scriptpos,int32_t vinscriptlen)
uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256 prev_hash,int32_t prev_vout,uint32_t sequence,int32_t hdrsi,uint16_t fileid,uint32_t scriptpos,int32_t vinscriptlen)
{
struct iguana_spend *s; struct iguana_kvitem *ptr = 0; bits256 txid;
uint32_t spendind,unspentind,txidind=0,pkind,external=0; uint64_t value = 0;
@ -657,7 +657,7 @@ uint32_t iguana_ramchain_addspend(struct iguana_info *coin,RAMCHAIN_FUNC,bits256
s->sequenceid = sequence;
s->external = external, s->spendtxidind = txidind,
s->prevout = prev_vout;
s->ipbits = ipbits;
s->fileid = fileid;
s->scriptpos = scriptpos;
s->scriptlen = vinscriptlen;
/*static uint64_t good,bad;
@ -724,7 +724,7 @@ uint32_t iguana_ramchain_addspend256(struct iguana_info *coin,struct iguana_peer
s->spendind = spendind;
if ( (s->vinscriptlen= vinscriptlen) > 0 && vinscript != 0 && addr != 0 && addr->vinsfp != 0 && vinscriptlen < IGUANA_MAXSCRIPTSIZE)
{
s->ipbits = (uint32_t)addr->ipbits;
s->fileid = (uint32_t)addr->addrind;
s->scriptpos = (uint32_t)ftell(addr->vinsfp);
if ( fwrite(vinscript,1,vinscriptlen,addr->vinsfp) != vinscriptlen )
printf("error writing vinscriptlen.%d\n",vinscriptlen);
@ -1260,7 +1260,7 @@ int32_t iguana_ramchain_verify(struct iguana_info *coin,struct iguana_ramchain *
{
if ( memcmp(&ramchain->A[k],&ramchain->creditsA[k],sizeof(ramchain->A[k])) != 0 )
{
printf("k.%d balance.(%.8f vs %.8f) lastU.(%d %d)\n",k,dstr(ramchain->A[k].total),dstr(ramchain->creditsA[k].total),ramchain->A[k].lastind,ramchain->creditsA[k].lastind);
printf("k.%d balance.(%.8f vs %.8f) lastU.(%d %d)\n",k,dstr(ramchain->A[k].total),dstr(ramchain->creditsA[k].total),ramchain->A[k].lastunspentind,ramchain->creditsA[k].lastunspentind);
//return(-14);
}
//if ( memcmp(&ramchain->P2[k],&ramchain->roP2[k],sizeof(ramchain->P2[k])) != 0 )
@ -1614,7 +1614,7 @@ int32_t iguana_ramchain_cmp(struct iguana_ramchain *A,struct iguana_ramchain *B,
int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *ramchain,struct iguana_bundle *bp)
{
RAMCHAIN_DECLARE; RAMCHAIN_DESTDECLARE;
int32_t j,hdrsi,prevout,scriptlen; uint32_t scriptpos,ipbits,sequenceid,destspendind=0,desttxidind=0;
int32_t j,hdrsi,prevout,scriptlen; uint32_t scriptpos,sequenceid,destspendind=0,desttxidind=0; uint16_t fileid;
bits256 prevhash; uint64_t value; uint8_t type; struct iguana_unspent *u;
struct iguana_txid *tx; struct iguana_ramchaindata *rdata; uint8_t *rmd160;
//if ( dest != 0 )
@ -1654,7 +1654,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
}
for (j=0; j<tx->numvouts; j++)
{
ipbits = 0;
fileid = 0;
scriptpos = 0;
scriptlen = 0;
if ( ramchain->H.unspentind < rdata->numunspents )
@ -1665,7 +1665,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
value = u->value;
hdrsi = u->hdrsi;
type = u->type;
ipbits = u->ipbits;
fileid = u->fileid;
scriptpos = u->scriptpos;
scriptlen = u->scriptlen;
if ( u->pkind < rdata->numpkinds )
@ -1677,7 +1677,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
scriptdata = iguana_ramchain_scriptdecode(&metalen,&scriptlen,Kspace,type,_script,u->scriptoffset,P[u->pkind].pubkeyoffset < ramchain->H.scriptoffset ? P[u->pkind].pubkeyoffset : 0);
}*/
//fprintf(stderr,"iter add %p[%d] type.%d\n",scriptdata,scriptlen,type);
if ( iguana_ramchain_addunspent(coin,RAMCHAIN_ARG,value,hdrsi,rmd160,j,type,ipbits,scriptpos,scriptlen) == 0 )
if ( iguana_ramchain_addunspent(coin,RAMCHAIN_ARG,value,hdrsi,rmd160,j,type,fileid,scriptpos,scriptlen) == 0 )
return(-3);
}
}
@ -1687,7 +1687,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
value = U[ramchain->H.unspentind].value;
rmd160 = U[ramchain->H.unspentind].rmd160;
type = U[ramchain->H.unspentind].type & 0xf;
ipbits = U[ramchain->H.unspentind].ipbits;
fileid = U[ramchain->H.unspentind].fileid;
scriptpos = U[ramchain->H.unspentind].scriptpos;
scriptlen = U[ramchain->H.unspentind].scriptlen;
/*if ( U[ramchain->H.unspentind].scriptoffset != 0 )
@ -1710,7 +1710,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
if ( dest != 0 )
{
//fprintf(stderr,"dest add %p[%d] type.%d offset.%d vs %d\n",scriptdata,scriptlen,type,dest->H.scriptoffset,dest->H.data->scriptspace);
if ( iguana_ramchain_addunspent(coin,RAMCHAIN_DESTARG,value,hdrsi,rmd160,j,type,ipbits,scriptpos,scriptlen) == 0 )
if ( iguana_ramchain_addunspent(coin,RAMCHAIN_DESTARG,value,hdrsi,rmd160,j,type,fileid,scriptpos,scriptlen) == 0 )
return(-5);
} //else printf("addunspent20 done\n");
} else return(-6);
@ -1733,19 +1733,19 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
tx = &T[ramchain->H.txidind];
for (j=0; j<tx->numvins; j++)
{
ipbits = 0;
fileid = 0;
scriptpos = 0;
scriptlen = 0;
if ( ramchain->expanded != 0 )
{
ipbits = Sx[ramchain->H.spendind].ipbits;
fileid = Sx[ramchain->H.spendind].fileid;
scriptpos = Sx[ramchain->H.spendind].scriptpos;
scriptlen = Sx[ramchain->H.spendind].scriptlen;
//scriptlen = iguana_vinscriptdecode(coin,ramchain,&metalen,_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]);
//fprintf(stderr,"from expanded iter\n");
if ( iguana_ramchain_addspend(coin,RAMCHAIN_ARG,prevhash,prevout,Sx[ramchain->H.spendind].sequenceid,bp->hdrsi,ipbits,scriptpos,scriptlen) == 0 )
if ( iguana_ramchain_addspend(coin,RAMCHAIN_ARG,prevhash,prevout,Sx[ramchain->H.spendind].sequenceid,bp->hdrsi,fileid,scriptpos,scriptlen) == 0 )
{
char str[65];
printf("hdrsi.%d txidind.%d spendind.%d spendtxid.%x %d vin.%d %s vout.%d\n",bp->bundleheight,ramchain->H.txidind,ramchain->H.spendind,Sx[ramchain->H.spendind].spendtxidind,Sx[ramchain->H.spendind].spendtxidind&0xfffffff,j,bits256_str(str,prevhash),prevout);
@ -1762,7 +1762,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
sequenceid = S[ramchain->H.spendind].sequenceid;
prevhash = S[ramchain->H.spendind].prevhash2;
prevout = S[ramchain->H.spendind].prevout;
ipbits = S[ramchain->H.spendind].ipbits;
fileid = S[ramchain->H.spendind].fileid;
scriptpos = S[ramchain->H.spendind].scriptpos;
scriptlen = S[ramchain->H.spendind].vinscriptlen;
/*if ( S[ramchain->H.spendind].scriptoffset != 0 )
@ -1781,7 +1781,7 @@ int32_t iguana_ramchain_iterate(struct iguana_info *coin,struct iguana_ramchain
}
if ( dest != 0 )
{
if ( iguana_ramchain_addspend(coin,RAMCHAIN_DESTARG,prevhash,prevout,sequenceid,bp->hdrsi,ipbits,scriptpos,scriptlen) == 0 )
if ( iguana_ramchain_addspend(coin,RAMCHAIN_DESTARG,prevhash,prevout,sequenceid,bp->hdrsi,fileid,scriptpos,scriptlen) == 0 )
return(-9);
//printf("from dest iter scriptspace.%d\n",dest->H.stacksize);
}
@ -2391,7 +2391,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str
bp_n = (endi - starti + 1);
scriptspace = 1;
sigspace = pubkeyspace = 0;
for (bundlei=starti,numtxids=numunspents=numspends=0; bundlei<=endi; bundlei++)
for (bundlei=starti,numtxids=numunspents=scriptspace=numspends=0; bundlei<=endi; bundlei++)
{
if ( (block= bp->blocks[bundlei]) == 0 || bits256_nonz(block->RO.hash2) == 0 || block != iguana_blockfind(coin,block->RO.hash2) || memcmp(block->RO.hash2.bytes,bp->hashes[bundlei].bytes,sizeof(bits256)) != 0 )
{

328
iguana/iguana_unspents.c

@ -34,7 +34,7 @@ struct iguana_hhaccount *iguana_hhaccountfind(struct iguana_info *coin,uint16_t
return(hhacct);
}
int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,int32_t hdrsi,uint32_t spendind,uint32_t height)
int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight)
{
struct iguana_hhutxo *hhutxo,*tmputxo; struct iguana_hhaccount *hhacct,*tmpacct;
uint8_t buf[sizeof(spent_hdrsi) + sizeof(uint32_t)];
@ -60,7 +60,7 @@ int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t
}
return(0);
}
printf("utxoupdate spenthdrsi.%d pkind.%d %.8f from [%d:%d] spendind.%u\n",spent_hdrsi,spent_pkind,dstr(spent_value),hdrsi,height%coin->chain->bundlesize,spendind);
printf("utxoupdate spenthdrsi.%d pkind.%d %.8f from [%d:%d] spendind.%u\n",spent_hdrsi,spent_pkind,dstr(spent_value),fromheight/coin->chain->bundlesize,fromheight%coin->chain->bundlesize,spendind);
if ( (hhutxo= iguana_hhutxofind(coin,spent_hdrsi,spent_unspentind)) != 0 && hhutxo->u.spentflag != 0 )
return(-1);
hhutxo = calloc(1,sizeof(*hhutxo));
@ -71,71 +71,44 @@ int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t
HASH_ADD(hh,coin->accountstable,buf,sizeof(buf),hhacct);
}
hhutxo->u.spentflag = 1;
hhutxo->u.height = height;
hhutxo->u.prevunspentind = hhacct->a.lastind;
hhacct->a.lastind = spent_unspentind;
hhutxo->u.fromheight = fromheight;
hhutxo->u.prevunspentind = hhacct->a.lastunspentind;
hhacct->a.lastunspentind = spent_unspentind;
hhacct->a.total += spent_value;
return(0);
}
int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t height,uint32_t spendind,struct iguana_bundle *spentbp,uint32_t unspentind)
int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *ramchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight)
{
struct iguana_unspent *u,*spentU; struct iguana_account *A2;
int32_t flag,errs=0; struct iguana_utxo *utxo,*Uextras; uint32_t pkind;
Uextras = spentbp->ramchain.Uextras;
A2 = spentbp->ramchain.A;
if ( incremental != 0 || (A2 != 0 && Uextras != 0) )
struct iguana_account *A2; struct iguana_ramchaindata *rdata; struct iguana_utxo *utxo;
if ( (rdata= ramchain->H.data) != 0 )
{
spentU = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Uoffset);
u = &spentU[unspentind];
if ( (pkind= u->pkind) != 0 && pkind < spentbp->ramchain.H.data->numpkinds )
{
flag = -1;
if ( incremental == 0 )
{
if ( Uextras == 0 || A2 == 0 )
{
printf("null ptrs.[%d] %p %p\n",spentbp->hdrsi,spentbp->ramchain.Uextras,spentbp->ramchain.A);
errs++;
}
else
A2 = ramchain->A;
if ( ramchain->Uextras != 0 && A2 != 0 )
{
utxo = &Uextras[unspentind];
utxo = &ramchain->Uextras[spent_unspentind];
if ( utxo->spentflag == 0 )
{
utxo->prevunspentind = A2[pkind].lastind;
utxo->prevunspentind = A2[spent_pkind].lastunspentind;
utxo->spentflag = 1;
utxo->height = height;
A2[pkind].total += u->value;
A2[pkind].lastind = unspentind;
flag = 0;
}
}
}
else
{
if ( bp != spentbp )
{
utxo = &Uextras[unspentind];
if ( utxo->spentflag == 0 )
flag = iguana_utxoupdate(coin,spentbp->hdrsi,unspentind,pkind,u->value,bp->hdrsi,spendind,height);
utxo->fromheight = fromheight;
A2[spent_pkind].total += spent_value;
A2[spent_pkind].lastunspentind = spent_unspentind;
return(0);
}
else flag = iguana_utxoupdate(coin,spentbp->hdrsi,unspentind,pkind,u->value,bp->hdrsi,spendind,height);
} else printf("null ptrs.[%d] u.%u p.%u %.8f from ht.%d s.%u\n",spent_hdrsi,spent_unspentind,spent_pkind,dstr(spent_value),fromheight,spendind);
}
if ( flag != 0 )
else // do the equivalent of historical, ie mark as spent, linked list, balance
{
errs++;
printf("iguana_balancegen: pkind.%d double spend of hdrsi.%d unspentind.%d\n",pkind,spentbp->hdrsi,unspentind);
getchar();
}
}
else
{
errs++;
printf("iguana_balancegen: pkind overflow %d vs %d\n",pkind,spentbp->ramchain.H.data->numpkinds);
if ( iguana_utxoupdate(coin,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,fromheight) == 0 )
return(0);
}
printf("iguana_volatileupdate: [%d] spent.(u%u %.8f pkind.%d) double spend? at ht.%d [%d] spendind.%d\n",spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind);
exit(-1);
}
return(-errs);
return(-1);
}
struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_ramchain **ramchainp,int64_t *balancep,uint32_t *lastunspentindp,struct iguana_pkhash *p,uint8_t rmd160[20],int32_t firsti,int32_t endi)
@ -158,7 +131,7 @@ struct iguana_pkhash *iguana_pkhashfind(struct iguana_info *coin,struct iguana_r
{
*ramchainp = ramchain;
*balancep = ACCTS[pkind].total;
*lastunspentindp = ACCTS[pkind].lastind;
*lastunspentindp = ACCTS[pkind].lastunspentind;
*p = P[pkind];
return(p);
} //else printf("not found pkind.%d vs num.%d\n",pkind,ramchain->H.data->numpkinds);
@ -191,7 +164,7 @@ char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi)
} return(clonestr("{\"error\":\"no bundle\"}"));
}
struct iguana_bundle *iguana_spent(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 spend_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;
@ -359,15 +332,16 @@ uint8_t *iguana_rmdarray(struct iguana_info *coin,int32_t *numrmdsp,cJSON *array
return(rmdarray);
}
int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp)
int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp)
{
static uint64_t total,emitted;
int32_t spendind,n,txidind,errs=0,emit=0,i,j,k,retval = -1; uint32_t unspentind,now;
int32_t spendind,n,txidind,errs=0,emit=0,i,j,k,retval = -1; long fsize;
uint32_t spent_unspentind,spent_pkind,now;
struct iguana_bundle *spentbp; struct iguana_blockRO *B; FILE *fp; char fname[1024],str[65];
bits256 prevhash,zero,sha256; struct iguana_unspent *u; long fsize; struct iguana_txid *nextT;
bits256 prevhash,zero,sha256; struct iguana_unspent *u,*spentU; struct iguana_txid *nextT;
struct iguana_spend *S,*s; struct iguana_spendvector *ptr; struct iguana_ramchain *ramchain;
ramchain = &bp->ramchain;
//printf("UTXO gen.%d ramchain data.%p\n",bp->bundleheight,ramchain->H.data);
//printf("iguana_spendvectors gen.%d ramchain data.%p\n",bp->bundleheight,ramchain->H.data);
if ( ramchain->H.data == 0 || (n= ramchain->H.data->numspends) < 1 )
return(0);
B = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Boffset);
@ -375,7 +349,7 @@ int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp)
nextT = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset);
if ( ramchain->Xspendinds != 0 )
{
//printf("iguana_utxogen: already have Xspendinds[%d]\n",ramchain->numXspends);
//printf("iguana_spendvectors: already have Xspendinds[%d]\n",ramchain->numXspends);
return(0);
}
ptr = mycalloc('x',sizeof(*ptr),n);
@ -405,45 +379,52 @@ int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp)
u = 0;
if ( s->external != 0 && s->prevout >= 0 )
{
if ( (spentbp= iguana_spent(coin,&prevhash,&unspentind,ramchain,bp->hdrsi,s)) != 0 )
if ( (spentbp= iguana_externalspent(coin,&prevhash,&spent_unspentind,ramchain,bp->hdrsi,s)) != 0 && spentbp->ramchain.H.data != 0 )
{
if ( spentbp == bp )
{
if ( now > spentbp->lastprefetch+60 || (spentbp->dirty % 150000) == 0 )
char str[65];
printf("unexpected spendbp: height.%d bp.[%d] U%d <- S%d.[%d] [ext.%d %s prev.%d]\n",bp->bundleheight+i,spentbp->hdrsi,spent_unspentind,spendind,bp->hdrsi,s->external,bits256_str(str,prevhash),s->prevout);
errs++;
}
if ( now > spentbp->lastprefetch+60 || (spentbp->dirty % 100000) == 0 )
{
//printf("u current.%d prefetch.[%d] lag.%u\n",spentbp == bp,spentbp->hdrsi,now - spentbp->lastprefetch);
iguana_ramchain_prefetch(coin,&spentbp->ramchain);
spentbp->lastprefetch = now;
}
spentbp->dirty++;
if ( (ptr[emit].ind= 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 )
{
if ( (ptr[emit].unspentind= spent_unspentind) != 0 && spentbp->hdrsi < bp->hdrsi )
{
ptr[emit].hdrsi = spentbp->hdrsi;
ptr[emit].height = bp->bundleheight + i;
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("utxogen: null unspentind for spendind.%d hdrsi.%d [%d]\n",spendind,spentbp->hdrsi,bp->hdrsi);
errs++;
}
if ( spentbp == bp )
{
char str[65];
printf("unexpected spendbp: height.%d bp.[%d] U%d <- S%d.[%d] [ext.%d %s prev.%d]\n",bp->bundleheight+i,spentbp->hdrsi,unspentind,spendind,bp->hdrsi,s->external,bits256_str(str,prevhash),s->prevout);
printf("spendvectors: null unspentind for spendind.%d hdrsi.%d [%d]\n",spendind,spentbp->hdrsi,bp->hdrsi);
errs++;
}
}
else
{
errs++;
printf("utxogen: unresolved spendind.%d hdrsi.%d\n",spendind,bp->hdrsi);
printf("spendvectors: unresolved spendind.%d hdrsi.%d\n",spendind,bp->hdrsi);
break;
}
}
}
}
}
}
if ( txidind != bp->ramchain.H.data->numtxids )
{
printf("numtxid.%d != bp numtxids %d\n",txidind,bp->ramchain.H.data->numtxids);
@ -460,8 +441,6 @@ int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp)
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 ( iguana_peerfname(coin,&hdrsi,dirname,fname,0,bp->hashes[0],zero,bp->n) >= 0 )
{
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(sha256.bytes,1,sizeof(sha256),fp) != sizeof(sha256) )
@ -481,7 +460,6 @@ int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp)
//printf("filesize %ld Xspendptr.%p %p num.%d\n",fsize,ramchain->Xspendptr,ramchain->Xspendinds,ramchain->numXspends);
} else printf("Error creating.(%s)\n",fname);
}
}
if ( ptr != 0 )
myfree(ptr,sizeof(*ptr) * n);
printf("utxo %d spendinds.[%d] errs.%d [%.2f%%] emitted.%d %s of %d\n",spendind,bp->hdrsi,errs,100.*(double)emitted/(total+1),emit,mbstr(str,sizeof(*ptr) * emit),n);
@ -492,26 +470,28 @@ int32_t iguana_utxogen(struct iguana_info *coin,struct iguana_bundle *bp)
int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight)
{
uint32_t unspentind,txidind,h,i,j,k,ind,now; struct iguana_ramchain *ramchain;
struct iguana_bundle *spentbp; struct iguana_txid *T,*nextT; struct iguana_blockRO *B;
int32_t hdrsi,spendind,n,errs=0,incremental,emit=0; struct iguana_spend *S,*s;
uint32_t spent_unspentind,spent_pkind,txidind,h,i,j,k,now; uint64_t spent_value;
struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata;
struct iguana_spendvector *spend; struct iguana_unspent *spentU,*u;
struct iguana_txid *T,*nextT; struct iguana_blockRO *B;
int32_t spent_hdrsi,spendind,n,errs=0,incremental,emit=0; struct iguana_spend *S,*s;
ramchain = &bp->ramchain;
if ( startheight == bp->bundleheight && endheight == bp->bundleheight+bp->n-1 )
incremental = 0;
else incremental = 1;
if ( ramchain->H.data == 0 || (n= ramchain->H.data->numspends) < 1 )
return(0);
S = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Soffset);
B = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Boffset);
nextT = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset);
if ( (rdata= ramchain->H.data) == 0 || (n= ramchain->H.data->numspends) < 1 )
return(-1);
S = (void *)(long)((long)rdata + rdata->Soffset);
B = (void *)(long)((long)rdata + rdata->Boffset);
nextT = (void *)(long)((long)rdata + rdata->Toffset);
if ( ramchain->Xspendinds == 0 )
{
printf("iguana_balancegen.%d: no Xspendinds[%d]\n",bp->hdrsi,ramchain->numXspends);
return(0);
return(-1);
}
iguana_ramchain_prefetch(coin,ramchain);
printf("BALANCEGEN.%d hdrs.%d\n",bp->bundleheight,bp->hdrsi);
txidind = spendind = ramchain->H.data->firsti;
txidind = spendind = rdata->firsti;
for (i=0; i<bp->n; i++)
{
//printf("hdrs.[%d] B[%d] 1st txidind.%d txn_count.%d firstvin.%d firstvout.%d\n",bp->hdrsi,i,B[i].firsttxidind,B[i].txn_count,B[i].firstvin,B[i].firstvout);
@ -532,59 +512,54 @@ int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp,int3
for (k=0; k<nextT[txidind].numvins && errs==0; k++,spendind++)
{
s = &S[spendind];
unspentind = 0;
spentbp = 0;
h = spent_hdrsi = -1;
spent_value = 0;
spent_unspentind = spent_pkind = 0;
if ( s->external != 0 && s->prevout >= 0 )
{
if ( emit >= ramchain->numXspends )
errs++;
else
{
h = ramchain->Xspendinds[emit].height;
unspentind = ramchain->Xspendinds[emit].ind;
if ( (hdrsi= ramchain->Xspendinds[emit].hdrsi) >= 0 && hdrsi < bp->hdrsi )
spentbp = coin->bundles[hdrsi];
else
{
printf("iguana_balancegen[%d] s.%d illegal hdrsi.%d emit.%d\n",bp->hdrsi,spendind,hdrsi,emit);
errs++;
}
//printf("%d of %d: [%d] X spendind.%d -> (%d u%d)\n",emit,ramchain->numXspends,bp->hdrsi,spendind,hdrsi,unspentind);
spend = &ramchain->Xspendinds[emit];
spent_value = spend->value;
spent_pkind = spend->pkind;
spent_unspentind = spend->unspentind;
spent_hdrsi = spend->hdrsi;
h = spend->bundlei + (spent_hdrsi * coin->chain->bundlesize);
emit++;
}
}
else if ( s->prevout >= 0 )
{
spentbp = bp;
h = bp->bundleheight + i;
if ( (ind= s->spendtxidind) != 0 && ind < spentbp->ramchain.H.data->numtxids )
{
T = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Toffset);
unspentind = T[ind].firstvout + s->prevout;
spent_hdrsi = bp->hdrsi;
if ( s->spendtxidind != 0 && s->spendtxidind < rdata->numtxids )
{
T = (void *)(long)((long)rdata + rdata->Toffset);
spent_unspentind = T[s->spendtxidind].firstvout + s->prevout;
spentU = (void *)(long)((long)rdata + rdata->Uoffset);
u = &spentU[spent_unspentind];
if ( (spent_pkind= u->pkind) != 0 && spent_pkind < rdata->numpkinds )
spent_value = u->value;
//printf("txidind.%d 1st.%d prevout.%d\n",txidind,T[txidind].firstvout,s->prevout);
}
else
{
printf("iguana_balancegen txidind overflow %u vs %u\n",ind,spentbp->ramchain.H.data->numtxids);
printf("iguana_balancegen [%d] txidind overflow %u vs %u\n",bp->hdrsi,s->spendtxidind,rdata->numtxids);
errs++;
}
}
else continue;
if ( spentbp != 0 && unspentind > 0 && unspentind < spentbp->ramchain.H.data->numunspents )
{
if ( 1 && (now > spentbp->lastprefetch+60 || (spentbp->dirty % 150000) == 0) )
if ( spent_unspentind > 0 && spent_pkind > 0 )
{
iguana_ramchain_prefetch(coin,&spentbp->ramchain);
spentbp->lastprefetch = now;
}
spentbp->dirty++;
if ( iguana_volatileupdate(coin,incremental,bp,h,spendind,spentbp,unspentind) < 0 )
if ( iguana_volatileupdate(coin,incremental,ramchain,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,h) < 0 )
errs++;
}
else
{
errs++;
printf("iguana_balancegen: error with unspentind.%d vs max.%d spentbp.%p\n",unspentind,spentbp!=0?spentbp->ramchain.H.data->numunspents:-1,spentbp);
printf("iguana_balancegen: error with unspentind.%d [%d]\n",spent_unspentind,spent_hdrsi);
}
}
}
@ -608,6 +583,69 @@ int32_t iguana_balancegen(struct iguana_info *coin,struct iguana_bundle *bp,int3
return(-errs);
}
int32_t iguana_RTutxo(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *RTramchain,int32_t bundlei)
{
struct iguana_txid *T,*spentT; int32_t height,spendind,txidind,j,k; bits256 prevhash;
struct iguana_bundle *spentbp; struct iguana_unspent *spentU,*u;
struct iguana_ramchaindata *RTdata;
uint32_t spent_unspentind; struct iguana_blockRO *B; struct iguana_spend *S,*s;
if ( (RTdata= RTramchain->H.data) == 0 || RTdata->numspends < 1 )
{
printf("iguana_RTutxo null data or no spends %p\n",RTramchain->H.data);
return(0);
}
B = (void *)(long)((long)RTdata + RTdata->Boffset);
S = (void *)(long)((long)RTdata + RTdata->Soffset);
T = (void *)(long)((long)RTdata + RTdata->Toffset);
txidind = B[bundlei].firsttxidind;
spendind = B[bundlei].firstvin;
height = bp->bundleheight + bundlei;
for (j=0; j<B[bundlei].txn_count; j++,txidind++)
{
if ( txidind != T[txidind].txidind || spendind != T[txidind].firstvin )
{
printf("RTutxogen: txidind %u != %u nextT[txidind].firsttxidind || spendind %u != %u nextT[txidind].firstvin\n",txidind,T[txidind].txidind,spendind,T[txidind].firstvin);
return(-1);
}
for (k=0; k<T[txidind].numvins; k++,spendind++)
{
s = &S[spendind];
if ( s->external != 0 && s->prevout >= 0 )
{
if ( (spentbp= iguana_externalspent(coin,&prevhash,&spent_unspentind,RTramchain,bp->hdrsi,s)) == 0 || spent_unspentind == 0 || spent_unspentind >= RTdata->numunspents || spentbp->hdrsi < 0 || spentbp->hdrsi >= bp->hdrsi || spentbp == bp )
{
char str[65];
printf("RTutxo: unexpected spendbp: height.%d bp.[%d] U%d <- S%d.[%d] [ext.%d %s prev.%d]\n",height,spentbp->hdrsi,spent_unspentind,spendind,bp->hdrsi,s->external,bits256_str(str,prevhash),s->prevout);
return(-1);
}
}
else if ( s->prevout >= 0 )
{
spentbp = bp;
if ( spentbp->ramchain.H.data != 0 && s->spendtxidind != 0 && s->spendtxidind < spentbp->ramchain.H.data->numtxids )
{
spentT = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Toffset);
spent_unspentind = spentT[s->spendtxidind].firstvout + s->prevout;
//printf("txidind.%d 1st.%d prevout.%d\n",txidind,T[txidind].firstvout,s->prevout);
}
else
{
printf("RTutxo txidind overflow %u vs %u\n",s->spendtxidind,spentbp->ramchain.H.data != 0?spentbp->ramchain.H.data->numtxids:-1);
return(-1);
}
}
else return(0); // coinbase always already spent
if ( spentbp != 0 && spentbp->ramchain.H.data != 0 && spent_unspentind != 0 && spent_unspentind < spentbp->ramchain.H.data->numunspents )
{
spentU = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Uoffset);
u = &spentU[spent_unspentind];
return(iguana_volatileupdate(coin,1,RTramchain,spentbp->hdrsi,spent_unspentind,u->pkind,u->value,spendind,height));
}
}
}
return(-1);
}
void iguana_purgevolatiles(struct iguana_info *coin,struct iguana_ramchain *ramchain)
{
if ( ramchain->allocatedA != 0 && ramchain->A != 0 )
@ -800,7 +838,7 @@ int32_t iguana_volatileinit(struct iguana_info *coin)
void iguana_RTramchainfree(struct iguana_info *coin)
{
iguana_utxoupdate(coin,-1,0,0,0,-1,0,-1); // free hashtables
iguana_utxoupdate(coin,-1,0,0,0,0,-1); // free hashtables
iguana_ramchain_free(coin,&coin->RTramchain,1);
}
@ -840,66 +878,6 @@ void iguana_RTramchainalloc(struct iguana_info *coin,struct iguana_bundle *bp)
}
}
int32_t iguana_RTutxo(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *RTramchain,int32_t bundlei)
{
struct iguana_txid *nextT,*T; int32_t spendind,txidind,j,k; struct iguana_bundle *spentbp;
uint32_t unspentind,ind; struct iguana_blockRO *B; struct iguana_spend *S,*s; bits256 prevhash;
if ( RTramchain->H.data == 0 || RTramchain->H.data->numspends < 1 )
return(0);
B = (void *)(long)((long)RTramchain->H.data + RTramchain->H.data->Boffset);
S = (void *)(long)((long)RTramchain->H.data + RTramchain->H.data->Soffset);
nextT = (void *)(long)((long)RTramchain->H.data + RTramchain->H.data->Toffset);
txidind = B[bundlei].firsttxidind;
spendind = B[bundlei].firstvin;
for (j=0; j<B[bundlei].txn_count; j++,txidind++)
{
if ( txidind != nextT[txidind].txidind || spendind != nextT[txidind].firstvin )
{
printf("RTutxogen: txidind %u != %u nextT[txidind].firsttxidind || spendind %u != %u nextT[txidind].firstvin\n",txidind,nextT[txidind].txidind,spendind,nextT[txidind].firstvin);
return(-1);
}
for (k=0; k<nextT[txidind].numvins; k++,spendind++)
{
s = &S[spendind];
if ( s->external != 0 && s->prevout >= 0 )
{
if ( (spentbp= iguana_spent(coin,&prevhash,&unspentind,RTramchain,bp->hdrsi,s)) == 0 || unspentind == 0 || unspentind >= RTramchain->H.data->numunspents || spentbp->hdrsi < 0 || spentbp->hdrsi >= bp->hdrsi || spentbp == bp )
{
char str[65];
printf("RTutxogen: unexpected spendbp: height.%d bp.[%d] U%d <- S%d.[%d] [ext.%d %s prev.%d]\n",bp->bundleheight+bundlei,spentbp->hdrsi,unspentind,spendind,bp->hdrsi,s->external,bits256_str(str,prevhash),s->prevout);
return(-1);
}
}
else if ( 0 && s->prevout >= 0 )
{
printf("s.%p bp.%p data.%p\n",s,bp,spentbp->ramchain.H.data);
spentbp = bp;
if ( (ind= s->spendtxidind) != 0 && ind < spentbp->ramchain.H.data->numtxids )
{
T = (void *)(long)((long)spentbp->ramchain.H.data + spentbp->ramchain.H.data->Toffset);
unspentind = T[ind].firstvout + s->prevout;
//printf("txidind.%d 1st.%d prevout.%d\n",txidind,T[txidind].firstvout,s->prevout);
}
else
{
printf("RTutxogen txidind overflow %u vs %u\n",ind,spentbp->ramchain.H.data->numtxids);
return(-1);
}
}
else continue;
if ( spentbp != 0 && unspentind != 0 && unspentind < spentbp->ramchain.H.data->numunspents )
{
if ( iguana_volatileupdate(coin,1,bp,bp->bundleheight+bundlei,spendind,spentbp,unspentind) < 0 )
{
printf("iguana_volatileupdate error h.%d spendind.%d spent.%d u.%d\n",bp->bundleheight+bundlei,spendind,spentbp->hdrsi,unspentind);
return(-1);
}
}
}
}
return(0);
}
int32_t iguana_realtime_update(struct iguana_info *coin)
{
struct iguana_bundle *bp; struct iguana_ramchaindata *rdata; int32_t bundlei,err,n,flag=0;
@ -963,9 +941,15 @@ int32_t iguana_realtime_update(struct iguana_info *coin)
break;
}
block = iguana_blockfind(coin,block->RO.prev_block);
if ( n++ >= bp->n )
n++;
if ( coin->RTgenesis != 0 && n >= bp->n )
break;
}
if ( coin->RTgenesis == 0 && n == coin->RTheight )
{
printf("RTgenesis verified\n");
coin->RTgenesis = (uint32_t)time(NULL);
}
printf(">>>> RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,(long)dest->H.data->allocsize);
}
return(0);

Loading…
Cancel
Save