Browse Source

Merge remote-tracking branch 'origin/master' into fix-jenkins-build-steps

release/v0.1
Shailesh 9 years ago
parent
commit
ef2c5cc6a0
  1. 2
      basilisk/basilisk_bitcoin.c
  2. 1
      crypto777/inet.c
  3. 11
      crypto777/m_android
  4. 8
      gecko/gecko.c
  5. 2
      iguana/coins/genbtc
  6. 78
      iguana/iguana777.c
  7. 2
      iguana/iguana777.h
  8. 18
      iguana/iguana_bundles.c
  9. 4
      iguana/iguana_msg.c
  10. 23
      iguana/iguana_peers.c
  11. 4
      iguana/iguana_ramchain.c
  12. 176
      iguana/iguana_realtime.c
  13. 72
      iguana/iguana_recv.c
  14. 111
      iguana/iguana_unspents.c
  15. 22
      iguana/m_android
  16. 2
      iguana/main.c
  17. 4
      iguana/secp256k1/m_android
  18. 14
      includes/iguana_funcs.h
  19. 2
      includes/iguana_structs.h

2
basilisk/basilisk_bitcoin.c

@ -266,7 +266,7 @@ int32_t basilisk_bitcoinscan(struct iguana_info *coin,uint8_t origblockspace[IGU
if ( (n= iguana_gentxarray(coin,rawmem,&txdata,&len,blockspace,datalen)) == datalen )
{
len = n;
iguana_gotblockM(coin,0,&txdata,rawmem->ptr,&H,blockspace,datalen);
iguana_gotblockM(coin,0,&txdata,rawmem->ptr,&H,blockspace,datalen,0);
flag = 1;
//if ( (rand() % 1000) == 0 )
printf("%s h.%-7d len.%-6d | HWM.%d\n",coin->symbol,h,datalen,coin->blocks.hwmchain.height);

1
crypto777/inet.c

@ -19,6 +19,7 @@
#ifndef crypto777_inet_h
#define crypto777_inet_h
#include "OS_portable.h"
#include <arpa/inet.h>
#ifdef _WIN32
#define in6_addr sockaddr

11
crypto777/m_android

@ -1,2 +1,9 @@
git pull
cd iguana; ./m_android; cd ..
#!/bin/bash
if [[ $# -eq 0 ]]; then
git pull
#cd iguana; ./m_android; cd ..
fi
echo "Compiling crypto777..."
$CC2 -c -O2 *.c jpeg/*.c jpeg/unix/*.c
rm -f ../agents/libcrypto777.a; $AR rcu ../agents/libcrypto777.a *.o

8
gecko/gecko.c

@ -47,10 +47,10 @@ void gecko_iteration(struct supernet_info *myinfo,struct iguana_info *btcd,struc
longesthdrsi = virt->longestchain / virt->chain->bundlesize;
if ( (bp= virt->bundles[hwmhdrsi]) != 0 )
{
iguana_RTspendvectors(myinfo,virt,bp);
iguana_RTramchainalloc("RTbundle",virt,bp);
iguana_update_balances(virt);
iguana_realtime_update(myinfo,virt);
//iguana_RTspendvectors(myinfo,virt,bp);
//iguana_RTramchainalloc("RTbundle",virt,bp);
//iguana_update_balances(virt);
//iguana_realtime_update(myinfo,virt);
}
if ( 0 && hwmhdrsi <= longesthdrsi )//&& virt->blocks.hwmchain.height < virt->longestchain-1 )
{

2
iguana/coins/genbtc

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":8,\"endpend\":6,\"services\":129,\"maxpeers\":64,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"
curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":5,\"poll\":1,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTC\",\"startpend\":64,\"endpend\":16,\"services\":129,\"maxpeers\":512,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":8333}"

78
iguana/iguana777.c

@ -399,7 +399,7 @@ int32_t iguana_helperB(struct iguana_info *coin,int32_t helperid,struct iguana_b
printf("iguana_helperB unexpected null bp\n");
return(-1);
}
if ( bp != coin->current )
//if ( bp != coin->current )
{
iguana_ramchain_prefetch(coin,&bp->ramchain,7);
if ( convertflag == 0 )
@ -416,10 +416,16 @@ int32_t iguana_helperB(struct iguana_info *coin,int32_t helperid,struct iguana_b
void iguana_update_balances(struct iguana_info *coin)
{
int32_t i,hdrsi,max; struct iguana_bundle *bp; char fname[1024];
if ( coin->RTheight > 0 )
{
printf("Need to restart iguana to generate new balances files\n");
printf("RT dataset can expand past bundle boundary, so no need to update balance files now\n");
return;
}
max = coin->bundlescount;
if ( coin->bundles[max-1] != 0 && coin->bundles[max-1]->emitfinish <= 1 && coin->RTheight == 0 )
max--;
if ( iguana_balancefinished(coin) < max && iguana_spendvectorsaves(coin) == 0 )
//if ( iguana_balancefinished(coin) < max && iguana_spendvectorsaves(coin) == 0 )
{
if ( coin->origbalanceswritten <= 1 )
hdrsi = 0;
@ -429,11 +435,12 @@ void iguana_update_balances(struct iguana_info *coin)
{
iguana_volatilespurge(coin,&bp->ramchain);
sprintf(fname,"%s/%s/accounts/debits.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
//OS_removefile(fname,0);
OS_removefile(fname,0);
sprintf(fname,"%s/%s/accounts/lastspends.%d",GLOBAL_DBDIR,coin->symbol,bp->bundleheight);
//OS_removefile(fname,0);
OS_removefile(fname,0);
iguana_volatilesalloc(coin,&bp->ramchain,0);//i < hdrsi);
}
printf("accounts files purged\n");
sleep(3);
for (hdrsi=0; hdrsi<max; hdrsi++)
{
@ -443,17 +450,20 @@ void iguana_update_balances(struct iguana_info *coin)
{
//iguana_ramchain_prefetch(coin,&bp->ramchain,3);
if ( iguana_balancegen(coin,0,bp,0,coin->chain->bundlesize-1,0) == 0 )
{
fprintf(stderr,"%d ",hdrsi);
bp->balancefinish = (uint32_t)time(NULL);
}
else printf("balancegen error.[%d]\n",bp->hdrsi);
}
} else printf("null bp.[%d]\n",hdrsi);
}
if ( max != coin->origbalanceswritten )
//if ( max != coin->origbalanceswritten )
{
coin->balanceflush = max+1;
while ( coin->balanceflush != 0 )
sleep(3);
} else printf("skip flush when max.%d and orig.%d\n",max,coin->origbalanceswritten);
}// else printf("skip flush when max.%d and orig.%d\n",max,coin->origbalanceswritten);
}
}
@ -495,9 +505,29 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
//printf("helperid.%d convertfinished.%d vs max %d bundlescount.%d\n",helperid,n,max,coin->bundlescount);
sleep(IGUANA_NUMHELPERS+3);
}
if ( helperid < incr )
{
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
{
if ( (bp= coin->bundles[hdrsi]) == 0 )
continue;
if ( iguana_bundlevalidate(coin,bp,0) != bp->n )
{
printf("validate.[%d] error. refresh page or restart iguana and it should regenerate\n",bp->hdrsi);
exit(-1);
} // else printf("%s helperid.%d validated.[%d]\n",coin->symbol,helperid,hdrsi);
}
}
while ( iguana_validated(coin) < max || iguana_utxofinished(coin) < max )
{
printf("%s helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",coin->symbol,helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max);
sleep(IGUANA_NUMHELPERS+3);
}
if ( helperid == 0 )
{
printf("start iguana_update_balances\n");
iguana_update_balances(coin);
printf("iguana_update_balances completed\n");
if ( 1 )
{
for (i=0; i<max; i++)
@ -513,30 +543,20 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int
//printf("helper.%d check validates\n",helperid);
//incr = IGUANA_NUMHELPERS;
//incr = 1;
if ( helperid < incr )
{
for (hdrsi=helperid; hdrsi<max; hdrsi+=incr)
{
if ( (bp= coin->bundles[hdrsi]) == 0 )
continue;
if ( iguana_bundlevalidate(coin,bp,0) != bp->n )
{
printf("validate.[%d] error. refresh page or restart iguana and it should regenerate\n",bp->hdrsi);
exit(-1);
} // else printf("%s helperid.%d validated.[%d]\n",coin->symbol,helperid,hdrsi);
}
}
while ( iguana_validated(coin) < max || iguana_utxofinished(coin) < max || iguana_balancefinished(coin) < max )
{
printf("%s helperid.%d waiting for spendvectorsaved.%u v.%d u.%d b.%d vs max.%d\n",coin->symbol,helperid,coin->spendvectorsaved,iguana_validated(coin),iguana_utxofinished(coin),iguana_balancefinished(coin),max);
sleep(IGUANA_NUMHELPERS+3);
}
if ( helperid == 0 )
{
coin->spendvectorsaved = (uint32_t)time(NULL);
coin->spendvalidated = 0;
printf("%s UTXOGEN spendvectorsaved <- %u\n",coin->symbol,coin->spendvectorsaved);
iguana_utxoaddr_gen(myinfo,coin,(coin->bundlescount - 1) * coin->chain->bundlesize);
if ( iguana_utxoaddr_gen(myinfo,coin,(coin->bundlescount - 1) * coin->chain->bundlesize) < 0 )
{
printf("retry utxoaddr_gen\n");
if ( iguana_utxoaddr_gen(myinfo,coin,(coin->bundlescount - 1) * coin->chain->bundlesize) < 0 )
{
printf("restart iguana: fatal error generating ledger file for %s\n",coin->symbol);
exit(1);
}
}
}
else
{
@ -682,6 +702,8 @@ void iguana_coinloop(void *arg)
flag = 0;
for (i=0; i<n; i++)
{
if ( n > 1 && (rand() % (n*100)) > 100 )
continue;
if ( (coin= coins[i]) != 0 )
{
if ( coin->peers == 0 )
@ -768,11 +790,13 @@ void iguana_coinloop(void *arg)
}
}
//printf("%s flag.%d isRT.%d polltimeout.%d numranked.%d\n",coin->symbol,flag,coin->isRT,coin->polltimeout,coin->peers->numranked);
if ( flag == 0 && coin->isRT == 0 && coin->peers != 0 )
/*if ( flag == 0 && coin->isRT == 0 && coin->peers != 0 )
usleep(coin->polltimeout*1000 + (coin->peers->numranked == 0)*1000000);
else if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize )
usleep(coin->polltimeout*5000 + 90000 + (coin->peers->numranked == 0)*1000000);
else usleep(coin->polltimeout*1000);
else usleep(coin->polltimeout*1000);*/
if ( flag == 0 )
usleep(100000);
}
}

2
iguana/iguana777.h

@ -19,6 +19,8 @@
#if (defined(_WIN32) || defined(__WIN32__)) && \
!defined(WIN32) && !defined(__SYMBIAN32__)
#define WIN32
#else
#include <arpa/inet.h>
#endif
//#define BTC2_VERSION

18
iguana/iguana_bundles.c

@ -218,15 +218,21 @@ int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blo
}
else
{
printf("bp.[%d]->blocks[%d] mismatch %p != %p\n",bp->hdrsi,bundlei,bp->blocks[bundlei],block);
if ( coin->RTheight > 0 && bp->bundleheight+bundlei > coin->firstRTheight )
{
if ( (block= iguana_blockfind("reset",coin,bp->hashes[0])) != 0 )
if ( bundlei > 1 )
bundlei -= 2;
if ( bp->bundleheight+bundlei > coin->blocks.hwmchain.height && (block= iguana_blockfind("reset",coin,bp->hashes[0])) != 0 )
{
printf("RESET HWM to %d\n",coin->firstRTheight);
iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block);
printf("RESET HWM to %d ht.%d\n",bp->bundleheight+bundlei,block->height);
return(-1);
}
} //else printf("couldnt find block at %d\n",bp->bundleheight+bundlei);
}
else if ( bundlei > 0 )
{
printf("bp.[%d]->blocks[%d] mismatch %p != %p\n",bp->hdrsi,bundlei,bp->blocks[bundlei],block);
bp->blocks[bundlei] = 0;
}
iguana_blockunmark(coin,block,bp,bundlei,1);
return(-1);
@ -452,8 +458,6 @@ char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi)
retjson = cJSON_CreateArray();
PKbits = RAMCHAIN_PTR(rdata,PKoffset);
P = RAMCHAIN_PTR(rdata,Poffset);
//PKbits = (void *)(long)((long)rdata + rdata->PKoffset);
//P = (void *)(long)((long)rdata + rdata->Poffset);
for (pkind=0; pkind<numpkinds; pkind++,P++)
{
init_hexbytes_noT(rmdstr,P->rmd160,20);
@ -1163,7 +1167,7 @@ int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,in
iguana_meminit(&coin->internaladdr.TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0);
if ( coin->internaladdr.HASHMEM.ptr == 0 )
iguana_meminit(&coin->internaladdr.HASHMEM,"HASHPTRS",0,256,0);
if ( iguana_msgparser(coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen) < 0 )
if ( iguana_msgparser(coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen,1) < 0 )
printf("error parsing speculativecache.[%d:%d]\n",bp->hdrsi,bundlei);
}
free(data);

4
iguana/iguana_msg.c

@ -827,7 +827,7 @@ int32_t iguana_intvectors(struct iguana_info *coin,struct iguana_peer *addr,int3
//printf("intvectors.%c recvlen.%d\n",intvectors,recvlen);
}
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
{
uint8_t serialized[16384]; char *ipaddr; struct supernet_info *myinfo = SuperNET_MYINFO(0);
int32_t i,n=0,retval=-1,ishost,srvmsg,bloom,sendlen=0,intvectors,len= -100; uint64_t nonce,x; bits256 hash2;
@ -873,7 +873,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc
if ( (n= iguana_gentxarray(coin,rawmem,&txdata,&len,data,recvlen)) == recvlen )
{
len = n;
iguana_gotblockM(coin,addr,&txdata,rawmem->ptr,H,data,recvlen);
iguana_gotblockM(coin,addr,&txdata,rawmem->ptr,H,data,recvlen,fromcache);
}
else
{

23
iguana/iguana_peers.c

@ -500,7 +500,7 @@ int32_t iguana_send(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *s
remains -= numsent;
serialized += numsent;
if ( remains > 0 )
printf("iguana sent.%d remains.%d of len.%d\n",numsent,remains,len);
printf("%s iguana sent.%d remains.%d of len.%d\n",addr->ipaddr,numsent,remains,len);
}
}
addr->totalsent += len;
@ -566,7 +566,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len)
return(len);
}
void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len)
void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache)
{
struct iguana_msghdr checkH;
memset(&checkH,0,sizeof(checkH));
@ -582,7 +582,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig
iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0);
//printf("Init %s memory %p %p %p\n",addr->ipaddr,addr->RAWMEM.ptr,addr->TXDATA.ptr,addr->HASHMEM.ptr);
}
if ( iguana_msgparser(coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len) < 0 || addr->dead != 0 )
if ( iguana_msgparser(coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len,fromcache) < 0 || addr->dead != 0 )
{
printf("%p addr->dead.%d or parser break at %u\n",&addr->dead,addr->dead,(uint32_t)time(NULL));
addr->dead = (uint32_t)time(NULL);
@ -631,14 +631,14 @@ void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_pee
buf = mycalloc('p',1,len);
if ( (recvlen= iguana_recv(addr->ipaddr,usock,buf,len)) < 0 )
{
printf("recv error on (%s) len.%d errno.%d (%s)\n",H.command,len,-recvlen,strerror(-recvlen));
printf("%s recv error on (%s) len.%d errno.%d (%s)\n",addr->ipaddr,H.command,len,-recvlen,strerror(-recvlen));
if ( buf != _buf )
myfree(buf,len);
addr->dead = (uint32_t)time(NULL);
//addr->dead = (uint32_t)time(NULL);
return;
}
}
iguana_parsebuf(coin,addr,&H,buf,len);
iguana_parsebuf(coin,addr,&H,buf,len,0);
if ( buf != _buf )
myfree(buf,len);
return;
@ -1200,7 +1200,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
if ( req->datalen != 0 )
{
//char str[65]; printf("CACHE.%p parse[%d] %s %s\n",req,req->recvlen,req->H.command,bits256_str(str,req->zblock.RO.hash2));
iguana_parsebuf(coin,addr,&req->H,req->serializeddata,req->recvlen);
iguana_parsebuf(coin,addr,&req->H,req->serializeddata,req->recvlen,1);
} else printf("CACHE error no datalen\n");
coin->cachefreed++;
myfree(req,req->allocsize);
@ -1300,9 +1300,12 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
myfree(buf,bufsize);
if ( addr->filehash2 != 0 )
myfree(addr->filehash2,addr->maxfilehash2*sizeof(*addr->filehash2)), addr->filehash2 = 0;
iguana_mempurge(&addr->RAWMEM);
iguana_mempurge(&addr->TXDATA);
iguana_mempurge(&addr->HASHMEM);
if ( 0 )
{
iguana_mempurge(&addr->RAWMEM);
iguana_mempurge(&addr->TXDATA);
iguana_mempurge(&addr->HASHMEM);
}
#ifdef IGUANA_PEERALLOC
while ( (remaining= iguana_peerallocated(coin,addr)) > 0 )
{

4
iguana/iguana_ramchain.c

@ -2804,7 +2804,7 @@ int32_t iguana_RTramchaindata(struct iguana_info *coin,struct OS_memspace *TXDAT
printf(" script type.%d\n",type);
}
bitcoin_address(coinaddr,coin->chain->pubtype,V.rmd160,sizeof(V.rmd160));
iguana_RTunspent(coin,block,polarity,coinaddr,V.rmd160,tx->txid,j,tx->vouts[j].value);
iguana_RTunspent(coin,block,polarity,coinaddr,V.rmd160,type,script,scriptlen,tx->txid,j,tx->vouts[j].value);
}
ramchain->H.spendind += tx->tx_in;
}
@ -2816,7 +2816,7 @@ int32_t iguana_RTramchaindata(struct iguana_info *coin,struct OS_memspace *TXDAT
tx = &txarray[i];
for (j=0; j<tx->tx_in; j++)
{
iguana_RTspend(coin,block,polarity,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout);
iguana_RTspend(coin,block,polarity,tx->vins[i].vinscript,tx->vins[i].scriptlen,tx->txid,j,tx->vins[j].prev_hash,tx->vins[j].prev_vout);
}
}
iguana_RTtxid(coin,block,polarity,i,txn_count,tx->txid,tx->tx_out,tx->tx_in,tx->lock_time,tx->version,tx->timestamp,unspents,spends);

176
iguana/iguana_realtime.c

@ -464,11 +464,11 @@ int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *
return(flag);
}
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_RTunspent(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,char *coinaddr,uint8_t *rmd160,int32_t type,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vout,int64_t value)
{
int32_t i;
// fill in array element and update counters
if ( strcmp("BTC",coin->symbol) != 0 )
if ( 0 && strcmp("BTC",coin->symbol) != 0 )
{
for (i=0; i<20; i++)
printf("%02x",rmd160[i]);
@ -476,11 +476,11 @@ void iguana_RTunspent(struct iguana_info *coin,struct iguana_block *block,int64_
}
}
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_RTspend(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vini,bits256 prev_hash,int32_t prev_vout)
{
char str[65],str2[65];
// fill in array element and update counters
if ( strcmp("BTC",coin->symbol) != 0 )
if ( 0 && strcmp("BTC",coin->symbol) != 0 )
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);
}
@ -488,7 +488,7 @@ void iguana_RTtxid(struct iguana_info *coin,struct iguana_block *block,int64_t p
{
char str[65];
// add to hashtable block <-> txids[]
if ( strcmp("BTC",coin->symbol) != 0 )
if ( 0 && strcmp("BTC",coin->symbol) != 0 )
printf("%s txid.(%s) vouts.%d vins.%d version.%d lock.%u t.%u %lld\n",coin->symbol,bits256_str(str,txid),numvouts,numvins,version,locktime,timestamp,(long long)polarity);
}
@ -496,52 +496,81 @@ 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);
coin->lastRTheight = 0;
coin->RTheight = coin->firstRTheight;
printf("%s RTreset %d\n",coin->symbol,coin->RTheight);
}
void iguana_RTunmap(uint8_t *ptr,uint32_t len)
{
munmap(&ptr[-sizeof(len)],len+sizeof(len));
OS_releasemap(&ptr[-2*sizeof(len)],len+2*sizeof(len));
}
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp)
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t checkonly)
{
FILE *fp; char fname[1024],str[65]; long filesize; uint8_t *ptr; uint32_t i,nonz,checklen;
FILE *fp; char fname[1024],str[65]; long filesize; int32_t len; uint8_t *ptr; uint32_t i,nonz,checknumtx,checklen;
sprintf(fname,"%s/%s/RT/%s.raw",GLOBAL_TMPDIR,coin->symbol,bits256_str(str,hash2));
OS_compatible_path(fname);
if ( *recvlenp > 0 )
if ( *recvlenp == -1 )
OS_removefile(fname,0);
else
{
if ( (fp= fopen(fname,"wb")) != 0 )
if ( (checkonly != 0 || *recvlenp > 0) && (fp= fopen(fname,"rb")) != 0 )
{
if ( fwrite(recvlenp,1,sizeof(*recvlenp),fp) != sizeof(*recvlenp) || fwrite(data,1,*recvlenp,fp) != *recvlenp )
printf("error writing %s len.%d\n",bits256_str(str,hash2),*recvlenp);
fseek(fp,0,SEEK_END);
filesize = ftell(fp);
rewind(fp);
if ( fread(&len,1,sizeof(len),fp) == sizeof(len) && len == filesize-sizeof(int32_t)*2 )
{
fclose(fp);
//printf("already have %s\n",bits256_str(str,hash2));
*recvlenp = 0;
if ( checkonly != 0 )
return((void *)"already have rawdata");
return(0);
}
//printf("len.%d filesize.%ld\n",len,filesize);
fclose(fp);
//printf("created %s\n",fname);
} else printf("couldnt create %s\n",fname);
}
else if ( *recvlenp == 0 )
{
if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 )
}
if ( *recvlenp > 0 )
{
memcpy(&checklen,ptr,sizeof(checklen));
if ( checklen == (int32_t)(filesize - sizeof(checklen)) )
if ( coin->RTheight == 0 && coin->blocks.hwmchain.height < coin->longestchain-coin->chain->bundlesize && iguana_utxofinished(coin) < coin->bundlescount-3 )
{
for (i=nonz=0; i<checklen; i++)
if ( ptr[sizeof(checklen) + i] != 0 )
nonz++;
*recvlenp = (int32_t)(filesize - sizeof(checklen));
return(&ptr[sizeof(*recvlenp)]);
} else printf("checklen.%d vs %d\n",checklen,(int32_t)(filesize - sizeof(checklen)));
//printf("skip %s\n",bits256_str(str,hash2));
return(0);
}
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(recvlenp,1,sizeof(*recvlenp),fp) != sizeof(*recvlenp) || fwrite(numtxp,1,sizeof(*numtxp),fp) != sizeof(*numtxp) || fwrite(data,1,*recvlenp,fp) != *recvlenp )
printf("error writing %s len.%d numtx.%d\n",bits256_str(str,hash2),*recvlenp,*numtxp);
fclose(fp);
//printf("numtx.%d len.%d %s\n",*numtxp,*recvlenp,fname);
} else printf("couldnt create %s\n",fname);
}
else if ( checkonly == 0 )
{
if ( (ptr= OS_mapfile(fname,&filesize,0)) != 0 )
{
memcpy(&checklen,ptr,sizeof(checklen));
memcpy(&checknumtx,&ptr[sizeof(checklen)],sizeof(checknumtx));
*numtxp = checknumtx;
if ( checklen == (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)) )//&& checknumtx == *numtxp )
{
for (i=nonz=0; i<checklen; i++)
if ( ptr[2*sizeof(checklen) + i] != 0 )
nonz++;
*recvlenp = (int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx));
return(&ptr[sizeof(*recvlenp) + sizeof(checknumtx)]);
} else printf("checklen.%d vs %d, checknumtx %d vs %d\n",checklen,(int32_t)(filesize - sizeof(checklen) - sizeof(checknumtx)),checknumtx,*numtxp);
}
}
}
else if ( *recvlenp == -1 )
OS_removefile(fname,0);
return(0);
}
void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight)
{
int32_t hdrsi,bundlei,height,recvlen=-1; struct iguana_bundle *bp;
int32_t hdrsi,bundlei,height,numtx=0,recvlen=-1; struct iguana_bundle *bp;
printf("start RTpurge from %d\n",lastheight - coin->chain->bundlesize*10);
for (height=lastheight-coin->chain->bundlesize*10; height<lastheight; height++)
{
@ -550,19 +579,34 @@ void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight)
hdrsi = (height / coin->chain->bundlesize);
bundlei = (height % coin->chain->bundlesize);
if ( (bp= coin->bundles[hdrsi]) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 )
iguana_RTrawdata(coin,bp->hashes[bundlei],0,&recvlen);
iguana_RTrawdata(coin,bp->hashes[bundlei],0,&recvlen,&numtx,0); // delete file
}
printf("end RTpurge.%d\n",lastheight);
}
void iguana_RTiterate(struct iguana_info *coin,int32_t offset,struct iguana_block *block,int64_t polarity)
int32_t iguana_RTiterate(struct iguana_info *coin,int32_t offset,struct iguana_block *block,int64_t polarity)
{
struct iguana_txblock txdata; uint8_t *serialized; int32_t n,len; uint32_t recvlen = 0;
if ( (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
struct iguana_txblock txdata; uint8_t *serialized; int32_t i,n,errs=0,numtx,len; uint32_t recvlen = 0;
if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
{
printf("cant load from tmpdir ht.%d polarity.%lld\n",block->height,(long long)polarity);
return;
char str[65];
//printf("errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
coin->RTrawdata[offset] = iguana_RTrawdata(coin,block->RO.hash2,0,&coin->RTrecvlens[offset],&coin->RTnumtx[offset],0);
if ( (numtx= coin->RTnumtx[offset]) == 0 || (serialized= coin->RTrawdata[offset]) == 0 || (recvlen= coin->RTrecvlens[offset]) == 0 )
{
printf("B errs.%d cant load %s ht.%d polarity.%lld numtx.%d %p recvlen.%d\n",errs,bits256_str(str,block->RO.hash2),block->height,(long long)polarity,coin->RTnumtx[offset],coin->RTrawdata[offset],coin->RTrecvlens[offset]);
struct iguana_peer *addr;
iguana_blockQ("RTiterate",coin,0,-1,block->RO.hash2,1);
if ( coin->peers != 0 && coin->peers->numranked > 0 )
{
for (i=0; i<coin->peers->numranked&&i<8; i++)
if ( (addr= coin->peers->ranked[i]) != 0 )
iguana_sendblockreqPT(coin,addr,0,-1,block->RO.hash2,1);
}
return(-1);
}
}
printf("%s RTiterate.%lld offset.%d numtx.%d len.%d\n",coin->symbol,(long long)polarity,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset]);
memset(&txdata,0,sizeof(txdata));
if ( coin->RTrawmem.ptr == 0 )
iguana_meminit(&coin->RTrawmem,"RTrawmem",0,IGUANA_MAXPACKETSIZE * 2,0);
@ -573,8 +617,11 @@ void iguana_RTiterate(struct iguana_info *coin,int32_t offset,struct iguana_bloc
iguana_memreset(&coin->RTrawmem), iguana_memreset(&coin->RTmem), iguana_memreset(&coin->RThashmem);
if ( (n= iguana_gentxarray(coin,&coin->RTrawmem,&txdata,&len,serialized,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,recvlen);
iguana_RTramchaindata(coin,&coin->RTmem,&coin->RThashmem,polarity,block,coin->RTrawmem.ptr,numtx);
return(0);
} else printf("gentxarray n.%d RO.txn_count.%d recvlen.%d\n",n,numtx,recvlen);
iguana_RTreset(coin);
return(-1);
}
struct iguana_block *iguana_RTblock(struct iguana_info *coin,int32_t height)
@ -588,34 +635,41 @@ struct iguana_block *iguana_RTblock(struct iguana_info *coin,int32_t height)
return(0);
}
void iguana_RTblockadd(struct iguana_info *coin,struct iguana_block *block)
int32_t iguana_RTblockadd(struct iguana_info *coin,struct iguana_block *block)
{
int32_t offset;
if ( block != 0 )
{
offset = block->height - coin->firstRTheight;
printf("%s RTblockadd.%d offset.%d\n",coin->symbol,block->height,offset);
if ( coin->RTrawdata[offset] == 0 )
coin->RTrawdata[offset] = iguana_RTrawdata(coin,block->RO.hash2,0,&coin->RTrecvlens[offset]);
coin->RTrawdata[offset] = iguana_RTrawdata(coin,block->RO.hash2,0,&coin->RTrecvlens[offset],&coin->RTnumtx[offset],0);
//printf("%s RTblockadd.%d offset.%d numtx.%d len.%d\n",coin->symbol,block->height,offset,coin->RTnumtx[offset],coin->RTrecvlens[offset]);
block->RO.txn_count = coin->RTnumtx[offset];
coin->RTblocks[offset] = block;
iguana_RTiterate(coin,offset,block,1);
if ( iguana_RTiterate(coin,offset,block,1) < 0 )
return(-1);
}
return(0);
}
void iguana_RTblocksub(struct iguana_info *coin,struct iguana_block *block)
int32_t iguana_RTblocksub(struct iguana_info *coin,struct iguana_block *block)
{
int32_t offset;
if ( block != 0 )
{
offset = block->height - coin->firstRTheight;
printf("%s RTblocksub.%d offset.%d\n",coin->symbol,block->height,offset);
iguana_RTiterate(coin,offset,block,-1);
block->RO.txn_count = coin->RTnumtx[offset];
//printf("%s RTblocksub.%d offset.%d\n",coin->symbol,block->height,offset);
if ( iguana_RTiterate(coin,offset,block,-1) < 0 )
return(-1);
if ( coin->RTrawdata[offset] != 0 && coin->RTrecvlens[offset] != 0 )
iguana_RTunmap(coin->RTrawdata[offset],coin->RTrecvlens[offset]);
coin->RTrawdata[offset] = 0;
coin->RTrecvlens[offset] = 0;
coin->RTnumtx[offset] = 0;
coin->RTblocks[offset] = 0;
}
return(0);
}
void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block)
@ -625,12 +679,6 @@ void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block)
{
if ( block->height > coin->lastRTheight )
{
if ( coin->lastRTheight == 0 )
{
coin->firstRTheight = coin->RTheight;
iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight);
}
n = (block->height - coin->RTheight) + 1;
for (i=0; i<n; i++)
{
@ -639,19 +687,26 @@ void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block)
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);
if ( iguana_RTblockadd(coin,addblock) < 0 )
return;
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);
}
else
{
printf("missing RTaddblock at i.%d RTheight.%d vs %p %d\n",i,coin->RTheight,addblock,addblock!=0?addblock->height:-1);
iguana_RTreset(coin);
return;
}
}
coin->RTheight += n;
coin->RTheight += i;
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);
if ( iguana_RTblocksub(coin,subblock) < 0 || iguana_RTblockadd(coin,block) < 0 )
return;
printf("== RTnewblock RTheight %d prev %d\n",coin->RTheight,coin->lastRTheight);
}
}
@ -661,14 +716,17 @@ void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block)
{
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);
{
if ( iguana_RTblocksub(coin,iguana_RTblock(coin,coin->lastRTheight--)) < 0 )
return;
}
if ( iguana_RTblockadd(coin,block) < 0 )
return;
coin->lastRTheight = block->height;
}
}

72
iguana/iguana_recv.c

@ -63,12 +63,12 @@ int32_t iguana_speculativesearch(struct iguana_info *coin,struct iguana_block **
int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe)
{
static bits256 lastreq,lastreq2;
int32_t len,j; struct iguana_bundle *checkbp; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; struct iguana_block *block=0;
int32_t len,j,recvlen,numtx; struct iguana_bundle *checkbp; uint8_t serialized[sizeof(struct iguana_msghdr) + sizeof(uint32_t)*32 + sizeof(bits256)]; struct iguana_block *block=0;
char hexstr[65]; init_hexbytes_noT(hexstr,hash2.bytes,sizeof(hash2));
if ( addr == 0 || memcmp(lastreq.bytes,hash2.bytes,sizeof(hash2)) == 0 || memcmp(lastreq2.bytes,hash2.bytes,sizeof(hash2)) == 0 )
{
//printf("duplicate req %s or null addr.%p\n",bits256_str(hexstr,hash2),addr);
if ( (rand() % 10 ) != 0 )
if ( iamthreadsafe == 0 && (rand() % 10 ) != 0 )
return(0);
}
if ( addr->usock < 0 )
@ -78,8 +78,13 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
{
if ( checkbp->emitfinish != 0 || ((block= checkbp->blocks[j]) != 0 && block->txvalid != 0 && block->mainchain != 0 && block->valid != 0) )
{
//printf("found valid [%d:%d] in blockreqPT\n",checkbp->hdrsi,j);
return(0);
//char str[65];
recvlen = numtx = 0;
if ( iguana_RTrawdata(coin,hash2,0,&recvlen,&numtx,1) != 0 )
{
//printf("found valid [%d:%d] in blockreqPT\n",checkbp->hdrsi,j);
return(0);
} //else printf("no RTrawdata for %s\n",bits256_str(str,hash2));
}
}
if ( 0 && coin->enableCACHE != 0 && iguana_speculativesearch(coin,&block,hash2) != 0 )
@ -117,7 +122,7 @@ int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,
if ( block != 0 )
block->issued = addr->pendtime;
if ( 0 && coin->current == bp )
printf("REQ.(%s) bundlei.%d hdrsi.%d\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1);
printf("REQ.(%s) [%d:%d] %s\n",bits256_str(hexstr,hash2),bundlei,bp!=0?bp->hdrsi:-1,addr->ipaddr);
} else printf("MSG_BLOCK null datalen.%d\n",len);
return(len);
}
@ -308,9 +313,9 @@ void iguana_bundletime(struct iguana_info *coin,struct iguana_bundle *bp,int32_t
}
}
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen)
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache)
{
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,speculative=0,i,j,bundlei,copyflag; struct iguana_block *block; struct iguana_bundle *bp; uint32_t now; char str[65];
struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,speculative=0,i,j,bundlei,copyflag,numtx; struct iguana_block *block; struct iguana_bundle *bp; uint32_t now; char str[65];
if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE )
{
printf("iguana_getblockM: illegal recvlen.%d\n",recvlen);
@ -350,13 +355,13 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
else if ( 0 && coin->enableCACHE != 0 )
printf("cache.%d validated.(%s)\n",coin->enableCACHE,bits256_str(str,origtxdata->zblock.RO.hash2));
origtxdata->zblock.txvalid = 1;
if ( coin->virtualchain == 0 && addr != 0 && addr != &coin->internaladdr )
if ( fromcache == 0 && coin->virtualchain == 0 && addr != 0 && addr != &coin->internaladdr )
{
static uint64_t received[IGUANA_MAXPEERS],count[IGUANA_MAXPEERS],lastcount,lastreceived,last;
received[addr->addrind] += recvlen;
count[addr->addrind]++;
now = (uint32_t)time(NULL);
if ( ((rand() % 1000) == 0 && now > last+10) || now > last+600 )
if ( ((rand() % 10000) == 0 && now > last+60) || now > last+600 )
{
int64_t sum2 = 0,sum = 0,diffr,diff; double bw = 0.;
for (i=0; i<sizeof(received)/sizeof(*received); i++)
@ -470,11 +475,14 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
txdata = origtxdata;
if ( addr != 0 )
{
if ( addr->pendblocks > 0 )
addr->pendblocks--;
addr->lastblockrecv = (uint32_t)time(NULL);
addr->recvblocks += 1.;
addr->recvtotal += recvlen;
if ( fromcache == 0 )
{
if ( addr->pendblocks > 0 )
addr->pendblocks--;
addr->lastblockrecv = (uint32_t)time(NULL);
addr->recvblocks += 1.;
addr->recvtotal += recvlen;
}
if ( speculative == 0 && iguana_ramchain_data(coin,addr,origtxdata,txarray,origtxdata->zblock.RO.txn_count,data,recvlen) >= 0 )
{
txdata->zblock.fpipbits = (uint32_t)addr->ipbits;
@ -495,15 +503,19 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i
}*/
} //else printf("cant save block\n");
}
iguana_RTrawdata(coin,txdata->zblock.RO.hash2,data,&recvlen);
numtx = origtxdata->zblock.RO.txn_count;
iguana_RTrawdata(coin,txdata->zblock.RO.hash2,data,&recvlen,&numtx,0);
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));
req->zblock.RO.txn_count = req->numtx = txdata->zblock.RO.txn_count;
coin->recvcount++;
coin->recvtime = (uint32_t)time(NULL);
if ( fromcache == 0 )
{
coin->recvcount++;
coin->recvtime = (uint32_t)time(NULL);
netBLOCKS++;
}
req->addr = addr;
netBLOCKS++;
queue_enqueue("recvQ",&coin->recvQ,&req->DL,0);
}
@ -551,7 +563,7 @@ void iguana_gotheadersM(struct iguana_info *coin,struct iguana_peer *addr,struct
void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *blockhashes,int32_t n)
{
struct iguana_bundlereq *req; int32_t i,num;
struct iguana_bundlereq *req; int32_t i,num,j,flag; struct iguana_bundle *bp;
if ( addr != 0 )
{
addr->recvhdrs++;
@ -575,7 +587,27 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi
if ( coin->RTheight > 0 )
{
for (i=1; i<n; i++)
iguana_sendblockreqPT(coin,addr,0,-1,blockhashes[i],0);
{
flag = 0;
if ( (bp= coin->current) != 0 )
{
for (j=0; j<bp->n; j++)
{
if ( j < bp->numspec && bp->speculative != 0 && bits256_cmp(bp->speculative[j],blockhashes[i]) == 0 )
{
flag = 1;
break;
}
if ( bits256_cmp(bp->hashes[j],blockhashes[i]) == 0 )
{
flag = 1;
break;
}
}
}
// if ( flag == 0 )
iguana_sendblockreqPT(coin,addr,0,-1,blockhashes[i],0);
}
}
else if ( n > coin->chain->bundlesize )
iguana_sendblockreqPT(coin,addr,0,-1,blockhashes[1],0);

111
iguana/iguana_unspents.c

@ -939,7 +939,7 @@ struct iguana_utxoaddr *iguana_utxoaddrfind(int32_t createflag,struct iguana_inf
return(utxoaddr);
}
int64_t iguana_bundle_unspents(struct iguana_info *coin,struct iguana_bundle *bp,int32_t maketable,struct iguana_utxoaddr **prevp)
int64_t iguana_bundle_unspents(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_utxoaddr **prevp)
{
struct iguana_utxoaddr *utxoaddr; uint32_t unspentind,pkind; struct iguana_ramchaindata *rdata=0; struct iguana_pkhash *P; struct iguana_unspent *U; struct iguana_utxo *U2=0; int64_t value,balance = 0;
if ( bp == 0 || (rdata= bp->ramchain.H.data) == 0 || (U2= bp->ramchain.Uextras) == 0 )
@ -960,21 +960,18 @@ int64_t iguana_bundle_unspents(struct iguana_info *coin,struct iguana_bundle *bp
else
{
balance += value;
if ( maketable != 0 )
if ( (pkind= U[unspentind].pkind) < rdata->numpkinds && pkind > 0 )
{
if ( (pkind= U[unspentind].pkind) < rdata->numpkinds && pkind > 0 )
if ( (utxoaddr= iguana_utxoaddrfind(1,coin,bp->hdrsi,pkind,P[pkind].rmd160,prevp)) != 0 )
{
if ( (utxoaddr= iguana_utxoaddrfind(1,coin,bp->hdrsi,pkind,P[pkind].rmd160,prevp)) != 0 )
{
//printf("%.8f ",dstr(value));
utxoaddr->histbalance += value;
}
else printf("cant find pkind.%u for unspentind.%u hdrsi.%d\n",pkind,unspentind,bp->hdrsi);
} else printf("illegal pkind.%u for unspentind.%u hdrsi.%d\n",pkind,unspentind,bp->hdrsi);
}
//printf("%.8f ",dstr(value));
utxoaddr->histbalance += value;
} else printf("cant find pkind.%u for unspentind.%u hdrsi.%d\n",pkind,unspentind,bp->hdrsi);
} else printf("illegal pkind.%u for unspentind.%u hdrsi.%d\n",pkind,unspentind,bp->hdrsi);
}
} // else printf("[%d] u%u spent %.8f\n",bp->hdrsi,unspentind,dstr(value));
}
printf("[%d %.8f] ",bp->hdrsi,dstr(balance));
return(balance);
}
@ -1003,25 +1000,6 @@ static int _utxoaddr_cmp(const void *a,const void *b)
#undef item_b
}
void iguana_utxoaddr_purge(struct iguana_info *coin)
{
struct iguana_utxoaddr *utxoaddr,*tmp;
if ( coin->utxoaddrs != 0 )
{
printf("free %s utxoaddrs\n",coin->symbol);
HASH_ITER(hh,coin->utxoaddrs,utxoaddr,tmp)
{
if ( utxoaddr != 0 )
{
HASH_DELETE(hh,coin->utxoaddrs,utxoaddr);
free(utxoaddr);
}
}
coin->utxoaddrs = 0;
}
memset(coin->utxoaddrhash.bytes,0,sizeof(coin->utxoaddrhash));
}
int32_t iguana_utxoaddr_save(struct iguana_info *coin,char *fname,int64_t balance,uint32_t *counts,uint32_t *offsets,uint8_t *table)
{
FILE *fp; bits256 hash; int32_t retval = -1;
@ -1084,6 +1062,36 @@ int32_t iguana_utxoaddr_map(struct iguana_info *coin,char *fname)
return(0);
}
void iguana_utxoaddr_purge(struct iguana_info *coin)
{
struct iguana_utxoaddr *utxoaddr,*tmp;
if ( coin->utxoaddrs != 0 )
{
printf("free %s utxoaddrs\n",coin->symbol);
HASH_ITER(hh,coin->utxoaddrs,utxoaddr,tmp)
{
if ( utxoaddr != 0 )
{
HASH_DELETE(hh,coin->utxoaddrs,utxoaddr);
free(utxoaddr);
}
}
coin->utxoaddrs = 0;
}
if ( coin->utxoaddrfileptr != 0 )
{
OS_releasemap(coin->utxoaddrfileptr,coin->utxoaddrfilesize);
coin->utxoaddrfileptr = 0;
coin->utxoaddrtable = 0;
coin->utxoaddroffsets = 0;
}
memset(coin->utxoaddrhash.bytes,0,sizeof(coin->utxoaddrhash));
coin->histbalance = 0;
coin->utxoaddrlastcount = 0;
coin->utxoaddrind = 0;
coin->utxoaddrfilesize = 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)
{
static int32_t good,bad;
@ -1114,7 +1122,7 @@ int32_t iguana_utxoaddr_check(struct supernet_info *myinfo,struct iguana_info *c
}
good++;
if ( ((good + bad) % 1000) == 0 )
printf("%s utxoaddr validate good.%d bad.%d\n",coin->symbol,good,bad);
printf("%s total %d utxoaddr validate good.%d bad.%d%s\n",coin->symbol,coin->utxoaddrind,good,bad,strcmp(coin->symbol,"BTC") == 0 ? " | (if this is taking too long, just exit and restart iguana)" : "");
return(0);
}
@ -1153,18 +1161,19 @@ int32_t iguana_utxoaddr_validate(struct supernet_info *myinfo,struct iguana_info
iguana_rwutxoaddr(0,ind,item,&UA);
errs += iguana_utxoaddr_check(myinfo,coin,lastheight,unspents,max,&UA);
total++;
if ( (total % 1000) == 0 )
fprintf(stderr,".");
//if ( (total % 1000) == 0 )
// fprintf(stderr,".");
}
}
}
free(unspents);
printf("validate errs.%d\n",errs);
return(errs);
}
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; struct iguana_block *block;
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;
for (hdrsi=0; hdrsi<coin->bundlescount-1; hdrsi++)
{
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight )
@ -1173,14 +1182,16 @@ 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("BTCD",coin->symbol) == 0 )
if ( strcmp("BTC",coin->symbol) != 0 )
errs = 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 )
if ( errs == 0 && coin->histbalance > 0 )
{
coin->RTheight = height;
if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
iguana_RTnewblock(coin,block);
coin->firstRTheight = coin->RTheight = height;
iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight);
//if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
// iguana_RTnewblock(coin,block);
return(coin->histbalance);
}
}
@ -1203,7 +1214,7 @@ int64_t iguana_utxoaddr_gen(struct supernet_info *myinfo,struct iguana_info *coi
{
if ( (bp= coin->bundles[hdrsi]) != 0 && bp->bundleheight < maxheight )
{
balance += iguana_bundle_unspents(coin,bp,1,&last);
balance += iguana_bundle_unspents(coin,bp,&last);
fprintf(stderr,"(%d %.8f) ",hdrsi,dstr(balance));
height = bp->bundleheight + bp->n;
}
@ -1303,14 +1314,24 @@ 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);
else
{
coin->firstRTheight = coin->RTheight = height;
iguana_RTreset(coin);
iguana_RTpurge(coin,coin->firstRTheight);
//if ( (block= iguana_blockfind("utxogen",coin,coin->blocks.hwmchain.RO.hash2)) != 0 )
// iguana_RTnewblock(coin,block);
return(coin->histbalance);
}
}
}
free(counts);
return(0.);
sprintf(fname,"%s/%s/balancecrc.%d",GLOBAL_DBDIR,coin->symbol,height/coin->chain->bundlesize - 1);
OS_removefile(fname,0);
sprintf(fname,"%s/%s/balancecrc.%d",GLOBAL_DBDIR,coin->symbol,height/coin->chain->bundlesize - 2);
OS_removefile(fname,0);
printf("return neg one remove %s\n",fname);
return(-1);
}
void iguana_utxoaddrs_purge(struct iguana_info *coin)

