From 1f35fabccbdb759173d03d4f7eedcc78567736e2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 12 Aug 2016 19:52:59 -0300 Subject: [PATCH] test --- iguana/iguana777.c | 2 +- iguana/iguana_realtime.c | 13 ++++++------ iguana/iguana_spendvectors.c | 38 +++++++++++++++++++++++++----------- iguana/iguana_unspents.c | 9 +++++++++ iguana/iguana_volatiles.c | 15 +++++++++++--- includes/iguana_funcs.h | 4 +++- includes/iguana_structs.h | 4 ++-- 7 files changed, 60 insertions(+), 25 deletions(-) diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 701072ef8..595e9b25a 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -437,7 +437,7 @@ void iguana_update_balances(struct iguana_info *coin) if ( bp != coin->current ) { //iguana_ramchain_prefetch(coin,&bp->ramchain,3); - if ( iguana_balancegen(coin,0,bp,0,bp->bundleheight + coin->chain->bundlesize-1,0) == 0 ) + if ( iguana_balancegen(coin,0,bp,bp->bundleheight,bp->bundleheight + coin->chain->bundlesize-1,0) == 0 ) bp->balancefinish = (uint32_t)time(NULL); } } else printf("null bp.[%d]\n",hdrsi); diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index b17baa9c9..78f262702 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -22,7 +22,7 @@ void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp) if ( coin->utxotable != 0 ) { printf("free RTramchain\n"); - iguana_utxoupdate(coin,-1,0,0,0,0,-1); // free hashtables + iguana_utxoupdate(coin,-1,0,0,0,0,-1,0); // free hashtables coin->RTheight = coin->balanceswritten * coin->chain->bundlesize; coin->RTgenesis = 0; iguana_ramchain_free(coin,&coin->RTramchain,1); @@ -147,9 +147,8 @@ void iguana_RThdrs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t num datalen = iguana_gethdrs(coin,serialized,coin->chain->gethdrsmsg,bits256_str(str,bp->hashes[0])); for (i=0; ipeers->numranked; i++) { - if ( (rand() & 1) == 0 ) - queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); - else queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,coin->blocks.hwmchain.RO.hash2)),1); + queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); + queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,coin->blocks.hwmchain.RO.hash2)),1); if ( (addr= coin->peers->ranked[i]) != 0 && addr->usock >= 0 && addr->dead == 0 && datalen > 0 ) { iguana_send(coin,addr,serialized,datalen); @@ -170,7 +169,7 @@ void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin lasti = bp->n - 1; orignumemit = bp->numtmpspends; iterate = 0; - if ( iguana_spendvectors(myinfo,coin,bp,&coin->RTramchain,coin->RTstarti,lasti,0,iterate) < 0 ) + if ( iguana_spendvectors(myinfo,coin,bp,&coin->RTramchain,coin->RTstarti%coin->chain->bundlesize,lasti,0,iterate) < 0 ) { printf("RTutxo error -> RTramchainfree\n"); coin->RTdatabad = 1; @@ -202,7 +201,7 @@ void iguana_RTspendvectors(struct supernet_info *myinfo,struct iguana_info *coin else if ( coin->RTgenesis == 0 && coin->firstRTgenesis == 0 ) coin->firstRTgenesis++, printf(">>>>>> IGUANA %s READY FOR REALTIME RPC <<<<<<\n",coin->symbol); //printf("iguana_balancegen [%d] (%d to %d)\n",bp->hdrsi,coin->RTstarti,(coin->RTheight-1)%bp->n); - coin->RTstarti = (coin->RTheight % bp->n); + coin->RTstarti = coin->RTheight; } } @@ -388,7 +387,7 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info * } } if ( dest != 0 && flag != 0 ) - printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,dest->H.data!=0?(long)dest->H.data->allocsize:-1); + printf("<<<< flag.%d RT.%d:%d hwm.%d L.%d T.%d U.%d S.%d P.%d X.%d -> size.%ld balance %.8f + %.8f - %.8f = supply %.8f\n",flag,coin->RTheight,n,coin->blocks.hwmchain.height,coin->longestchain,dest->H.txidind,dest->H.unspentind,dest->H.spendind,dest->pkind,dest->externalind,dest->H.data!=0?(long)dest->H.data->allocsize:-1,dstr(coin->histbalance),dstr(coin->RTcredits),dstr(coin->RTdebits),dstr(coin->histbalance + coin->RTcredits - coin->RTdebits)); if ( coin->RTdatabad != 0 ) { bits256 lastbundle; diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index 8493f01b1..9c206c793 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -444,19 +444,25 @@ int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coi int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t starti,int32_t endheight,int32_t startemit) { - uint32_t spent_unspentind,spent_pkind,txidind,h,i,j,endi,k,now; uint64_t spent_value; + 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; struct iguana_spendvector *Xspendinds; - struct iguana_txid *T; struct iguana_blockRO *B; struct iguana_bundle *spentbp; + 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; 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; else ramchain = &bp->ramchain; + starti %= coin->chain->bundlesize; if ( (rdata= ramchain->H.data) == 0 || (n= rdata->numspends) < 1 ) return(-1); - S = (void *)(long)((long)rdata + rdata->Soffset); - B = (void *)(long)((long)rdata + rdata->Boffset); - T = (void *)(long)((long)rdata + rdata->Toffset); + S = RAMCHAIN_PTR(rdata,Soffset); + B = RAMCHAIN_PTR(rdata,Boffset); + T = RAMCHAIN_PTR(rdata,Toffset); + U = RAMCHAIN_PTR(rdata,Uoffset); + P = RAMCHAIN_PTR(rdata,Poffset); + //S = (void *)(long)((long)rdata + rdata->Soffset); + //B = (void *)(long)((long)rdata + rdata->Boffset); + //T = (void *)(long)((long)rdata + rdata->Toffset); numXspends = ramchain->numXspends; if ( (Xspendinds= ramchain->Xspendinds) == 0 ) { @@ -467,9 +473,10 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig //return(-1); } } - endi = (endheight % bp->n); + endi = (endheight % coin->chain->bundlesize); txidind = B[starti].firsttxidind; spendind = B[starti].firstvin; + unspentind = B[starti].firstvout; emit = startemit; if ( 0 && (coin->RTheight == 0 || bp->bundleheight+bp->n < coin->RTheight) ) fprintf(stderr,"BALANCEGEN.[%d] %p[%d] starti.%d s%d <-> endi.%d s%d startemit.%d\n",bp->hdrsi,Xspendinds,numXspends,starti,spendind,endi,B[endi].firstvin+B[endi].numvins,startemit); @@ -478,21 +485,30 @@ int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct ig now = (uint32_t)time(NULL); if ( 0 && bp == coin->current ) 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); - if ( txidind != B[i].firsttxidind || spendind != B[i].firstvin ) + if ( txidind != B[i].firsttxidind || spendind != B[i].firstvin || unspentind != B[i].firstvout ) { - printf("balancegen: txidind %u != %u B[%d].firsttxidind || spendind %u != %u B[%d].firstvin errs.%d\n",txidind,B[i].firsttxidind,i,spendind,B[i].firstvin,i,errs); + printf("balancegen: txidind %u != %u B[%d].firsttxidind || spendind %u != %u B[%d].firstvin errs.%d (%u != %u)\n",txidind,B[i].firsttxidind,i,spendind,B[i].firstvin,i,errs,unspentind,B[i].firstvout); return(-1); } for (j=0; jcurrent ) printf("starti.%d txidind.%d txi.%d numvins.%d spendind.%d\n",i,txidind,j,T[txidind].numvins,spendind); + for (k=0; kpkind].rmd160,&coin->RTprev)) != 0 ) + { + utxoaddr->RTcredits += u->value; + coin->RTcredits += u->value; + } + } for (k=0; khistbalance = balance; return(balance); } + +void iguana_utxoaddrs_purge(struct iguana_info *coin) +{ + struct iguana_utxoaddr *utxoaddr; + coin->RTdebits = coin->RTdebits = 0; + for (utxoaddr=coin->RTprev; utxoaddr!=0; utxoaddr=utxoaddr->hh.prev) + utxoaddr->RTcredits = utxoaddr->RTdebits = 0; +} diff --git a/iguana/iguana_volatiles.c b/iguana/iguana_volatiles.c index 5228d4a5b..0387a4637 100755 --- a/iguana/iguana_volatiles.c +++ b/iguana/iguana_volatiles.c @@ -29,7 +29,7 @@ struct iguana_hhaccount *iguana_hhaccountfind(struct iguana_info *coin,uint64_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,uint32_t spendind,uint32_t fromheight) +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,uint8_t *rmd160) { struct iguana_hhutxo *hhutxo,*tmputxo; struct iguana_hhaccount *hhacct,*tmpacct; uint64_t uval,pval; if ( spent_hdrsi < 0 ) @@ -78,6 +78,12 @@ 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; + if ( (utxoaddr= iguana_utxoaddrfind(1,coin,rmd160,&coin->RTprev)) != 0 ) + { + utxoaddr->RTdebits += spent_value; + coin->RTdebits += spent_value; + } return(0); } @@ -177,7 +183,7 @@ int32_t iguana_spentflag(struct supernet_info *myinfo,struct iguana_info *coin,i int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *spentchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight) { - struct iguana_account *A2; struct iguana_ramchaindata *rdata; struct iguana_utxo *utxo; + struct iguana_account *A2; struct iguana_unspent *spentU; struct iguana_pkhash *spentP; struct iguana_ramchaindata *rdata; struct iguana_utxo *utxo; if ( (rdata= spentchain->H.data) != 0 ) { portable_mutex_lock(&coin->RTmutex); @@ -209,7 +215,9 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc else // do the equivalent of historical, ie mark as spent, linked list, balance { //double startmillis = OS_milliseconds(); static double totalmillis; static int32_t utxon; - if ( iguana_utxoupdate(coin,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,fromheight) == 0 ) + spentP = RAMCHAIN_PTR(rdata,Poffset); + spentU = RAMCHAIN_PTR(rdata,Uoffset); + if ( iguana_utxoupdate(coin,spent_hdrsi,spent_unspentind,spent_pkind,spent_value,spendind,fromheight,spentP[spentU[spent_unspentind].pkind].rmd160) == 0 ) { /*totalmillis += (OS_milliseconds() - startmillis); if ( (++utxon % 100000) == 0 ) @@ -326,6 +334,7 @@ void iguana_volatilespurge(struct iguana_info *coin,struct iguana_ramchain *ramc ramchain->lastspendsfileptr = 0; ramchain->lastspendsfilesize = 0; } + iguana_utxoaddrs_purge(coin); } } diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 6f9c3c0ab..5b3e707e4 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -327,6 +327,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp); int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag,int32_t iterate); int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight,int32_t startemit); +struct iguana_utxoaddr *iguana_utxoaddrfind(int32_t createflag,struct iguana_info *coin,uint8_t rmd160[20],struct iguana_utxoaddr **prevp); int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag); void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp); struct iguana_bloominds iguana_calcbloom(bits256 hash2); @@ -430,7 +431,8 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin int64_t iguana_fastfindcreate(struct iguana_info *coin); int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr); int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struct iguana_ramchain *spentchain,int16_t spent_hdrsi,uint32_t spent_unspentind,uint32_t spent_pkind,uint64_t spent_value,uint32_t spendind,uint32_t fromheight); -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); +void iguana_utxoaddrs_purge(struct iguana_info *coin); +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,uint8_t *rmd160); int32_t iguana_unspentslists(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *totalp,int64_t *unspents,int32_t max,int64_t required,int32_t minconf,cJSON *addresses,char *remoteaddr); int64_t iguana_unspentset(struct supernet_info *myinfo,struct iguana_info *coin); int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t lasthdrsi); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 15e5de3b2..69346d184 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -253,7 +253,7 @@ struct iguana_utxo { uint32_t fromheight:31,lockedflag:1,prevunspentind:31,spent struct iguana_hhaccount { UT_hash_handle hh; uint64_t pval; struct iguana_account a; } __attribute__((packed)); struct iguana_hhutxo { UT_hash_handle hh; uint64_t uval; struct iguana_utxo u; } __attribute__((packed)); -struct iguana_utxoaddr { UT_hash_handle hh; int64_t balance; uint8_t rmd160[20]; } __attribute__((packed)); +struct iguana_utxoaddr { UT_hash_handle hh; int64_t balance,RTcredits,RTdebits; uint8_t rmd160[20]; } __attribute__((packed)); // GLOBAL one zero to non-zero write (unless reorg) struct iguana_spendvector { uint64_t value; uint32_t pkind,unspentind; int32_t fromheight; uint16_t hdrsi:15,tmpflag:1; } __attribute__((packed)); // unspentind @@ -422,7 +422,7 @@ 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; uint32_t utxodatasize,utxoaddrind; + struct iguana_utxoaddr *utxoaddrs,*RTprev; uint32_t utxodatasize,utxoaddrind; int64_t histbalance,RTcredits,RTdebits; }; struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };