From 1cf7de9dd02f11b416ac4dcaedd25d882501f704 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Sep 2016 04:45:38 -0300 Subject: [PATCH 1/6] test --- iguana/iguana_blocks.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index 93a993063..7ff74e3e8 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -203,39 +203,35 @@ void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag) { struct iguana_block *block,*prev; int32_t size; - /*if ( height > 0 && height > coin->blocks.maxbits ) - { - printf("%s: illegal height.%d when max.%d, or nonz depth.%d\n",debugstr,height,coin->blocks.maxbits,coin->blockdepth); - //getchar(); - return(0); - }*/ - while ( coin->blockdepth > 0 ) + /*while ( coin->blockdepth > 0 ) { usleep(100000); if ( coin->blockdepth > 0 ) printf("A %s >>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth); //fprintf(stderr,">>>>>>>>>> OK only if rare %s blockhashset.%d depth.%d\n",debugstr,height,depth); //printf("%d\n",1/(1 - depth/depth)); - } + }*/ + portable_mutex_lock(&coin->blocks_mutex); coin->blockdepth++; HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); if ( block != 0 ) { if ( coin->blockdepth > 0 ) coin->blockdepth--; - while ( coin->blockdepth > 0 ) + /*while ( coin->blockdepth > 0 ) { usleep(100000); if ( coin->blockdepth > 0 ) printf("B %s >>>>>>>>>> OK only if rare %s match blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth); //fprintf(stderr,">>>>>>>>>> OK only if rare%s match blockhashset.%d depth.%d\n",debugstr,height,depth); //printf("%d\n",1/(1 - depth/depth)); - } + }*/ + portable_mutex_unlock(&coin->blocks_mutex); return(block); } if ( createflag > 0 ) { - portable_mutex_lock(&coin->blocks_mutex); + //portable_mutex_lock(&coin->blocks_mutex); size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); block = calloc(1,size); block->RO.hash2 = hash2; @@ -261,18 +257,19 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin if ( tmp != block ) printf("%s height.%d search error %p != %p\n",str,height,block,tmp); } - portable_mutex_unlock(&coin->blocks_mutex); + //portable_mutex_unlock(&coin->blocks_mutex); } if ( coin->blockdepth > 0 ) coin->blockdepth--; - while ( coin->blockdepth > 0 ) + portable_mutex_unlock(&coin->blocks_mutex); + /* while ( coin->blockdepth > 0 ) { usleep(100000); if ( coin->blockdepth > 0 ) printf("C %s >>>>>>>>>> OK only if rare %s create blockhashset.%d depth.%d\n",coin->symbol,debugstr,height,coin->blockdepth); //fprintf(stderr,">>>>>>>>>> OK only if rare%s create blockhashset.%d depth.%d\n",debugstr,height,depth); //printf("%d\n",1/(1 - depth/depth)); - } + }*/ return(block); } From 59beb66cd4c2120f25ce6aa8ff29e281d9ae2834 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Sep 2016 05:07:26 -0300 Subject: [PATCH 2/6] test --- iguana/iguana_blocks.c | 147 +++++++++++++++++++++++++++----------- iguana/iguana_init.c | 32 +++++++-- includes/iguana_structs.h | 1 + 3 files changed, 134 insertions(+), 46 deletions(-) diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index 7ff74e3e8..f32f2f757 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -174,35 +174,62 @@ struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_blo void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct iguana_block *block) { - char str[65],str2[65]; struct iguana_block *next; - if ( memcmp(block->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) + char str[65],str2[65]; struct iguana_block *next; struct iguana_zblock *znext,*zprev = (void *)prev,*zblock = (void *)block; + if ( coin->chain->zcash != 0 ) { - printf("illegal blocklink mismatched hashes\n"); - iguana_exit(0,0); - return; + if ( memcmp(block->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) + { + printf("illegal blocklink mismatched hashes\n"); + iguana_exit(0,0); + return; + } + block->hh.prev = prev; + if ( (next= prev->hh.next) != 0 ) + { + if ( next != block ) + { + if ( memcmp(next->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) + { + printf("illegal blocklink next mismatched hashes\n"); + return; + } + if ( memcmp(next->RO.hash2.bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 ) + printf("blocklink collision: %s vs %s\n",bits256_str(str,block->RO.hash2),bits256_str(str2,next->RO.hash2)); + else printf("blocklink corruption: identical hashes with diff ptrs %s %p %p\n",bits256_str(str,block->RO.hash2),block,next); + } + prev->hh.next = block; // could make a linked list of all at same height for multibranch + } else prev->hh.next = block; } - block->hh.prev = prev; - if ( (next= prev->hh.next) != 0 ) + else { - if ( next != block ) + if ( memcmp(zblock->RO.prev_block.bytes,zprev->RO.hash2.bytes,sizeof(bits256)) != 0 ) + { + printf("illegal blocklink mismatched zhashes\n"); + iguana_exit(0,0); + return; + } + zblock->hh.prev = zprev; + if ( (znext= zprev->hh.next) != 0 ) { - if ( memcmp(next->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) + if ( znext != zblock ) { - printf("illegal blocklink next mismatched hashes\n"); - return; + if ( memcmp(znext->RO.prev_block.bytes,zprev->RO.hash2.bytes,sizeof(bits256)) != 0 ) + { + printf("illegal blocklink next mismatched hashes\n"); + return; + } + if ( memcmp(znext->RO.hash2.bytes,zblock->RO.hash2.bytes,sizeof(bits256)) != 0 ) + printf("blocklink collision: %s vs %s\n",bits256_str(str,zblock->RO.hash2),bits256_str(str2,znext->RO.hash2)); + else printf("blocklink corruption: identical hashes with diff ptrs %s %p %p\n",bits256_str(str,zblock->RO.hash2),zblock,znext); } - if ( memcmp(next->RO.hash2.bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 ) - printf("blocklink collision: %s vs %s\n",bits256_str(str,block->RO.hash2),bits256_str(str2,next->RO.hash2)); - else printf("blocklink corruption: identical hashes with diff ptrs %s %p %p\n",bits256_str(str,block->RO.hash2),block,next); - } - prev->hh.next = block; // could make a linked list of all at same height for multibranch - } else prev->hh.next = block; - printf("link.(%s) -> (%s)\n",bits256_str(str,prev->RO.hash2),bits256_str(str,block->RO.hash2)); + zprev->hh.next = zblock; // could make a linked list of all at same height for multibranch + } else zprev->hh.next = zblock; + } } struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag) { - struct iguana_block *block,*prev; int32_t size; + struct iguana_block *block=0,*prev; int32_t size; struct iguana_zblock *zblock=0,*zprev; /*while ( coin->blockdepth > 0 ) { usleep(100000); @@ -213,8 +240,10 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin }*/ portable_mutex_lock(&coin->blocks_mutex); coin->blockdepth++; - HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); - if ( block != 0 ) + if ( coin->chain->zcash != 0 ) + HASH_FIND(hh,coin->blocks.zhash,&hash2,sizeof(hash2),zblock); + else HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); + if ( block != 0 || zblock != 0 ) { if ( coin->blockdepth > 0 ) coin->blockdepth--; @@ -227,24 +256,44 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin //printf("%d\n",1/(1 - depth/depth)); }*/ portable_mutex_unlock(&coin->blocks_mutex); - return(block); + return((coin->chain->zcash != 0) ? (struct iguana_block *)zblock : block); } if ( createflag > 0 ) { //portable_mutex_lock(&coin->blocks_mutex); - size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); - block = calloc(1,size); - block->RO.hash2 = hash2; - block->RO.allocsize = size; - iguana_blocksizecheck("blockhashset",coin->chain->zcash,block); - block->hh.itemind = height, block->height = -1; - HASH_ADD(hh,coin->blocks.hash,RO.hash2,sizeof(hash2),block); - block->hh.next = block->hh.prev = 0; - if ( bits256_nonz(block->RO.prev_block) > 0 ) + if ( coin->chain->zcash == 0 ) { - HASH_FIND(hh,coin->blocks.hash,&block->RO.prev_block,sizeof(block->RO.prev_block),prev); - if ( prev != 0 ) - _iguana_blocklink(coin,prev,block); + size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); + block = calloc(1,size); + block->RO.hash2 = hash2; + block->RO.allocsize = size; + iguana_blocksizecheck("blockhashset",coin->chain->zcash,block); + block->hh.itemind = height, block->height = -1; + HASH_ADD(hh,coin->blocks.hash,RO.hash2,sizeof(hash2),block); + block->hh.next = block->hh.prev = 0; + if ( bits256_nonz(block->RO.prev_block) > 0 ) + { + HASH_FIND(hh,coin->blocks.hash,&block->RO.prev_block,sizeof(block->RO.prev_block),prev); + if ( prev != 0 ) + _iguana_blocklink(coin,prev,block); + } + } + else + { + size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); + zblock = calloc(1,size); + zblock->RO.hash2 = hash2; + zblock->RO.allocsize = size; + iguana_blocksizecheck("blockhashset",coin->chain->zcash,(void *)zblock); + zblock->hh.itemind = height, zblock->height = -1; + HASH_ADD(hh,coin->blocks.zhash,RO.hash2,sizeof(hash2),zblock); + zblock->hh.next = zblock->hh.prev = 0; + if ( bits256_nonz(zblock->RO.prev_block) > 0 ) + { + HASH_FIND(hh,coin->blocks.hash,&zblock->RO.prev_block,sizeof(zblock->RO.prev_block),zprev); + if ( zprev != 0 ) + _iguana_blocklink(coin,(void *)zprev,(void *)zblock); + } } //char str[65]; if ( coin->virtualchain != 0 ) @@ -270,7 +319,7 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin //fprintf(stderr,">>>>>>>>>> OK only if rare%s create blockhashset.%d depth.%d\n",debugstr,height,depth); //printf("%d\n",1/(1 - depth/depth)); }*/ - return(block); + return((coin->chain->zcash != 0) ? (struct iguana_block *)zblock : block); } bits256 *iguana_blockhashptr(struct iguana_info *coin,int32_t height) @@ -308,15 +357,31 @@ struct iguana_block *iguana_blockptr(char *debugstr,struct iguana_info *coin,int int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block) { + struct iguana_zblock *zblock = (void *)block; int32_t bsize = zcash != 0 ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block); - if ( block->RO.allocsize != bsize ) + if ( zcash == 0 ) { - if ( block->RO.allocsize == 0 || block->RO.allocsize < bsize ) + if ( block->RO.allocsize != bsize ) { - //printf("%s block validate warning: mismatched size %d vs %d\n",debugstr,block->RO.allocsize,bsize); - block->RO.allocsize = bsize; - } else return(-1); - return(bsize); + if ( block->RO.allocsize == 0 || block->RO.allocsize < bsize ) + { + //printf("%s block validate warning: mismatched size %d vs %d\n",debugstr,block->RO.allocsize,bsize); + block->RO.allocsize = bsize; + } else return(-1); + return(bsize); + } + } + else + { + if ( zblock->RO.allocsize != bsize ) + { + if ( zblock->RO.allocsize == 0 || zblock->RO.allocsize < bsize ) + { + //printf("%s block validate warning: mismatched size %d vs %d\n",debugstr,block->RO.allocsize,bsize); + zblock->RO.allocsize = bsize; + } else return(-1); + return(bsize); + } } return(0); } diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 9d6ec1aee..e2f020e23 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -440,17 +440,30 @@ void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp) void iguana_blockpurge(struct iguana_info *coin,struct iguana_block *block) { - if ( block->req != 0 ) + struct iguana_zblock *zblock = (void *)block; + if ( coin->chain->zcash == 0 ) { - printf("purge req inside block\n"); - myfree(block->req,block->req->allocsize); + if ( block->req != 0 ) + { + printf("purge req inside block\n"); + myfree(block->req,block->req->allocsize); + } + free(block); + } + else + { + if ( zblock->req != 0 ) + { + printf("purge req inside zblock\n"); + myfree(zblock->req,zblock->req->allocsize); + } + free(zblock); } - free(block); } void iguana_blockspurge(struct iguana_info *coin) { - struct iguana_block *block,*tmp; + struct iguana_block *block,*tmp; struct iguana_zblock *zblock,*ztmp; if ( 1 && coin->blocks.hash != 0 ) { HASH_ITER(hh,coin->blocks.hash,block,tmp) @@ -460,6 +473,15 @@ void iguana_blockspurge(struct iguana_info *coin) } coin->blocks.hash = 0; } + if ( 1 && coin->blocks.zhash != 0 ) + { + HASH_ITER(hh,coin->blocks.zhash,zblock,ztmp) + { + HASH_DEL(coin->blocks.zhash,zblock); + iguana_blockpurge(coin,(void *)zblock); + } + coin->blocks.zhash = 0; + } /*if ( coin->blocks.RO != 0 ) { printf("deprecated coin->blocks.RO used??\n"); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 5d5b6e56a..51d321a0a 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -254,6 +254,7 @@ struct iguana_blocks { char coin[8]; struct iguanakv *db; + struct iguana_zblock *zhash; struct iguana_block *hash; //struct iguana_blockRO *RO; int32_t maxbits; int32_t maxblocks,initblocks,hashblocks,pending,issuedblocks,recvblocks,emitblocks,parsedblocks,dirty; struct iguana_zblock hwmchain,prev,prev2; From d539dee654e44d1c636e188a977c5027fc1ce3e6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Sep 2016 05:21:34 -0300 Subject: [PATCH 3/6] test --- iguana/iguana_blocks.c | 147 +++++++++++--------------------------- iguana/iguana_init.c | 40 ++--------- includes/iguana_structs.h | 5 +- 3 files changed, 49 insertions(+), 143 deletions(-) diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index f32f2f757..7ff74e3e8 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -174,62 +174,35 @@ struct iguana_block *iguana_prevblock(struct iguana_info *coin,struct iguana_blo void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct iguana_block *block) { - char str[65],str2[65]; struct iguana_block *next; struct iguana_zblock *znext,*zprev = (void *)prev,*zblock = (void *)block; - if ( coin->chain->zcash != 0 ) + char str[65],str2[65]; struct iguana_block *next; + if ( memcmp(block->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) { - if ( memcmp(block->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) - { - printf("illegal blocklink mismatched hashes\n"); - iguana_exit(0,0); - return; - } - block->hh.prev = prev; - if ( (next= prev->hh.next) != 0 ) - { - if ( next != block ) - { - if ( memcmp(next->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) - { - printf("illegal blocklink next mismatched hashes\n"); - return; - } - if ( memcmp(next->RO.hash2.bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 ) - printf("blocklink collision: %s vs %s\n",bits256_str(str,block->RO.hash2),bits256_str(str2,next->RO.hash2)); - else printf("blocklink corruption: identical hashes with diff ptrs %s %p %p\n",bits256_str(str,block->RO.hash2),block,next); - } - prev->hh.next = block; // could make a linked list of all at same height for multibranch - } else prev->hh.next = block; + printf("illegal blocklink mismatched hashes\n"); + iguana_exit(0,0); + return; } - else + block->hh.prev = prev; + if ( (next= prev->hh.next) != 0 ) { - if ( memcmp(zblock->RO.prev_block.bytes,zprev->RO.hash2.bytes,sizeof(bits256)) != 0 ) - { - printf("illegal blocklink mismatched zhashes\n"); - iguana_exit(0,0); - return; - } - zblock->hh.prev = zprev; - if ( (znext= zprev->hh.next) != 0 ) + if ( next != block ) { - if ( znext != zblock ) + if ( memcmp(next->RO.prev_block.bytes,prev->RO.hash2.bytes,sizeof(bits256)) != 0 ) { - if ( memcmp(znext->RO.prev_block.bytes,zprev->RO.hash2.bytes,sizeof(bits256)) != 0 ) - { - printf("illegal blocklink next mismatched hashes\n"); - return; - } - if ( memcmp(znext->RO.hash2.bytes,zblock->RO.hash2.bytes,sizeof(bits256)) != 0 ) - printf("blocklink collision: %s vs %s\n",bits256_str(str,zblock->RO.hash2),bits256_str(str2,znext->RO.hash2)); - else printf("blocklink corruption: identical hashes with diff ptrs %s %p %p\n",bits256_str(str,zblock->RO.hash2),zblock,znext); + printf("illegal blocklink next mismatched hashes\n"); + return; } - zprev->hh.next = zblock; // could make a linked list of all at same height for multibranch - } else zprev->hh.next = zblock; - } + if ( memcmp(next->RO.hash2.bytes,block->RO.hash2.bytes,sizeof(bits256)) != 0 ) + printf("blocklink collision: %s vs %s\n",bits256_str(str,block->RO.hash2),bits256_str(str2,next->RO.hash2)); + else printf("blocklink corruption: identical hashes with diff ptrs %s %p %p\n",bits256_str(str,block->RO.hash2),block,next); + } + prev->hh.next = block; // could make a linked list of all at same height for multibranch + } else prev->hh.next = block; + printf("link.(%s) -> (%s)\n",bits256_str(str,prev->RO.hash2),bits256_str(str,block->RO.hash2)); } struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag) { - struct iguana_block *block=0,*prev; int32_t size; struct iguana_zblock *zblock=0,*zprev; + struct iguana_block *block,*prev; int32_t size; /*while ( coin->blockdepth > 0 ) { usleep(100000); @@ -240,10 +213,8 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin }*/ portable_mutex_lock(&coin->blocks_mutex); coin->blockdepth++; - if ( coin->chain->zcash != 0 ) - HASH_FIND(hh,coin->blocks.zhash,&hash2,sizeof(hash2),zblock); - else HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); - if ( block != 0 || zblock != 0 ) + HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); + if ( block != 0 ) { if ( coin->blockdepth > 0 ) coin->blockdepth--; @@ -256,44 +227,24 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin //printf("%d\n",1/(1 - depth/depth)); }*/ portable_mutex_unlock(&coin->blocks_mutex); - return((coin->chain->zcash != 0) ? (struct iguana_block *)zblock : block); + return(block); } if ( createflag > 0 ) { //portable_mutex_lock(&coin->blocks_mutex); - if ( coin->chain->zcash == 0 ) + size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); + block = calloc(1,size); + block->RO.hash2 = hash2; + block->RO.allocsize = size; + iguana_blocksizecheck("blockhashset",coin->chain->zcash,block); + block->hh.itemind = height, block->height = -1; + HASH_ADD(hh,coin->blocks.hash,RO.hash2,sizeof(hash2),block); + block->hh.next = block->hh.prev = 0; + if ( bits256_nonz(block->RO.prev_block) > 0 ) { - size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); - block = calloc(1,size); - block->RO.hash2 = hash2; - block->RO.allocsize = size; - iguana_blocksizecheck("blockhashset",coin->chain->zcash,block); - block->hh.itemind = height, block->height = -1; - HASH_ADD(hh,coin->blocks.hash,RO.hash2,sizeof(hash2),block); - block->hh.next = block->hh.prev = 0; - if ( bits256_nonz(block->RO.prev_block) > 0 ) - { - HASH_FIND(hh,coin->blocks.hash,&block->RO.prev_block,sizeof(block->RO.prev_block),prev); - if ( prev != 0 ) - _iguana_blocklink(coin,prev,block); - } - } - else - { - size = (int32_t)((coin->chain->zcash != 0) ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block)); - zblock = calloc(1,size); - zblock->RO.hash2 = hash2; - zblock->RO.allocsize = size; - iguana_blocksizecheck("blockhashset",coin->chain->zcash,(void *)zblock); - zblock->hh.itemind = height, zblock->height = -1; - HASH_ADD(hh,coin->blocks.zhash,RO.hash2,sizeof(hash2),zblock); - zblock->hh.next = zblock->hh.prev = 0; - if ( bits256_nonz(zblock->RO.prev_block) > 0 ) - { - HASH_FIND(hh,coin->blocks.hash,&zblock->RO.prev_block,sizeof(zblock->RO.prev_block),zprev); - if ( zprev != 0 ) - _iguana_blocklink(coin,(void *)zprev,(void *)zblock); - } + HASH_FIND(hh,coin->blocks.hash,&block->RO.prev_block,sizeof(block->RO.prev_block),prev); + if ( prev != 0 ) + _iguana_blocklink(coin,prev,block); } //char str[65]; if ( coin->virtualchain != 0 ) @@ -319,7 +270,7 @@ struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin //fprintf(stderr,">>>>>>>>>> OK only if rare%s create blockhashset.%d depth.%d\n",debugstr,height,depth); //printf("%d\n",1/(1 - depth/depth)); }*/ - return((coin->chain->zcash != 0) ? (struct iguana_block *)zblock : block); + return(block); } bits256 *iguana_blockhashptr(struct iguana_info *coin,int32_t height) @@ -357,31 +308,15 @@ struct iguana_block *iguana_blockptr(char *debugstr,struct iguana_info *coin,int int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block) { - struct iguana_zblock *zblock = (void *)block; int32_t bsize = zcash != 0 ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block); - if ( zcash == 0 ) + if ( block->RO.allocsize != bsize ) { - if ( block->RO.allocsize != bsize ) + if ( block->RO.allocsize == 0 || block->RO.allocsize < bsize ) { - if ( block->RO.allocsize == 0 || block->RO.allocsize < bsize ) - { - //printf("%s block validate warning: mismatched size %d vs %d\n",debugstr,block->RO.allocsize,bsize); - block->RO.allocsize = bsize; - } else return(-1); - return(bsize); - } - } - else - { - if ( zblock->RO.allocsize != bsize ) - { - if ( zblock->RO.allocsize == 0 || zblock->RO.allocsize < bsize ) - { - //printf("%s block validate warning: mismatched size %d vs %d\n",debugstr,block->RO.allocsize,bsize); - zblock->RO.allocsize = bsize; - } else return(-1); - return(bsize); - } + //printf("%s block validate warning: mismatched size %d vs %d\n",debugstr,block->RO.allocsize,bsize); + block->RO.allocsize = bsize; + } else return(-1); + return(bsize); } return(0); } diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index e2f020e23..d2a784ec6 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -440,30 +440,17 @@ void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp) void iguana_blockpurge(struct iguana_info *coin,struct iguana_block *block) { - struct iguana_zblock *zblock = (void *)block; - if ( coin->chain->zcash == 0 ) + if ( block->req != 0 ) { - if ( block->req != 0 ) - { - printf("purge req inside block\n"); - myfree(block->req,block->req->allocsize); - } - free(block); - } - else - { - if ( zblock->req != 0 ) - { - printf("purge req inside zblock\n"); - myfree(zblock->req,zblock->req->allocsize); - } - free(zblock); + printf("purge req inside block\n"); + myfree(block->req,block->req->allocsize); } + free(block); } void iguana_blockspurge(struct iguana_info *coin) { - struct iguana_block *block,*tmp; struct iguana_zblock *zblock,*ztmp; + struct iguana_block *block,*tmp; if ( 1 && coin->blocks.hash != 0 ) { HASH_ITER(hh,coin->blocks.hash,block,tmp) @@ -473,22 +460,7 @@ void iguana_blockspurge(struct iguana_info *coin) } coin->blocks.hash = 0; } - if ( 1 && coin->blocks.zhash != 0 ) - { - HASH_ITER(hh,coin->blocks.zhash,zblock,ztmp) - { - HASH_DEL(coin->blocks.zhash,zblock); - iguana_blockpurge(coin,(void *)zblock); - } - coin->blocks.zhash = 0; - } - /*if ( coin->blocks.RO != 0 ) - { - printf("deprecated coin->blocks.RO used??\n"); - myfree(coin->blocks.RO,coin->blocks.maxbits * sizeof(*coin->blocks.RO)); - coin->blocks.RO = 0; - } - coin->blocks.maxbits = */coin->blocks.maxblocks = coin->blocks.initblocks = coin->blocks.hashblocks = coin->blocks.issuedblocks = coin->blocks.recvblocks = coin->blocks.emitblocks = coin->blocks.parsedblocks = coin->blocks.dirty = 0; + coin->blocks.maxblocks = coin->blocks.initblocks = coin->blocks.hashblocks = coin->blocks.issuedblocks = coin->blocks.recvblocks = coin->blocks.emitblocks = coin->blocks.parsedblocks = coin->blocks.dirty = 0; printf("clear hwmchain\n"); memset(&coin->blocks.hwmchain,0,sizeof(coin->blocks.hwmchain)); } diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 51d321a0a..e5b02b3f8 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -222,7 +222,7 @@ struct iguana_blockRO RO struct iguana_block { iguana_blockfields; - //struct iguana_zcashRO zRO[]; + struct iguana_zcashRO zRO[]; } PACKEDSTRUCT; struct iguana_zblock // mu @@ -254,8 +254,7 @@ struct iguana_blocks { char coin[8]; struct iguanakv *db; - struct iguana_zblock *zhash; - struct iguana_block *hash; //struct iguana_blockRO *RO; int32_t maxbits; + struct iguana_block *hash; int32_t maxblocks,initblocks,hashblocks,pending,issuedblocks,recvblocks,emitblocks,parsedblocks,dirty; struct iguana_zblock hwmchain,prev,prev2; }; From a47da23b6ebf10e68563d710c4facc1c387862d5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Sep 2016 05:24:47 -0300 Subject: [PATCH 4/6] test --- iguana/coins/genltc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/coins/genltc b/iguana/coins/genltc index 457e57e10..d2dd64f2c 100755 --- a/iguana/coins/genltc +++ b/iguana/coins/genltc @@ -1,2 +1,2 @@ -curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":256,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9332,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}" +curl --url "http://127.0.0.1:7778" --data "{\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":68,\"endpend\":68,\"services\":129,\"maxpeers\":256,\"newcoin\":\"LTC\",\"name\":\"Litecoin\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"fbc0b6db\",\"p2p\":9333,\"rpc\":9332,\"pubval\":48,\"p2shval\":5,\"wifval\":176,\"txfee_satoshis\":\"100000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2\",\"genesis\":{\"version\":1,\"timestamp\":1317972665,\"nBits\":\"1e0ffff0\",\"nonce\":2084524493,\"merkle_root\":\"97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9\"},\"alertpubkey\":\"040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9\",\"protover\":70002}" From eb0bae2e53a138236dff4211f9927904f0e45018 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Sep 2016 05:27:48 -0300 Subject: [PATCH 5/6] test --- iguana/iguana_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index d2a784ec6..5308e619b 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -378,7 +378,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 { if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 ) lastbundle = hash2, lastheight = height; - else if ( missing++ > coin->MAXBUNDLES && strcmp("BTC",coin->symbol) == 0 ) + else if ( missing++ > coin->MAXBUNDLES && strcmp("BTCD",coin->symbol) != 0 ) { printf("missing.%d\n",missing); break; From f4e3d2cf958c2113d40928487c03319bfa5c8e2c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 19 Sep 2016 05:34:29 -0300 Subject: [PATCH 6/6] test --- iguana/iguana_chains.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index d276e5373..30042426e 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -125,7 +125,7 @@ int32_t blockhash_scrypt(uint8_t *blockhashp,uint8_t *serialized,int32_t len) blockhashfunc iguana_hashalgo(char *hashalgostr) { - //return(blockhash_sha256); +return(blockhash_sha256); // all coins seem to use this for genesis if ( hashalgostr == 0 || hashalgostr[0] == 0 || strcmp(hashalgostr,"sha256") == 0 ) return(blockhash_sha256); else if ( strcmp(hashalgostr,"scrypt") == 0 )