22
iguana/m_android

@ -1,8 +1,18 @@
#!/bin/bash
rm ../agents/iguana *.o
git pull
cd secp256k1; ./m_unix; cd ..
$CC2 -g -Wno-deprecated -c -O2 *.c databases/iguana_DB.c
$CC2 -g -Wno-deprecated -c main.c iguana777.c iguana_bundles.c
#$CC2 -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lcurl -lssl -lcrypto -lpthread -lm #../includes/libsecp256k1.a -lgmp
$CC2 -g -o ../agents/iguana *.o ../agents/libcrypto777.a -lpthread -lm
if [[ $# -eq 0 ]]; then
git pull
fi
echo "Compiling libsecp256k1.a ..."
cd secp256k1; ./m_android; cd ..
#$CC2 -o ../agents/iguana -O2 *.c ../basilisk/*.c -I $NDK/platforms/android-19/arch-arm/usr/include ../agents/libcrypto777.a ../agents/libsecp256k1.a ../OSlibs/android/lib/libcurl.a -lssl -lcrypto -lm -lc -lz
echo "Compiling iguana ... "
#$CC2 -o ../agents/iguana -O2 *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c -I ./secp256k1/include -I $NDK/platforms/android-21/arch-arm/usr/include ../agents/libcrypto777.a ../agents/libsecp256k1.a ../OSlibs/android/lib/libcurl.a -L../OSlibs/android/lib/ -lssl -lcrypto -L$NDK/platforms/android-21/arch-arm/usr/lib -lm -lc -lz -nostdlib -lgcc
$CC2 -g -Wno-deprecated -O2 -c *.c ../basilisk/basilisk.c ../gecko/gecko.c ../datachain/datachain.c
$CC2 -g -Wno-deprecated -c main.c iguana777.c iguana_bundles.c ../basilisk/basilisk.c
$CC2 -g -o ../agents/iguana -O2 *.o ../agents/libcrypto777.a -lm

2
iguana/main.c

@ -408,7 +408,7 @@ void mainloop(struct supernet_info *myinfo)
//portable_mutex_lock(&myinfo->allcoins_mutex);
HASH_ITER(hh,myinfo->allcoins,coin,tmp)
{
if ( coin->current != 0 && coin->active != 0 && coin->started != 0 )
if ( coin->RTheight == 0 && coin->current != 0 && coin->active != 0 && coin->started != 0 )
{
isRT *= coin->isRT;
if ( coin->peers != 0 )

4
iguana/secp256k1/m_android

@ -1 +1,3 @@
$CC2 -c -o ../secp256k1.o -I. -I./src -I./include -I./src -O3 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden -DHAVE_CONFIG_H src/secp256k1.c
#$CC -c -o ../secp256k1.o -I. -I./src -I /Newpub/android-ndk-r9b/platforms/android-19/arch-arm/usr/include -I./include -I./src -O3 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden -DHAVE_CONFIG_H src/secp256k1.c
$CC2 -c -o ../sec256k1.o -I. -I./src -I./include -I./src -O3 -W -std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings -fvisibility=hidden -DHAVE_CONFIG_H src/secp256k1.c

14
includes/iguana_funcs.h

@ -45,7 +45,7 @@ int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hasha
int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block);
void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height);
//void iguana_freetx(struct iguana_msgtx *tx,int32_t n);
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen);
int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache);
// send message
int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H);
@ -65,7 +65,7 @@ void iguana_syncramchain(struct iguana_info *coin);
//int32_t iguana_validateramchain(struct iguana_info *coin,int64_t *netp,uint64_t *creditsp,uint64_t *debitsp,int32_t height,struct iguana_block *block,int32_t hwmheight,struct iguana_prevdep *lp);
int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence);
uint32_t iguana_updatescript(struct iguana_info *coin,uint32_t blocknum,uint32_t txidind,uint32_t spendind,uint32_t unspentind,uint64_t value,uint8_t *script,int32_t scriptlen,uint32_t sequence);
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen);
void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache);
int32_t iguana_parseblock(struct iguana_info *coin,struct iguana_block *block,struct iguana_msgtx *tx,int32_t numtx);
uint32_t iguana_txidind(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,bits256 txid);
bits256 iguana_txidstr(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,char *txidstr,uint32_t txidind);
@ -323,7 +323,7 @@ uint8_t *iguana_walletrmds(struct supernet_info *myinfo,struct iguana_info *coin
char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi);
uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8_t rmd160[20],struct iguana_pkhash *P,uint32_t pkind,struct iguana_ramchain *ramchain);
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);
void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache);
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);
@ -541,10 +541,12 @@ struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct igu
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 *unspents,void *spends);
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_RTspend(struct iguana_info *coin,struct iguana_block *block,int64_t polarity,uint8_t *script,int32_t scriptlen,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,int32_t type,uint8_t *script,int32_t scriptlen,bits256 txid,int32_t vout,int64_t value);
void iguana_RTreset(struct iguana_info *coin);
void iguana_RTpurge(struct iguana_info *coin,int32_t lastheight);
void iguana_RTnewblock(struct iguana_info *coin,struct iguana_block *block);
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp);
void *iguana_RTrawdata(struct iguana_info *coin,bits256 hash2,uint8_t *data,int32_t *recvlenp,int32_t *numtxp,int32_t checkonly);
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);

2
includes/iguana_structs.h

@ -428,7 +428,7 @@ struct iguana_info
int64_t histbalance,RTcredits,RTdebits;
void *utxoaddrfileptr; long utxoaddrfilesize;
uint32_t utxoaddrlastcount,*utxoaddroffsets; uint8_t *utxoaddrtable; bits256 utxoaddrhash;
struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536];
struct iguana_block *RTblocks[65536]; uint8_t *RTrawdata[65536]; int32_t RTrecvlens[65536],RTnumtx[65536];
};
struct vin_signer { bits256 privkey; char coinaddr[64]; uint8_t siglen,sig[80],rmd160[20],pubkey[66]; };

Loading…
Cancel
Save