Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
ba2e94dc5f
  1. 4
      crypto777/iguana_utils.c
  2. 4
      iguana/iguana777.h
  3. 2
      iguana/iguana_chains.c
  4. 157
      iguana/iguana_unspents.c
  5. 1
      includes/iguana_apideclares.h

4
crypto777/iguana_utils.c

@ -516,6 +516,7 @@ int32_t revsort64s(uint64_t *buf,uint32_t num,int32_t size)
qsort(buf,num,size,_decreasing_uint64);
return(0);
}
/*int32_t iguana_sortbignum(void *buf,int32_t size,uint32_t num,int32_t structsize,int32_t dir)
{
int32_t retval = 0;
@ -538,8 +539,7 @@ int32_t revsort64s(uint64_t *buf,uint32_t num,int32_t size)
if ( retval < 0 )
printf("iguana_sortbignum only does bits256 and rmd160 for now\n");
return(retval);
}
*/
}*/
void touppercase(char *str)
{

4
iguana/iguana777.h

@ -474,11 +474,13 @@ struct iguana_waccount { UT_hash_handle hh; char account[128]; struct iguana_wad
struct iguana_wallet { UT_hash_handle hh; struct iguana_waccount *waccts; };
struct scriptinfo { UT_hash_handle hh; uint32_t fpos; uint16_t scriptlen; uint8_t script[]; };
struct hhbits256 { UT_hash_handle hh; bits256 txid; int32_t height; uint16_t firstvout; };
struct iguana_info
{
char name[64],symbol[8],statusstr[512],scriptsfname[2][512];
struct iguana_peers peers; struct iguana_peer internaladdr; void *fastfind;
struct iguana_peers peers; struct iguana_peer internaladdr;
struct hhbits256 *fastfind,*tmpfastfind; FILE *fastfps[0x100]; bits256 *fast[0x100]; long fastsizes[0x100];
uint64_t instance_nonce,myservices,totalsize,totalrecv,totalpackets,sleeptime;
int64_t mining,totalfees,TMPallocated,MAXRECVCACHE,MAXMEM,PREFETCHLAG,estsize,activebundles;
int32_t MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,origbalanceswritten,balanceswritten,RTheight,RTdatabad;

2
iguana/iguana_chains.c

@ -57,7 +57,7 @@ static struct iguana_chain Chains[] =
"0000044966f40703b516c5af180582d53f783bfd319bb045e2dc3e05ea695d46",
"0100000000000000000000000000000000000000000000000000000000000000000000002b5b9d8cdd624d25ce670a7aa34726858388da010d4ca9ec8fd86369cc5117fd0132a253ffff0f1ec58c7f0000",
// "0100000000000000000000000000000000000000000000000000000000000000000000002b5b9d8cdd624d25ce670a7aa34726858388da010d4ca9ec8fd86369cc5117fd0132a253ffff0f1ec58c7f0001010000000132a253010000000000000000000000000000000000000000000000000000000000000000ffffffff4100012a3d3138204a756e652032303134202d204269746f696e20796f75722077617920746f206120646f75626c6520657370726573736f202d20636e6e2e636f6dffffffff010000000000000000000000000000",
14630,14632,1,0x1e,
14631,14632,1,0x1e,
{ { 12000, (80 * SATOSHIDEN) }, }
},
//[CHAIN_VPN] =

157
iguana/iguana_unspents.c

@ -274,7 +274,7 @@ int32_t iguana_volatilesmap(struct iguana_info *coin,struct iguana_ramchain *ram
if ( err == 0 )
return(0);
}
printf("couldnt map [%d]\n",ramchain->height/coin->chain->bundlesize);
//printf("couldnt map [%d]\n",ramchain->height/coin->chain->bundlesize);
iguana_volatilespurge(coin,ramchain);
return(err);
}
@ -734,24 +734,141 @@ struct iguana_bundle *iguana_externalspent(struct iguana_info *coin,bits256 *pre
int32_t iguana_txidfastfind(struct iguana_info *coin,int32_t *heightp,bits256 txid,int32_t lasthdrsi)
{
/*struct iguana_fasttxid *tp;
HASH_FIND(hh,ramchain->fastfind,&txid,sizeof(txid),tp);
if ( tp != 0 )
{
*heightp = tp->height;
return(tp->firstvout);
}*/
bits256 *sorted; int32_t i,j,val,num,tablesize,*hashtable;
if ( (sorted= coin->fast[txid.bytes[31]]) != 0 )
{
num = sorted[0].uints[0];
tablesize = sorted[0].uints[1];
hashtable = (int32_t *)&sorted[1 + num + tablesize];
val = txid.uints[0];
for (j=0; j<tablesize; j++)
{
if ( val >= tablesize )
val = 0;
if ( (i= hashtable[val]) == 0 )
return(-1);
else if ( memcmp(&txid,&sorted[i],sizeof(bits256)-sizeof(int32_t)-sizeof(int16_t)) == 0 )
{
*heightp = sorted[i].uints[7];
return(sorted[i].ushorts[13]);
}
}
}
return(-1);
}
/* HASH_ADD_KEYPTR(hh,ramchain->txids,key,keylen,ptr);
int32_t iguana_fastfindadd(struct iguana_info *coin,bits256 txid,int32_t height,uint16_t firstvout)
{
FILE *fp;
if ( (fp= coin->fastfps[txid.bytes[31]]) != 0 )
{
txid.uints[7] = height;
txid.ushorts[13] = firstvout;
if ( fwrite(&txid,1,sizeof(txid),fp) == sizeof(txid) )
return(1);
}
return(0);
}
if ( (tp= iguana_txidfind(coin,heightp,&TX,txid,lasthdrsi)) != 0 )
return(tp->firstvout);
return(-1);
}*/
int64_t iguana_fastfindinitbundle(struct iguana_info *coin,struct iguana_bundle *bp,int32_t iter)
{
int32_t i; struct iguana_txid *T; struct iguana_ramchaindata *rdata; int64_t n = 0;
if ( (rdata= bp->ramchain.H.data) != 0 )
{
T = (void *)(long)((long)rdata + rdata->Toffset);
n = rdata->numtxids;
if ( iter == 1 )
{
for (i=0; i<n; i++)
iguana_fastfindadd(coin,T[i].txid,bp->bundleheight + T[i].bundlei,T[i].firstvout);
fprintf(stderr,"[%d:%u] ",bp->hdrsi,(int32_t)n);
}
}
return(n);
}
static int _bits256_cmp(const void *a,const void *b)
{
return(bits256_cmp(*(bits256 *)a,*(bits256 *)b));
}
int64_t iguana_fastfindinit(struct iguana_info *coin)
{
int32_t i,j,val,iter,errs,num,ind,tablesize,*hashtable; bits256 *sortbuf,hash2; long allocsize; struct iguana_bundle *bp; char fname[512]; int64_t total = 0;
if ( coin->current != 0 && coin->bundlescount == coin->current->hdrsi+1 )
{
sprintf(fname,"DB/%s/fastfind",coin->symbol), OS_ensure_directory(fname);
for (i=0; i<0x100; i++)
{
sprintf(fname,"DB/%s/fastfind/%d",coin->symbol,i), OS_compatible_path(fname);
if ( (coin->fastfps[i]= fopen(fname,"wb")) == 0 )
break;
}
if ( i == 0x100 )
{
for (iter=0; iter<2; iter++)
{
for (i=0; i<coin->bundlescount; i++)
if ( (bp= coin->bundles[i]) != 0 )
total += iguana_fastfindinitbundle(coin,bp,iter);
printf("iguana_fastfindinit iter.%d total.%lld\n",iter,(long long)total);
}
for (i=errs=0; i<0x100; i++)
{
sprintf(fname,"DB/%s/fastfind/%d",coin->symbol,i), OS_ensure_directory(fname);
fclose(coin->fastfps[i]);
if ( (sortbuf= OS_filestr(&allocsize,fname)) != 0 )
{
qsort(sortbuf,allocsize/sizeof(bits256),sizeof(bits256),_bits256_cmp);
if ( (coin->fastfps[i]= fopen(fname,"wb")) != 0 )
{
num = (int32_t)allocsize/sizeof(bits256);
tablesize = (num << 1);
hashtable = calloc(sizeof(*hashtable),tablesize);
for (ind=1; ind<=num; ind++)
{
hash2 = sortbuf[ind-1];
val = hash2.uints[0];
for (j=0; j<tablesize; j++)
{
if ( val >= tablesize )
val = 0;
if ( hashtable[val] == 0 )
{
hashtable[val] = ind;
break;
}
}
}
memset(&hash2,0,sizeof(hash2));
hash2.uints[0] = num;
hash2.uints[1] = tablesize;
if ( fwrite(&hash2,1,sizeof(hash2),coin->fastfps[i]) == sizeof(hash2) && fwrite(sortbuf,sizeof(bits256),num,coin->fastfps[i]) == num && fwrite(hashtable,sizeof(*hashtable),tablesize,coin->fastfps[i]) == tablesize )
{
fclose(coin->fastfps[i]);
coin->fastfps[i] = 0;
if ( (coin->fast[i]= OS_mapfile(fname,&coin->fastsizes[i],0)) != 0 )
errs++;
}
else
{
printf("error saving (%s)\n",fname);
OS_removefile(fname,0);
fclose(coin->fastfps[i]);
coin->fastfps[i] = 0;
}
free(hashtable);
}
free(sortbuf);
}
}
printf("initialized with errs.%d\n",errs);
}
}
return(total);
}
struct iguana_bundle *iguana_fastexternalspent(struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spent_hdrsi,struct iguana_spend *s,int32_t prefetchflag)
struct iguana_bundle *iguana_fastexternalspent(struct iguana_info *coin,bits256 *prevhashp,uint32_t *unspentindp,struct iguana_ramchain *ramchain,int32_t spent_hdrsi,struct iguana_spend *s)
{
int32_t prev_vout,height,hdrsi,firstvout; uint32_t ind; static long counter;
struct iguana_txid *T; bits256 *X; bits256 prev_hash; struct iguana_ramchaindata *rdata;
@ -1175,7 +1292,7 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp,st
if ( s->external != 0 && s->prevout >= 0 )
{
if ( coin->fastfind != 0 )
spentbp = iguana_fastexternalspent(coin,&prevhash,&spent_unspentind,ramchain,bp->hdrsi,s,2);
spentbp = iguana_fastexternalspent(coin,&prevhash,&spent_unspentind,ramchain,bp->hdrsi,s);
else spentbp = iguana_externalspent(coin,&prevhash,&spent_unspentind,ramchain,bp->hdrsi,s,2);
if ( spentbp != 0 && spentbp->ramchain.H.data != 0 )
{
@ -2240,6 +2357,16 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
STRING_ARG(iguana,initfastfind,activecoin)
{
if ( (coin= iguana_coinfind(activecoin)) != 0 )
{
iguana_fastfindinit(coin);
coin->fastfind = coin->tmpfastfind;
return(clonestr("{\"result\":\"fast find initialized\"}"));
} else return(clonestr("{\"error\":\"no coin to initialize\"}"));
}
TWOSTRINGS_AND_INT(iguana,balance,activecoin,address,height)
{
int32_t minconf=1,maxconf=SATOSHIDEN; int64_t total; uint8_t rmd160[20],pubkey33[33],addrtype;

1
includes/iguana_apideclares.h

@ -87,6 +87,7 @@ SS_D_I_SS(bitcoinrpc,sendfrom,fromaccount,toaddress,amount,minconf,comment,comme
S_A_I_S(bitcoinrpc,sendmany,fromaccount,array,minconf,comment);
S_D_SS(bitcoinrpc,sendtoaddress,address,amount,comment,comment2);
STRING_ARG(iguana,initfastfind,activecoin);
STRING_ARG(iguana,peers,activecoin);
STRING_AND_INT(iguana,maxpeers,activecoin,max);
STRING_ARG(iguana,getconnectioncount,activecoin);

Loading…
Cancel
Save