From e7c631d6deb41cc5dc4fbee49d91964ac4dc5015 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 13 Aug 2016 23:47:29 -0300 Subject: [PATCH] test --- iguana/iguana_realtime.c | 8 ++- iguana/iguana_recv.c | 2 +- iguana/iguana_spendvectors.c | 4 +- iguana/iguana_unspents.c | 136 +++++++++++++++++++++-------------- includes/iguana_funcs.h | 4 +- 5 files changed, 94 insertions(+), 60 deletions(-) diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 63f48fe60..93f0fddd7 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -213,11 +213,11 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info * struct iguana_block *block=0; struct iguana_blockRO *B; struct iguana_ramchain *dest=0,blockR; if ( coin->peers == 0 && coin->virtualchain == 0 ) return(0); - offset = (strcmp("BTC",coin->symbol) != 0); + offset = 0;//(strcmp("BTC",coin->symbol) != 0); if ( coin->RTheight-offset > coin->blocks.hwmchain.height+1 ) { printf("inversion RT %d > %d\n",coin->RTheight,coin->blocks.hwmchain.height+1); - coin->RTheight = 0; + //coin->RTheight = 0; } if ( coin->current != 0 && (coin->blocks.hwmchain.height % coin->chain->bundlesize) == coin->chain->bundlesize-1 && coin->blocks.hwmchain.height/coin->chain->bundlesize == coin->longestchain/coin->chain->bundlesize ) { @@ -268,8 +268,10 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info * }*/ return(0); } - if ( coin->RTdatabad == 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi >= coin->balanceswritten && coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && ((coin->RTheight < coin->blocks.hwmchain.height-offset && time(NULL) > bp->lastRT) || time(NULL) > bp->lastRT+1) ) + if ( coin->RTdatabad == 0 && bp->hdrsi == coin->longestchain/coin->chain->bundlesize && bp->hdrsi >= coin->balanceswritten-1 && ((coin->RTheight < coin->blocks.hwmchain.height-offset && time(NULL) > bp->lastRT) || time(NULL) > bp->lastRT+1) ) //coin->RTheight >= bp->bundleheight && coin->RTheight < bp->bundleheight+bp->n && { + if ( coin->RTheight == 0 ) + coin->RTheight = bp->bundleheight; if ( (block= bp->blocks[0]) == 0 || block->txvalid == 0 || block->mainchain == 0 ) { if ( block != 0 ) diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 76ddbd1ff..c75362506 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -1648,7 +1648,7 @@ int32_t iguana_processrecv(struct supernet_info *myinfo,struct iguana_info *coin { fprintf(stderr,"%s call balanceflush\n",coin->symbol); //portable_mutex_lock(&coin->RTmutex); - if ( iguana_balanceflush(coin,coin->balanceflush) > 0 ) + if ( iguana_balanceflush(myinfo,coin,coin->balanceflush) > 0 ) printf("balanceswritten.%d flushed coin->balanceflush %d vs %d coin->longestchain/coin->chain->bundlesize\n",coin->balanceswritten,coin->balanceflush,coin->longestchain/coin->chain->bundlesize); //portable_mutex_unlock(&coin->RTmutex); fprintf(stderr,"%s back balanceflush\n",coin->symbol); diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index 13ae5d167..1a05f0bf1 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -807,7 +807,7 @@ void iguana_initfinal(struct iguana_info *coin,bits256 lastbundle) } } -int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi) +int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coin,int32_t refhdrsi) { int32_t hdrsi,numpkinds,iter,numhdrsi,i,numunspents,err; struct iguana_bundle *bp; char fname[1024],fname2[1024],destfname[1024]; bits256 balancehash,allbundles; FILE *fp,*fp2; @@ -912,7 +912,7 @@ int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi) } } char str[65]; printf("BALANCES WRITTEN for %d orig.%d bundles %s\n",coin->balanceswritten,coin->origbalanceswritten,bits256_str(str,coin->balancehash)); - iguana_utxoaddr_gen(coin,(coin->balanceswritten - 1) * coin->chain->bundlesize); + iguana_utxoaddr_gen(myinfo,coin,(coin->balanceswritten - 1) * coin->chain->bundlesize); if ( 0 && coin->balanceswritten > coin->origbalanceswritten+10 ) // strcmp(coin->symbol,"BTC") == 0 && { coin->active = 0; diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index fdef82449..518368acc 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -23,10 +23,10 @@ int32_t iguana_unspentind2txid(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *spentheightp,bits256 *txidp,int32_t *voutp,int16_t hdrsi,uint32_t unspentind) { - /*struct iguana_ramchaindata *rdata=0; struct iguana_bundle *bp=0; struct iguana_unspent *U,*u; struct iguana_txid *T,*t; + struct iguana_ramchaindata *rdata=0; struct iguana_bundle *bp=0; struct iguana_unspent *U,*u; struct iguana_txid *T,*t; *voutp = *spentheightp = -1; memset(txidp,0,sizeof(*txidp)); - if ( hdrsi < coin->bundlescount-1 ) + if ( hdrsi == coin->bundlescount-1 ) rdata = coin->RTramchain.H.data; else if ( (bp= coin->bundles[hdrsi]) != 0 ) rdata = bp->ramchain.H.data; @@ -50,7 +50,7 @@ int32_t iguana_unspentind2txid(struct supernet_info *myinfo,struct iguana_info * rdata = bp->ramchain.H.data; else break; } - return(-1);*/ + return(-1); //{"txid":"e34686afc17ec37a8438f0c9a7e48f98d0c625c7917a59c2d7fa22b53d570115","vout":1,"address":"16jsjc1YvzDXqKf7PorMhTyK8ym3ra3uxm","scriptPubKey":"76a9143ef4734c1141725c095342095f6e0e7748b6c16588ac","amount":0.01000000,"timestamp":0,"height":419261,"confirmations":1729,"checkind":4497018,"account":"default","spendable":true,"spent":{"hdrsi":209,"pkind":2459804,"unspentind":4497018,"prevunspentind":0,"satoshis":"1000000","txidind":1726947,"vout":1,"type":2,"fileid":0,"scriptpos":0,"scriptlen":25},"spentheight":419713,"dest":{"spentfrom":"22651e62f248fe2e72053d650f177e4b246ee016605102a40419e603b2bbeac8","vin":0,"timestamp":0,"vouts":[{"1KRhTPvoxyJmVALwHFXZdeeWFbcJSbkFPu":0.00010000}, {"1GQHQ7vwVpGeir2kKrYATsLtrkUQSc7FGY":0.00980000}],"total":0.00990000,"ratio":1}} cJSON *retarray,*item,*uitem,*sitem; char *retstr; int32_t i,n,retval = -1; *voutp = *spentheightp = -1; @@ -396,9 +396,8 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co { if ( ramchain->height < (coin->bundlescount-1)*coin->chain->bundlesize ) { - //printf("iguana_pkhashbalance.[%d] %d: unexpected null spents.%p or rdata.%p\n",ramchain->height,(coin->bundlescount-1)*coin->chain->bundlesize,ramchain->Uextras,rdata); - } - else iguana_volatilesalloc(coin,ramchain,0); + printf("iguana_pkhashbalance.[%d] %d: unexpected null spents.%p or rdata.%p\n",ramchain->height,(coin->bundlescount-1)*coin->chain->bundlesize,ramchain->Uextras,rdata); + } else iguana_volatilesalloc(coin,ramchain,0); return(0); } unspentind = lastunspentind; @@ -420,7 +419,7 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co unspents[*nump << 1] = ((uint64_t)hdrsi << 32) | unspentind; unspents[(*nump << 1) + 1] = U[unspentind].value; } - //printf("%.8f ",dstr(U[unspentind].value)); + //printf("+%.8f ",dstr(U[unspentind].value)); (*nump)++; if ( array != 0 ) jaddi(array,iguana_unspentjson(myinfo,coin,hdrsi,unspentind,T,&U[unspentind],rmd160,coinaddr,pubkey33,spentheight,remoteaddr)); @@ -432,7 +431,7 @@ int64_t iguana_pkhashbalance(struct supernet_info *myinfo,struct iguana_info *co } if ( p->pkind != U[unspentind].pkind ) printf("warning: [%d] p->pkind.%u vs U->pkind.%u for u%d\n",hdrsi,p->pkind,U[unspentind].pkind,unspentind); - } + } else printf("skip uheight.%d lastheight.%d\n",uheight,lastheight); pkind = p->pkind; unspentind = U[unspentind].prevunspentind; } @@ -477,20 +476,23 @@ int32_t iguana_pkhasharray(struct supernet_info *myinfo,struct iguana_info *coin { if ( (bp= coin->bundles[i]) == 0 ) continue; - if ( lastheight > 0 && bp->bundleheight > lastheight ) - { - //printf("lastheight.%d less than %d\n",lastheight,bp->bundleheight+bp->n); - break; - } - if ( (coin->blocks.hwmchain.height - (bp->bundleheight + bp->n - 1)) > maxconf ) - { - //printf("%d more than minconf.%d\n",(coin->blocks.hwmchain.height - (bp->bundleheight + bp->n - 1)),maxconf); - continue; - } - if ( (coin->blocks.hwmchain.height - bp->bundleheight) < minconf ) + if ( 0 ) { - //printf("%d less than minconf.%d\n",(coin->blocks.hwmchain.height - bp->bundleheight),minconf); - break; + if ( lastheight > 0 && bp->bundleheight > lastheight ) + { + //printf("lastheight.%d less than %d\n",lastheight,bp->bundleheight+bp->n); + break; + } + if ( (coin->blocks.hwmchain.height - (bp->bundleheight + bp->n - 1)) > maxconf ) + { + //printf("%d more than minconf.%d\n",(coin->blocks.hwmchain.height - (bp->bundleheight + bp->n - 1)),maxconf); + continue; + } + if ( (coin->blocks.hwmchain.height - bp->bundleheight) < minconf ) + { + //printf("%d less than minconf.%d\n",(coin->blocks.hwmchain.height - bp->bundleheight),minconf); + break; + } } if ( iguana_pkhashfind(coin,&ramchain,&deposits,&lastunspentind,P != 0 ? &P[n] : &_p,rmd160,i,i) != 0 ) { @@ -706,9 +708,47 @@ int32_t iguana_unspent_check(struct supernet_info *myinfo,struct iguana_info *co return(-1); } +int32_t iguana_addr_unspents(struct supernet_info *myinfo,struct iguana_info *coin,int64_t *sump,int64_t *unspents,int32_t max,char *coinaddr,char *remoteaddr) +{ + int32_t n,k,numunspents,minconf = 0; int64_t total; uint8_t rmd160[20],pubkey[65],addrtype; + total = 0; + n = numunspents = 0; + bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); + iguana_pkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,coin->blocks.hwmchain.height - minconf,unspents,&n,max-1000,remoteaddr); + /*if ( n > 0 ) + { + candidates = unspents; + for (j=0; j> 32); + unspentind = (int32_t)candidates[j << 1]; + if ( iguana_unspent_check(myinfo,coin,hdrsi,unspentind) == 0 ) + { + //printf("(%d u%d) %.8f not in mempool\n",hdrsi,unspentind,dstr(candidates[(j << 1) + 1])); + //for (k=0; klongestchain,coin->blocks.hwmchain.height - minconf); - total = 0; - n = 0; if ( coin->RELAYNODE != 0 || coin->VALIDATENODE != 0 ) { - bitcoin_addr2rmd160(&addrtype,rmd160,coinaddr); - iguana_pkhasharray(myinfo,coin,0,minconf,coin->longestchain,&total,0,coin->bundlescount,rmd160,coinaddr,pubkey,coin->blocks.hwmchain.height - minconf,unspents,&n,max-1000,remoteaddr); - if ( n > 0 ) - { - candidates = unspents; - for (j=0; j> 32); - unspentind = (int32_t)candidates[j << 1]; - if ( iguana_unspent_check(myinfo,coin,hdrsi,unspentind) == 0 ) - { - //printf("(%d u%d) %.8f not in mempool\n",hdrsi,unspentind,dstr(candidates[(j << 1) + 1])); - for (k=0; ksymbol), OS_portable_path(fname); if ( iguana_utxoaddr_map(coin,fname) != 0 ) { @@ -1089,10 +1102,29 @@ int64_t iguana_utxoaddr_gen(struct iguana_info *coin,int32_t maxheight) offset += n; } //for (utxoaddr=last; utxoaddr!=0; utxoaddr=utxoaddr->hh.prev) + max = 1024 * 1024; + unspents = calloc(1,max); + max /= sizeof(*unspents); HASH_ITER(hh,coin->utxoaddrs,utxoaddr,tmp) { if ( utxoaddr->histbalance > 0 ) { + sum = 0; + numunspents = 0; + for (iter=0; iter<1; iter++) + { + bitcoin_address(coinaddr,iter == 0 ? coin->chain->pubtype : coin->chain->p2shtype,utxoaddr->rmd160,sizeof(utxoaddr->rmd160)); + numunspents += iguana_addr_unspents(myinfo,coin,&sum,&unspents[numunspents],max-numunspents,coinaddr,0); + if ( sum == utxoaddr->histbalance ) + break; + } + if ( sum != utxoaddr->histbalance ) + { + for (i=0; i>32)&0xffffffff,(long long)unspents[i<<1]&0xffffffff,dstr(unspents[(i<<1)+1])); + bitcoin_address(coinaddr,coin->chain->pubtype,utxoaddr->rmd160,sizeof(utxoaddr->rmd160)); + printf("%s: sum %.8f != %.8f numunspents.%d diff %.8f\n",coinaddr,dstr(sum),dstr(utxoaddr->histbalance),numunspents,dstr(utxoaddr->histbalance)-dstr(sum)); + } memset(item,0,UTXOADDR_ITEMSIZE); iguana_rwnum(1,&item[0],sizeof(utxoaddr->hdrsi),&utxoaddr->hdrsi); memcpy(&item[2],&utxoaddr->rmd160[2],18); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 786a17ce4..4904ffa44 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -335,7 +335,7 @@ int32_t iguana_bloomfind(struct iguana_info *coin,struct iguana_bloom16 *bloom,i struct iguana_bloominds iguana_bloomset(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit); int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp); //void iguana_balancesQ(struct iguana_info *coin,struct iguana_bundle *bp); -int32_t iguana_balanceflush(struct iguana_info *coin,int32_t refhdrsi); +int32_t iguana_balanceflush(struct supernet_info *myinfo,struct iguana_info *coin,int32_t refhdrsi); int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int32_t starti,int32_t max); int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); @@ -520,7 +520,7 @@ int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t ma int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB); bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *txstartp,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,cJSON *txobj,struct vin_info *V); int32_t iguana_ROallocsize(struct iguana_info *virt); -int64_t iguana_utxoaddr_gen(struct iguana_info *coin,int32_t maxheight); +int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coin,int32_t maxheight); long iguana_bundlesload(struct supernet_info *myinfo,struct iguana_info *coin); void basilisk_wait(struct supernet_info *myinfo,struct iguana_info *coin); int32_t bitcoin_pubkey_combine(void *ctx,uint8_t *combined_pub,uint8_t *skipkey,bits256 *evenkeys,int32_t n,bits256 *oddkeys,int32_t m);