Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
890a8eb0b5
  1. 2
      iguana/iguana777.h
  2. 4
      iguana/iguana_bundles.c
  3. 4
      iguana/iguana_recv.c
  4. 153
      iguana/iguana_unspents.c

2
iguana/iguana777.h

@ -18,7 +18,7 @@
#include "../crypto777/OS_portable.h"
#include "SuperNET.h"
#define SPARSECOUNT(x) ((3*(x)) >> 1)
#define SPARSECOUNT(x) ((x) << 1)
typedef int32_t (*blockhashfunc)(uint8_t *blockhashp,uint8_t *serialized,int32_t len);

4
iguana/iguana_bundles.c

@ -638,7 +638,7 @@ int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32
{
char str[64];
if ( bp->hdrsi == coin->bundlescount-1 || bp == coin->current )
printf("hdr ITERATE bundle.%d vs %d: h.%d n.%d r.%d s.%d finished.%d speculative.%p[%d]\n",bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->emitfinish,bp->speculative,bp->numspec);
printf("hdr ITERATE.%d bundle.%d vs %d: h.%d n.%d r.%d s.%d finished.%d speculative.%p[%d]\n",bp->hdrsi,bp->bundleheight,coin->longestchain-coin->chain->bundlesize,bp->numhashes,bp->n,bp->numrecv,bp->numsaved,bp->emitfinish,bp->speculative,bp->numspec);
queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1);
}
if ( bp->speculative != 0 )
@ -651,7 +651,7 @@ int32_t iguana_bundlehdr(struct iguana_info *coin,struct iguana_bundle *bp,int32
if ( now > bp->issued[i]+60 )
{
bp->issued[i] = now;
//printf("speculative.[%d:%d]\n",bp->hdrsi,i);
printf("speculative.[%d:%d]\n",bp->hdrsi,i);
iguana_blockQ("speculative",coin,0,-1,bp->speculative[i],0);
}
//break;

4
iguana/iguana_recv.c

@ -636,14 +636,14 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct
int32_t bundlei,i,len; struct iguana_bundle *bp; bits256 allhash,zero; uint8_t serialized[512]; struct iguana_peer *addr; struct iguana_block *block;
memset(zero.bytes,0,sizeof(zero));
bp = 0, bundlei = -2;
if ( num < 2 )
return(req);
iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]);
//iguana_blockQ(coin,0,-1,blockhashes[1],0);
//iguana_blockQ(coin,0,-4,blockhashes[1],1);
char str[65];
//if ( 0 && num > 2 )
printf("blockhashes[%d] %d of %d %s bp.%d[%d]\n",num,bp==0?-1:bp->hdrsi,coin->bundlescount,bits256_str(str,blockhashes[1]),bp==0?-1:bp->bundleheight,bundlei);
if ( num < 2 )
return(req);
if ( bp != 0 )
{
bp->dirty++;

153
iguana/iguana_unspents.c

@ -159,7 +159,7 @@ int32_t iguana_volatileupdate(struct iguana_info *coin,int32_t incremental,struc
uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tablesize,uint8_t *key,int32_t keylen,uint32_t setind,void *refdata,int32_t refsize,struct iguana_ramchain *ramchain)
{
static uint8_t masks[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
int32_t i,j,x,n,modval; int64_t bitoffset; uint8_t *ptr;
int32_t i,j,x,n,modval,offset; int64_t bitoffset; uint8_t *ptr; uint32_t *table;
if ( tablesize == 0 )
{
printf("iguana_sparseadd tablesize zero illegal\n");
@ -189,82 +189,117 @@ uint32_t iguana_sparseadd(uint8_t *bits,uint32_t ind,int32_t width,uint32_t tabl
ramchain->sparsesearches++;
if ( 0 && setind == 0 )
printf("tablesize.%d width.%d bitoffset.%d\n",tablesize,width,(int32_t)bitoffset);
if ( (ramchain->sparsesearches % 100000) == 0 )
printf("%7d.[%-2d %8d] %5.3f sparse searches.%-8ld iters.%-8ld hits.%-8ld %5.2f%% max.%ld\n",ramchain->height,width,tablesize,(double)ramchain->sparseiters/(1+ramchain->sparsesearches),ramchain->sparsesearches,ramchain->sparseiters,ramchain->sparsehits,100.*(double)ramchain->sparsehits/(1+ramchain->sparsesearches),ramchain->sparsemax+1);
for (i=0; i<tablesize; i++,ind++,bitoffset+=width)
if ( (ramchain->sparsesearches % 10000000) == 0 )
printf("%7d.[%-2d %8d] %5.3f sparse searches.%-10ld iters.%-10ld hits.%-10ld %5.2f%% max.%ld\n",ramchain->height,width,tablesize,(double)ramchain->sparseiters/(1+ramchain->sparsesearches),ramchain->sparsesearches,ramchain->sparseiters,ramchain->sparsehits,100.*(double)ramchain->sparsehits/(1+ramchain->sparsesearches),ramchain->sparsemax+1);
if ( width == 32 )
{
ramchain->sparseiters++;
if ( ind >= tablesize )
table = (uint32_t *)ptr;
offset = (int32_t)(bitoffset >> 5);
for (i=0; i<tablesize; i++,ind++,offset++)
{
ind = 0;
bitoffset = 0;
}
x = 0;
if ( width == 32 )
memcpy(&x,&bits[bitoffset >> 3],4);
else if ( width == 16 )
memcpy(&x,&bits[bitoffset >> 3],2);
else if ( width != 8 )
{
ptr = &bits[bitoffset >> 3];
modval = (bitoffset & 7);
if ( 0 && setind == 0 )
printf("tablesize.%d width.%d bitoffset.%d modval.%d i.%d\n",tablesize,width,(int32_t)bitoffset,modval,i);
for (x=j=0; j<width; j++,modval++)
if ( ind >= tablesize )
{
if ( modval >= 8 )
ptr++, modval = 0;
x <<= 1;
x |= (*ptr & masks[modval]) >> modval;
ind = 0;
offset = 0;
}
if ( (x= table[offset]) == 0 )
{
if ( ++i > ramchain->sparsemax )
ramchain->sparsemax = i;
ramchain->sparseiters += i;
table[offset] = setind;
return(setind);
}
else if ( memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 )
{
if ( setind == 0 )
ramchain->sparsehits++;
else if ( setind != x )
printf("sparseadd index collision setind.%d != x.%d refsize.%d keylen.%d\n",setind,x,refsize,keylen);
if ( ++i > ramchain->sparsemax )
ramchain->sparsemax = i;
ramchain->sparseiters += i;
return(x);
}
}
else x = bits[bitoffset >> 3];
if ( 0 && setind == 0 )
printf("x.%d\n",x);
if ( x == 0 )
}
else
{
for (i=0; i<tablesize; i++,ind++,bitoffset+=width)
{
if ( (x= setind) == 0 )
return(0);
ramchain->sparseiters++;
if ( ind >= tablesize )
{
ind = 0;
bitoffset = 0;
}
x = 0;
if ( width == 32 )
memcpy(&bits[bitoffset >> 3],&setind,4);
memcpy(&x,&bits[bitoffset >> 3],4);
else if ( width == 16 )
memcpy(&bits[bitoffset >> 3],&setind,2);
memcpy(&x,&bits[bitoffset >> 3],2);
else if ( width != 8 )
{
ptr = &bits[(bitoffset+width-1) >> 3];
modval = ((bitoffset+width-1) & 7);
for (j=0; j<width; j++,x>>=1,modval--)
ptr = &bits[bitoffset >> 3];
modval = (bitoffset & 7);
if ( 0 && setind == 0 )
printf("tablesize.%d width.%d bitoffset.%d modval.%d i.%d\n",tablesize,width,(int32_t)bitoffset,modval,i);
for (x=j=0; j<width; j++,modval++)
{
if ( modval < 0 )
ptr--, modval = 7;
if ( (x & 1) != 0 )
*ptr |= masks[modval];
if ( modval >= 8 )
ptr++, modval = 0;
x <<= 1;
x |= (*ptr & masks[modval]) >> modval;
}
}
else bits[bitoffset >> 3] = setind;
if ( 0 )
else x = bits[bitoffset >> 3];
if ( 0 && setind == 0 )
printf("x.%d\n",x);
if ( x == 0 )
{
for (x=j=0; j<width; j++)
if ( (x= setind) == 0 )
return(0);
if ( width == 32 )
memcpy(&bits[bitoffset >> 3],&setind,4);
else if ( width == 16 )
memcpy(&bits[bitoffset >> 3],&setind,2);
else if ( width != 8 )
{
x <<= 1;
x |= GETBIT(bits,bitoffset+width-1-j) != 0;
ptr = &bits[(bitoffset+width-1) >> 3];
modval = ((bitoffset+width-1) & 7);
for (j=0; j<width; j++,x>>=1,modval--)
{
if ( modval < 0 )
ptr--, modval = 7;
if ( (x & 1) != 0 )
*ptr |= masks[modval];
}
}
//if ( x != setind )
else bits[bitoffset >> 3] = setind;
if ( 0 )
{
for (x=j=0; j<width; j++)
{
x <<= 1;
x |= GETBIT(bits,bitoffset+width-1-j) != 0;
}
//if ( x != setind )
printf("x.%u vs setind.%d ind.%d bitoffset.%d, width.%d\n",x,setind,ind,(int32_t)bitoffset,width);
}
if ( i > ramchain->sparsemax )
ramchain->sparsemax = i;
return(setind);
}
else if ( memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 )
{
if ( setind == 0 )
ramchain->sparsehits++;
else if ( setind != x )
printf("sparseadd index collision setind.%d != x.%d refsize.%d keylen.%d\n",setind,x,refsize,keylen);
if ( i > ramchain->sparsemax )
ramchain->sparsemax = i;
return(x);
}
if ( i > ramchain->sparsemax )
ramchain->sparsemax = i;
return(setind);
}
else if ( memcmp((void *)(long)((long)refdata + x*refsize),key,keylen) == 0 )
{
if ( setind == 0 )
ramchain->sparsehits++;
else if ( setind != x )
printf("sparseadd index collision setind.%d != x.%d refsize.%d keylen.%d\n",setind,x,refsize,keylen);
if ( i > ramchain->sparsemax )
ramchain->sparsemax = i;
return(x);
}
}
return(0);

Loading…
Cancel
Save