From 0eb8e45600074cc7dca6e2f3f69d72c9d34caa53 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 16 Aug 2016 19:48:08 -0300 Subject: [PATCH] test --- iguana/iguana_blocks.c | 3 + iguana/iguana_ramchain.c | 62 +++++++++++ iguana/iguana_realtime.c | 206 +++++++++++++++++++++++++++++++++++ iguana/iguana_recv.c | 12 +- iguana/iguana_spendvectors.c | 7 +- iguana/iguana_unspents.c | 22 ++-- iguana/iguana_volatiles.c | 14 +-- includes/iguana_funcs.h | 5 + includes/iguana_structs.h | 14 ++- 9 files changed, 319 insertions(+), 26 deletions(-) diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index 618954963..591f78dca 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -79,6 +79,8 @@ void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,stru block->RO.timestamp = origblock->RO.timestamp; if ( block->RO.bits == 0 ) block->RO.bits = origblock->RO.bits; + if ( block->serialized == 0 ) + block->serialized = origblock->serialized; if ( block->RO.txn_count == 0 ) block->RO.txn_count = origblock->RO.txn_count; if ( block->RO.version == 0 ) @@ -674,6 +676,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl process_iguanablock(block->serdata,CHAINPARMS); }*/ iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block); + iguana_RTnewblock(coin,block); return(block); } } diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 69b9ffd71..507533bf6 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -2763,3 +2763,65 @@ void iguana_ramchainmerge(struct iguana_info *coin) // jl777: verify prev/next h } } #endif + +int32_t iguana_RTramchaindata(struct iguana_info *coin,struct OS_memspace *TXDATA,struct OS_memspace *HASHMEM,int64_t polarity,struct iguana_block *block,struct iguana_msgtx *txarray,int32_t txn_count) +{ + RAMCHAIN_DECLARE; struct vin_info V; struct iguana_ramchain R,*ramchain = &R; struct iguana_msgtx *tx; char fname[1024],str[65],coinaddr[64]; uint8_t *script; struct iguana_ramchaindata *rdata; int32_t hdrsi,bundlei,i,j,k,type,scriptlen,firsti = 1; + if ( block->RO.txn_count != txn_count ) + { + printf("txn_count mismatch ht.%d %d != %d\n",block->height,block->RO.txn_count,txn_count); + return(-1); + } + hdrsi = (block->height / coin->chain->bundlesize); + bundlei = (block->height % coin->chain->bundlesize); + if ( iguana_ramchain_init(fname,ramchain,TXDATA,HASHMEM,1,block->RO.txn_count,block->RO.numvouts,block->RO.numvins,0,0,1,0,1,coin->chain->zcash) == 0 ) + { + printf("error iguana_ramchain_init\n"); + return(-1); + } + iguana_ramchain_link(ramchain,block->RO.hash2,hdrsi,block->height,bundlei,1,firsti,0); + if ( (rdata= ramchain->H.data) != 0 ) + { + _iguana_ramchain_setptrs(RAMCHAIN_PTRS,rdata); + if ( T == 0 || U == 0 || S == 0 || B == 0 ) + { + printf("fatal error getting txdataptrs %p %p %p %p\n",T,U,S,B); + return(-1); + } + for (i=0; iH.txidind++) + { + tx = &txarray[i]; + printf("txid.(%s) vouts.%d vins.%d\n",bits256_str(str,tx->txid),tx->tx_out,tx->tx_in); + iguana_RTtxid(coin,block,polarity,i,txn_count,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp); + for (j=0; jtx_out; j++) + { + script = tx->vouts[j].pk_script; + scriptlen = tx->vouts[j].pk_scriptlen; + type = iguana_calcrmd160(coin,0,&V,script,scriptlen,tx->txid,j,0xffffffff); + if ( (type == 12 && scriptlen == 0) || (type == 1 && bitcoin_pubkeylen(script+1) <= 0) ) + { + for (k=0; kchain->pubtype,V.rmd160,sizeof(V.rmd160)); + iguana_RTunspent(coin,block,polarity,coinaddr,V.rmd160,tx->txid,j,tx->vouts[j].value); + } + ramchain->H.spendind += tx->tx_in; + } + //printf("scriptoffset.%d after %d txids\n",ramchain->H.scriptoffset,txn_count); + ramchain->H.txidind = ramchain->H.spendind = rdata->firsti; + for (i=0; iH.txidind++) + { + tx = &txarray[i]; + for (j=0; jtx_in; j++) + { + iguana_RTspend(coin,block,polarity,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout); + } + } + iguana_ramchain_free(coin,ramchain,0); + return(0); + } + iguana_ramchain_free(coin,ramchain,0); + return(-1); +} diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 95fb68a47..ba4fbfe3f 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -463,3 +463,209 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info * #endif return(flag); } + +void iguana_RTreset(struct iguana_info *coin) +{ + iguana_utxoaddrs_purge(coin); + iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables + printf("%s RTreset\n",coin->symbol); +} + +void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight) +{ + int32_t hdrsi,bundlei,height; struct iguana_block *block; struct iguana_bundle *bp; + for (height=0; heightchain->bundlesize); + bundlei = (height % coin->chain->bundlesize); + if ( (bp= coin->bundles[hdrsi]) != 0 && (block= bp->blocks[bundlei]) != 0 ) + { + portable_mutex_lock(&coin->RTmutex); + if ( block->serialized != 0 ) + { + printf("purge txarray[%d] ht.%d\n",block->RO.txn_count,block->height); + free(block->serialized); + block->serialized = 0; + } + portable_mutex_unlock(&coin->RTmutex); + } + } +} + +void iguana_RTtxid(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,int32_t txi,int32_t txn_count,bits256 txid,int32_t numvouts,int32_t numvins,uint32_t locktime,uint32_t version,uint32_t timestamp) +{ + char str[65]; + printf("txid.(%s) vouts.%d vins.%d version.%d lock.%u t.%u %lld\n",bits256_str(str,txid),numvouts,numvins,version,locktime,timestamp,(long long)polarity); +} + +void iguana_RTspend(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout) +{ + char str[65],str2[65]; + printf("%s vini.%d spend.(%s/v%d) %lld\n",bits256_str(str,txid),vini,bits256_str(str2,prev_hash),prev_vout,(long long)polarity); +} + +void iguana_RTunspent(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,char *coinaddr,uint8_t *rmd160,bits256 txid,int32_t vout,int64_t value) +{ + int32_t i; + for (i=0; i<20; i++) + printf("%02x",rmd160[i]); + printf(" %s vout.%d %.8f %lld\n",coinaddr,vout,dstr(value),(long long)polarity); + +} + +void iguana_RTiterate(struct iguana_info *coin,struct iguana_block *block,int64_t polarity) +{ + struct iguana_txblock txdata; int32_t n,len; + if ( block->serialized != 0 ) + { + memset(&txdata,0,sizeof(txdata)); + if ( coin->RTrawmem.ptr == 0 ) + iguana_meminit(&coin->RTrawmem,"RTrawmem",0,IGUANA_MAXPACKETSIZE * 2,0); + if ( coin->RTmem.ptr == 0 ) + iguana_meminit(&coin->RTmem,"RTmem",0,IGUANA_MAXPACKETSIZE * 2,0); + if ( coin->RThashmem.ptr == 0 ) + iguana_meminit(&coin->RThashmem,"RThashmem",0,IGUANA_MAXPACKETSIZE * 2,0); + iguana_memreset(&coin->RTrawmem), iguana_memreset(&coin->RTmem), iguana_memreset(&coin->RThashmem); + if ( (n= iguana_gentxarray(coin,&coin->RTrawmem,&txdata,&len,block->serialized,block->RO.recvlen)) > 0 ) + { + iguana_RTramchaindata(coin,&coin->RTmem,&coin->RThashmem,polarity,block,coin->RTrawmem.ptr,block->RO.txn_count); + } else printf("gentxarray n.%d RO.txn_count.%d recvlen.%d\n",n,block->RO.txn_count,block->RO.recvlen); + } else printf("so serialized for ht.%d %p\n",block->height,block); + + /* struct iguana_utxoaddr *utxoaddr; struct iguana_pkhash *P; struct iguana_txid *T,*t; struct iguana_unspent20 *u,*U; struct iguana_spend256 *S,*s; int32_t i,prevout,hdrsi,bundlei,spent_hdrsi; int64_t spent_value; uint32_t spendind,pkind,unspentind,txidind,spent_txidind,spent_pkind; uint8_t rmd160[20]; char fname[1024],str[65]; long filesize; int32_t err; void *ptr=0; struct iguana_ramchain R; struct iguana_ramchaindata *rdata; bits256 prevhash2; + memset(&R,0,sizeof(R)); + hdrsi = (block->height / coin->chain->bundlesize); + bundlei = (block->height % coin->chain->bundlesize); + if ( (bp= coin->bundles[hdrsi]) != 0 && (ptr= iguana_bundlefile(coin,fname,&filesize,bp,bundlei)) != 0 ) + { + if ( iguana_mapchaininit(fname,coin,&R,bp,bundlei,block,ptr,filesize) >= 0 && (rdata= R.H.data) != 0 ) + { + T = RAMCHAIN_PTR(rdata,Toffset); + P = RAMCHAIN_PTR(rdata,Poffset); + U = RAMCHAIN_PTR(rdata,Uoffset); + S = RAMCHAIN_PTR(rdata,Soffset); + unspentind = spendind = pkind = rdata->firsti; + for (txidind=rdata->firsti; txidindnumtxids; txidind++) + { + t = &T[txidind]; + for (i=0; inumvouts; i++,unspentind++) + { + u = &U[unspentind]; + if ( (RTutxo= iguana_RTutxofind(1,coin,hdrsi,pkind,u->rmd160)) != 0 ) + { + RTutxo->RTcredits += (polarity * u->value); + coin->RTcredits += (polarity * u->value); + //printf("[%d] u%u += %.8f\n",bp->hdrsi,u->pkind,dstr(u->value)); + } else printf("cant find utxoaddr\n"); + } + for (i=0; inumvins; i++,spendind++) + { + s = &S[spendind]; + prevhash = s->prevhash2; + prevout = s->prevout; + if ( (spent_txidind= iguana_RTtxidind(coin,&spent_hdrsi,&spent_unspentind,prevhash)) > 0 ) + { + //if ( iguana_volatileupdate(coin,incremental,&spentbp->ramchain,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,h) < 0 ) //(spentbp == coin->current) ? &coin->RTramchain : + if ( (utxoaddr= iguana_utxoaddrfind(1,coin,spent_hdrsi,spent_pkind,rmd160,&coin->RTprev)) != 0 ) + { + utxoaddr->RTdebits += (polarity * spent_value); + coin->RTdebits += (polarity * spent_value); + //printf("from.%d [%d] u%u -= %.8f\n",fromheight,spent_hdrsi,spent_pkind,dstr(spent_value)); + } + } else printf("cant find (%s)\n",bits256_str(str,prevhash2)); + } + } + } + }*/ +} + +struct iguana_block *iguana_RTblock(struct iguana_info *coin,int32_t height) +{ + int32_t offset; + offset = height - coin->firstRTheight; + //printf("%s iguana_RTblock.%d offset.%d\n",coin->symbol,height,offset); + if ( offset < sizeof(coin->RTblocks)/sizeof(*coin->RTblocks) ) + return(coin->RTblocks[offset]); + else printf("RTblock offset.%d too big\n",offset); + return(0); +} + +void iguana_RTblockadd(struct iguana_info *coin,struct iguana_block *block) +{ + int32_t offset; + offset = block->height - coin->firstRTheight; + if ( block != 0 ) + { + printf("%s RTblockadd.%d offset.%d\n",coin->symbol,block->height,offset); + iguana_RTiterate(coin,block,1); + coin->RTblocks[offset] = block; + } +} + +void iguana_RTblocksub(struct iguana_info *coin,struct iguana_block *block) +{ + int32_t offset; + offset = block->height - coin->firstRTheight; + if ( block != 0 ) + { + printf("%s RTblocksub.%d offset.%d\n",coin->symbol,block->height,offset); + iguana_RTiterate(coin,block,-1); + coin->RTblocks[offset] = 0; + } +} + +void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block) +{ + int32_t i,n,height,hdrsi,bundlei; struct iguana_block *addblock,*subblock; struct iguana_bundle *bp; + if ( coin->RTheight > 0 ) + { + if ( block->height > coin->lastRTheight ) + { + if ( coin->lastRTheight == 0 ) + { + coin->firstRTheight = coin->RTheight; + iguana_RTpurge(coin,coin->firstRTheight); + } + n = (block->height - coin->RTheight) + 1; + for (i=0; iRTheight + i); + hdrsi = (height / coin->chain->bundlesize); + bundlei = (height % coin->chain->bundlesize); + if ( (bp= coin->bundles[hdrsi]) != 0 && (addblock= bp->blocks[bundlei]) != 0 && addblock->height == coin->RTheight+i ) + { + iguana_RTblockadd(coin,addblock); + coin->lastRTheight = addblock->height; + } else printf("missing RTaddblock at i.%d RTheight.%d vs %p %d\n",i,coin->RTheight,addblock,addblock!=0?addblock->height:-1); + } + coin->RTheight += n; + printf(">= RTnewblock RTheight %d prev %d\n",coin->RTheight,coin->lastRTheight); + } + else if ( block->height == coin->lastRTheight ) + { + if ( (subblock= iguana_RTblock(coin,block->height)) != 0 && subblock != block ) + { + iguana_RTblocksub(coin,block); + iguana_RTblockadd(coin,block); + printf("== RTnewblock RTheight %d prev %d\n",coin->RTheight,coin->lastRTheight); + } + } + else + { + if ( block->height < coin->firstRTheight ) + { + if ( coin->lastRTheight > 0 ) + printf("ht.%d reorg past firstRTheight.%d\n",block->height,coin->firstRTheight); + coin->lastRTheight = 0; + iguana_RTreset(coin); + } + else + { + while ( coin->lastRTheight >= block->height ) + iguana_RTblocksub(coin,iguana_RTblock(coin,coin->lastRTheight--)); + iguana_RTblockadd(coin,block); + coin->lastRTheight = block->height; + } + } + } +} diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 03ad113fe..3328d18f1 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -495,6 +495,14 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i }*/ } //else printf("cant save block\n"); } + portable_mutex_lock(&coin->RTmutex); + if ( txdata->zblock.serialized == 0 ) + { + txdata->zblock.serialized = calloc(1,recvlen); + memcpy(txdata->zblock.serialized,data,recvlen); + txdata->zblock.RO.recvlen = recvlen; + } + portable_mutex_unlock(&coin->RTmutex); req->zblock = txdata->zblock; if ( coin->virtualchain != 0 ) printf("%s recvlen.%d ipbits.%x prev.(%s)\n",coin->symbol,req->zblock.RO.recvlen,req->zblock.fpipbits,bits256_str(str,txdata->zblock.RO.prev_block)); @@ -787,12 +795,12 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl void iguana_checklongestchain(struct iguana_info *coin,struct iguana_bundle *bp,int32_t num) { int32_t i; struct iguana_peer *addr; - if ( coin->RTheight > 0 && num > 3 && num < bp->n ) + if ( coin->RTheight > 0 && num > 30 && num < bp->n ) { if ( coin->longestchain > bp->bundleheight+num+10*coin->chain->minconfirms ) { printf("strange.%d suspicious longestchain.%d vs [%d:%d] %d bp->n %d\n",coin->longestchain_strange,coin->longestchain,bp->hdrsi,num,bp->bundleheight+num,bp->n); - if ( coin->longestchain_strange++ > 10 ) + if ( coin->longestchain_strange++ > 100 ) { coin->badlongestchain = coin->longestchain; coin->longestchain = bp->bundleheight+num; diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index fc73a530e..9ed3281da 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -449,7 +449,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig uint32_t spent_unspentind,spent_pkind,unspentind,txidind,h,i,j,endi,k,now; uint64_t spent_value; struct iguana_ramchain *ramchain; struct iguana_ramchaindata *rdata; struct iguana_spendvector *spend; struct iguana_unspent *spentU,*u,*U; struct iguana_spendvector *Xspendinds; - struct iguana_txid *T; struct iguana_blockRO *B; struct iguana_bundle *spentbp; struct iguana_utxoaddr *utxoaddr; struct iguana_pkhash *P; + struct iguana_txid *T; struct iguana_blockRO *B; struct iguana_bundle *spentbp; struct iguana_pkhash *P; //struct iguana_utxoaddr *utxoaddr; int32_t spent_hdrsi,spendind,n,numXspends,errs=0,emit=0; struct iguana_spend *S,*s; /*if ( (starti % coin->chain->bundlesize) != 0 || (endheight % coin->chain->bundlesize) != coin->chain->bundlesize-1 ) ramchain = &coin->RTramchain; @@ -502,7 +502,7 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig } if ( 0 && bp == coin->current ) printf("starti.%d txidind.%d txi.%d numvins.%d spendind.%d\n",i,txidind,j,T[txidind].numvins,spendind); - if ( bp == coin->current )//ramchain == &coin->RTramchain ) + /*if ( bp == coin->current )//ramchain == &coin->RTramchain ) { for (k=0; khdrsi,u->pkind,dstr(u->value)); } else printf("cant find utxoaddr\n"); } - } else unspentind += T[txidind].numvouts; + } else */ + unspentind += T[txidind].numvouts; for (k=0; khistbalance),coin->utxoaddrlastcount,total,last,lastcount,size,coin->utxoaddrfilesize); + return(total + 1 + lastcount); } - printf("%.8f LASTCOUNT %d vs total %d, last %d vs lastcount %d, size.%d %ld\n",dstr(coin->histbalance),coin->utxoaddrlastcount,total,last,lastcount,size,coin->utxoaddrfilesize); - return(total + 1 + lastcount); + return(0); } int32_t iguana_utxoaddr_check(struct supernet_info *myinfo,struct iguana_info *coin,int32_t lastheight,int64_t *unspents,int32_t max,struct iguana_utxoaddr *utxoaddr) @@ -1112,7 +1113,7 @@ int32_t iguana_utxoaddr_check(struct supernet_info *myinfo,struct iguana_info *c } good++; if ( ((good + bad) % 1000) == 0 ) - printf("utxoaddr validate good.%d bad.%d\n",good,bad); + printf("%s utxoaddr validate good.%d bad.%d\n",coin->symbol,good,bad); return(0); } @@ -1162,7 +1163,7 @@ int32_t iguana_utxoaddr_validate(struct supernet_info *myinfo,struct iguana_info int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight) { - char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t checkbalance=0,balance = 0; + char fname[1024],fname2[1024],coinaddr[64],str[65],checkaddr[64]; struct iguana_utxoaddr *utxoaddr,UA,*tmp,*last=0; uint16_t hdrsi; uint8_t *table,item[UTXOADDR_ITEMSIZE]; uint32_t *counts,*offsets,offset,n; int32_t errs=0,height=0,j,k,ind,tablesize=0; struct iguana_bundle *bp; struct iguana_ramchaindata *rdata=0; int64_t checkbalance=0,balance = 0; struct iguana_block *block; for (hdrsi=0; hdrsibundlescount-1; hdrsi++) { if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight ) @@ -1171,12 +1172,14 @@ int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coi sprintf(fname2,"%s/%s/utxoaddrs.%d",GLOBAL_DBDIR,coin->symbol,height), OS_portable_path(fname2); if ( iguana_utxoaddr_map(coin,fname2) != 0 ) { - if ( strcmp("BTC",coin->symbol) != 0 ) - errs = iguana_utxoaddr_validate(myinfo,coin,height); + if ( strcmp("BTCD",coin->symbol) == 0 ) + errs = 0;//iguana_utxoaddr_validate(myinfo,coin,height); printf("nogen %s HIST BALANCE %s %.8f errs %d\n",fname2,bits256_str(str,coin->utxoaddrhash),dstr(coin->histbalance),errs); if ( coin->histbalance > 0 ) { coin->RTheight = height; + if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + iguana_RTnewblock(coin,block); return(coin->histbalance); } } @@ -1293,13 +1296,14 @@ continue; OS_removefile(fname,0); OS_removefile(fname2,0); } + coin->RTheight = height; + if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + iguana_RTnewblock(coin,block); return(coin->histbalance); } } - coin->histbalance = balance; - coin->RTheight = height; free(counts); - return(balance); + return(0.); } void iguana_utxoaddrs_purge(struct iguana_info *coin) diff --git a/iguana/iguana_volatiles.c b/iguana/iguana_volatiles.c index e25a8ae13..4d4f242f0 100755 --- a/iguana/iguana_volatiles.c +++ b/iguana/iguana_volatiles.c @@ -94,13 +94,13 @@ int32_t iguana_utxoupdate(struct iguana_info *coin,int16_t spent_hdrsi,uint32_t hhutxo->u.prevunspentind = hhacct->a.lastunspentind; hhacct->a.lastunspentind = spent_unspentind; hhacct->a.total += spent_value; - struct iguana_utxoaddr *utxoaddr; + /*struct iguana_utxoaddr *utxoaddr; if ( (utxoaddr= iguana_utxoaddrfind(1,coin,spent_hdrsi,spent_pkind,rmd160,&coin->RTprev)) != 0 ) { utxoaddr->RTdebits += spent_value; coin->RTdebits += spent_value; //printf("from.%d [%d] u%u -= %.8f\n",fromheight,spent_hdrsi,spent_pkind,dstr(spent_value)); - } + }*/ return(0); } @@ -218,7 +218,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc } if ( (rdata= spentchain->H.data) != 0 ) { - portable_mutex_lock(&coin->RTmutex); + //portable_mutex_lock(&coin->RTmutex); if ( incremental == 0 ) { if ( spentchain->Uextras == 0 || spentchain->A2 == 0 ) @@ -236,7 +236,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc utxo->fromheight = fromheight; A2[spent_pkind].total += spent_value; A2[spent_pkind].lastunspentind = spent_unspentind; - portable_mutex_unlock(&coin->RTmutex); + //portable_mutex_unlock(&coin->RTmutex); return(0); } else @@ -245,7 +245,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc printf("from.%d spent_unspentind[%d] in hdrs.[%d] is spent fromht.%d %.8f\n",fromheight,spent_unspentind,spent_hdrsi,utxo->fromheight,dstr(spent_value)); else { - portable_mutex_unlock(&coin->RTmutex); + //portable_mutex_unlock(&coin->RTmutex); return(0); } } @@ -261,11 +261,11 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc /*totalmillis += (OS_milliseconds() - startmillis); if ( (++utxon % 100000) == 0 ) printf("ave utxo[%d] %.2f micros total %.2f seconds\n",utxon,(1000. * totalmillis)/utxon,totalmillis/1000.);*/ - portable_mutex_unlock(&coin->RTmutex); + //portable_mutex_unlock(&coin->RTmutex); return(0); } } - portable_mutex_unlock(&coin->RTmutex); + //portable_mutex_unlock(&coin->RTmutex); printf("end iguana_volatileupdate.%d: [%d] spent.(u%u %.8f pkind.%d) double spend? at ht.%d [%d] spendind.%d (%p %p)\n",incremental,spent_hdrsi,spent_unspentind,dstr(spent_value),spent_pkind,fromheight,fromheight/coin->chain->bundlesize,spendind,spentchain->Uextras,spentchain->A2); /*if ( coin->current != 0 && fromheight >= coin->current->bundleheight ) coin->RTdatabad = 1; diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index c4b37e7c4..85d500e10 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -539,6 +539,11 @@ int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct igua int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen); struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits); int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]); +int32_t iguana_RTramchaindata(struct iguana_info *coin,struct OS_memspace *TXDATA,struct OS_memspace *HASHMEM,int64_t polarity,struct iguana_block *block,struct iguana_msgtx *txarray,int32_t txn_count); +void iguana_RTtxid(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,int32_t txi,int32_t txn_count,bits256 txid,int32_t numvouts,int32_t numvins,uint32_t locktime,uint32_t version,uint32_t timestamp); +void iguana_RTspend(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout); +void iguana_RTunspent(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,char *coinaddr,uint8_t *rmd160,bits256 txid,int32_t vout,int64_t value); +void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block); void iguana_RTramchainalloc(char *fname,struct iguana_info *coin,struct iguana_bundle *bp); void iguana_update_balances(struct iguana_info *coin); void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index a8c097669..c0b1f35c3 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -185,7 +185,7 @@ struct iguana_zblockRO #define iguana_blockfields double PoW; \ int32_t height,fpos; uint32_t fpipbits,issued,lag:19,protected:1,peerid:12; \ uint16_t hdrsi:15,mainchain:1,bundlei:11,valid:1,queued:1,txvalid:1,newtx:1,processed:1; \ -UT_hash_handle hh; struct iguana_bundlereq *req; \ +UT_hash_handle hh; struct iguana_bundlereq *req; uint8_t *serialized; \ struct iguana_blockRO RO struct iguana_block @@ -406,12 +406,12 @@ struct iguana_info portable_mutex_t peers_mutex,blocks_mutex,special_mutex,RTmutex; char changeaddr[64]; struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; - struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; + struct OS_memspace RTrawmem,RTmem,RThashmem; // struct iguana_ramchain RTramchain; bits256 RThash1; int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified,blockdepth; uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked,lastcheckpoint; double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused; - int32_t disableUTXO,initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes,balanceflush,basilisk_busy; bits256 reqtxids[64]; + int32_t disableUTXO,initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,firstRTheight,polltimeout,numreqtxids,allhashes,balanceflush,basilisk_busy; bits256 reqtxids[64]; void *launched,*started,*rpcloop; uint64_t bloomsearches,bloomhits,bloomfalse,collisions,txfee_perkb,txfee; uint8_t *blockspace; int32_t blockspacesize; struct OS_memspace blockMEM; @@ -423,8 +423,12 @@ struct iguana_info struct iguana_zblock newblock; char *newblockstr; int32_t relay_RTheights[BASILISK_MAXRELAYS]; struct iguana_blocks blocks; void *mempool; void *mempools[BASILISK_MAXRELAYS]; - struct iguana_utxoaddr *utxoaddrs,*RTprev; uint32_t utxodatasize,utxoaddrind; int64_t histbalance,RTcredits,RTdebits; - void *utxoaddrfileptr; long utxoaddrfilesize; uint32_t utxoaddrlastcount,*utxoaddroffsets; uint8_t *utxoaddrtable; bits256 utxoaddrhash; + + struct iguana_utxoaddr *utxoaddrs,*RTprev; uint32_t utxodatasize,utxoaddrind; + int64_t histbalance,RTcredits,RTdebits; + void *utxoaddrfileptr; long utxoaddrfilesize; + uint32_t utxoaddrlastcount,*utxoaddroffsets; uint8_t *utxoaddrtable; bits256 utxoaddrhash; + struct iguana_block *RTblocks[65536]; }; struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };