From 0b58d06820f6de2ba058887c7a98f24ee1b727f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Jun 2016 23:49:35 -0300 Subject: [PATCH] test --- crypto777/iguana_utils.c | 11 +++++++---- iguana/iguana777.h | 14 ++++++++++---- iguana/iguana_blocks.c | 9 ++++----- iguana/iguana_init.c | 3 +-- iguana/iguana_ramchain.c | 21 ++++++++++++++++----- iguana/iguana_recv.c | 12 ++++++++++-- 6 files changed, 48 insertions(+), 22 deletions(-) diff --git a/crypto777/iguana_utils.c b/crypto777/iguana_utils.c index 222417d1c..b449fd66d 100755 --- a/crypto777/iguana_utils.c +++ b/crypto777/iguana_utils.c @@ -130,10 +130,13 @@ bits256 bits256_from_compact(uint32_t c) uint32_t nbytes,nbits,i; bits256 x; memset(x.bytes,0,sizeof(x)); nbytes = (c >> 24) & 0xFF; - nbits = (8 * (nbytes - 3)); - x.ulongs[0] = c & 0xFFFFFF; - for (i=0; i= 3 ) + { + nbits = (8 * (nbytes - 3)); + x.ulongs[0] = c & 0xFFFFFF; + for (i=0; ivalid = block->mainchain = 1; block->hdrsi = hdrsi, block->bundlei = bundlei; 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->hh.prev = prev; 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 ) { 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); char str[65],str2[65]; bits256 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]); process_iguanablock(block->serdata,CHAINPARMS); }*/ + iguana_blockzcopy(coin->chain->zcash,(void *)&coin->blocks.hwmchain,block); return(block); } } @@ -674,7 +673,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl 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; 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); block = block->hh.next, height++; } -} +}*/ int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newblock) { diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 41fbbf508..6b6881dbf 100755 --- a/iguana/iguana_init.c +++ b/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); printf("size.%d genesis block PoW %f ptr %f\n",block->RO.allocsize,block->PoW,ptr->PoW); 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"); return(hash2); } diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 8d4d4622b..10afcec34 100755 --- a/iguana/iguana_ramchain.c +++ b/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) { - 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) ) { 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; in; 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"); 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]; //coin->blocks.RO[bp->bundleheight+i] = B[i]; 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)); @@ -2284,6 +2291,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana block->queued = 1; block->txvalid = 1; block->height = bp->bundleheight + i; + //printf("bundleload bundlei.%d < height %d %d\n",i,block->height,i); block->hdrsi = bp->hdrsi; block->bundlei = i; 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); bp->blocks[i] = block; if ( (prev= block->hh.prev) != 0 ) + { 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 ) { 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 ) { //printf("try extend.%d\n",bp->bundleheight+i); - //_iguana_chainlink(coin,block); wrong context + //_iguana_chainlink(coin,block); //wrong context } prev2 = prev, prev = block; } diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index ad1569144..545b434a4 100755 --- a/iguana/iguana_recv.c +++ b/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 i,j,numcached,cachelen=0; uint8_t *tmp; char str[65]; - if ( coin->enableCACHE == 0 ) + if ( coin->enableCACHE == 0 || recvlen < 0 ) return(-1); 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 ) block->RO.prev_block = blockhashes[i-1]; block->height = bp->bundleheight + i; + //printf("allhashcmp ht.%d for %d\n",block->height,i); block->mainchain = 1; 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 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 ) return(0); 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; if ( (bp= coin->bundles[hdrsi]) != 0 ) { + for (bundlei=0; bundleichain->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; 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; if ( 1 ) { + int32_t hdrsi0,bundlei0; if ( (next= iguana_bundleblock(coin,&hash2,coin->bundles[hdrsi],bundlei)) == 0 ) { hdrsi0 = (coin->blocks.hwmchain.height) / coin->chain->bundlesize;