From de9bc6e9bdee35c573f04ab7017d01e11f9512c4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sat, 2 Apr 2016 20:20:32 -0600 Subject: [PATCH] test --- SuperNET/hostnet777.c | 2 +- SuperNET/main.c | 2 +- deprecated/obsolete.h | 82 ++++++++++++++ iguana/SuperNET_hexmsg.c | 4 +- iguana/iguana777.c | 6 +- iguana/iguana777.h | 9 +- iguana/iguana_blocks.c | 62 +++++++---- iguana/iguana_bundles.c | 43 +++++--- iguana/iguana_init.c | 77 ++++++------- iguana/iguana_ramchain.c | 30 ++--- iguana/iguana_recv.c | 232 ++++++++++++++++----------------------- iguana/iguana_unspents.c | 7 +- iguana/main.c | 8 +- iguana/ramchain_api.c | 2 +- pangea/hostnet777.c | 2 +- 15 files changed, 317 insertions(+), 251 deletions(-) diff --git a/SuperNET/hostnet777.c b/SuperNET/hostnet777.c index fc9c99f58..54341bbba 100755 --- a/SuperNET/hostnet777.c +++ b/SuperNET/hostnet777.c @@ -146,7 +146,7 @@ extern int32_t Debuglevel; #include "../includes/curve25519.h" -static bits256 zeropoint; +static const bits256 zeropoint; int64_t hostnet777_convmT(struct hostnet777_mtime *mT,int64_t othermillitime) { diff --git a/SuperNET/main.c b/SuperNET/main.c index 1ba57afe1..b429a8eab 100755 --- a/SuperNET/main.c +++ b/SuperNET/main.c @@ -216,7 +216,7 @@ bits256 SuperNET_OPRETURN(struct supernet_info *myinfo,char *symbol,double fee,u bits256 SuperNET_agentannounce(struct supernet_info *myinfo,struct supernet_agent *agent,cJSON *network) { - static bits256 zero; + static const bits256 zero; uint8_t buf[80 + sizeof(struct iguana_msghdr)],*data; bits256 pubkey,sig; int32_t i,len=0; uint8_t netmagic[4]; char *sigstr,*announce,*pubkeystr; memset(buf,0,sizeof(buf)); diff --git a/deprecated/obsolete.h b/deprecated/obsolete.h index 4a4038b6c..f3be3ee17 100755 --- a/deprecated/obsolete.h +++ b/deprecated/obsolete.h @@ -15165,5 +15165,87 @@ len = 0; } if ( n > 0 ) printf("issued %d priority requests [%d] to unstick stuckiters.%d lag.%d\n",n,bp->hdrsi,coin->stuckiters,lag);*/ + /*if ( 0 && n >= coin->chain->bundlesize ) + { + blockhashes = malloc(sizeof(*blockhashes) * coin->chain->bundlesize); + for (i=0; ichain->bundlesize; i++) + blockhashes[i] = blocks[i].RO.hash2; + for (i=0; ibundlescount; i++) + { + if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 ) + { + blockhashes[0] = bp->hashes[0]; + vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes)); + if ( bits256_cmp(allhash,bp->allhash) == 0 ) + { + if ( bp->queued != 0 ) + bp->queued = 0; + if ( iguana_allhashcmp(coin,bp,blockhashes,coin->chain->bundlesize) > 0 ) + { + free(blockhashes); + return(req); + } + } + } + } + free(blockhashes); + }*/ + + + /*void iguana_patch(struct iguana_info *coin,struct iguana_block *block) + { + int32_t i,j,origheight,height; struct iguana_block *prev,*next; struct iguana_bundle *bp; + prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1); + block->hh.prev = prev; + if ( prev != 0 ) + { + if ( prev->mainchain != 0 ) + { + prev->hh.next = block; + if ( memcmp(block->RO.prev_block.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 ) + _iguana_chainlink(coin,block); + if ( (next= block->hh.next) != 0 && bits256_nonz(next->RO.hash2) > 0 ) + next->height = block->height + 1; + } + else if ( 0 && block->height < 0 ) + { + for (i=0; i<1; i++) + { + if ( (prev= prev->hh.prev) == 0 ) + break; + if ( prev->mainchain != 0 && prev->height >= 0 ) + { + j = i; + origheight = (prev->height + i + 2); + prev = block->hh.prev; + height = (origheight - 1); + while ( i > 0 && prev != 0 ) + { + if ( prev->mainchain != 0 && prev->height != height ) + { + printf("mainchain height mismatch j.%d at i.%d %d != %d\n",j,i,prev->height,height); + break; + } + prev = prev->hh.prev; + height--; + } + if ( i == 0 ) + { + //printf("SET HEIGHT.%d j.%d\n",origheight,j); + if ( (bp= coin->bundles[origheight / coin->chain->bundlesize]) != 0 ) + { + iguana_bundlehash2add(coin,0,bp,origheight % coin->chain->bundlesize,block->RO.hash2); + block->height = origheight; + block->mainchain = 1; + prev = block->hh.prev; + prev->hh.next = block; + } + } //else printf("break at i.%d for j.%d origheight.%d\n",i,j,origheight); + break; + } + } + } + } + }*/ #endif diff --git a/iguana/SuperNET_hexmsg.c b/iguana/SuperNET_hexmsg.c index 876637d15..58a036748 100755 --- a/iguana/SuperNET_hexmsg.c +++ b/iguana/SuperNET_hexmsg.c @@ -152,7 +152,7 @@ bits256 catgory_default_hit(struct category_chain *catchain,int32_t height,void bits256 category_default_func(struct category_chain *catchain,int32_t func,int32_t height,void *prevgenerator,void *addr,void *blockhashp,bits256 heaviest) { - static bits256 zero; + static const bits256 zero; if ( catchain->hashlen != sizeof(bits256) || catchain->addrlen != sizeof(bits256) ) { printf("unsupported hashlen.%d or addrlen.%d\n",catchain->hashlen,catchain->addrlen); @@ -205,7 +205,7 @@ bits256 category_default_func(struct category_chain *catchain,int32_t func,int32 int32_t category_default_ishwm(struct category_chain *catchain,int32_t prevheight,void *prevblockhashp,void *blockhashp,void *prevgenerator,void *addr) { - bits256 checkhash,prevwt,oldhit,hit,heaviest; static bits256 zero; + bits256 checkhash,prevwt,oldhit,hit,heaviest; static const bits256 zero; checkhash = category_default_blockfind(prevheight); if ( memcmp(checkhash.bytes,prevblockhashp,catchain->hashlen) == 0 ) { diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 3b0c81ef6..542396f93 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -557,7 +557,6 @@ void iguana_coinloop(void *arg) //fprintf(stderr,"metrics\n"); coin->peers.lastmetrics = iguana_updatemetrics(coin); // ranks peers } - iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); if ( coin->longestchain+10000 > coin->blocks.maxbits ) iguana_recvalloc(coin,coin->longestchain + 100000); flag += iguana_processrecv(coin); @@ -565,8 +564,11 @@ void iguana_coinloop(void *arg) coin->idletime = (uint32_t)time(NULL); } } - if ( flag == 0 || coin->RTheight >= coin->longestchain-3 ) + if ( flag == 0 && coin->isRT == 0 ) + usleep(coin->polltimeout*1000 + (coin->peers.numranked == 0)*1000000); + else if ( coin->RTheight >= coin->longestchain-3 ) usleep(coin->polltimeout*1000 + coin->isRT*90000 + (coin->peers.numranked == 0)*1000000); + else usleep(25000); } } diff --git a/iguana/iguana777.h b/iguana/iguana777.h index e43ff3ead..e176d63eb 100755 --- a/iguana/iguana777.h +++ b/iguana/iguana777.h @@ -487,7 +487,7 @@ struct iguana_info struct iguana_bundle *bundles[IGUANA_MAXBUNDLES],*current,*lastpending; struct iguana_ramchain RTramchain; struct OS_memspace RTmem,RThashmem; int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified; - uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,idletime,stucktime,stuckmonitor,maxstuck; + uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime; double backstopmillis; bits256 backstophash2; int64_t spaceused; int32_t initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,polltimeout,numreqtxids,allhashes; bits256 reqtxids[64]; void *launched,*started; @@ -578,8 +578,8 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi // blocks bits256 iguana_blockhash(struct iguana_info *coin,int32_t height); -#define iguana_blockfind(coin,hash2) iguana_blockhashset(coin,-1,hash2,0) -struct iguana_block *iguana_blockhashset(struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag); +#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0) +struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag); uint32_t iguana_syncs(struct iguana_info *coin); void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t height); @@ -592,7 +592,7 @@ int32_t iguana_recvinit(struct iguana_info *coin,int32_t initialheight); int32_t ramcoder_decompress(uint8_t *data,int32_t maxlen,uint8_t *bits,uint32_t numbits,bits256 seed); int32_t ramcoder_compress(uint8_t *bits,int32_t maxlen,uint8_t *data,int32_t datalen,bits256 seed); uint64_t hconv_bitlen(uint64_t bitlen); -struct iguana_block *iguana_blockptr(struct iguana_info *coin,int32_t height); +struct iguana_block *iguana_blockptr(char *debugstr,struct iguana_info *coin,int32_t height); int32_t iguana_processrecv(struct iguana_info *coin); // single threaded void iguana_recvalloc(struct iguana_info *coin,int32_t numitems); void iguana_coins(void *arg); @@ -844,6 +844,7 @@ int32_t _SuperNET_encryptjson(char *destfname,char *passphrase,int32_t passsize, int32_t bitcoin_pubkeylen(const uint8_t *pubkey); struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p,struct iguana_bundle *bp,int32_t i); void *iguana_ramchainfile(struct iguana_info *coin,struct iguana_ramchain *dest,struct iguana_ramchain *R,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block); +int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block); extern int32_t HDRnet,netBLOCKS; diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index e08b7fee9..72667bb42 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -15,7 +15,7 @@ #include "iguana777.h" -#define iguana_blockfind(coin,hash2) iguana_blockhashset(coin,-1,hash2,0) +#define iguana_blockfind(str,coin,hash2) iguana_blockhashset(str,coin,-1,hash2,0) void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct iguana_block *block) { @@ -45,27 +45,36 @@ void _iguana_blocklink(struct iguana_info *coin,struct iguana_block *prev,struct printf("link.(%s) -> (%s)\n",bits256_str(str,prev->RO.hash2),bits256_str(str,block->RO.hash2)); } -struct iguana_block *iguana_blockhashset(struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag) +struct iguana_block *iguana_blockhashset(char *debugstr,struct iguana_info *coin,int32_t height,bits256 hash2,int32_t createflag) { static int depth; struct iguana_block *block,*prev; - if ( height > 0 && (height > coin->blocks.maxbits || depth != 0) ) + if ( height > 0 && height > coin->blocks.maxbits ) { - printf("illegal height.%d when max.%d, or nonz depth.%d\n",height,coin->blocks.maxbits,depth); + printf("%s: illegal height.%d when max.%d, or nonz depth.%d\n",debugstr,height,coin->blocks.maxbits,depth); //getchar(); return(0); } + while ( depth != 0 ) + { + printf("%s blockhashset.%d depth.%d\n",debugstr,height,depth); + printf("%d\n",1/(1 - depth/depth)); + } depth++; - //portable_mutex_lock(&coin->blocks_mutex); HASH_FIND(hh,coin->blocks.hash,&hash2,sizeof(hash2),block); if ( block != 0 ) { - // portable_mutex_unlock(&coin->blocks_mutex); depth--; + while ( depth != 0 ) + { + printf("%s match blockhashset.%d depth.%d\n",debugstr,height,depth); + printf("%d\n",1/(1 - depth/depth)); + } return(block); } if ( createflag > 0 ) { + portable_mutex_lock(&coin->blocks_mutex); block = calloc(1,sizeof(*block)); block->RO.hash2 = hash2; block->hh.itemind = height, block->height = -1; @@ -87,18 +96,29 @@ struct iguana_block *iguana_blockhashset(struct iguana_info *coin,int32_t height 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); depth--; + while ( depth != 0 ) + { + printf("%s create blockhashset.%d depth.%d\n",debugstr,height,depth); + printf("%d\n",1/(1 - depth/depth)); + } return(block); } bits256 *iguana_blockhashptr(struct iguana_info *coin,int32_t height) { - int32_t i; struct iguana_bundle *bp; bits256 *hashptr; - if ( height >= 0 ) + int32_t hdrsi,bundlei,bundlesize; struct iguana_bundle *bp; //bits256 *hashptr; + if ( height >= 0 && (bundlesize= coin->chain->bundlesize) != 0 ) { - for (i=0; ibundlescount; i++) + hdrsi = (height / bundlesize); + bundlei = height - (hdrsi * bundlesize); + if ( hdrsi >= 0 && hdrsi < bundlesize && bundlei >= 0 && bundlei < bundlesize && (bp= coin->bundles[hdrsi]) != 0 ) + { + return(&bp->hashes[bundlei]); + } + /*for (i=0; ibundlescount; i++) { if ( (bp= coin->bundles[i]) != 0 ) { @@ -109,7 +129,7 @@ bits256 *iguana_blockhashptr(struct iguana_info *coin,int32_t height) return(hashptr); } } - } + }*/ } return(0); } @@ -122,11 +142,11 @@ bits256 iguana_blockhash(struct iguana_info *coin,int32_t height) return(zero); } -struct iguana_block *iguana_blockptr(struct iguana_info *coin,int32_t height) +struct iguana_block *iguana_blockptr(char *debugstr,struct iguana_info *coin,int32_t height) { static const bits256 zero; bits256 hash2 = iguana_blockhash(coin,height); if ( memcmp(zero.bytes,hash2.bytes,sizeof(zero)) != 0 ) - return(iguana_blockfind(coin,hash2)); + return(iguana_blockfind(debugstr,coin,hash2)); return(0); } @@ -276,11 +296,11 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl hwmchain = &coin->blocks.hwmchain; if ( 0 && hwmchain->height > 0 && ((bp= coin->current) == 0 || hwmchain->height/coin->chain->bundlesize > bp->hdrsi+0*bp->isRT) ) return(0); - if ( (block= iguana_blockfind(coin,newblock->RO.hash2)) != 0 ) + if ( (block= iguana_blockfind("chainlink",coin,newblock->RO.hash2)) != 0 ) { if ( memcmp(coin->chain->genesis_hashdata,block->RO.hash2.bytes,sizeof(bits256)) == 0 ) block->PoW = PoW_from_compact(block->RO.bits,coin->chain->unitval), height = 0; - else if ( (prev= iguana_blockfind(coin,block->RO.prev_block)) != 0 ) + else if ( (prev= iguana_blockfind("chainprev",coin,block->RO.prev_block)) != 0 ) { if ( memcmp(prev->RO.hash2.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 ) prev->mainchain = 1; @@ -375,9 +395,9 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl } if ( coin->started != 0 && (block->height % coin->chain->bundlesize) == coin->minconfirms && (block->height > coin->longestchain-coin->chain->bundlesize*2 || ((block->height / coin->chain->bundlesize) % 10) == 9) ) { - //printf("savehdrs\n"); + printf("savehdrs.[%d] ht.%d\n",bp->hdrsi,block->height); iguana_savehdrs(coin); - //printf("done savehdrs\n"); + printf("done savehdrs.%d\n",bp->hdrsi); } } } @@ -417,18 +437,18 @@ int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newbloc } else { - block = iguana_blockhashset(coin,-1,newblock->RO.hash2,1); + block = iguana_blockhashset("chainextend",coin,-1,newblock->RO.hash2,1); if ( block != newblock ) iguana_blockcopy(coin,block,newblock); block->valid = 1; - if ( block->hh.prev == 0 && (prev= iguana_blockfind(coin,block->RO.prev_block)) != 0 ) + if ( block->hh.prev == 0 && (prev= iguana_blockfind("extendprev",coin,block->RO.prev_block)) != 0 ) { if ( prev->hh.next == 0 && block->hh.prev == 0 ) prev->hh.next = block, block->hh.prev = prev; //printf("extend newblock.%s prevm.%d\n",bits256_str(str,block->prev_block),prev->mainchain); if ( prev->mainchain == 0 ) { - if ( (block= iguana_blockfind(coin,coin->blocks.hwmchain.RO.hash2)) != 0 && block->mainchain == 0 ) + if ( (block= iguana_blockfind("extendmain",coin,coin->blocks.hwmchain.RO.hash2)) != 0 && block->mainchain == 0 ) { //printf("c hwmchain is not mainchain anymore?\n"); prev->mainchain = 1; @@ -454,7 +474,7 @@ int32_t iguana_chainextend(struct iguana_info *coin,struct iguana_block *newbloc } } } - if ( (block= iguana_blockfind(coin,coin->blocks.hwmchain.RO.hash2)) != 0 && block->mainchain == 0 ) + if ( (block= iguana_blockfind("extendcheck",coin,coin->blocks.hwmchain.RO.hash2)) != 0 && block->mainchain == 0 ) { printf("hwmchain is not mainchain anymore?\n"); block->mainchain = 1; diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 1ced5f657..c9dd85c41 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -197,14 +197,27 @@ int32_t iguana_hash2set(struct iguana_info *coin,char *debugstr,struct iguana_bu int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blockp,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2) { - struct iguana_block *block =0; struct iguana_bundle *otherbp; // + struct iguana_block *block =0; struct iguana_bundle *otherbp; int32_t otherbundlei,setval,bundlesize,err = 0; if ( blockp != 0 ) *blockp = 0; if ( bp == 0 || bits256_nonz(hash2) == 0 ) return(-1111); - if ( bits256_nonz(hash2) > 0 && (block= iguana_blockhashset(coin,-1,hash2,1)) != 0 ) + if ( bits256_nonz(hash2) != 0 && (block= iguana_blockhashset("bundlehash2add",coin,-1,hash2,1)) != 0 ) { + if ( bp->blocks[bundlei] != 0 && bp->blocks[bundlei] != block ) + { + printf("bp->blocks[%d] mismatch %p != %p\n",bundlei,bp->blocks[bundlei],block); + return(-1); + } + if ( bits256_nonz(bp->hashes[bundlei]) != 0 && bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 ) + { + char str[65],str2[65]; + printf("bp->hashes[%d] mismatch %s != %s%s\n",bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str2,block->RO.hash2),block->mainchain?".main":""); + if ( block->mainchain != 0 ) + bp->hashes[bundlei] = block->RO.hash2; + else return(-1); + } /*if ( (block->hdrsi != bp->hdrsi || block->bundlei != bundlei) && (block->hdrsi != 0 || block->bundlei != 0) ) { return(-2); @@ -348,7 +361,7 @@ struct iguana_bundle *iguana_bundlecreate(struct iguana_info *coin,int32_t *bund struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_txid *tx,int32_t txidind) { - static bits256 zero; + static const bits256 zero; int32_t hdrsi,iter; int64_t Toffset; char fname[1024]; FILE *fp; struct iguana_ramchaindata rdata; for (iter=0; iter<2; iter++) { @@ -374,7 +387,7 @@ struct iguana_txid *iguana_bundletx(struct iguana_info *coin,struct iguana_bundl void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp) { - static bits256 zero; + static const bits256 zero; char fname[1024]; int32_t hdrsi,m,j; uint32_t ipbits; if ( bp->purgetime == 0 && time(NULL) > bp->emitfinish+30 ) { @@ -414,15 +427,17 @@ uint8_t iguana_recentpeers(struct iguana_info *coin,int32_t *capacityp,struct ig struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p,struct iguana_bundle *bp,int32_t i) { - struct iguana_block *block = 0; + struct iguana_bundle *nextbp; struct iguana_block *block = 0; memset(hash2p,0,sizeof(*hash2p)); if ( i == bp->n ) { if ( bits256_nonz(bp->nextbundlehash2) != 0 ) - block = iguana_blockfind(coin,bp->nextbundlehash2); - else return(0); + { + if ( bp->hdrsi < coin->bundlescount && (nextbp= coin->bundles[bp->hdrsi+1]) != 0 ) + block = nextbp->blocks[0]; + } else return(0); } - if ( block != 0 || (block= bp->blocks[i]) != 0 || (bits256_nonz(bp->hashes[i]) != 0 && (block= iguana_blockfind(coin,bp->hashes[i])) != 0) ) + if ( block != 0 || (block= bp->blocks[i]) != 0 )//|| bits256_nonz(bp->hashes[i]) != 0 )//&& (block= iguana_blockfind("bundleblock2",coin,bp->hashes[i])) != 0) ) { *hash2p = block->RO.hash2; return(block); @@ -430,7 +445,7 @@ struct iguana_block *iguana_bundleblock(struct iguana_info *coin,bits256 *hash2p else if ( bp->speculative != 0 && bits256_nonz(bp->speculative[i]) != 0 ) { *hash2p = bp->speculative[i]; - block = iguana_blockfind(coin,bp->speculative[i]); + block = bp->blocks[i];//iguana_blockfind("speculative",coin,bp->speculative[i]); //char str[65]; printf("[%d:%d] %s\n",bp->hdrsi,i,bits256_str(str,*hash2p)); } return(block); @@ -888,7 +903,7 @@ static int32_t revsortds(double *buf,uint32_t num,int32_t size) int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei) { int32_t recvlen; struct iguana_msghdr H; uint8_t *data; struct iguana_block *block; - if ( (data= bp->speculativecache[bundlei]) != 0 && bp->speculative != 0 && (block= iguana_blockfind(coin,bp->speculative[bundlei])) != 0 ) + if ( (data= bp->speculativecache[bundlei]) != 0 && bp->speculative != 0 && (block= iguana_blockfind("cacheprocess",coin,bp->speculative[bundlei])) != 0 ) { iguana_bundlehash2add(coin,0,bp,bundlei,bp->speculative[bundlei]); recvlen = *(int32_t *)data; @@ -975,7 +990,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) for (j=coin->blocks.hwmchain.height-bp->bundleheight+1; j<=bp->n; j++) { if ( (block= iguana_bundleblock(coin,&hash2,bp,j)) == 0 && bits256_nonz(hash2) != 0 ) - block = iguana_blockfind(coin,hash2); + block = iguana_blockfind("bundlestats",coin,hash2); if ( block == 0 || bits256_nonz(block->RO.prev_block) == 0 || _iguana_chainlink(coin,block) == 0 ) break; } @@ -985,7 +1000,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) for (j=0; jn; j++) { if ( bp->blocks[j] == 0 ) - bp->blocks[j] = iguana_blockfind(coin,bp->hashes[j]); + bp->blocks[j] = iguana_blockfind("bundlestats2",coin,bp->hashes[j]); } } else @@ -999,9 +1014,11 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag) { for (j=0; jn; j++) { + if ( bp->blocks[j] == 0 && bp->speculative != 0 && bits256_nonz(bp->speculative[j]) != 0 ) + bp->blocks[j] = iguana_blockhashset("speculative3",coin,bp->bundleheight+j,bp->speculative[j],1); if ( bp->speculativecache[j] != 0 ) { - if ( (block= iguana_blockhashset(coin,-1,bp->speculative[j],1)) != 0 && block->processed == 0 ) + if ( (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0 && block->processed == 0 ) iguana_cacheprocess(coin,bp,j); numcached++; } diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index fecb4d666..063251e49 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -103,7 +103,7 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain) block.RO.txn_count = 1; block.RO.numvouts = 1; iguana_gotdata(coin,0,0); - if ( (ptr= iguana_blockhashset(coin,0,hash2,1)) != 0 ) + if ( (ptr= iguana_blockhashset("genesis0",coin,0,hash2,1)) != 0 ) { ptr->mainchain = 1; iguana_blockcopy(coin,ptr,&block); @@ -121,57 +121,42 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain) getchar(); } int32_t bundlei = -2; - static bits256 zero; + static const bits256 zero; iguana_bundlecreate(coin,&bundlei,0,hash2,zero,1); - _iguana_chainlink(coin,iguana_blockfind(coin,hash2)); + _iguana_chainlink(coin,iguana_blockfind("genesis",coin,hash2)); return(hash2); } int32_t iguana_savehdrs(struct iguana_info *coin) { - int32_t height,i,n,retval = 0; char fname[512],shastr[65],tmpfname[512],str[65],oldfname[512]; - bits256 hash2,sha256all,*hashes; FILE *fp; + char fname[512],shastr[65],tmpfname[512],str2[65],str[65],oldfname[512]; + bits256 sha256all; FILE *fp; struct iguana_bundle *bp; int32_t hdrsi,n,retval = 0; n = coin->blocks.hwmchain.height + 1; - hashes = mycalloc('h',coin->chain->bundlesize,sizeof(*hashes)); sprintf(oldfname,"confs/%s_oldhdrs.txt",coin->symbol), OS_compatible_path(oldfname); sprintf(tmpfname,"%s/%s/hdrs.txt",GLOBALTMPDIR,coin->symbol), OS_compatible_path(tmpfname); sprintf(fname,"confs/%s_hdrs.txt",coin->symbol), OS_compatible_path(fname); if ( (fp= fopen(tmpfname,"w")) != 0 ) { fprintf(fp,"%d\n",n); - for (height=0; height<=n; height+=coin->chain->bundlesize) + for (hdrsi=0; hdrsibundlescount; hdrsi++) { - for (i=0; ichain->bundlesize; i++) + if ( (bp= coin->bundles[hdrsi]) != 0 && bp->numhashes >= bp->n ) { - hashes[i] = iguana_blockhash(coin,height+i); - if ( bits256_str(str,hashes[i]) == 0 ) - break; - } - if ( i == coin->chain->bundlesize ) - { - struct iguana_bundle *bp; - if ( (bp= coin->bundles[height/coin->chain->bundlesize]) != 0 ) + shastr[0] = 0; + if ( bits256_nonz(bp->allhash) == 0 ) { - if ( bits256_nonz(bp->allhash) == 0 ) - { - vcalc_sha256(shastr,sha256all.bytes,hashes[0].bytes,sizeof(*hashes) * coin->chain->bundlesize); - bp->allhash = sha256all; - } - else - { - sha256all = bp->allhash; - bits256_str(shastr,bp->allhash); - } + vcalc_sha256(shastr,sha256all.bytes,bp->hashes[0].bytes,sizeof(*bp->hashes) * coin->chain->bundlesize); + bp->allhash = sha256all; } - } else shastr[0] = 0; - hash2 = iguana_blockhash(coin,height); - if ( bits256_nonz(hash2) > 0 ) - { - fprintf(fp,"%d %s %s\n",height,bits256_str(str,hash2),shastr); - retval = height; - } + else + { + sha256all = bp->allhash; + bits256_str(shastr,bp->allhash); + } + fprintf(fp,"%d %s %s %s\n",bp->bundleheight,bits256_str(str,bp->hashes[0]),shastr,bits256_str(str2,bp->hashes[1])); + } else break; } - //printf("new hdrs.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)iguana_filesize(fname)); + printf("compare hdrs.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)OS_filesize(fname)); if ( ftell(fp) > OS_filesize(fname) ) { printf("new hdrs.txt %ld vs (%s) %ld\n",ftell(fp),fname,(long)OS_filesize(fname)); @@ -185,14 +170,13 @@ int32_t iguana_savehdrs(struct iguana_info *coin) printf("iguana_savehdrs: couldnt create.(%s)\n",tmpfname); return(-1); } - myfree(hashes,coin->chain->bundlesize * sizeof(*hashes)); return(retval); } void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) { int32_t i,j,k,m,c,height,flag,bundlei; char checkstr[1024],line[1024]; - struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,zero,lastbundle; + struct iguana_peer *addr; struct iguana_bundle *bp; bits256 allhash,hash2,hash1,zero,lastbundle; struct iguana_block *block; memset(&zero,0,sizeof(zero)); lastbundle = zero; @@ -255,7 +239,6 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) height = (height * 10) + (line[k] - '0'); else break; } - //printf("parseline: k.%d %d height.%d m.%d bundlesize.%d (%s)\n",k,line[k],height,m,coin->chain->bundlesize,&line[k+1+65]);// + strlen(line+k+1)]); if ( line[k] == ' ' ) { decode_hex(hash2.bytes,sizeof(hash2),line+k+1); @@ -265,17 +248,29 @@ void iguana_parseline(struct iguana_info *coin,int32_t iter,FILE *fp) iguana_recvalloc(coin,height + 100000); decode_hex(allhash.bytes,sizeof(allhash),line+k+1 + 64 + 1); init_hexbytes_noT(checkstr,allhash.bytes,sizeof(allhash)); - if ( strcmp(checkstr,line+k+1 + 64 + 1) == 0 ) + //printf("parseline: k.%d %d height.%d m.%d bundlesize.%d (%s) check.(%s)\n",k,line[k],height,m,coin->chain->bundlesize,&line[k+1+65],checkstr);// + strlen(line+k+1)]); + if ( strncmp(checkstr,line+k+1 + 64 + 1,64) == 0 ) { init_hexbytes_noT(checkstr,hash2.bytes,sizeof(hash2)); - //char str[65],str2[65]; printf(">>>> bundle.%d got (%s)/(%s) allhash.(%s)\n",height,bits256_str(str,hash2),checkstr,bits256_str(str2,allhash)); + if ( strlen(line+k+1 + 2*64 + 2) == sizeof(hash1)*2 ) + decode_hex(hash1.bytes,sizeof(hash1),line+k+1 + 2*64 + 2); + else memset(hash1.bytes,0,sizeof(hash1)); + //char str[65],str2[65]; printf(">>>> bundle.%d got (%s)/(%s) allhash.(%s)\n",height,bits256_str(str,hash1),checkstr,bits256_str(str2,allhash)); if ( (bp= iguana_bundlecreate(coin,&bundlei,height,hash2,allhash,0)) != 0 ) { bp->bundleheight = height; + if ( bits256_nonz(hash1) != 0 ) + { + if ( (block= iguana_blockhashset("inithash1",coin,height+1,hash1,1)) != 0 ) + { + iguana_bundlehashadd(coin,bp,1,block); + block->mainchain = 1; + } + } if ( height == 0 && coin->current == 0 ) coin->current = coin->bundles[0] = bp; lastbundle = hash2; - if ( (block= iguana_blockfind(coin,hash2)) != 0 ) + if ( (block= iguana_blockfind("parse",coin,hash2)) != 0 ) block->mainchain = 1, block->height = height; if ( iguana_bundleload(coin,&bp->ramchain,bp,2) != 0 ) { @@ -337,7 +332,7 @@ void iguana_ramchainpurge(struct iguana_info *coin,struct iguana_bundle *bp,stru void iguana_bundlepurge(struct iguana_info *coin,struct iguana_bundle *bp) { - int32_t i; static bits256 zero; + int32_t i; static const bits256 zero; iguana_ramchainpurge(coin,bp,&bp->ramchain); if ( bp->speculative != 0 ) { diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index f0504ac45..23e0a625c 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -651,7 +651,7 @@ void iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain *r T = (void *)(long)((long)ramchain->H.data + ramchain->H.data->Toffset); TXbits = (void *)(long)((long)ramchain->H.data + ramchain->H.data->TXoffset); numtxids = ramchain->H.data->numtxids; - tlen = ramchain->H.data->numtxsparse * ramchain->H.data->txsparsebits; + tlen = (ramchain->H.data->numtxsparse * ramchain->H.data->txsparsebits) >> 3; for (i=1; iH.data + ramchain->H.data->PKoffset); numpkinds = ramchain->H.data->numpkinds; numunspents = ramchain->H.data->numunspents; - plen = ramchain->H.data->numpksparse * ramchain->H.data->pksparsebits; + plen = (ramchain->H.data->numpksparse * ramchain->H.data->pksparsebits) >> 3; for (i=1; in; i++) { - if ( (bp->blocks[i]= iguana_blockhashset(coin,-1,B[i].hash2,1)) == 0 ) + if ( (bp->blocks[i]= iguana_blockhashset("mapchain",coin,-1,B[i].hash2,1)) == 0 ) { printf("Error getting blockptr\n"); return(0); @@ -1904,7 +1904,7 @@ void iguana_ramchain_disp(struct iguana_ramchain *ramchain) void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,struct iguana_bundle *bp,int32_t i,int32_t deletefile) { - void *ptr; int32_t recvlen,hdrsi,checki; char fname[1024]; static bits256 zero; + void *ptr; int32_t recvlen,hdrsi,checki; char fname[1024]; static const bits256 zero; block->queued = 0; block->fpipbits = 0; block->fpos = -1; @@ -1931,7 +1931,7 @@ void iguana_blockunmark(struct iguana_info *coin,struct iguana_block *block,stru int32_t iguana_oldbundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **ptrs,long *filesizes,struct iguana_bundle *bp) { - static bits256 zero; + static const bits256 zero; int32_t j,bundlei,num,hdrsi,checki; struct iguana_block *block; uint32_t fpipbits; char fname[1024]; for (bundlei=num=0; bundlein; bundlei++) { @@ -1971,7 +1971,7 @@ int32_t iguana_oldbundlefiles(struct iguana_info *coin,uint32_t *ipbits,void **p void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei) { - int32_t checki,hdrsi; void *ptr = 0; static bits256 zero; + int32_t checki,hdrsi; void *ptr = 0; static const bits256 zero; *filesizep = 0; if ( (checki= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,bp->hashes[bundlei],zero,1,1)) != bundlei || bundlei < 0 || bundlei >= coin->chain->bundlesize ) { @@ -2030,7 +2030,7 @@ void iguana_bundlemapfree(struct iguana_info *coin,struct OS_memspace *mem,struc int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,struct iguana_ramchain *newchain,struct OS_memspace *hashmem,int32_t cmpflag,struct iguana_bundle *bp) { - static bits256 zero; + static const bits256 zero; bits256 firsthash2,lasthash2; int32_t err,bundlei,hdrsi,numblocks,firsti,height,retval= -1; struct iguana_ramchain checkR,*mapchain; char fname[1024]; uint32_t scriptspace,scriptoffset,stacksize; uint8_t *destoffset,*srcoffset; @@ -2115,7 +2115,7 @@ int32_t iguana_ramchain_expandedsave(struct iguana_info *coin,RAMCHAIN_FUNC,stru struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag) { - static bits256 zero; + static const bits256 zero; struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512]; struct iguana_block *block; struct iguana_ramchain *mapchain; memset(ramchain,0,sizeof(*ramchain)); @@ -2128,7 +2128,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana T = (void *)(long)((long)mapchain->H.data + mapchain->H.data->Toffset); for (i=0; in; i++) { - if ( (block= bp->blocks[i]) != 0 || (block= iguana_blockhashset(coin,bp->bundleheight+i,bp->hashes[i],1)) != 0 ) + if ( (block= bp->blocks[i]) != 0 || (block= iguana_blockhashset("bundleload",coin,bp->bundleheight+i,bp->hashes[i],1)) != 0 ) { block->queued = 1; block->height = bp->bundleheight + i; @@ -2250,7 +2250,7 @@ int32_t iguana_mapchaininit(struct iguana_info *coin,struct iguana_ramchain *map // helper threads: NUM_HELPERS int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,uint32_t starttime) // helper thread { - static int depth; static bits256 zero; + static int depth; static const bits256 zero; RAMCHAIN_DESTDECLARE; RAMCHAIN_DECLARE; void **ptrs; long *filesizes; uint32_t *ipbits; char fname[1024]; struct iguana_ramchain *R,*mapchain,*dest,newchain; uint32_t fpipbits; @@ -2281,9 +2281,9 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi); return(-1); } - if ( (block= bp->blocks[bundlei]) == 0 || bits256_nonz(block->RO.hash2) == 0 || block != iguana_blockfind(coin,block->RO.hash2) || memcmp(block->RO.hash2.bytes,bp->hashes[bundlei].bytes,sizeof(bits256)) != 0 ) + if ( (block= bp->blocks[bundlei]) == 0 || bits256_nonz(block->RO.hash2) == 0 || memcmp(block->RO.hash2.bytes,bp->hashes[bundlei].bytes,sizeof(bits256)) != 0 ) // block != iguana_blockfind("bundlesave",coin,block->RO.hash2) { - printf("block.%p error vs %p\n",block,iguana_blockfind(coin,block->RO.hash2)); + printf("block.%p error vs %p\n",block,iguana_blockfind("bundlesaveerr",coin,block->RO.hash2)); break; } fpipbits = block->fpipbits, fpos = block->fpos; @@ -2336,7 +2336,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi); return(-1); } - if ( (block= bp->blocks[i]) != 0 && block == iguana_blockfind(coin,bp->hashes[i]) ) + if ( (block= bp->blocks[i]) != 0 )//&& block == iguana_blockfind("saveHT",coin,bp->hashes[i]) ) { if ( bits256_nonz(block->RO.prev_block) == 0 && i > 0 ) block->RO.prev_block = bp->hashes[i-1]; @@ -2348,7 +2348,7 @@ int32_t iguana_bundlesaveHT(struct iguana_info *coin,struct OS_memspace *mem,str return(-1); } destB[i] = block->RO; - } else printf("error getting block (%d:%d) %p vs %p\n",bp->hdrsi,i,block,iguana_blockfind(coin,bp->hashes[i])); + } else printf("error getting block (%d:%d) %p vs %p\n",bp->hdrsi,i,block,bp->blocks[i]); } dest->H.txidind = dest->H.unspentind = dest->H.spendind = dest->pkind = dest->H.data->firsti; dest->externalind = dest->H.stacksize = 0; @@ -2439,7 +2439,7 @@ void iguana_mergefree(struct iguana_info *coin,struct OS_memspace *mem,struct ig int32_t iguana_bundlemergeHT(struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,struct iguana_bundle *nextbp,uint32_t starttime) { - static int32_t depth; static bits256 zero; + static int32_t depth; static const bits256 zero; RAMCHAIN_DESTDECLARE; struct OS_memspace HASHMEM,HASHMEMA,HASHMEMB; uint32_t now = (uint32_t)time(NULL); char str[65],fnameA[1024],fnameB[1024]; struct iguana_ramchain _Achain,_Bchain,*A,*B,R,newchain,*dest = &R; int32_t err,retval = -1,firsti = 1; diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index cc3d73926..f304b4fd0 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -161,7 +161,7 @@ void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,st struct iguana_txblock *iguana_peertxdata(struct iguana_info *coin,int32_t *bundleip,char *fname,struct OS_memspace *mem,uint32_t ipbits,bits256 hash2) { int32_t bundlei,datalen,checki,hdrsi,fpos; char str[65],str2[65]; FILE *fp; - bits256 checkhash2; struct iguana_txblock *txdata = 0; static bits256 zero; + bits256 checkhash2; struct iguana_txblock *txdata = 0; static const bits256 zero; if ( (bundlei= iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,ipbits,hash2,zero,1)) >= 0 ) //if ( (bundlei= iguana_peerfname(coin,&hdrsi,fname,ipbits,hash2)) >= 0 ) { @@ -485,65 +485,9 @@ void iguana_gotblockhashesM(struct iguana_info *coin,struct iguana_peer *addr,bi printf("bundlesQ blockhashes.%s [%d]\n",bits256_str(str,blockhashes[1]),n); queue_enqueue("recvQ",&coin->recvQ,&req->DL,0); if ( n > coin->chain->bundlesize ) - iguana_blockQ("hashesM",coin,0,-1,blockhashes[1],1); + iguana_sendblockreqPT(coin,addr,0,-1,blockhashes[1],0); } -/*void iguana_patch(struct iguana_info *coin,struct iguana_block *block) -{ - int32_t i,j,origheight,height; struct iguana_block *prev,*next; struct iguana_bundle *bp; - prev = iguana_blockhashset(coin,-1,block->RO.prev_block,1); - block->hh.prev = prev; - if ( prev != 0 ) - { - if ( prev->mainchain != 0 ) - { - prev->hh.next = block; - if ( memcmp(block->RO.prev_block.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 ) - _iguana_chainlink(coin,block); - if ( (next= block->hh.next) != 0 && bits256_nonz(next->RO.hash2) > 0 ) - next->height = block->height + 1; - } - else if ( 0 && block->height < 0 ) - { - for (i=0; i<1; i++) - { - if ( (prev= prev->hh.prev) == 0 ) - break; - if ( prev->mainchain != 0 && prev->height >= 0 ) - { - j = i; - origheight = (prev->height + i + 2); - prev = block->hh.prev; - height = (origheight - 1); - while ( i > 0 && prev != 0 ) - { - if ( prev->mainchain != 0 && prev->height != height ) - { - printf("mainchain height mismatch j.%d at i.%d %d != %d\n",j,i,prev->height,height); - break; - } - prev = prev->hh.prev; - height--; - } - if ( i == 0 ) - { - //printf("SET HEIGHT.%d j.%d\n",origheight,j); - if ( (bp= coin->bundles[origheight / coin->chain->bundlesize]) != 0 ) - { - iguana_bundlehash2add(coin,0,bp,origheight % coin->chain->bundlesize,block->RO.hash2); - block->height = origheight; - block->mainchain = 1; - prev = block->hh.prev; - prev->hh.next = block; - } - } //else printf("break at i.%d for j.%d origheight.%d\n",i,j,origheight); - break; - } - } - } - } -}*/ - uint32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bits256 *blockhashes,int32_t num) { bits256 allhash; int32_t err,i,n; struct iguana_block *block,*prev; @@ -553,7 +497,7 @@ uint32_t iguana_allhashcmp(struct iguana_info *coin,struct iguana_bundle *bp,bit if ( memcmp(allhash.bytes,bp->allhash.bytes,sizeof(allhash)) == 0 ) { if ( bp->bundleheight > 0 ) - prev = iguana_blockfind(coin,iguana_blockhash(coin,bp->bundleheight-1)); + prev = iguana_blockfind("allhashcmp",coin,iguana_blockhash(coin,bp->bundleheight-1)); else prev = 0; for (i=n=0; ichain->bundlesize&&in; i++) { @@ -612,17 +556,75 @@ void iguana_bundlespeculate(struct iguana_info *coin,struct iguana_bundle *bp,in } */ //else printf("speculative.%p %d vs %d cmp.%d\n",bp->speculative,bundlei,bp->numspec,bp->speculative!=0?memcmp(hash2.bytes,bp->speculative[bundlei].bytes,sizeof(hash2)):-1);*/ } +int32_t iguana_bundlehashadd(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block) +{ + static const bits256 zero; + struct iguana_ramchain blockR; int32_t hdrsi,checki; long size = 0; FILE *fp; char fname[1024]; + block->bundlei = bundlei; + block->hdrsi = bp->hdrsi; + if ( bits256_nonz(bp->hashes[bundlei]) != 0 && bits256_cmp(bp->hashes[bundlei],block->RO.hash2) != 0 ) + { + char str[65],str2[65]; printf("mismatched.[%d:%d] %s <-? %s%s\n",bp->hdrsi,bundlei,bits256_str(str,bp->hashes[bundlei]),bits256_str(str2,block->RO.hash2),block->mainchain?".main":""); + if ( block == bp->blocks[bundlei] ) + { + if ( block->mainchain == 0 ) + return(-1); + } + else if ( bp->blocks[bundlei] != 0 ) + { + printf("mismatched blockptr.%p vs %p\n",block,bp->blocks[bundlei]); + return(-1); + } + } + bp->blocks[bundlei] = block; + iguana_bundlehash2add(coin,0,bp,bundlei,block->RO.hash2); + if ( bp->emitfinish == 0 ) + { + block->fpos = -1; + if ( iguana_ramchainfile(coin,0,&blockR,bp,bundlei,block) == 0 ) + { + size = sizeof(blockR); + iguana_ramchain_free(coin,&blockR,1); + } + else if ( 0 && block->txvalid == 0 && bp->hdrsi == coin->longestchain/bp->n ) + { + checki = iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1,0); + if ( (fp= fopen(fname,"rb")) != 0 ) + { + fseek(fp,0,SEEK_END); + size = (uint32_t)ftell(fp); + fclose(fp); + } + } + if ( size != 0 ) + { + printf("initialize with fp.[%d:%d] len.%ld\n",bp->hdrsi,bundlei,size); + block->RO.recvlen = (int32_t)size; + block->fpipbits = 1; + block->txvalid = 1; + block->fpos = 0; + block->issued = (uint32_t)time(NULL); + } + else + { + if ( block->issued == 0 ) + iguana_blockQ("bundleset",coin,bp,bundlei,block->RO.hash2,coin->current == 0 || bp->hdrsi <= coin->current->hdrsi+coin->MAXBUNDLES); + iguana_blockunmark(coin,block,bp,bundlei,0); + } + } + return(0); +} // main context, ie single threaded struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_block **blockp,int32_t *bundleip,struct iguana_block *origblock) { - struct iguana_block *block,*prevblock; bits256 zero,hash2,prevhash2; struct iguana_bundle *prevbp,*bp = 0; int32_t prevbundlei,hdrsi,checki,bundlei = -2; FILE *fp; char fname[1024]; // struct iguana_ramchain blockR; + struct iguana_block *block,*prevblock; bits256 zero,hash2,prevhash2; struct iguana_bundle *prevbp,*bp = 0; int32_t prevbundlei,bundlei = -2; // struct iguana_ramchain blockR; *bundleip = -2; *blockp = 0; if ( origblock == 0 ) return(0); memset(zero.bytes,0,sizeof(zero)); hash2 = origblock->RO.hash2; - if ( (block= iguana_blockhashset(coin,-1,hash2,1)) != 0 ) + if ( (block= iguana_blockhashset("bundleset",coin,-1,hash2,1)) != 0 ) { prevhash2 = origblock->RO.prev_block; if ( block != origblock ) @@ -636,47 +638,14 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl bp = 0, bundlei = -2; if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei < coin->chain->bundlesize ) { + iguana_bundlehashadd(coin,bp,bundlei,block); //fprintf(stderr,"bundle found %d:%d\n",bp->hdrsi,bundlei); - block->bundlei = bundlei; - block->hdrsi = bp->hdrsi; - bp->blocks[bundlei] = block; - iguana_bundlehash2add(coin,0,bp,bundlei,hash2); - /*if ( iguana_ramchainfile(coin,0,&blockR,bp,bundlei,block) == 0 ) - { - block->RO.recvlen = sizeof(blockR); - iguana_ramchain_free(coin,&blockR,1); - block->fpipbits = 1; - block->txvalid = 1; - block->fpos = 0; - block->issued = (uint32_t)time(NULL); - } - else if ( block->issued == 0 ) - iguana_blockQ("bundleset",coin,bp,bundlei,block->RO.hash2,coin->current == 0 || bp->hdrsi <= coin->current->hdrsi+coin->MAXBUNDLES);*/ - if ( bp->emitfinish == 0 && block->txvalid == 0 && bp->hdrsi == coin->longestchain/bp->n )//&& bits256_nonz(block->RO.hash2) != 0 && b - { - block->fpos = -1; - checki = iguana_peerfname(coin,&hdrsi,GLOBALTMPDIR,fname,0,block->RO.hash2,zero,1,0); - if ( (fp= fopen(fname,"rb")) != 0 ) - { - fseek(fp,0,SEEK_END); - block->RO.recvlen = (uint32_t)ftell(fp); - block->fpipbits = 1; - block->txvalid = 1; - block->fpos = 0; - block->issued = (uint32_t)time(NULL); - printf("initialize with fp.[%d:%d] len.%d\n",hdrsi,bundlei,block->RO.recvlen); - fclose(fp); - } - else iguana_blockunmark(coin,block,bp,bundlei,1); - } - if ( block->issued == 0 ) - iguana_blockQ("bundleset",coin,bp,bundlei,block->RO.hash2,coin->current == 0 || bp->hdrsi <= coin->current->hdrsi+coin->MAXBUNDLES); - - //printf("bundlehashadd set.%d\n",bundlei); + //printf("bundlehashadd set.%d\n",bundlei); if ( bundlei > 0 ) { //printf("bundlehashadd prev %d\n",bundlei); - iguana_bundlehash2add(coin,0,bp,bundlei-1,prevhash2); + if ( bits256_nonz(prevhash2) != 0 ) + iguana_bundlehash2add(coin,0,bp,bundlei-1,prevhash2); } else if ( bp->hdrsi > 0 && (bp= coin->bundles[bp->hdrsi-1]) != 0 ) iguana_bundlehash2add(coin,0,bp,coin->chain->bundlesize-1,prevhash2); @@ -687,7 +656,7 @@ struct iguana_bundle *iguana_bundleset(struct iguana_info *coin,struct iguana_bl iguana_bundlefind(coin,&prevbp,&prevbundlei,prevhash2); //if ( 0 && block->blockhashes != 0 ) // fprintf(stderr,"has blockhashes bp.%p[%d] prevbp.%p[%d]\n",bp,bundlei,prevbp,prevbundlei); - if ( prevbp != 0 && prevbundlei >= 0 && (prevblock= iguana_blockfind(coin,prevhash2)) != 0 ) + if ( prevbp != 0 && prevbundlei >= 0 && (prevblock= iguana_blockfind("bundleset2",coin,prevhash2)) != 0 ) { if ( prevbundlei < coin->chain->bundlesize ) { @@ -752,31 +721,6 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct iguana_info *coin,struct ig } if ( blocks != 0 && n > 0 ) { - /*if ( 0 && n >= coin->chain->bundlesize ) - { - blockhashes = malloc(sizeof(*blockhashes) * coin->chain->bundlesize); - for (i=0; ichain->bundlesize; i++) - blockhashes[i] = blocks[i].RO.hash2; - for (i=0; ibundlescount; i++) - { - if ( (bp= coin->bundles[i]) != 0 && bp->emitfinish == 0 ) - { - blockhashes[0] = bp->hashes[0]; - vcalc_sha256(0,allhash.bytes,blockhashes[0].bytes,coin->chain->bundlesize * sizeof(*blockhashes)); - if ( bits256_cmp(allhash,bp->allhash) == 0 ) - { - if ( bp->queued != 0 ) - bp->queued = 0; - if ( iguana_allhashcmp(coin,bp,blockhashes,coin->chain->bundlesize) > 0 ) - { - free(blockhashes); - return(req); - } - } - } - } - free(blockhashes); - }*/ for (i=match=0; ihdrsi == coin->bundlescount-1 && bits256_nonz(bp->nextbundlehash2) != 0 ) { init_hexbytes_noT(hashstr,bp->nextbundlehash2.bytes,sizeof(bits256)); @@ -840,7 +784,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct memset(zero.bytes,0,sizeof(zero)); bp = 0, bundlei = -2; iguana_bundlefind(coin,&bp,&bundlei,blockhashes[1]); - if ( 1 && num >= 2*coin->chain->bundlesize ) + if ( 1 && num >= coin->chain->bundlesize ) 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); @@ -874,6 +818,8 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct for (i=bp->numspec; in; i++) { bp->speculative[i] = blockhashes[i]; + if ( bp->blocks[i] == 0 ) + bp->blocks[i] = iguana_blockhashset("recvhashes3",coin,bp->bundleheight+i,blockhashes[i],1); //printf("speculate new issue [%d:%d]\n",bp->hdrsi,i); if ( 0 && bp->blocks[i] == 0 ) iguana_blockQ("speculate",coin,bp,-i,blockhashes[i],0); @@ -914,7 +860,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct } //printf("%s no match to allhashes\n",bits256_str(str,blockhashes[1])); struct iguana_block *block; - if ( (block= iguana_blockhashset(coin,-1,blockhashes[1],1)) != 0 ) + if ( (block= iguana_blockhashset("recvhashes",coin,-1,blockhashes[1],1)) != 0 ) { //block->blockhashes = blockhashes, req->hashes = 0; //printf("set block->blockhashes[%d]\n",num); @@ -931,10 +877,10 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct iguana_info *coin,struct } else { - if ( (block= iguana_blockfind(coin,blockhashes[1])) == 0 ) + if ( (block= iguana_blockfind("recvhashes2",coin,blockhashes[1])) == 0 ) { - iguana_blockhashset(coin,-1,blockhashes[1],1); - if ( (block= iguana_blockfind(coin,blockhashes[1])) != 0 ) + iguana_blockhashset("recvhashes3",coin,-1,blockhashes[1],1); + if ( (block= iguana_blockfind("recvhashes4",coin,blockhashes[1])) != 0 ) iguana_blockQ("recvhash6",coin,0,-6,blockhashes[1],1); // should be RT block } block->newtx = 1; @@ -994,7 +940,7 @@ struct iguana_bundlereq *iguana_recvblock(struct iguana_info *coin,struct iguana printf("reissue hdrs request for [%d]\n",bp->hdrsi); queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(bits256_str(str,bp->hashes[0])),1); } - if ( (block= iguana_blockhashset(coin,-1,origblock->RO.hash2,1)) != 0 ) + if ( (block= iguana_blockhashset("recvblock",coin,-1,origblock->RO.hash2,1)) != 0 ) { if ( block != origblock ) iguana_blockcopy(coin,block,origblock); @@ -1056,12 +1002,16 @@ 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,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; char str[1024]; + if ( time(NULL) < coin->lastreqtime+2 ) + return(0); + iguana_bundlestats(coin,str,IGUANA_DEFAULTLAG); + coin->lastreqtime = (uint32_t)time(NULL); hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize; if ( (bp= coin->bundles[hdrsi]) != 0 ) { bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; - if ( (next= bp->blocks[bundlei]) != 0 || (next= iguana_blockfind(coin,bp->hashes[bundlei])) != 0 ) + if ( (next= bp->blocks[bundlei]) != 0 || (next= iguana_blockfind("reqblocks",coin,bp->hashes[bundlei])) != 0 ) { if ( bits256_nonz(next->RO.prev_block) > 0 ) _iguana_chainlink(coin,next); @@ -1079,9 +1029,9 @@ int32_t iguana_reqblocks(struct iguana_info *coin) lflag = 0; hdrsi = (coin->blocks.hwmchain.height+1) / coin->chain->bundlesize; bundlei = (coin->blocks.hwmchain.height+1) % coin->chain->bundlesize; - if ( (next= iguana_blockfind(coin,iguana_blockhash(coin,coin->blocks.hwmchain.height+1))) == 0 ) + if ( (next= iguana_blockfind("reqloop",coin,iguana_blockhash(coin,coin->blocks.hwmchain.height+1))) == 0 ) { - if ( (block= iguana_blockfind(coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) + if ( (block= iguana_blockfind("reqloop2",coin,coin->blocks.hwmchain.RO.hash2)) != 0 ) next = block->hh.next; //, next/block->mainchain = 1; } if ( next == 0 && hdrsi < coin->bundlescount && (bp= coin->bundles[hdrsi]) != 0 && (next= bp->blocks[bundlei]) != 0 ) @@ -1130,7 +1080,7 @@ int32_t iguana_reqblocks(struct iguana_info *coin) hash2 = bp->speculative[bundlei]; if ( bits256_nonz(hash2) > 0 ) { - if ( (block= iguana_blockfind(coin,hash2)) != 0 && bits256_cmp(block->RO.prev_block,coin->blocks.hwmchain.RO.hash2) == 0 ) + if ( (block= iguana_blockfind("reqblocks",coin,hash2)) != 0 && bits256_cmp(block->RO.prev_block,coin->blocks.hwmchain.RO.hash2) == 0 ) { //printf("speculative is next at %d\n",coin->backstop); if ( _iguana_chainlink(coin,block) != 0 ) @@ -1178,7 +1128,7 @@ int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single *newhwmp = 0; while ( coin->active != 0 && (req= queue_dequeue(&coin->recvQ,0)) != 0 ) { - if ( (flag % 100) == 50 ) + if ( (flag % 1000) == 500 ) iguana_reqblocks(coin); flag++; //fprintf(stderr,"flag.%d %s recvQ.%p type.%c n.%d\n",flag,req->addr != 0 ? req->addr->ipaddr : "0",req,req->type,req->n); @@ -1215,7 +1165,6 @@ int32_t iguana_processrecvQ(struct iguana_info *coin,int32_t *newhwmp) // single if ( flag >= IGUANA_BUNDLELOOP ) break; } - iguana_reqblocks(coin); return(flag); } @@ -1284,7 +1233,7 @@ int32_t iguana_blockQ(char *argstr,struct iguana_info *coin,struct iguana_bundle } //lag = (priority == 0) ? IGUANA_DEFAULTLAG*3 : IGUANA_DEFAULTLAG; now = (uint32_t)time(NULL); - block = iguana_blockfind(coin,hash2); + block = iguana_blockfind("blockQ",coin,hash2); if ( priority != 0 || block == 0 )//|| iguana_blockstatus(coin,block) == 0 ) { if ( bp != 0 ) @@ -1471,7 +1420,12 @@ int32_t iguana_processrecv(struct iguana_info *coin) // single threaded int32_t newhwm = 0,hwmheight,flag = 0; hwmheight = coin->blocks.hwmchain.height; flag += iguana_processrecvQ(coin,&newhwm); + flag += iguana_reqblocks(coin); flag += iguana_reqhdrs(coin); + coin->RTramchain_busy = 1; + flag += (iguana_realtime_update(coin) > 0); + coin->RTramchain_busy = (coin->RTgenesis == 0 || queue_size(&balancesQ) != 0); + iguana_jsonQ(); if ( hwmheight != coin->blocks.hwmchain.height ) flag = 1; return(flag); diff --git a/iguana/iguana_unspents.c b/iguana/iguana_unspents.c index 9714bfe95..1589f17b3 100755 --- a/iguana/iguana_unspents.c +++ b/iguana/iguana_unspents.c @@ -697,7 +697,6 @@ uint32_t iguana_spendvectorconv(struct iguana_info *coin,struct iguana_spendvect count++; if ( (count % 1000000) == 0 ) printf("iguana_spendvectorconv.[%llu] errs.%llu converted.%llu %.2f%%\n",(long long)count,(long long)errs,(long long)converted,100. * (long long)converted/count); - //printf("[%d] tmpflag.%d u%d %.8f p%u\n",ptr->hdrsi,ptr->tmpflag,ptr->unspentind,dstr(ptr->value),ptr->pkind); if ( ptr->tmpflag != 0 ) { if ( ptr->hdrsi >= 0 && ptr->hdrsi < coin->bundlescount && (spentbp= coin->bundles[ptr->hdrsi]) != 0 ) @@ -716,6 +715,7 @@ uint32_t iguana_spendvectorconv(struct iguana_info *coin,struct iguana_spendvect errs++; return(0); } + else printf("[%d] tmpflag.%d u%d %.8f p%u\n",ptr->hdrsi,ptr->tmpflag,ptr->unspentind,dstr(ptr->value),ptr->pkind); return(ptr->pkind); } @@ -859,6 +859,7 @@ int32_t iguana_spendvectors(struct iguana_info *coin,struct iguana_bundle *bp) } else { + memset(&ptr[emit],0,sizeof(ptr[emit])); ptr[emit].hdrsi = spentbp->hdrsi; ptr[emit].unspentind = spent_unspentind; ptr[emit].fromheight = bp->bundleheight + i; @@ -1253,7 +1254,7 @@ int32_t iguana_volatileinit(struct iguana_info *coin) fclose(fp); } if ( filecrc != 0 ) - printf("have filecrc.%08x for %s milli.%.0f\n",filecrc,bits256_str(str,balancehash),OS_milliseconds()); + printf("have filecrc.%08x for %s milli.%.0f from_ro.%d\n",filecrc,bits256_str(str,balancehash),OS_milliseconds(),from_ro); if ( from_ro == 0 ) { if ( filecrc == 0 ) @@ -1429,7 +1430,7 @@ int32_t iguana_realtime_update(struct iguana_info *coin) printf("blockhash error at %d\n",coin->RTheight-n-1); break; } - block = iguana_blockfind(coin,block->RO.prev_block); + block = iguana_blockfind("RTupdate",coin,block->RO.prev_block); n++; if ( coin->RTgenesis != 0 && n >= bp->n ) break; diff --git a/iguana/main.c b/iguana/main.c index dc3e9e274..587368579 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -370,10 +370,6 @@ void mainloop(struct supernet_info *myinfo) //printf("done main active.%d started.%p\n",coin->active,coin->started); //iguana_reqblocks(coin); //printf("done2 main active.%d started.%p\n",coin->active,coin->started); - coin->RTramchain_busy = 1; - if ( iguana_realtime_update(coin) > 0 ) - flag++; - if ( (ptr= queue_dequeue(&balancesQ,0)) != 0 ) { bp = ptr->bp; @@ -415,15 +411,13 @@ void mainloop(struct supernet_info *myinfo) } } } - coin->RTramchain_busy = (coin->RTgenesis == 0 || queue_size(&balancesQ) != 0); if ( 0 && flag != 0 ) printf("call RT update busy.%d\n",coin->RTramchain_busy); } } } - iguana_jsonQ(); pangea_queues(SuperNET_MYINFO(0)); - if ( flag == 0 ) + //if ( flag == 0 ) usleep(1000 + isRT*100000 + (numpeers == 0)*1000000); } } diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index c3940b802..f17e2676b 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -54,7 +54,7 @@ HASH_AND_INT(bitcoinrpc,getblock,blockhash,remoteonly) char *blockstr; struct iguana_msgblock msg; struct iguana_block *block; cJSON *retjson; bits256 txid; retjson = cJSON_CreateObject(); memset(&msg,0,sizeof(msg)); - if ( remoteonly == 0 && (block= iguana_blockfind(coin,blockhash)) != 0 ) + if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 ) { return(jprint(iguana_blockjson(coin,block,1),1)); /* int32_t len,i; char str[65],hexstr[(sizeof(uint32_t)+sizeof(struct iguana_msgblock))*2+1],*blockstr; diff --git a/pangea/hostnet777.c b/pangea/hostnet777.c index 7aebec1e2..fcf25ead8 100755 --- a/pangea/hostnet777.c +++ b/pangea/hostnet777.c @@ -145,7 +145,7 @@ extern int32_t Debuglevel; #include "../includes/curve25519.h" -static bits256 zeropoint; +static const bits256 zeropoint; int64_t hostnet777_convmT(struct hostnet777_mtime *mT,int64_t othermillitime) {