Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
0b58d06820
  1. 11
      crypto777/iguana_utils.c
  2. 14
      iguana/iguana777.h
  3. 9
      iguana/iguana_blocks.c
  4. 3
      iguana/iguana_init.c
  5. 21
      iguana/iguana_ramchain.c
  6. 12
      iguana/iguana_recv.c

11
crypto777/iguana_utils.c

@ -130,10 +130,13 @@ bits256 bits256_from_compact(uint32_t c)
uint32_t nbytes,nbits,i; bits256 x; uint32_t nbytes,nbits,i; bits256 x;
memset(x.bytes,0,sizeof(x)); memset(x.bytes,0,sizeof(x));
nbytes = (c >> 24) & 0xFF; nbytes = (c >> 24) & 0xFF;
nbits = (8 * (nbytes - 3)); if ( nbytes >= 3 )
x.ulongs[0] = c & 0xFFFFFF; {
for (i=0; i<nbits; i++) nbits = (8 * (nbytes - 3));
x = bits256_lshift(x); x.ulongs[0] = c & 0xFFFFFF;
for (i=0; i<nbits; i++)
x = bits256_lshift(x);
}
return(x); return(x);
} }

14
iguana/iguana777.h

@ -350,9 +350,15 @@ struct iguana_blockRO
uint32_t timestamp,nonce,bits,version; uint32_t timestamp,nonce,bits,version;
uint32_t firsttxidind,firstvin,firstvout,firstpkind,firstexternalind,recvlen:24,tbd:8; uint32_t firsttxidind,firstvin,firstvout,firstpkind,firstexternalind,recvlen:24,tbd:8;
uint16_t txn_count,numvouts,numvins,allocsize; uint16_t txn_count,numvouts,numvins,allocsize;
}; } __attribute__((packed));
struct iguana_zcashRO { bits256 bignonce; uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; } __attribute__((packed));
struct iguana_zcashRO { bits256 bignonce; uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; }; struct iguana_zblockRO
{
struct iguana_blockRO RO;
struct iguana_zcashRO zRO;
} __attribute__((packed));
#define iguana_blockfields double PoW; \ #define iguana_blockfields double PoW; \
int32_t height,fpos; uint32_t fpipbits,issued,lag:20,peerid:12; \ int32_t height,fpos; uint32_t fpipbits,issued,lag:20,peerid:12; \
@ -364,13 +370,13 @@ struct iguana_block
{ {
iguana_blockfields; iguana_blockfields;
struct iguana_zcashRO zRO[]; struct iguana_zcashRO zRO[];
}; } __attribute__((packed));
struct iguana_zblock // mu struct iguana_zblock // mu
{ {
iguana_blockfields; iguana_blockfields;
struct iguana_zcashRO zRO; struct iguana_zcashRO zRO;
}; } __attribute__((packed));
#define IGUANA_LHASH_BLOCKS 0 #define IGUANA_LHASH_BLOCKS 0
#define IGUANA_LHASH_TXIDS 1 // #define IGUANA_LHASH_TXIDS 1 //

9
iguana/iguana_blocks.c

@ -501,6 +501,7 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight)
block->valid = block->mainchain = 1; block->valid = block->mainchain = 1;
block->hdrsi = hdrsi, block->bundlei = bundlei; block->hdrsi = hdrsi, block->bundlei = bundlei;
block->height = height; block->height = height;
//printf("set height.%d for bundlei.%d\n",height,bundlei);
block->PoW = PoW_from_compact(block->RO.bits,coin->chain->unitval) + prevPoW; block->PoW = PoW_from_compact(block->RO.bits,coin->chain->unitval) + prevPoW;
block->hh.prev = prev; block->hh.prev = prev;
if ( prev != 0 ) if ( prev != 0 )
@ -592,9 +593,6 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
if ( coin->isRT != 0 || block->height == hwmchain->height ) if ( coin->isRT != 0 || block->height == hwmchain->height )
{ {
coin->blocks.maxblocks = (block->height + 1); coin->blocks.maxblocks = (block->height + 1);
if ( coin->chain->zcash != 0 )
coin->blocks.hwmchain = *(struct iguana_zblock *)block;
else *(struct iguana_block *)&coin->blocks.hwmchain = *block;
//printf("[%s] <- ht.%d %f\n",bits256_str(str,block->RO.hash2),coin->blocks.hwmchain.height,coin->blocks.hwmchain.PoW); //printf("[%s] <- ht.%d %f\n",bits256_str(str,block->RO.hash2),coin->blocks.hwmchain.height,coin->blocks.hwmchain.PoW);
char str[65],str2[65]; bits256 zero; char str[65],str2[65]; bits256 zero;
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
@ -667,6 +665,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
printf(" call process_iguanablock2.%p ht.%d nbits.%08x\n",block->serdata,block->height,*(uint32_t *)&block->serdata[72]); printf(" call process_iguanablock2.%p ht.%d nbits.%08x\n",block->serdata,block->height,*(uint32_t *)&block->serdata[72]);
process_iguanablock(block->serdata,CHAINPARMS); process_iguanablock(block->serdata,CHAINPARMS);
}*/ }*/
iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block);
return(block); return(block);
} }
} }
@ -674,7 +673,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
return(0); return(0);
} }
void iguana_blocksetheights(struct iguana_info *coin,struct iguana_block *block) /*void iguana_blocksetheights(struct iguana_info *coin,struct iguana_block *block)
{ {
int32_t height; int32_t height;
if ( (height= block->height) < 0 ) if ( (height= block->height) < 0 )
@ -685,7 +684,7 @@ void iguana_blocksetheights(struct iguana_info *coin,struct iguana_block *block)
iguana_bundlehash2add(coin,0,coin->bundles[height/coin->chain->bundlesize],height % coin->chain->bundlesize,block->RO.hash2); iguana_bundlehash2add(coin,0,coin->bundles[height/coin->chain->bundlesize],height % coin->chain->bundlesize,block->RO.hash2);
block = block->hh.next, height++; block = block->hh.next, height++;
} }
} }*/
int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock) int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock)
{ {

3
iguana/iguana_init.c

@ -129,8 +129,7 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
iguana_blockzcopy(coin->chain->zcash,block,ptr); iguana_blockzcopy(coin->chain->zcash,block,ptr);
printf("size.%d genesis block PoW %f ptr %f\n",block->RO.allocsize,block->PoW,ptr->PoW); printf("size.%d genesis block PoW %f ptr %f\n",block->RO.allocsize,block->PoW,ptr->PoW);
coin->blocks.recvblocks = coin->blocks.issuedblocks = 1; coin->blocks.recvblocks = coin->blocks.issuedblocks = 1;
} } else printf("genesis block doesnt validate for %s ht.%d\n",coin->symbol,height);
else printf("genesis block doesnt validate for %s ht.%d\n",coin->symbol,height);
} else printf("couldnt hashset genesis\n"); } else printf("couldnt hashset genesis\n");
return(hash2); return(hash2);
} }

21
iguana/iguana_ramchain.c

@ -1368,7 +1368,7 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
struct iguana_ramchain *_iguana_ramchain_map(struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded,uint8_t zcash) struct iguana_ramchain *_iguana_ramchain_map(struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded,uint8_t zcash)
{ {
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize; void *ptr; char str[65],str2[65],dirstr[64]; struct iguana_block *block; struct iguana_blockRO *bRO; struct iguana_ramchaindata *rdata; RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize; void *ptr; char str[65],str2[65],dirstr[64]; struct iguana_block *block; struct iguana_zblockRO zRO; struct iguana_ramchaindata *rdata;
/*if ( ramchain->expanded != 0 && (ramchain->sigsfileptr == 0 || ramchain->sigsfilesize == 0) ) /*if ( ramchain->expanded != 0 && (ramchain->sigsfileptr == 0 || ramchain->sigsfilesize == 0) )
{ {
sprintf(sigsfname,"sigs/%s/%s",coin->symbol,bits256_str(str,hash2)); sprintf(sigsfname,"sigs/%s/%s",coin->symbol,bits256_str(str,hash2));
@ -1474,17 +1474,24 @@ struct iguana_ramchain *_iguana_ramchain_map(struct iguana_info *coin,char *fnam
{ {
for (i=0; i<bp->n; i++) for (i=0; i<bp->n; i++)
{ {
if ( bp->blocks[i] == 0 && (bp->blocks[i]= iguana_blockhashset("mapchain",coin,-1,bRO->hash2,1)) == 0 ) iguana_blockzcopyRO(zcash,(void *)&zRO,0,B,i);
if ( bp->blocks[i] == 0 && (bp->blocks[i]= iguana_blockhashset("mapchain",coin,-1,zRO.RO.hash2,1)) == 0 )
{ {
printf("Error getting blockptr\n"); printf("Error getting blockptr\n");
return(0); return(0);
} }
if ( (bRO= iguana_blockzcopyRO(zcash,&bp->blocks[i]->RO,0,B,i)) != 0 ) else
{
bp->hashes[i] = zRO.RO.hash2;
//bp->blocks[i]->RO = zRO.RO;
iguana_blockzcopyRO(zcash,&bp->blocks[i]->RO,0,(void *)&zRO,0);
}
/* if ( (bRO= iguana_blockzcopyRO(zcash,&bp->blocks[i]->RO,0,B,i)) != 0 )
{ {
//memcpy(&bp->blocks[i]->RO,bRO,bROsize);//coin->blocks.RO[bp->bundleheight + i]; //memcpy(&bp->blocks[i]->RO,bRO,bROsize);//coin->blocks.RO[bp->bundleheight + i];
//coin->blocks.RO[bp->bundleheight+i] = B[i]; //coin->blocks.RO[bp->bundleheight+i] = B[i];
bp->hashes[i] = bRO->hash2; bp->hashes[i] = bRO->hash2;
} }*/
} }
} }
//printf("iguana_ramchain_map.(%s) size %ld vs %ld vs filesize.%ld numblocks.%d expanded.%d fpos.%d sum %ld\n",fname,(long)iguana_ramchain_size(RAMCHAIN_ARG,ramchain->numblocks,rdata->scriptspace),(long)rdata->allocsize,(long)filesize,ramchain->numblocks,expanded,(int32_t)fpos,(long)(fpos+rdata->allocsize)); //printf("iguana_ramchain_map.(%s) size %ld vs %ld vs filesize.%ld numblocks.%d expanded.%d fpos.%d sum %ld\n",fname,(long)iguana_ramchain_size(RAMCHAIN_ARG,ramchain->numblocks,rdata->scriptspace),(long)rdata->allocsize,(long)filesize,ramchain->numblocks,expanded,(int32_t)fpos,(long)(fpos+rdata->allocsize));
@ -2284,6 +2291,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
block->queued = 1; block->queued = 1;
block->txvalid = 1; block->txvalid = 1;
block->height = bp->bundleheight + i; block->height = bp->bundleheight + i;
//printf("bundleload bundlei.%d < height %d %d\n",i,block->height,i);
block->hdrsi = bp->hdrsi; block->hdrsi = bp->hdrsi;
block->bundlei = i; block->bundlei = i;
block->fpipbits = (uint32_t)calc_ipbits("127.0.0.1"); block->fpipbits = (uint32_t)calc_ipbits("127.0.0.1");
@ -2292,7 +2300,10 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2); iguana_hash2set(coin,"bundleload",bp,i,block->RO.hash2);
bp->blocks[i] = block; bp->blocks[i] = block;
if ( (prev= block->hh.prev) != 0 ) if ( (prev= block->hh.prev) != 0 )
{
prev2 = prev->hh.prev; prev2 = prev->hh.prev;
prev->hh.next = block;
}
if ( prev2 != 0 && prev != 0 && strcmp(coin->symbol,"BTCD") == 0 && bp->bundleheight > 20000 && prev != 0 && iguana_targetbits(coin,block,prev,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan) != block->RO.bits ) if ( prev2 != 0 && prev != 0 && strcmp(coin->symbol,"BTCD") == 0 && bp->bundleheight > 20000 && prev != 0 && iguana_targetbits(coin,block,prev,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan) != block->RO.bits )
{ {
printf("nbits target error %x != %x ht.%d\n",iguana_targetbits(coin,block,prev,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan),block->RO.bits,block->height); printf("nbits target error %x != %x ht.%d\n",iguana_targetbits(coin,block,prev,prev2,1,coin->chain->targetspacing,coin->chain->targettimespan),block->RO.bits,block->height);
@ -2300,7 +2311,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana
if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 ) if ( bp->bundleheight+i == coin->blocks.hwmchain.height+1 )
{ {
//printf("try extend.%d\n",bp->bundleheight+i); //printf("try extend.%d\n",bp->bundleheight+i);
//_iguana_chainlink(coin,block); wrong context //_iguana_chainlink(coin,block); //wrong context
} }
prev2 = prev, prev = block; prev2 = prev, prev = block;
} }

12
iguana/iguana_recv.c

@ -214,7 +214,7 @@ struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundl
int32_t iguana_speculativefind(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_block *block,uint8_t *data,int32_t recvlen) int32_t iguana_speculativefind(struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_block *block,uint8_t *data,int32_t recvlen)
{ {
int32_t i,j,numcached,cachelen=0; uint8_t *tmp; char str[65]; int32_t i,j,numcached,cachelen=0; uint8_t *tmp; char str[65];
if ( coin->enableCACHE == 0 ) if ( coin->enableCACHE == 0 || recvlen < 0 )
return(-1); return(-1);
if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE ) if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE )
{ {
@ -585,6 +585,7 @@ uint32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bit
if ( i > 0 ) if ( i > 0 )
block->RO.prev_block = blockhashes[i-1]; block->RO.prev_block = blockhashes[i-1];
block->height = bp->bundleheight + i; block->height = bp->bundleheight + i;
//printf("allhashcmp ht.%d for %d\n",block->height,i);
block->mainchain = 1; block->mainchain = 1;
if ( prev != 0 ) if ( prev != 0 )
{ {
@ -1151,7 +1152,7 @@ int32_t iguana_blockreq(struct iguana_info *coin,int32_t height,int32_t priority
int32_t iguana_reqblocks(struct iguana_info *coin) int32_t iguana_reqblocks(struct iguana_info *coin)
{ {
int32_t hdrsi,hdrsi0,bundlei0,lflag,bundlei,iters=0,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp; int32_t hdrsi,lflag,bundlei,iters=0,flag = 0; bits256 hash2; struct iguana_block *next,*block; struct iguana_bundle *bp;
if ( time(NULL) < coin->lastreqtime+2 ) if ( time(NULL) < coin->lastreqtime+2 )
return(0); return(0);
coin->lastreqtime = (uint32_t)time(NULL); coin->lastreqtime = (uint32_t)time(NULL);
@ -1159,6 +1160,12 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize; hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize;
if ( (bp= coin->bundles[hdrsi]) != 0 ) if ( (bp= coin->bundles[hdrsi]) != 0 )
{ {
for (bundlei=0; bundlei<coin->chain->bundlesize; bundlei++)
if ( (block= bp->blocks[bundlei]) != 0 && bits256_cmp(block->RO.hash2,bp->hashes[bundlei]) != 0 && bits256_nonz(bp->hashes[bundlei]) != 0 )
{
char str[65]; printf("%s [%d] bundlei.%d ht.%d vs expected %d\n",bits256_str(str,bp->hashes[bundlei]),hdrsi,bundlei,block->height,bp->bundleheight+bundlei);
bp->blocks[bundlei] = iguana_blockfind("fixit",coin,bp->hashes[bundlei]);
}
bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize;
if ( (next= bp->blocks[bundlei]) != 0 || (next= iguana_blockfind("reqblocks",coin,bp->hashes[bundlei])) != 0 ) if ( (next= bp->blocks[bundlei]) != 0 || (next= iguana_blockfind("reqblocks",coin,bp->hashes[bundlei])) != 0 )
{ {
@ -1180,6 +1187,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin)
bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize;
if ( 1 ) if ( 1 )
{ {
int32_t hdrsi0,bundlei0;
if ( (next= iguana_bundleblock(coin,&hash2,coin->bundles[hdrsi],bundlei)) == 0 ) if ( (next= iguana_bundleblock(coin,&hash2,coin->bundles[hdrsi],bundlei)) == 0 )
{ {
hdrsi0 = (coin->blocks.hwmchain.height) / coin->chain->bundlesize; hdrsi0 = (coin->blocks.hwmchain.height) / coin->chain->bundlesize;

Loading…
Cancel
Save