From 25660ec88e5497794d127c9463b0f3d4c002b6d3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 8 Sep 2016 04:17:39 -0300 Subject: [PATCH] debug version --- basilisk/basilisk.c | 5 +- gecko/gecko.c | 4 +- gecko/gecko_blocks.c | 8 +-- gecko/gecko_headers.c | 4 +- gecko/gecko_mempool.c | 2 +- gecko/gecko_miner.c | 2 +- iguana/coins/genbtcd | 2 +- iguana/coins/genbtcdsigs | 1 + iguana/confs/BTCD_peers.txt | 1 + iguana/iguana777.c | 24 ++++---- iguana/iguana_accept.c | 10 ++-- iguana/iguana_blocks.c | 10 ++-- iguana/iguana_bundles.c | 42 ++++++------- iguana/iguana_chains.c | 28 ++++----- iguana/iguana_init.c | 10 ++-- iguana/iguana_interpreter.c | 52 +++++++++------- iguana/iguana_msg.c | 71 +++++++++++++++------- iguana/iguana_payments.c | 100 ++++++++++++++++++++----------- iguana/iguana_peers.c | 18 +++--- iguana/iguana_ramchain.c | 8 +-- iguana/iguana_realtime.c | 2 +- iguana/iguana_recv.c | 18 +++--- iguana/iguana_scripts.c | 9 ++- iguana/iguana_sign.c | 112 ++++++++++++++++++----------------- iguana/iguana_spendvectors.c | 6 +- iguana/iguana_tx.c | 17 ++---- iguana/iguana_wallet.c | 9 ++- iguana/main.c | 2 +- iguana/ramchain_api.c | 6 +- includes/iguana_funcs.h | 52 ++++++++-------- includes/iguana_structs.h | 4 +- 31 files changed, 357 insertions(+), 282 deletions(-) create mode 100755 iguana/coins/genbtcdsigs diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index ba9ab65ba..81c7b9a91 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -838,10 +838,10 @@ void basilisks_loop(void *arg) { if ( time(NULL) > coin->lastunspentsupdate+10 ) { - //printf(">>>>>>>>>>>>> update\n"); + //printf(">>>>>>>>>>>>> update %s\n",coin->symbol); basilisk_unspents_update(myinfo,coin); coin->lastunspentsupdate = (uint32_t)time(NULL); - //printf(">>>>>>>>>>>>> update finished\n"); + //printf(">>>>>>>>>>>>> update %s finished\n",coin->symbol); } } if ( RELAYID < 0 && myinfo->expiration != 0 ) @@ -968,6 +968,7 @@ HASH_ARRAY_STRING(basilisk,history,hash,vals,hexstr) jadd(retjson,"spends",spends); jaddstr(retjson,"coin",coin->symbol); jaddnum(retjson,"balance",dstr(total)); + //printf("return history balance %s %.8f\n",coin->symbol,dstr(total)); return(jprint(retjson,1)); } diff --git a/gecko/gecko.c b/gecko/gecko.c index 496279174..cfb88c1f3 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -179,7 +179,7 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo virt->chain = calloc(1,sizeof(*virt->chain)); virt->enableCACHE = 1; serialized = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); - iguana_chaininit(virt->chain,1,valsobj); + iguana_chaininit(myinfo,virt->chain,1,valsobj); virt->chain->isPoS = 1; hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); if ( gecko_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits,0,0) > 0 ) @@ -212,7 +212,7 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo if ( virt->blocks.hwmchain.height == 0 ) { memset(&txdata,0,sizeof(txdata)); - if ( (n= iguana_gentxarray(virt,&virt->TXMEM,&txdata,&len,serialized,datalen) == datalen) || n == datalen-1 ) + if ( (n= iguana_gentxarray(myinfo,virt,&virt->TXMEM,&txdata,&len,serialized,datalen) == datalen) || n == datalen-1 ) { txdata.zblock.height = 0; txdata.zblock.RO.allocsize = iguana_ROallocsize(virt); diff --git a/gecko/gecko_blocks.c b/gecko/gecko_blocks.c index 0e0b61045..d1c0e1dbe 100755 --- a/gecko/gecko_blocks.c +++ b/gecko/gecko_blocks.c @@ -169,7 +169,7 @@ int32_t gecko_hwmset(struct supernet_info *myinfo,struct iguana_info *virt,struc prevbp->emitfinish = (uint32_t)(time(NULL) - 3600); iguana_bundlepurgefiles(virt,prevbp); iguana_savehdrs(virt); - iguana_bundlevalidate(virt,prevbp,1); + iguana_bundlevalidate(myinfo,virt,prevbp,1); for (i=0; iRO.txn_count; i++) gecko_txidpurge(virt,txarray[i].txid); } @@ -186,7 +186,7 @@ char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_info *virt,c struct iguana_txblock txdata; int32_t height,valid,adjacent,gap,n,i,j,len = -1; struct iguana_block *block,*prev; struct iguana_txid tx; char str[65],str2[65]; bits256 txid,threshold; struct iguana_msgtx *txs; memset(&txdata,0,sizeof(txdata)); iguana_memreset(&virt->TXMEM); - if ( (n= iguana_gentxarray(virt,&virt->TXMEM,&txdata,&len,data,datalen)) == datalen || n == datalen-1 ) + if ( (n= iguana_gentxarray(myinfo,virt,&virt->TXMEM,&txdata,&len,data,datalen)) == datalen || n == datalen-1 ) { if ( bits256_cmp(hash2,txdata.zblock.RO.hash2) != 0 ) { @@ -212,7 +212,7 @@ char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_info *virt,c } else printf("%s is new txid ht.%d i.%d\n",bits256_str(str,txid),virt->blocks.hwmchain.height,i); } txdata.zblock.RO.allocsize = iguana_ROallocsize(virt); - if ( iguana_blockvalidate(virt,&valid,(struct iguana_block *)&txdata.zblock,1) < 0 ) + if ( iguana_blockvalidate(myinfo,virt,&valid,(struct iguana_block *)&txdata.zblock,1) < 0 ) { char str[65]; printf("got block that doesnt validate? %s\n",bits256_str(str,txdata.zblock.RO.hash2)); return(clonestr("{\"error\":\"gecko block didnt validate\"}")); @@ -316,7 +316,7 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a //nBits = gecko_nBits(virt,&prevtimestamp,(struct iguana_block *)&virt->blocks.hwmchain,GECKO_DIFFITERS); //if ( gecko_blocknonce_verify(virt,data,hdrsize,nBits,virt->blocks.hwmchain.RO.timestamp,prevtimestamp) > 0 ) { - iguana_rwblock(symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen); + iguana_rwblock(myinfo,symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen); if ( bits256_cmp(hash2,checkhash2) == 0 ) { if ( gecko_blocknonce_verify(virt,data,hdrsize,msg.H.bits,0,0) > 0 ) diff --git a/gecko/gecko_headers.c b/gecko/gecko_headers.c index 520a3253b..71be8fef3 100755 --- a/gecko/gecko_headers.c +++ b/gecko/gecko_headers.c @@ -28,7 +28,7 @@ int32_t basilisk_respond_geckogetheaders(struct supernet_info *myinfo,struct igu { if ( block != 0 ) { - if ( (n= iguana_headerget(virt,&serialized[len],maxsize-len,block)) > 0 ) + if ( (n= iguana_headerget(myinfo,virt,&serialized[len],maxsize-len,block)) > 0 ) len += n; } hash2 = iguana_blockhash(virt,height+i+1); @@ -62,7 +62,7 @@ char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt prevhash2 = firsthash2; for (i=0; isymbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&hash2,&data[len],&msgB,datalen-len)) > 0 ) + if ( (n= iguana_rwblock(myinfo,virt->symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&hash2,&data[len],&msgB,datalen-len)) > 0 ) { if ( bits256_cmp(msgB.H.prev_block,prevhash2) == 0 ) { diff --git a/gecko/gecko_mempool.c b/gecko/gecko_mempool.c index 9ce486958..7bd5fbcf8 100755 --- a/gecko/gecko_mempool.c +++ b/gecko/gecko_mempool.c @@ -229,7 +229,7 @@ char *gecko_txarrived(struct supernet_info *myinfo,struct iguana_info *virt,char struct gecko_mempool *pool; int64_t txfee,vinstotal,voutstotal; uint64_t value; int32_t i,numvins,numvouts,txlen,spentheight,minconf,maxconf; struct iguana_msgtx msg; char *rawtx; struct gecko_memtx *memtx; struct iguana_info *btcd; struct iguana_outpoint outpt; memset(&msg,0,sizeof(msg)); iguana_memreset(&virt->TXMEM); - txlen = iguana_rwtx(virt->chain->zcash,0,virt,&virt->TXMEM,serialized,&msg,datalen,&txid,virt->chain->isPoS,strcmp("VPN",virt->symbol) == 0); + txlen = iguana_rwtx(myinfo,virt->chain->zcash,0,virt,&virt->TXMEM,serialized,&msg,datalen,&txid,virt->chain->isPoS,strcmp("VPN",virt->symbol) == 0); vinstotal = voutstotal = 0; maxconf = virt->longestchain; minconf = virt->chain->minconfirms; diff --git a/gecko/gecko_miner.c b/gecko/gecko_miner.c index f77193f93..6db99a1ed 100755 --- a/gecko/gecko_miner.c +++ b/gecko/gecko_miner.c @@ -247,7 +247,7 @@ char *gecko_blockconstruct(struct supernet_info *myinfo,struct iguana_info *virt } } newblock->RO.nonce = *noncep; - n = iguana_serialize_block(virt->chain,&newblock->RO.hash2,serialized,newblock); + n = iguana_serialize_block(myinfo,virt->chain,&newblock->RO.hash2,serialized,newblock); while ( 1 && time(NULL) <= newblock->RO.timestamp + GECKO_MAXFUTUREBLOCK ) { //printf("wait for block to be close enough to now: lag %ld\n",time(NULL) - newblock->RO.timestamp); diff --git a/iguana/coins/genbtcd b/iguana/coins/genbtcd index 46dab365f..c4a9b705c 100755 --- a/iguana/coins/genbtcd +++ b/iguana/coins/genbtcd @@ -1 +1 @@ -curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":8,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632}" +curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":512,\"endpend\":512,\"services\":129,\"maxpeers\":64,\"RELAY\":1,\"VALIDATE\":1,\"portp2p\":14631,\"rpc\":14632}" diff --git a/iguana/coins/genbtcdsigs b/iguana/coins/genbtcdsigs new file mode 100755 index 000000000..662f95c1c --- /dev/null +++ b/iguana/coins/genbtcdsigs @@ -0,0 +1 @@ +curl --url "http://127.0.0.1:7778" --data "{\"prefetchlag\":-1,\"poll\":50,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"newcoin\":\"BTCD\",\"startpend\":8,\"endpend\":4,\"services\":129,\"maxpeers\":64,\"RELAY\":1,\"VALIDATE\":2,\"portp2p\":14631,\"rpc\":14632}" diff --git a/iguana/confs/BTCD_peers.txt b/iguana/confs/BTCD_peers.txt index 34569c8ee..5226d6ac8 100644 --- a/iguana/confs/BTCD_peers.txt +++ b/iguana/confs/BTCD_peers.txt @@ -6,6 +6,7 @@ 89.248.160.242 89.248.160.243 89.248.160.244 +89.248.160.245 85.25.217.233 65.15.37.140 62.75.145.171 diff --git a/iguana/iguana777.c b/iguana/iguana777.c index 05902a5e2..1f3151c86 100755 --- a/iguana/iguana777.c +++ b/iguana/iguana777.c @@ -55,7 +55,7 @@ struct iguana_info *iguana_coinadd(char *symbol,char *name,cJSON *argjson,int32_ } else { - coin->chain = iguana_chainfind((char *)symbol,argjson,1); + coin->chain = iguana_chainfind(myinfo,(char *)symbol,argjson,1); coin->peers = calloc(1,sizeof(*coin->peers)); for (j=0; jDL,0); } -void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit) +void iguana_bundleQ(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit) { struct iguana_helper *ptr; - if ( 0 && bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(coin,bp,0) == bp->n ) + if ( 0 && bp->queued == 0 && bp->emitfinish <= 1 && iguana_bundleready(myinfo,coin,bp,0) == bp->n ) printf("bundle.[%d] is ready\n",bp->hdrsi); bp->queued = (uint32_t)time(NULL); ptr = mycalloc('q',1,sizeof(*ptr)); @@ -302,7 +302,7 @@ void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp) }*/ } -int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete) +int32_t iguana_emitfinished(struct supernet_info *myinfo,struct iguana_info *coin,int32_t queueincomplete) { struct iguana_bundle *bp; int32_t i,n = 0; for (i=0; ibundlescount-1; i++) @@ -312,7 +312,7 @@ int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete) if ( bp->emitfinish > 1 ) n++; else if ( bp->emitfinish == 0 && bp->queued == 0 ) - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); } } return(n); @@ -371,7 +371,7 @@ int32_t iguana_helperA(struct supernet_info *myinfo,struct iguana_info *coin,int return(-1); } //printf("helperid.%d validate gen utxo.[%d] utxofinish.%u\n",helperid,bp->hdrsi,bp->utxofinish); - if ( strcmp("BTC",coin->symbol) == 0 || iguana_bundlevalidate(coin,bp,0) == bp->n ) // + if ( strcmp("BTC",coin->symbol) == 0 || iguana_bundlevalidate(myinfo,coin,bp,0) == bp->n ) // { retval = 0; if ( bp->utxofinish > 1 || (retval= iguana_spendvectors(myinfo,coin,bp,&bp->ramchain,0,bp->n,convertflag,0)) >= 0 ) @@ -529,7 +529,7 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int printf("unexpected null bp for [%d]\n",hdrsi); continue; } - if ( iguana_bundlevalidate(coin,bp,0) != bp->n ) + if ( iguana_bundlevalidate(myinfo,coin,bp,0) != bp->n ) { printf("validate.[%d] error. refresh page or restart iguana and it should regenerate\n",bp->hdrsi); exit(-1); @@ -568,7 +568,7 @@ int32_t iguana_utxogen(struct supernet_info *myinfo,struct iguana_info *coin,int return(num); } -int32_t iguana_coin_mainiter(struct iguana_info *coin,int32_t *numpeersp) +int32_t iguana_coin_mainiter(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numpeersp) { int32_t n,j,isRT = 0; struct iguana_bundle *bp; if ( coin->RTheight == 0 && coin->firstRTheight == 0 && coin->current != 0 && coin->active != 0 && coin->started != 0 ) @@ -582,7 +582,7 @@ int32_t iguana_coin_mainiter(struct iguana_info *coin,int32_t *numpeersp) { n = coin->bundlescount-1; //printf("%s n.%d emitfinished.%d coin->spendvectorsaved %d\n",coin->symbol,n,iguana_emitfinished(coin,1),coin->spendvectorsaved); - if ( iguana_emitfinished(coin,1) >= n ) + if ( iguana_emitfinished(myinfo,coin,1) >= n ) { if ( coin->PREFETCHLAG >= 0 && coin->fastfind == 0 ) { @@ -667,13 +667,13 @@ void iguana_helper(void *arg) //printf("%s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); for (j=helperid; jbundlescount-1; j+=IGUANA_NUMHELPERS) if ( (bp= coin->bundles[j]) != 0 ) - iguana_bundlevalidate(coin,bp,0); + iguana_bundlevalidate(myinfo,coin,bp,0); coin->spendvalidated |= (1 << helperid); //printf("DONE %s spendvectorsaved.%u helperid.%d validate\n",coin->symbol,coin->spendvectorsaved,helperid); } } if ( helperid == 0 ) - iguana_coin_mainiter(coin,&numpeers); + iguana_coin_mainiter(myinfo,coin,&numpeers); } //portable_mutex_unlock(&myinfo->allcoins_mutex); n = queue_size(&bundlesQ); @@ -699,7 +699,7 @@ void iguana_helper(void *arg) { //printf("skip.[%d] nexttime.%u lag.%ld coin->active.%d\n",bp->hdrsi,bp->nexttime,time(NULL)-bp->nexttime,coin->active); allcurrent--; - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); } } else //if ( coin->active != 0 ) diff --git a/iguana/iguana_accept.c b/iguana/iguana_accept.c index b80d6628c..4d18d407a 100755 --- a/iguana/iguana_accept.c +++ b/iguana/iguana_accept.c @@ -198,7 +198,7 @@ int32_t iguana_process_msgrequestQ(struct supernet_info *myinfo,struct iguana_in { if ( coin->FULLNODE != 0 || coin->VALIDATENODE != 0 ) { - if ( (addr= msg->addr) != 0 && (len= iguana_peerblockrequest(coin,coin->blockspace,(int32_t)(coin->blockspacesize - sizeof(struct iguana_msghdr)),0,msg->hash2,0)) > 0 ) + if ( (addr= msg->addr) != 0 && (len= iguana_peerblockrequest(myinfo,coin,coin->blockspace,(int32_t)(coin->blockspacesize - sizeof(struct iguana_msghdr)),0,msg->hash2,0)) > 0 ) { //char str[65]; printf("msg Sendlen.%d block %s to %s\n",len,bits256_str(str,msg->hash2),addr->ipaddr); iguana_queue_send(addr,0,coin->blockspace,"block",len); @@ -288,11 +288,11 @@ int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits2 return(len - sizeof(struct iguana_msghdr)); } -int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block) +int32_t iguana_headerget(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block) { bits256 checkhash2; struct iguana_msgblock msgB; int32_t len = 0; iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,1); - if ( (len= iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&msgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 ) + if ( (len= iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&msgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 ) return(-1); if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 ) { @@ -317,7 +317,7 @@ int32_t iguana_peerhdrrequest(struct supernet_info *myinfo,struct iguana_info *c { if ( (block= bp->blocks[i]) != 0 ) { - if ( (n= iguana_headerget(coin,&serialized[len],maxsize-len,block)) < 0 ) + if ( (n= iguana_headerget(myinfo,coin,&serialized[len],maxsize-len,block)) < 0 ) { printf("%s error getting header ht.%d\n",coin->symbol,block->height); continue; @@ -350,7 +350,7 @@ int32_t iguana_peergetrequest(struct supernet_info *myinfo,struct iguana_info *c break; if ( flag == 0 ) { - if ( getblock != 0 && iguana_peerblockrequest(coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2,0) > 0 ) + if ( getblock != 0 && iguana_peerblockrequest(myinfo,coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2,0) > 0 ) flag = 1; else if ( getblock == 0 && iguana_peerhdrrequest(myinfo,coin,addr->blockspace,IGUANA_MAXPACKETSIZE,addr,hash2) > 0 ) flag = 1; diff --git a/iguana/iguana_blocks.c b/iguana/iguana_blocks.c index 511303f6f..3badb4d62 100755 --- a/iguana/iguana_blocks.c +++ b/iguana/iguana_blocks.c @@ -325,11 +325,11 @@ void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_blo } } -int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag) +int32_t iguana_blockvalidate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag) { bits256 hash2; uint8_t serialized[sizeof(struct iguana_msgblock) + 4096]; *validp = 0; - iguana_serialize_block(coin->chain,&hash2,serialized,block); + iguana_serialize_block(myinfo,coin->chain,&hash2,serialized,block); *validp = (memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0); block->valid = *validp; iguana_blocksizecheck("blockvalidate",coin->chain->zcash,block); @@ -555,7 +555,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan { //if ( memcmp(prev->RO.hash2.bytes,coin->blocks.hwmchain.RO.hash2.bytes,sizeof(bits256)) == 0 ) // prev->mainchain = 1; - if ( bits256_nonz(prev->RO.hash2) == 0 || (prev->valid == 0 && iguana_blockvalidate(coin,&valid,prev,0) < 0) ) + if ( bits256_nonz(prev->RO.hash2) == 0 || (prev->valid == 0 && iguana_blockvalidate(myinfo,coin,&valid,prev,0) < 0) ) { char str[65]; if ( 0 && bits256_nonz(prev->RO.hash2) != 0 ) @@ -588,7 +588,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan return(0); } //char str[65]; printf("extend? %s.h%d: %.15f vs %.15f ht.%d vs %d\n",bits256_str(str,block->RO.hash2),height,block->PoW,coin->blocks.hwmchain.PoW,height,coin->blocks.hwmchain.height); - if ( iguana_blockvalidate(coin,&valid,newblock,0) < 0 || valid == 0 ) + if ( iguana_blockvalidate(myinfo,coin,&valid,newblock,0) < 0 || valid == 0 ) return(0); block->height = height; block->valid = 1; @@ -706,7 +706,7 @@ struct iguana_block *_iguana_chainlink(struct supernet_info *myinfo,struct iguan int32_t iguana_chainextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *newblock) { struct iguana_block *block,*prev; int32_t valid,oldhwm; char str[65]; - if ( iguana_blockvalidate(coin,&valid,newblock,0) < 0 || valid == 0 ) + if ( iguana_blockvalidate(myinfo,coin,&valid,newblock,0) < 0 || valid == 0 ) { printf("chainextend: newblock.%s didnt validate\n",bits256_str(str,newblock->RO.hash2)); return(-1); diff --git a/iguana/iguana_bundles.c b/iguana/iguana_bundles.c index 541c343fb..17aa9c826 100755 --- a/iguana/iguana_bundles.c +++ b/iguana/iguana_bundles.c @@ -752,7 +752,7 @@ int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr) return(n); } -int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag) +int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag) { static bits256 zero; int32_t i,ready,valid; char fname[1024]; struct iguana_block *block; int32_t sum[0x100],counts[0x100]; struct iguana_blockRO *B; struct iguana_bundle *nextbp; void *ptr; long filesize; struct iguana_ramchain R; bits256 prevhash2; @@ -805,7 +805,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int counts[block->peerid]++; } //printf("(%x:%x) ",(uint32_t)block->RO.hash2.ulongs[3],(uint32_t)bp->hashes[i].ulongs[3]); - if ( block->txvalid == 0 || block->fpipbits == 0 || block->fpos < 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(coin,&valid,block,1) < 0 ) + if ( block->txvalid == 0 || block->fpipbits == 0 || block->fpos < 0 || (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0 ) { char str[65]; if ( requiredflag != 0 ) @@ -835,7 +835,7 @@ int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int { iguana_blockunmark(coin,block,bp,i,1); if ( 0 && requiredflag != 0 ) - printf("not ready altpath.(%d %d %d %d %d) [%d:%d]\n",block->txvalid == 0,block->fpipbits == 0 ,block->fpos < 0,(bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0),iguana_blockvalidate(coin,&valid,block,1) < 0,bp->hdrsi,i); + printf("not ready altpath.(%d %d %d %d %d) [%d:%d]\n",block->txvalid == 0,block->fpipbits == 0 ,block->fpos < 0,(bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0),iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0,bp->hdrsi,i); } else { @@ -925,10 +925,10 @@ int32_t iguana_bundletweak(struct iguana_info *coin,struct iguana_bundle *bp) return(coin->MAXBUNDLES); } -int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag) +int64_t iguana_bundlecalcs(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag) { int32_t bundlei,numhashes,numsaved,numrecv,numcached,minrequests; int64_t datasize; struct iguana_block *block; - if ( bp->emitfinish > 0 && (bp->ramchain.H.data != 0 || iguana_bundleready(coin,bp,0) == bp->n) ) + if ( bp->emitfinish > 0 && (bp->ramchain.H.data != 0 || iguana_bundleready(myinfo,coin,bp,0) == bp->n) ) { memset(bp->haveblock,0xff,sizeof(bp->haveblock)); bp->numhashes = bp->numsaved = bp->numcached = bp->numrecv = bp->n; @@ -1024,7 +1024,7 @@ int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB) { int32_t i; struct iguana_bundle *tmpbp; - if ( coin->firstRTheight == 0 && iguana_bundleready(coin,bp,0) == bp->n ) + if ( coin->firstRTheight == 0 && iguana_bundleready(myinfo,coin,bp,0) == bp->n ) { printf(">>>>>>>>>>>>>> EMIT.[%3d] %s | 1st.%-3d h.%-3d c.%-3d s.[%3d] maxB.%d NET.(h%d b%d) %ld:%02ld\n",bp->hdrsi,coin->symbol,coin->current!=0?coin->current->hdrsi:-1,coin->current!=0?coin->current->numhashes:-1,coin->current!=0?coin->current->numcached:-1,coin->current!=0?coin->current->numsaved:-1,coin->MAXBUNDLES,HDRnet,netBLOCKS,(time(NULL)-coin->startutc)/60,(time(NULL)-coin->startutc)%60); if ( bp->emitfinish != 0 ) @@ -1034,7 +1034,7 @@ int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *c } bp->emitfinish = 1; usleep(100000); // make sure new incoming packet didnt overwrite - if ( iguana_bundleready(coin,bp,1) == bp->n ) + if ( iguana_bundleready(myinfo,coin,bp,1) == bp->n ) { usleep(100000); // make sure new incoming packet didnt overwrite coin->emitbusy++; @@ -1089,7 +1089,7 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin { printf("%s not ready yet\n",coin->symbol); bp->nexttime = (uint32_t)time(NULL) + 1; - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); return(retval); } if ( coin->current == 0 ) @@ -1100,9 +1100,9 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin starti = currentbp == 0 ? 0 : currentbp->hdrsi; lasti = lastbp == 0 ? coin->bundlescount-1 : lastbp->hdrsi; range = lasti - starti + 1; - iguana_bundlecalcs(coin,bp,lag); + iguana_bundlecalcs(myinfo,coin,bp,lag); if ( coin->blockdepth == 0 && coin->blockdepth == 0 && bp->hdrsi == coin->bundlescount-1 ) - iguana_autoextend(coin,bp); + iguana_autoextend(myinfo,coin,bp); if ( 0 && bp->hdrsi == 0 ) printf("ITER utxo.%u now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",bp->utxofinish,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount); bp->nexttime = (uint32_t)time(NULL) + ((bp->hdrsi > starti) ? 0 : -2); @@ -1125,7 +1125,7 @@ int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin printf("starti.%d range.%d now.%u spec.%-4d bundle.%-4d h.%-4d r.%-4d s.%-4d F.%d T.%d issued.%d mb.%d/%d\n",starti,range,(uint32_t)time(NULL),bp->numspec,bp->bundleheight/coin->chain->bundlesize,bp->numhashes,bp->numrecv,bp->numsaved,bp->emitfinish,timelimit,counter,coin->MAXBUNDLES,coin->bundlescount); } else bp->nexttime++; if ( bp->emitfinish <= 1 ) - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); else { //printf("[%d] not queued\n",bp->hdrsi); @@ -1153,7 +1153,7 @@ static int32_t revsortds(double *buf,uint32_t num,int32_t size) return(0); }*/ -int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,int32_t bundlei) +int32_t iguana_cacheprocess(struct supernet_info *myinfo,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("cacheprocess",coin,bp->speculative[bundlei])) != 0 && block->processed == 0 ) @@ -1172,7 +1172,7 @@ int32_t iguana_cacheprocess(struct iguana_info *coin,struct iguana_bundle *bp,in iguana_meminit(&coin->internaladdr.TXDATA,"txdata",0,IGUANA_MAXPACKETSIZE*1.5,0); if ( coin->internaladdr.HASHMEM.ptr == 0 ) iguana_meminit(&coin->internaladdr.HASHMEM,"HASHPTRS",0,256,0); - if ( iguana_msgparser(coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen,1) < 0 ) + if ( iguana_msgparser(myinfo,coin,&coin->internaladdr,&coin->internaladdr.RAWMEM,&coin->internaladdr.TXDATA,&coin->internaladdr.HASHMEM,&H,&data[sizeof(recvlen)],recvlen,1) < 0 ) printf("error parsing speculativecache.[%d:%d]\n",bp->hdrsi,bundlei); } free(data); @@ -1335,7 +1335,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch if ( ((block= bp->blocks[j]) == 0 || bp == coin->current) && bp->speculativecache[j] != 0 ) { if ( (block != 0 || (block= iguana_blockhashset("bundlestats3",coin,-1,bp->speculative[j],1)) != 0) && block->processed == 0 ) - iguana_cacheprocess(coin,bp,j); + iguana_cacheprocess(myinfo,coin,bp,j); numcached++; } if ( block != 0 && block->issued > 1 ) @@ -1348,7 +1348,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch bp->metric = coin->bundlescount - bp->hdrsi; if ( done > coin->bundlescount*IGUANA_HEADPERCENTAGE && bp->hdrsi > coin->bundlescount*IGUANA_TAILPERCENTAGE ) bp->metric *= 1000; - iguana_bundlecalcs(coin,bp,lag); + iguana_bundlecalcs(myinfo,coin,bp,lag); estsize += bp->estsize; numhashes += bp->numhashes; numcached += bp->numcached; @@ -1373,19 +1373,19 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch } else { - if ( firstgap == 0 && bp->numsaved < bp->n && bp->numcached < bp->n && (bp->ramchain.H.data == 0 || bp->hdrsi == coin->longestchain/coin->chain->bundlesize || iguana_bundleready(coin,bp,bp->numsaved == bp->n) != bp->n) ) + if ( firstgap == 0 && bp->numsaved < bp->n && bp->numcached < bp->n && (bp->ramchain.H.data == 0 || bp->hdrsi == coin->longestchain/coin->chain->bundlesize || iguana_bundleready(myinfo,coin,bp,bp->numsaved == bp->n) != bp->n) ) { //printf("firstgap <- [%d] emit.%u bp->n.%d numsaved.%d numcached.%d numhashes.%d\n",bp->hdrsi,bp->emitfinish,bp->n,bp->numsaved,bp->numcached,bp->numhashes); firstgap = bp; if ( bp->queued == 0 ) - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); } //else printf("[%d] emit.%u bp->n.%d numsaved.%d numcached.%d numhashes.%d\n",bp->hdrsi,bp->emitfinish,bp->n,bp->numsaved,bp->numcached,bp->numhashes); if ( bp->emitfinish == 0 ) { if ( lastpending == 0 && bp->queued == 0 ) - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); if ( firstgap != 0 && bp->numsaved < bp->n && ++pending == coin->MAXBUNDLES ) { lastpending = bp; @@ -1501,7 +1501,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch coin->stucktime = coin->stuckiters = 0; if ( coin->stucktime != 0 && time(NULL)-coin->stucktime > coin->maxstuck ) coin->maxstuck = (uint32_t)time(NULL) - coin->stucktime; - sprintf(str,"%s.RT%d u.%d+c.%d b.%d v.%d (%d+%d/%d 1st.%d).s%d to %d N[%d] h.%d r.%d c.%d s.%d d.%d E.%d maxB.%d peers.%d/%d Q.(%d %d) (L.%d %d:%d) M.%d %s ledger.%08llx supply %.8f",coin->symbol,coin->RTheight,numutxo,numconverted,numbalances,iguana_validated(coin),firstgap!=0?firstgap->numcached:-1,firstgap!=0?firstgap->numsaved:-1,firstgap!=0?firstgap->numhashes:-1,firstgap!=0?firstgap->hdrsi:-1,firstgap!=0?firstgap->numspec:-1,coin->lastpending!=0?coin->lastpending->hdrsi:0,count,numhashes,coin->blocksrecv,numcached,numsaved,done,numemit,coin->MAXBUNDLES,p,coin->MAXPEERS,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ),coin->longestchain,coin->longestchain/coin->chain->bundlesize,coin->longestchain%coin->chain->bundlesize,coin->blocks.hwmchain.height,bits256_str(str5,coin->blocks.hwmchain.RO.hash2),(long long)coin->utxoaddrhash.txid,dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits)); + sprintf(str,"%s.RT%d u.%d+c.%d b.%d v.%d (%d+%d/%d 1st.%d).s%d to %d N[%d] h.%d r.%d c.%d s.%d d.%d E.%d maxB.%d peers.%d/%d Q.(%d %d) (L.%d %d:%d) M.%d %s ledger.%08llx supply %.8f sigs %u:%u",coin->symbol,coin->RTheight,numutxo,numconverted,numbalances,iguana_validated(coin),firstgap!=0?firstgap->numcached:-1,firstgap!=0?firstgap->numsaved:-1,firstgap!=0?firstgap->numhashes:-1,firstgap!=0?firstgap->hdrsi:-1,firstgap!=0?firstgap->numspec:-1,coin->lastpending!=0?coin->lastpending->hdrsi:0,count,numhashes,coin->blocksrecv,numcached,numsaved,done,numemit,coin->MAXBUNDLES,p,coin->MAXPEERS,queue_size(&coin->priorityQ),queue_size(&coin->blocksQ),coin->longestchain,coin->longestchain/coin->chain->bundlesize,coin->longestchain%coin->chain->bundlesize,coin->blocks.hwmchain.height,bits256_str(str5,coin->blocks.hwmchain.RO.hash2),(long long)coin->utxoaddrhash.txid,dstr(coin->histbalance)+dstr(coin->RTcredits)-dstr(coin->RTdebits),coin->sigserrs,coin->sigsvalidated); //if( strcmp("BTC",coin->symbol) == 0 ) // printf("%s\n",str); if ( coin->current != 0 && coin->current->hdrsi == coin->longestchain/coin->chain->bundlesize && numemit == coin->current->hdrsi && numutxo == coin->bundlescount-1 ) @@ -1518,7 +1518,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch //printf("bundleQ.[%d]\n",j); bp->balancefinish = bp->startutxo = 0; bp->utxofinish = 1; - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); } } } @@ -1533,7 +1533,7 @@ void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,ch fprintf(logfp,"%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck); fflush(logfp); } - //printf("%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck); + printf("%s bQ.%d %d:%02d:%02d stuck.%d max.%d\n",str,queue_size(&bundlesQ),(int32_t)difft.x/3600,(int32_t)(difft.x/60)%60,(int32_t)difft.x%60,coin->stucktime!=0?(uint32_t)time(NULL) - coin->stucktime:0,coin->maxstuck); strcpy(coin->lastdispstr,str); if ( (rand() % 100) == 0 ) myallocated(0,0); diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index d2c05b78f..9a9ba9623 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -161,7 +161,7 @@ bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhash return(hash2); } -bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root) +bits256 iguana_chaingenesis(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root) { struct iguana_msgblock msg; int32_t len; bits256 hash2; char blockhashstr[256]; uint8_t serialized[8192]; memset(&msg,0,sizeof(msg)); @@ -175,7 +175,7 @@ bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (* if ( hashalgostr != 0 && strcmp(hashalgostr,"sha256") != 0 ) hashalgo = iguana_hashalgo(hashalgostr); else hashalgo = blockhash_sha256; - len = iguana_rwblock(symbol,zcash,auxpow,hashalgo,1,&hash2,serialized,&msg,sizeof(1024)); + len = iguana_rwblock(myinfo,symbol,zcash,auxpow,hashalgo,1,&hash2,serialized,&msg,sizeof(1024)); blockhashstr[0] = 0; init_hexbytes_noT(blockhashstr,hash2.bytes,sizeof(hash2)); char str[65],str2[65]; @@ -284,7 +284,7 @@ uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *us return(port); } -void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) +void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,cJSON *argjson) { extern char Userhome[]; char *path,conf[512],*hexstr,genesisblock[1024]; uint16_t port; cJSON *rpair,*genesis,*rewards,*item; int32_t i,n,m; uint32_t nBits; uint8_t tmp[4]; @@ -411,7 +411,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) chain->nBits = nBits; chain->unitval = (nBits >> 24); printf("NETMAGIC %08x unitval.%02x nBits.%08x\n",*(uint32_t *)chain->netmagic,chain->unitval,chain->nBits); - chain->genesishash2 = iguana_chaingenesis(chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,chain->genesishash2,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root")); + chain->genesishash2 = iguana_chaingenesis(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,chain->genesishash2,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root")); memcpy(chain->genesis_hashdata,chain->genesishash2.bytes,32); char str[65]; init_hexbytes_noT(str,chain->genesis_hashdata,32); chain->genesis_hash = clonestr(str); @@ -460,7 +460,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) } } -void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson) +void iguana_chaininit(struct supernet_info *myinfo,struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson) { int32_t i; if ( chain->hashalgo != 0 ) @@ -486,7 +486,7 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs if ( chain->unitval == 0 ) chain->unitval = 0x1e; if ( argjson != 0 ) - iguana_chainparms(chain,argjson); + iguana_chainparms(myinfo,chain,argjson); if ( hasheaders != 0 ) { strcpy(chain->gethdrsmsg,"getheaders"); @@ -504,7 +504,7 @@ void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjs chain->rpcport = chain->portp2p + 1; } -struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createflag) +struct iguana_chain *iguana_chainfind(struct supernet_info *myinfo,char *name,cJSON *argjson,int32_t createflag) { struct iguana_chain *chain; uint32_t i; for (i=0; isymbol,"BTCD") != 0,argjson); + iguana_chaininit(myinfo,chain,strcmp(chain->symbol,"BTCD") != 0,argjson); return(chain); } continue; } if ( strcmp(name,chain->symbol) == 0 ) { - iguana_chaininit(chain,strcmp(chain->symbol,"BTCD") != 0,argjson); + iguana_chaininit(myinfo,chain,strcmp(chain->symbol,"BTCD") != 0,argjson); return(chain); } } chain = calloc(1,sizeof(*chain)); - iguana_chaininit(chain,1,argjson); + iguana_chaininit(myinfo,chain,1,argjson); return(chain); } -struct iguana_chain *iguana_findmagic(uint8_t netmagic[4]) +struct iguana_chain *iguana_findmagic(struct supernet_info *myinfo,uint8_t netmagic[4]) { struct iguana_chain *chain; uint8_t i; for (i=0; iname[0] == 0 || chain->genesis_hash == 0 ) continue; if ( memcmp(netmagic,chain->netmagic,4) == 0 ) - return(iguana_chainfind((char *)chain->symbol,0,0)); + return(iguana_chainfind(myinfo,(char *)chain->symbol,0,0)); } return NULL; } @@ -558,7 +558,7 @@ uint64_t iguana_miningreward(struct iguana_info *coin,uint32_t blocknum) return(reward); } -struct iguana_chain *iguana_createchain(cJSON *json) +struct iguana_chain *iguana_createchain(struct supernet_info *myinfo,cJSON *json) { char *symbol,*name; struct iguana_chain *chain = 0; if ( ((symbol= jstr(json,"newcoin")) != 0 || (symbol= jstr(json,"name")) != 0) && strlen(symbol) < 8 ) @@ -567,7 +567,7 @@ struct iguana_chain *iguana_createchain(cJSON *json) strcpy(chain->symbol,symbol); if ( (name= jstr(json,"description")) != 0 && strlen(name) < 32 ) strcpy(chain->name,name); - iguana_chaininit(chain,juint(json,"hasheaders"),json); + iguana_chaininit(myinfo,chain,juint(json,"hasheaders"),json); } return(chain); } diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index 62de02e5b..13d53b089 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -108,7 +108,7 @@ bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,str decode_hex(buf,(int32_t)strlen(chain->genesis_hex)/2,(char *)chain->genesis_hex); hash2 = iguana_calcblockhash(coin->symbol,coin->chain->hashalgo,buf,sizeof(struct iguana_msgblockhdr)); auxback = coin->chain->auxpow, coin->chain->auxpow = 0; - iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,buf,&msg,sizeof(buf)); + iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,buf,&msg,sizeof(buf)); coin->chain->auxpow = auxback; if ( coin->virtualchain == 0 && coin->MAXPEERS > 1 ) { @@ -210,7 +210,7 @@ int32_t iguana_savehdrs(struct iguana_info *coin) return(retval); } -int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1) +int32_t iguana_bundleinitmap(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1) { char str[65]; struct iguana_block *block; bp->bundleheight = height; @@ -226,7 +226,7 @@ int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,i coin->current = coin->bundles[0] = bp; if ( (block= iguana_blockfind("parse",coin,hash2)) != 0 ) block->mainchain = 1, block->height = height; - if ( iguana_bundleload(coin,&bp->ramchain,bp,2) != 0 ) + if ( iguana_bundleload(myinfo,coin,&bp->ramchain,bp,2) != 0 ) { if ( coin->current != 0 && coin->current->hdrsi+1 == bp->hdrsi ) coin->current = bp; @@ -333,7 +333,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 { //printf("created bundle.%d\n",bp->hdrsi); memset(hash1.bytes,0,sizeof(hash1)); - iguana_bundleinitmap(coin,bp,height,hash2,hash1); + iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1); lastbundle = hash2; } } @@ -362,7 +362,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3 } if ( height >= lastheight ) { - if ( iguana_bundleinitmap(coin,bp,height,hash2,hash1) == 0 ) + if ( iguana_bundleinitmap(myinfo,coin,bp,height,hash2,hash1) == 0 ) lastbundle = hash2, lastheight = height; } } diff --git a/iguana/iguana_interpreter.c b/iguana/iguana_interpreter.c index 0ad66ed15..783f3896b 100755 --- a/iguana/iguana_interpreter.c +++ b/iguana/iguana_interpreter.c @@ -498,7 +498,7 @@ static int32_t iguana_pushdata(struct iguana_interpreter *stacks,int64_t num64,u struct iguana_stackdata Snum; cJSON *item = 0; char tmpstr[2048]; int32_t num = (int32_t)num64; if ( stacks->lastpath[stacks->ifdepth] < 0 ) return(0); - printf("PUSH.(%lld %p %d)\n",(long long)num64,numbuf,numlen); + //printf("PUSH.(%lld %p %d)\n",(long long)num64,numbuf,numlen); if ( stacks->maxstackdepth > 0 ) { /*if ( numbuf != 0 ) @@ -726,17 +726,26 @@ void iguana_stack(struct iguana_interpreter *stacks,struct iguana_stackdata *arg int32_t iguana_checksig(struct iguana_info *coin,struct iguana_stackdata pubkeyarg,struct iguana_stackdata sigarg,bits256 sigtxid) { - uint8_t pubkey[MAX_SCRIPT_ELEMENT_SIZE],sig[MAX_SCRIPT_ELEMENT_SIZE]; int32_t plen,siglen; + uint8_t pubkey[MAX_SCRIPT_ELEMENT_SIZE],sig[MAX_SCRIPT_ELEMENT_SIZE]; int32_t retval,plen,siglen; plen = iguana_databuf(pubkey,pubkeyarg); siglen = iguana_databuf(sig,sigarg); - int32_t i; for (i=0; i 0 && siglen > 0 && siglen < 74 ) - return(bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,pubkey,plen) == 0); + { + if ( (retval= (bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,pubkey,plen) == 0)) == 0 ) + { + if ( 1 ) + { + int32_t i; char str[65]; + for (i=0; i 0 ) { if ( (array= jarray(&n,interpreter,"args")) == 0 || (interpret != 0 && n != numvars) ) @@ -1017,8 +1029,8 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip if ( V->suppress_pubkeys == 0 && (V->spendscript[0] != plen || V->spendscript[V->spendlen - 1] != IGUANA_OP_CHECKSIG || bitcoin_pubkeylen(&V->spendscript[1]) <= 0) ) { iguana_pushdata(stacks,0,V->signers[i].pubkey,plen); - printf(">>>>>>>>> suppress.%d pushdata plen.%d depth.%d\n",V->suppress_pubkeys,plen,stacks->stackdepth); - } else printf("<<<<<<<<<< skip pubkey push %d script[0].%d spendlen.%d depth.%d\n",plen,V->spendscript[0],V->spendlen,stacks->stackdepth); + //printf(">>>>>>>>> suppress.%d pushdata plen.%d depth.%d\n",V->suppress_pubkeys,plen,stacks->stackdepth); + } // else printf("<<<<<<<<<< skip pubkey push %d script[0].%d spendlen.%d depth.%d\n",plen,V->spendscript[0],V->spendlen,stacks->stackdepth); } } if ( V->userdatalen != 0 ) @@ -1143,7 +1155,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip break; } HASH_FIND(hh,OPTABLE,str,j,op); - printf("{%s}\n",str); + //printf("{%s}\n",str); str += j; if ( op != 0 ) { @@ -1545,7 +1557,7 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip } else if ( iguana_isnonz(stacks->stack[--stacks->stackdepth]) != 0 ) { - printf("Evaluate true, depth.%d errs.%d k.%d\n",stacks->stackdepth,errs,k); + //printf("Evaluate true, depth.%d errs.%d k.%d\n",stacks->stackdepth,errs,k); if ( errs == 0 ) jadd(interpreter,"result",jtrue()); else jadd(interpreter,"result",jfalse()); @@ -1554,9 +1566,9 @@ int32_t bitcoin_assembler(struct iguana_info *coin,cJSON *logarray,uint8_t scrip { jadd(interpreter,"result",jfalse()); printf("Evaluate FALSE, depth.%d errs.%d [0] size.%d num.%d\n",stacks->stackdepth,errs,stacks->stack[0].size,stacks->stack[0].U.val); + if ( stacks->logarray != 0 ) + printf("LOG.(%s)\n\n",jprint(stacks->logarray,0)); } - //if ( stacks->logarray != 0 ) - // printf("LOG.(%s)\n",jprint(stacks->logarray,0)); if ( numargs > 0 ) { for (i=0; ichain->auxpow != 0 ) @@ -142,7 +142,7 @@ int32_t iguana_eatauxpow(int32_t rwflag,char *symbol,uint8_t zcash,uint8_t *seri memset(&MEM,0,sizeof(MEM)); ptr = calloc(1,1000000); iguana_meminit(&MEM,"auxpow",ptr,1000000,0); - len += iguana_rwtx(coin->chain->zcash,rwflag,coin,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0); + len += iguana_rwtx(myinfo,coin->chain->zcash,rwflag,coin,&MEM,&serialized[len],&msg,(int32_t)MEM.totalsize,&coinbasetxid,coin->chain->isPoS,0); if ( len > maxlen ) return(-1); len += iguana_rwbignum(rwflag,&serialized[len],sizeof(auxhash2),auxhash2.bytes); @@ -178,7 +178,7 @@ int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)//,uint8_t } else return((int32_t)(sizeof(struct iguana_msgblockhdr) - sizeof(uint32_t) + sizeof(struct iguana_msgblockhdr_zcash) + auxpow*sizeof(bits256))); } -int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen) +int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen) { int32_t len = 0; uint64_t x; if ( (len= iguana_rwblockhdr(rwflag,zcash,serialized,msg)) < 0 ) @@ -189,7 +189,7 @@ int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hasha *hash2p = iguana_calcblockhash(symbol,hashalgo,serialized,len); //char str[65],str2[65]; printf("zcash.%d len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx hash2.%s\n",zcash,len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,bits256_str(str2,*hash2p)); if ( auxpow != 0 && (msg->H.version & 0x100) != 0 ) - len += iguana_eatauxpow(rwflag,symbol,zcash,&serialized[len],maxlen-len); + len += iguana_eatauxpow(myinfo,rwflag,symbol,zcash,&serialized[len],maxlen-len); if ( rwflag == 1 ) x = msg->txn_count; len += iguana_rwvarint(rwflag,&serialized[len],&x); @@ -205,7 +205,7 @@ int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hasha return(len); } -int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block) +int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block) { struct iguana_msgblock msg; int32_t i,len; memset(&msg,0,sizeof(msg)); @@ -227,7 +227,7 @@ int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_ } else printf("iguana_serialize_block has missing zRO\n"); } msg.txn_count = block->RO.txn_count; - len = iguana_rwblock(chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,&msg,IGUANA_MAXPACKETSIZE); + len = iguana_rwblock(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,&msg,IGUANA_MAXPACKETSIZE); return(len); } @@ -529,8 +529,6 @@ int32_t iguana_rwvin(int32_t rwflag,struct iguana_info *coin,struct OS_memspace printf("%02x ",msg->vinscript[i]); printf(" vinscriptlen.%d, prevhash.%llx prev_vout.%d | ",msg->scriptlen,(long long)msg->prev_hash.txid,msg->prev_vout); } - if ( coin->RTheight > 0 && iguana_validatesigs(coin,msg,vini) < 0 ) - printf("%s vin.%d error validatesigs\n",coin->symbol,vini); return(len); } @@ -579,7 +577,7 @@ int32_t iguana_rwjoinsplit(int32_t rwflag,uint8_t *serialized,struct iguana_msgj return(len); } -int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin) +int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin) { int32_t i,n,len = 0; uint8_t *txstart = serialized; char txidstr[65]; if ( maxsize < sizeof(msg->version) ) @@ -665,10 +663,40 @@ int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct } *txidp = bits256_doublesha256(txidstr,txstart,len); msg->allocsize = len; + if ( coin->VALIDATENODE != 0 && rwflag == 0 && (coin->VALIDATENODE > 1 || coin->RTheight > 0) ) + { + int32_t sigsvalid; struct iguana_block *block; + if ( (block= iguana_blockfind("sig",coin,msg->txid)) != 0 && block->sigsvalid != 0 ) + sigsvalid = 1; + else if ( iguana_validatesigs(myinfo,coin,txstart,len) == 0 ) + sigsvalid = 1; + else + { + static FILE *fp; + if ( block != 0 ) + block->sigsvalid = 1; + if ( fp == 0 ) + fp = fopen("validates","wb"); + if ( fp != 0 ) + { + char str[65]; + printf("error %s validating\n",bits256_str(str,*txidp)); + for (i=0; izRO)]; @@ -676,7 +704,7 @@ char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t r memset(&msg,0,sizeof(msg)); vpnstr[0] = 0; extraspace = calloc(1,extralen); - len = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); + len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,block,&msg,hash2,-1); for (i=0; isymbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); + len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen); hdrlen = len; if ( len > recvlen ) { @@ -721,7 +749,7 @@ int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struc printf("gentxarrayB error len.%d > recvlen.%d\n",len,recvlen); return(-1); } - if ( (n= iguana_rwtx(coin->chain->zcash,0,coin,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 ) + if ( (n= iguana_rwtx(myinfo,coin->chain->zcash,0,coin,mem,&data[len],&tx[i],recvlen - len,&tx[i].txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0)) < 0 ) { //for (i=0; icommand+1,"uperNET",strlen("uperNET")) == 0 || strncmp(H->command,"uperNet",strlen("uperNet")) == 0 ) { @@ -880,10 +907,10 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc printf(" auxblock\n"); } addr->msgcounts.block++; - if ( (n= iguana_gentxarray(coin,rawmem,&txdata,&len,data,recvlen)) == recvlen || n == recvlen-1 ) + if ( (n= iguana_gentxarray(myinfo,coin,rawmem,&txdata,&len,data,recvlen)) == recvlen || n == recvlen-1 ) { len = n; - iguana_gotblockM(coin,addr,&txdata,rawmem->ptr,H,data,recvlen,fromcache); + iguana_gotblockM(myinfo,coin,addr,&txdata,rawmem->ptr,H,data,recvlen,fromcache); } else { @@ -947,7 +974,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc { iguana_memreset(rawmem); tx = iguana_memalloc(rawmem,sizeof(*tx),1); - len += iguana_rwtx(coin->chain->zcash,0,coin,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); + len += iguana_rwtx(myinfo,coin->chain->zcash,0,coin,rawmem,&data[len],tx,recvlen-len,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes); len += iguana_rwmerklebranch(0,&data[len],coinbase_branch); len += iguana_rwmerklebranch(0,&data[len],blockchain_branch); @@ -957,7 +984,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc char str[65],str2[65]; if ( 0 && coin->chain->auxpow != 0 ) printf("%d %d of %d: %s %s v.%08x numtx.%d cmp.%d\n",len,i,n,bits256_str(str,hash2),bits256_str(str2,msg.H.prev_block),msg.H.version,tmp,bits256_cmp(prevhash2,msg.H.prev_block)); - } else len += iguana_rwblock(coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],&msg,recvlen); + } else len += iguana_rwblock(myinfo,coin->chain->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,&data[len],&msg,recvlen); iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(struct iguana_block *)&zblocks[i],&msg,hash2,-1); prevhash2 = hash2; } @@ -1095,7 +1122,7 @@ int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struc struct iguana_msgtx *tx; iguana_memreset(rawmem); tx = iguana_memalloc(rawmem,sizeof(*tx),1);//mycalloc('u',1,sizeof(*tx)); - len = iguana_rwtx(coin->chain->zcash,0,coin,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); + len = iguana_rwtx(myinfo,coin->chain->zcash,0,coin,rawmem,data,tx,recvlen,&tx->txid,coin->chain->isPoS,strcmp(coin->symbol,"VPN")==0); if ( addr != 0 ) { iguana_gotunconfirmedM(coin,addr,tx,data,recvlen); diff --git a/iguana/iguana_payments.c b/iguana/iguana_payments.c index 07b7ea747..fc7d0d97c 100755 --- a/iguana/iguana_payments.c +++ b/iguana/iguana_payments.c @@ -924,7 +924,7 @@ HASH_AND_INT(bitcoinrpc,getrawtransaction,txid,verbose) datalen = (int32_t)(strlen(blockstr) >> 1); data = malloc(datalen); decode_hex(data,datalen,blockstr); - if ( (txbytes= iguana_txscan(coin,verbose != 0 ? retjson : 0,data,datalen,txid)) != 0 ) + if ( (txbytes= iguana_txscan(myinfo,coin,verbose != 0 ? retjson : 0,data,datalen,txid)) != 0 ) { jaddstr(retjson,"result",txbytes); jaddbits256(retjson,"blockhash",blockhash); @@ -955,7 +955,7 @@ int64_t iguana_lockval(int32_t finalized,int64_t locktime) char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,char *rawtx,int32_t mempool,int32_t suppress_pubkeys) { - bits256 signedtxid,txid; struct iguana_outpoint outpt; struct iguana_msgvin vin; cJSON *log,*vins,*vouts,*txobj,*retjson; char *checkstr,*signedtx; int32_t finalized = 1,i,len,maxsize,numinputs,numoutputs,complete; struct vin_info *V; uint8_t *serialized,*serialized2; uint32_t sigsize,pubkeysize,p2shsize,suffixlen; int64_t inputsum,outputsum,lockval; + bits256 signedtxid,txid; struct iguana_outpoint outpt; struct iguana_msgvin vin; cJSON *log,*vins,*vouts,*txobj,*retjson; char *checkstr,*signedtx; int32_t plen,finalized = 1,i,len,maxsize,numinputs,numoutputs,complete; struct vin_info *V; uint8_t *serialized,*serialized2; uint32_t sigsize,pubkeysize,p2shsize,suffixlen; int64_t inputsum,outputsum,lockval; retjson = cJSON_CreateObject(); inputsum = outputsum = numinputs = numoutputs = 0; if ( rawtx != 0 && rawtx[0] != 0 && coin != 0 ) @@ -966,8 +966,9 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin if ( (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&msgtx->txid,msgtx,rawtx,extraspace,extralen,0,0,suppress_pubkeys)) != 0 ) { //printf("txobj.(%s)\n",jprint(txobj,0)); - if ( (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 ) + if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,0)) != 0 ) { + // no guarantee byte for byte identical tx is recreated if ( strcmp(rawtx,checkstr) != 0 ) { jaddstr(retjson,"error","converting from hex2json and json2hex mismatch"); @@ -978,7 +979,7 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin break; jaddnum(retjson,"mismatch position",i); jadd(retjson,"origtx",txobj); - if ( (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,msgtx,checkstr,extraspace,extralen,0,0,suppress_pubkeys)) != 0 ) + if ( 0 && (txobj= bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,msgtx,checkstr,extraspace,extralen,0,0,suppress_pubkeys)) != 0 ) jadd(retjson,"checktx",txobj); free(checkstr); return(jprint(retjson,1)); @@ -1006,33 +1007,46 @@ char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin len += iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize-len,&vin,jitem(vins,i),&V[i]); if ( iguana_RTunspentindfind(myinfo,coin,&outpt,V[i].coinaddr,V[i].spendscript,&V[i].spendlen,&V[i].amount,&V[i].height,msgtx->vins[i].prev_hash,msgtx->vins[i].prev_vout,coin->bundlescount-1,mempool) == 0 ) { + V[i].suppress_pubkeys = suppress_pubkeys; V[i].unspentind = outpt.unspentind; inputsum += V[i].amount; msgtx->vins[i].spendscript = V[i].spendscript; - msgtx->vins[i].spendlen = V[i].spendlen; + if ( (msgtx->vins[i].spendlen= V[i].spendlen) == 35 ) + { + if ( (plen= bitcoin_pubkeylen(msgtx->vins[i].spendscript+1)) > 0 ) + { + memcpy(V[i].signers[0].pubkey,msgtx->vins[i].spendscript+1,plen); + V[i].suppress_pubkeys = 1; + } + } V[i].hashtype = iguana_vinscriptparse(coin,&V[i],&sigsize,&pubkeysize,&p2shsize,&suffixlen,msgtx->vins[i].vinscript,msgtx->vins[i].scriptlen); + //if ( (V[i].signers[0].siglen= sigsize) > 0 ) + // memcpy(V[i].signers[0].sig,msgtx->vins[i].vinscript+1,sigsize); V[i].userdatalen = suffixlen; memcpy(V[i].spendscript,msgtx->vins[i].spendscript,msgtx->vins[i].spendlen); V[i].spendlen = msgtx->vins[i].spendlen; if ( msgtx->vins[i].sequence < IGUANA_SEQUENCEID_FINAL ) finalized = 0; - //printf("V %.8f (%s) spendscript.[%d] scriptlen.%d\n",dstr(V[i].amount),V[i].coinaddr,V[i].spendlen,V[i].spendlen); - } - } - V[0].suppress_pubkeys = suppress_pubkeys; - if ( (complete= bitcoin_verifyvins(coin,height,&signedtxid,&signedtx,msgtx,serialized2,maxsize,V,1,0,suppress_pubkeys)) > 0 && signedtx != 0 ) - { - msgtx->txid = signedtxid; - log = cJSON_CreateArray(); - lockval = iguana_lockval(finalized,jint(txobj,"locktime")); - if ( iguana_interpreter(coin,log,lockval,V,numinputs) < 0 ) - { - jaddstr(retjson,"error","interpreter rejects tx"); - } - jadd(retjson,"interpreter",log); + if ( V[i].M == 0 ) + V[i].M = 1; + if ( V[i].N < V[i].M ) + V[i].N = V[i].M; + //printf("V %dof%d %.8f (%s) spendscript.[%d] scriptlen.%d\n",V[i].M,V[i].N,dstr(V[i].amount),V[i].coinaddr,V[i].spendlen,V[i].spendlen); + } else printf("couldnt find spendscript\n"); } + complete = 0; + bitcoin_verifyvins(coin,height,&signedtxid,&signedtx,msgtx,serialized2,maxsize,V,1,0,suppress_pubkeys); + msgtx->txid = signedtxid; + log = cJSON_CreateArray(); + lockval = iguana_lockval(finalized,jint(txobj,"locktime")); + if ( iguana_interpreter(coin,log,lockval,V,numinputs) < 0 ) + jaddstr(retjson,"error","interpreter rejects tx"); + else complete = 1; + jadd(retjson,"interpreter",log); jaddnum(retjson,"complete",complete); free(serialized), free(serialized2); + if ( signedtx != 0 ) + free(signedtx); } } //char str[65]; printf("got txid.(%s)\n",bits256_str(str,txid)); @@ -1050,26 +1064,46 @@ STRING_AND_INT(bitcoinrpc,validaterawtransaction,rawtx,suppress) uint8_t *extraspace; int32_t extralen=65536; char *retstr; struct iguana_msgtx msgtx; if ( remoteaddr != 0 ) return(clonestr("{\"error\":\"no remote\"}")); - - //cJSON *txobj; char *teststr= "{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"20fe936da3707c8c4cc7eb0352160ec3f50b9454d46425df6347b2fbc5b2ec87ea00\",\"txid\":\"ee12e50b629d5d45438570fff841d1a2ba7d27f356de4aa06900c9a5e38cf141\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a9145cc47cc123e3f9b7dce0230009b9d3013a9e0c9687\"},\"suppress\":1,\"redeemScript\":\"6304165daa57b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a9143805600256ed8498ca1ec426759212e5835e8dc2882103a7b696908f77d69ec89887f8c4a0423b9e80b5974dc43301bd7d8abad07e1211ac68\"}],\"vout\":[{\"satoshis\":\"21821\",\"scriptPubkey\":{\"hex\":\"76a9143ef4734c1141725c095342095f6e0e7748b6c16588ac\"}}]}"; - - //cJSON *txobj; char *teststr= "{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"206efad760ee54b9b2e2a038a821ef9f950eb0e248545ac202c3e2074cd14f92cb00\",\"txid\":\"3f4759381a62154f2f0eefed1e4433342548ad7b269f912820383b715a39273c\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a91446dcccef39c1d8c6da2ccc35dce2bfa7ec0d168887\"},\"suppress\":1,\"redeemScript\":\"63041c60aa57b1752103175cf93574c31637b8c2d8acd5319e3cd23761b5e418d32c6bcb194972ba9273ac67a9142d75daf71325feaa593b8f30989e462892189914882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68\"}],\"vout\":[{\"satoshis\":\"18625\",\"scriptPubkey\":{\"hex\":\"76a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac\"}}]}"; - // 01000000013c27395a713b382028919f267bad48253433441eedef0e2f4f15621a3859473f00000000d147304402207ecd423b55c1aa45a994c4eb4337ff0891692fbb69954a9ba024745a99c5272d02207cea696425feb5388153ab7f2608d66a66e4c95cfda2d44e98bc56e25994d3f701206efad760ee54b9b2e2a038a821ef9f950eb0e248545ac202c3e2074cd14f92cb004c6763041c60aa57b1752103175cf93574c31637b8c2d8acd5319e3cd23761b5e418d32c6bcb194972ba9273ac67a9142d75daf71325feaa593b8f30989e462892189914882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68ffffffff01c1480000000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000 - // 01000000013c27395a713b382028919f267bad48253433441eedef0e2f4f15621a3859473f00000000fd8b00206efad760ee54b9b2e2a038a821ef9f950eb0e248545ac202c3e2074cd14f92cb004c6763041c60aa57b1752103175cf93574c31637b8c2d8acd5319e3cd23761b5e418d32c6bcb194972ba9273ac67a9142d75daf71325feaa593b8f30989e462892189914882102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac68ffffffff01c1480000000000001976a914b7128d2ee837cf03e30a2c0e3e0181f7b9669bb688ac00000000 - //cJSON *txobj; char *teststr= "{\"version\":1,\"locktime\":0,\"vin\":[{\"userdata\":\"20ae439d344513eab8e718d8214fe6ae8133b8b5b594afd64da21d0e40b9c37cdd00\",\"txid\":\"2c1320315f4fb519cbf2b4d7b67855013b9a09a85e515df43b41d407a0083b09\",\"vout\":0,\"scriptPubKey\":{\"hex\":\"a9142e7674400d04217f770f2222126dc7fee44b06b487\"},\"suppress\":1,\"redeemScript\":\"63041686a657b1752102a9669e63ef1ab04913615c2f3887ea3584f81e5f08feee9535b19ab3739d8afdac67a914ed74c61c27656abc6c20687c3a9212ffdc6f34cd88210398a4cb9f6ea7c52a4e27455028a95e2e4e397a110fb75f072c2c58a8bdcbf4baac68\"}],\"vout\":[{\"satoshis\":\"16733\",\"scriptPubkey\":{\"hex\":\"76a91454a752f0d71b89d7c014ed0be29ca231c9546f9f88ac\"}}]}"; extraspace = calloc(1,extralen); - /*if ( (txobj= cJSON_Parse(teststr)) != 0 ) - { - bits256 txid; - rawtx = bitcoin_json2hex(myinfo,coin,&txid,txobj,0); - txobj = bitcoin_hex2json(coin,coin->blocks.hwmchain.height,&txid,0,rawtx,extraspace,extralen,0,0,suppress); - printf("RAWTX.(%s) -> (%s)\n",rawtx,jprint(txobj,0)); - }*/ retstr = iguana_validaterawtx(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,extraspace,extralen,rawtx,0,suppress); free(extraspace); return(rawtx); } +int32_t iguana_validatesigs(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t datalen) +{ + uint8_t *extraspace; cJSON *retjson; int32_t extralen=65536; char *retstr,*rawtx; struct iguana_msgtx msgtx; int32_t suppress=0,retval = -1; + rawtx = calloc(1,datalen*2 + 1); + init_hexbytes_noT(rawtx,serialized,datalen); + extraspace = calloc(1,extralen); + for (suppress=0; suppress<1; suppress++) + { + if ( (retstr= iguana_validaterawtx(myinfo,coin,coin->blocks.hwmchain.height,&msgtx,extraspace,extralen,rawtx,0,suppress)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( jobj(retjson,"error") == 0 ) + { + retval = 0; + //char str[65]; printf("%s %s sigs validated\n",coin->symbol,bits256_str(str,msgtx.txid)); + coin->sigsvalidated++; + break; + } + else + { + printf("ERROR.(%s)\n",retstr); + coin->sigserrs++; + } + free_json(retjson); + } + free(retstr); + } + } + free(rawtx); + free(extraspace); + return(retval); +} + STRING_AND_INT(bitcoinrpc,decoderawtransaction,rawtx,suppress) { cJSON *txobj = 0; bits256 txid; uint8_t *extraspace; int32_t extralen = 65536; diff --git a/iguana/iguana_peers.c b/iguana/iguana_peers.c index 068dd8c49..ac5f2710d 100755 --- a/iguana/iguana_peers.c +++ b/iguana/iguana_peers.c @@ -566,7 +566,7 @@ int32_t iguana_recv(char *ipaddr,int32_t usock,uint8_t *recvbuf,int32_t len) return(len); } -void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache) +void iguana_parsebuf(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache) { struct iguana_msghdr checkH; memset(&checkH,0,sizeof(checkH)); @@ -582,7 +582,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig iguana_meminit(&addr->HASHMEM,"HASHPTRS",0,256,0);//IGUANA_MAXPACKETSIZE*16,0); //printf("Init %s memory %p %p %p\n",addr->ipaddr,addr->RAWMEM.ptr,addr->TXDATA.ptr,addr->HASHMEM.ptr); } - if ( iguana_msgparser(coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len,fromcache) < 0 || addr->dead != 0 ) + if ( iguana_msgparser(myinfo,coin,addr,&addr->RAWMEM,&addr->TXDATA,&addr->HASHMEM,H,buf,len,fromcache) < 0 || addr->dead != 0 ) { printf("%p addr->dead.%d or parser break at %u\n",&addr->dead,addr->dead,(uint32_t)time(NULL)); addr->dead = (uint32_t)time(NULL); @@ -604,7 +604,7 @@ void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct ig } } -void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen) +void _iguana_processmsg(struct supernet_info *myinfo,struct iguana_info *coin,int32_t usock,struct iguana_peer *addr,uint8_t *_buf,int32_t maxlen) { int32_t len,recvlen; void *buf = _buf; struct iguana_msghdr H; if ( (coin->peers != 0 && coin->peers->shuttingdown != 0) || addr->dead != 0 ) @@ -638,7 +638,7 @@ void _iguana_processmsg(struct iguana_info *coin,int32_t usock,struct iguana_pee return; } } - iguana_parsebuf(coin,addr,&H,buf,len,0); + iguana_parsebuf(myinfo,coin,addr,&H,buf,len,0); if ( buf != _buf ) myfree(buf,len); return; @@ -950,7 +950,7 @@ void iguana_processmsg(void *ptr) printf("iguana_processmsg cant find addr.%p symbol.%s\n",addr,addr!=0?addr->symbol:0); return; } - _iguana_processmsg(coin,addr->usock,addr,buf,sizeof(buf)); + _iguana_processmsg(SuperNET_MYINFO(0),coin,addr->usock,addr,buf,sizeof(buf)); addr->startrecv = 0; } @@ -981,7 +981,7 @@ int32_t iguana_pollsendQ(struct iguana_info *coin,struct iguana_peer *addr) return(0); } -int32_t iguana_pollrecv(struct iguana_info *coin,struct iguana_peer *addr,uint8_t *buf,int32_t bufsize) +int32_t iguana_pollrecv(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,uint8_t *buf,int32_t bufsize) { #ifndef IGUANA_DEDICATED_THREADS strcpy(addr->symbol,coin->symbol); @@ -992,7 +992,7 @@ int32_t iguana_pollrecv(struct iguana_info *coin,struct iguana_peer *addr,uint8_ } else #endif - _iguana_processmsg(coin,addr->usock,addr,buf,bufsize); + _iguana_processmsg(myinfo,coin,addr->usock,addr,buf,bufsize); return(1); } @@ -1202,7 +1202,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, if ( req->datalen != 0 ) { //char str[65]; printf("CACHE.%p parse[%d] %s %s\n",req,req->recvlen,req->H.command,bits256_str(str,req->zblock.RO.hash2)); - iguana_parsebuf(coin,addr,&req->H,req->serializeddata,req->recvlen,1); + iguana_parsebuf(myinfo,coin,addr,&req->H,req->serializeddata,req->recvlen,1); } else printf("CACHE error no datalen\n"); coin->cachefreed++; myfree(req,req->allocsize); @@ -1225,7 +1225,7 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin, { if ( (fds.revents & POLLIN) != 0 ) { - flag += iguana_pollrecv(coin,addr,buf,bufsize); + flag += iguana_pollrecv(myinfo,coin,addr,buf,bufsize); if ( addr->dead != 0 ) { printf("%s is dead\n",addr->ipaddr); diff --git a/iguana/iguana_ramchain.c b/iguana/iguana_ramchain.c index 4b3322e88..cb227d33f 100755 --- a/iguana/iguana_ramchain.c +++ b/iguana/iguana_ramchain.c @@ -2296,7 +2296,7 @@ int32_t iguana_ramchain_expandedsave(struct supernet_info *myinfo,struct iguana_ return(retval); } -struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag) +struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag) { static const bits256 zero; struct iguana_blockRO *B; struct iguana_txid *T; int32_t i,firsti = 1; char fname[512]; @@ -2352,7 +2352,7 @@ struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana } //printf("mapped bundle.%d\n",bp->bundleheight); bp->emitfinish = (uint32_t)time(NULL) + 1; - iguana_bundlecalcs(coin,bp,60); + iguana_bundlecalcs(myinfo,coin,bp,60); } else { @@ -2567,7 +2567,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi { if ( bits256_nonz(block->RO.prev_block) == 0 && i > 0 ) block->RO.prev_block = bp->hashes[i-1]; - if ( (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(coin,&valid,block,1) < 0 ) + if ( (bp->bundleheight+i > 0 && bits256_nonz(block->RO.prev_block) == 0) || iguana_blockvalidate(myinfo,coin,&valid,block,1) < 0 ) { char str[65]; printf("null prevblock error at ht.%d patch.(%s)\n",bp->bundleheight+i,bits256_str(str,bp->hashes[i-1])); iguana_bundlemapfree(coin,mem,&HASHMEM,ipbits,ptrs,filesizes,num,R,starti,endi); @@ -2629,7 +2629,7 @@ int32_t iguana_bundlesaveHT(struct supernet_info *myinfo,struct iguana_info *coi { //char dirname[1024]; //printf("delete %d files hdrs.[%d] retval.%d bp_n.%d\n",num,bp->hdrsi,retval,bp_n); - if ( iguana_bundleload(coin,&newchain,bp,0) == 0 ) + if ( iguana_bundleload(myinfo,coin,&newchain,bp,0) == 0 ) retval = -1; else //if ( bp_n == bp->n && bp->n == coin->chain->bundlesize && bp->hdrsi < coin->bundlescount-3 ) { diff --git a/iguana/iguana_realtime.c b/iguana/iguana_realtime.c index 9858c060a..440786f43 100755 --- a/iguana/iguana_realtime.c +++ b/iguana/iguana_realtime.c @@ -1056,7 +1056,7 @@ int32_t iguana_RTiterate(struct supernet_info *myinfo,struct iguana_info *coin,i //extern int32_t debugtest; //debugtest = 1; //fprintf(stderr,"T"); - if ( (n= iguana_gentxarray(coin,&coin->RTrawmem,&txdata,&len,serialized,recvlen)) > 0 ) + if ( (n= iguana_gentxarray(myinfo,coin,&coin->RTrawmem,&txdata,&len,serialized,recvlen)) > 0 ) { //fprintf(stderr,"R"); iguana_RTramchaindata(myinfo,coin,&coin->RTmem,&coin->RThashmem,polarity,block,coin->RTrawmem.ptr,numtx); diff --git a/iguana/iguana_recv.c b/iguana/iguana_recv.c index 9193ed0ae..1e0170b90 100755 --- a/iguana/iguana_recv.c +++ b/iguana/iguana_recv.c @@ -318,7 +318,7 @@ void iguana_bundletime(struct iguana_info *coin,struct iguana_bundle *bp,int32_t } } -void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache) +void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *origtxdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t recvlen,int32_t fromcache) { struct iguana_bundlereq *req; struct iguana_txblock *txdata = 0; int32_t valid,speculative=0,i,j,bundlei,copyflag,numtx; struct iguana_block *block; struct iguana_bundle *bp; uint32_t now; char str[65]; if ( recvlen < 0 || recvlen > IGUANA_MAXPACKETSIZE ) @@ -352,7 +352,7 @@ void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct i } } origtxdata->zblock.RO.allocsize = sizeof(origtxdata->zblock); - if ( iguana_blockvalidate(coin,&valid,(struct iguana_block *)&origtxdata->zblock,1) < 0 ) + if ( iguana_blockvalidate(myinfo,coin,&valid,(struct iguana_block *)&origtxdata->zblock,1) < 0 ) { printf("got block that doesnt validate? %s\n",bits256_str(str,origtxdata->zblock.RO.hash2)); return; @@ -661,7 +661,7 @@ uint32_t iguana_allhashcmp(struct supernet_info *myinfo,struct iguana_info *coin if ( 0 && n > 0 ) printf("ALLHASHES FOUND! %d allhashes.%d issued %d\n",bp->bundleheight,coin->allhashes,n); if ( bp->queued == 0 ) - iguana_bundleQ(coin,bp,bp->n*5 + (rand() % 500)); + iguana_bundleQ(myinfo,coin,bp,bp->n*5 + (rand() % 500)); return(bp->queued); } } @@ -907,7 +907,7 @@ struct iguana_bundle *iguana_bundleset(struct supernet_info *myinfo,struct iguan if ( (bp= iguana_bundlecreate(coin,bundleip,prevbp->bundleheight + coin->chain->bundlesize,hash2,zero,0)) != 0 ) { if ( bp->queued == 0 ) - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); } } if ( prevbundlei < coin->chain->bundlesize-1 ) @@ -1018,7 +1018,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc if ( firstbp->queued == 0 ) { //fprintf(stderr,"firstbp blockQ %d\n",firstbp->bundleheight); - iguana_bundleQ(coin,firstbp,1000); + iguana_bundleQ(myinfo,coin,firstbp,1000); } } if ( i == n && i == match && firstbp == coin->current && (addr= req->addr) != 0 ) @@ -1026,7 +1026,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc addr->RThashes[i] = firstbp->hashes[0]; for (i=1; ichain,&addr->RThashes[i],serialized,(struct iguana_block *)&zblocks[i]); + iguana_serialize_block(myinfo,coin->chain,&addr->RThashes[i],serialized,(struct iguana_block *)&zblocks[i]); } //memcpy(addr->RThashes,blockhashes,bp->numspec * sizeof(*addr->RThashes)); addr->numRThashes = n; @@ -1035,7 +1035,7 @@ struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struc return(req); } -void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp) +void iguana_autoextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp) { char hashstr[65]; struct iguana_bundle *newbp; int32_t bundlei; static const bits256 zero; if ( bp->hdrsi == coin->bundlescount-1 && bits256_nonz(bp->nextbundlehash2) != 0 ) @@ -1058,7 +1058,7 @@ void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp) queue_enqueue("hdrsQ",&coin->hdrsQ,queueitem(hashstr),1); //char str[65],str2[65]; printf("EXTEND last bundle %s/%s ht.%d\n",bits256_str(str,newbp->hashes[0]),bits256_str(str2,bp->nextbundlehash2),newbp->bundleheight); if ( newbp->queued == 0 ) - iguana_bundleQ(coin,newbp,1000); + iguana_bundleQ(myinfo,coin,newbp,1000); } } } @@ -1101,7 +1101,7 @@ struct iguana_bundlereq *iguana_recvblockhashes(struct supernet_info *myinfo,str } //printf("call allhashes\n"); if ( 0 && bp->hdrsi == coin->bundlescount-1 ) - iguana_autoextend(coin,bp); + iguana_autoextend(myinfo,coin,bp); if ( iguana_allhashcmp(myinfo,coin,bp,blockhashes,num) > 0 ) return(req); //printf("done allhashes\n"); diff --git a/iguana/iguana_scripts.c b/iguana/iguana_scripts.c index 1e6ad9a67..40ed820cc 100755 --- a/iguana/iguana_scripts.c +++ b/iguana/iguana_scripts.c @@ -91,11 +91,11 @@ int32_t bitcoin_p2shscript(uint8_t *script,int32_t n,const uint8_t *p2shscript,c script[n++] = (p2shlen & 0xff); script[n++] = ((p2shlen >> 8) & 0xff); } - else + else if ( p2shlen > 76 ) { script[n++] = 0x4c; script[n++] = p2shlen; - } + } else script[n++] = p2shlen; memcpy(&script[n],p2shscript,p2shlen), n += p2shlen; return(n); } @@ -495,7 +495,8 @@ int32_t bitcoin_scriptget(struct iguana_info *coin,int32_t *hashtypep,uint32_t * } vp->numpubkeys = j; *userdatap = &scriptsig[n]; - *userdatalenp = (len - n); + if ( len > n ) + *userdatalenp = (len - n); p2shscript = 0; while ( n < len ) { @@ -681,6 +682,8 @@ int32_t iguana_vinscriptdecode(struct iguana_info *coin,struct iguana_ramchain * if ( p2shlen > 0 && p2shlen < IGUANA_MAXSCRIPTSIZE ) { if ( p2shlen <= 75 ) + _script[scriptlen++] = p2shlen; + else if ( p2shlen <= 0xff ) _script[scriptlen++] = 0x4c, _script[scriptlen++] = p2shlen; else _script[scriptlen++] = 0x4d, _script[scriptlen++] = p2shlen & 0xff, _script[scriptlen++] = (p2shlen>>8) & 0xff; //printf("p2shlen.%d\n",p2shlen); diff --git a/iguana/iguana_sign.c b/iguana/iguana_sign.c index 45460ce25..8204993c3 100755 --- a/iguana/iguana_sign.c +++ b/iguana/iguana_sign.c @@ -62,7 +62,7 @@ int32_t iguana_vinparse(struct iguana_info *coin,int32_t rwflag,uint8_t *seriali else { if ( msg->vinscript != 0 && msg->scriptlen > 0 ) - memcpy(&serialized[len],msg->vinscript,msg->scriptlen), len += msg->scriptlen; // pubkeys here + memcpy(&serialized[len],msg->vinscript,msg->scriptlen), len += msg->scriptlen; // pubkeys here if ( msg->userdatalen > 0 && msg->userdata != 0 ) { //printf("userdata.%d scriptlen.%d\n",msg->userdatalen,msg->scriptlen); @@ -111,14 +111,17 @@ int32_t iguana_voutparse(int32_t rwflag,uint8_t *serialized,struct iguana_msgvou } if ( rwflag == 0 ) msg->pk_script = &serialized[len]; - else memcpy(&serialized[len],msg->pk_script,msg->pk_scriptlen); - if ( 0 ) + else if ( msg->pk_scriptlen > 0 ) { - int32_t i; - for (i=0; ipk_scriptlen; i++) - printf("%02x",msg->pk_script[i]); - printf(" [%p] scriptlen.%d rwflag.%d %.8f\n",msg->pk_script,msg->pk_scriptlen,rwflag,dstr(msg->value)); - } + memcpy(&serialized[len],msg->pk_script,msg->pk_scriptlen); + if ( 0 ) + { + int32_t i; + for (i=0; ipk_scriptlen; i++) + printf("%02x",msg->pk_script[i]); + printf(" [%p] scriptlen.%d rwflag.%d %.8f\n",msg->pk_script,msg->pk_scriptlen,rwflag,dstr(msg->value)); + } + } // else serialized[len++] = 0; len += msg->pk_scriptlen; return(len); } @@ -174,7 +177,7 @@ int32_t iguana_parsehexstr(uint8_t **destp,uint16_t *lenp,uint8_t *dest2,int32_t int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_msgvin *vin,cJSON *vinobj,struct vin_info *V) { - struct iguana_outpoint outpt; struct iguana_waddress *waddr; struct iguana_waccount *wacct; uint8_t lastbyte; uint32_t tmp=0; int32_t i,n,starti,suppress_pubkeys,siglen,plen,m,rwflag=1,need_op0=0,len = 0; char *userdata,*pubkeystr,*hexstr = 0,*redeemstr = 0,*spendstr = 0; cJSON *scriptjson = 0,*obj,*pubkeysjson = 0; + struct iguana_outpoint outpt; struct iguana_waddress *waddr; struct iguana_waccount *wacct; uint8_t lastbyte; uint32_t tmp=0; int32_t i,n,starti,suppress_pubkeys,siglen,plen,m,rwflag=1,need_op0=0,len = 0; char *userdata=0,*pubkeystr,*hexstr = 0,*redeemstr = 0,*spendstr = 0; cJSON *scriptjson = 0,*obj,*pubkeysjson = 0; //printf("PARSEVIN.(%s) vin.%p\n",jprint(vinobj,0),vin); if ( V == 0 ) memset(vin,0,sizeof(*vin)); @@ -240,7 +243,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin if ( hexstr != 0 ) { n = (int32_t)strlen(hexstr) >> 1; - printf("add.(%s) offset.%d\n",hexstr,len); + //printf("add.(%s) offset.%d\n",hexstr,len); vin->vinscript = &serialized[len]; decode_hex(&serialized[len],n,hexstr); vin->scriptlen = n + need_op0; @@ -257,8 +260,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin i++; } if ( m != n ) - printf("ERROR: "); - printf("len.%d n.%d i.%d\n",m,n,i); + printf("ERROR: len.%d n.%d i.%d\n",m,n,i); } len += n; } //else printf("iguana_parsevinobj: hex script missing (%s)\n",jprint(vinobj,0)); @@ -293,7 +295,7 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin if ( userdata != 0 ) { n = iguana_parsehexstr(&vin->userdata,&vin->userdatalen,V!=0?V->userdata:0,V!=0?&V->userdatalen:0,&serialized[len],userdata); - printf("parsed userdata.%d\n",n); + //printf("parsed userdata.%d\n",n); len += n; } //printf("len.%d: ",len); @@ -317,11 +319,29 @@ int32_t iguana_parsevinobj(struct supernet_info *myinfo,struct iguana_info *coin len += n; } tmp = (len - starti); - for (i=0; i> 8) & 0xff); + if ( tmp < 76 ) + { + serialized[starti-3] = tmp; + for (i=starti-2; i> 8) & 0xff); + } //printf("output sequence.[%d] <- %x\n",len,vin->sequence); len += iguana_rwnum(rwflag,&serialized[len],sizeof(vin->sequence),&vin->sequence); if ( spendstr != 0 ) @@ -351,8 +371,8 @@ int32_t iguana_parsevoutobj(struct iguana_info *coin,uint8_t *serialized,int32_t decode_hex(&serialized[len],n,hexstr); vout->pk_script = &serialized[len]; len += n; - } - } + } // else serialized[len++] = 0; + } //else serialized[len++] = 0; return(len); } @@ -431,7 +451,7 @@ bits256 bitcoin_sigtxid(struct iguana_info *coin,int32_t height,uint8_t *seriali dest.vins[i].redeemscript = 0; } len = iguana_rwmsgtx(coin,height,1,0,serialized,maxlen,&dest,&txid,vpnstr,0,0,0,suppress_pubkeys); - if ( len > 0 ) + if ( len > 0 ) // (dest.tx_in != 1 || bits256_nonz(dest.vins[0].prev_hash) != 0) && dest.vins[0].scriptlen > 0 && { #ifdef BTC2_VERSION if ( height >= BTC2_HARDFORK_HEIGHT ) @@ -531,7 +551,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ } for (i=0; itx_out; i++) { - //printf("vout.%d starts %d\n",i,len); + //printf("rwflag.%d vout.%d starts %d\n",rwflag,i,len); if ( (n= iguana_voutparse(rwflag,&serialized[len],&msg->vouts[i])) < 0 ) return(-1); len += n; @@ -549,7 +569,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ jaddnum(json,"numvouts",msg->tx_out); } len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->lock_time),&msg->lock_time); - //printf("lock_time.%08x\n",msg->lock_time); + //printf("lock_time.%08x len.%d\n",msg->lock_time,len); if ( strcmp(coin->symbol,"VPN") == 0 ) { uint16_t ddosflag = 0; @@ -613,7 +633,7 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin, { for (i=0; itx_in; i++) { - //printf("vinobj.%d starts offset.%d\n",i,len); + //printf("parsetxobj vinobj.%d starts offset.%d\n",i,len); len += iguana_parsevinobj(myinfo,coin,&serialized[len],maxsize,&msg->vins[i],jitem(array,i),V!=0?&V[i]:0); } } @@ -631,7 +651,7 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin, { for (i=0; itx_out; i++) { - //printf("parsevout.%d starts %d\n",i,len); + //printf("parsetxobj parsevout.%d starts %d\n",i,len); len += iguana_parsevoutobj(coin,&serialized[len],maxsize,&msg->vouts[i],jitem(array,i)); } } @@ -642,17 +662,6 @@ bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin, *txstartp = 0; msg->allocsize = len; msg->txid = txid = bits256_doublesha256(0,serialized,len); - //for (i=0; isuppress_pubkeys:0)) != msg->allocsize ) - { - //memset(txid.bytes,0,sizeof(txid)); - printf("error parsing txobj: expected %d got %d\n",msg->allocsize,len); - //msg->allocsize = 0; - } - msg->txid = txid;*/ - //char str[65]; printf("json -> %s\n",bits256_str(str,txid)); return(txid); } @@ -709,6 +718,8 @@ cJSON *bitcoin_data2json(struct iguana_info *coin,int32_t height,bits256 *txidp, jaddstr(txobj,"error","couldnt decode transaction"); jaddstr(txobj,"coin",coin->symbol); } + if ( n != len ) + printf("data2json n.%d vs len.%d\n",n,len); return(txobj); } @@ -719,7 +730,7 @@ cJSON *bitcoin_hex2json(struct iguana_info *coin,int32_t height,bits256 *txidp,s return(0); len = (int32_t)strlen(txbytes) >> 1; if ( (serialized= origserialized) == 0 ) - serialized = calloc(1,len); + serialized = calloc(1,len+4096); decode_hex(serialized,len,txbytes); txobj = bitcoin_data2json(coin,height,txidp,msgtx,extraspace,extralen,serialized,len,vins,suppress_pubkeys); if ( serialized != origserialized ) @@ -791,7 +802,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m msgtx->vins[vini].userdatalen = userdatalen; scriptlen += userdatalen; } - printf("USERDATALEN.%d scriptlen.%d redeemlen.%d\n",userdatalen,scriptlen,p2shlen); + //printf("USERDATALEN.%d scriptlen.%d redeemlen.%d\n",userdatalen,scriptlen,p2shlen); if ( p2shlen != 0 ) { if ( p2shlen < 76 ) @@ -822,7 +833,7 @@ int32_t iguana_msgtx_Vset(struct iguana_info *coin,uint8_t *serialized,int32_t m return(len); } -int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,int32_t sighash,int32_t signtx,int32_t suppress_pubkeys) +int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxlen,struct vin_info *V,uint32_t sighash,int32_t signtx,int32_t suppress_pubkeys) { bits256 sigtxid; uint8_t *sig; struct vin_info *vp; char vpnstr[64]; int32_t complete=0,plen,j,vini=0,flag=0,siglen,numvouts,numsigs; numvouts = msgtx->tx_out; @@ -863,7 +874,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign if ( bitcoin_verify(coin->ctx,sig,siglen-1,sigtxid,vp->signers[j].pubkey,bitcoin_pubkeylen(vp->signers[j].pubkey)) < 0 ) { - printf("SIG.%d.%d ERROR\n",vini,j); + //printf("SIG.%d.%d ERROR siglen.%d\n",vini,j,siglen); } else { @@ -874,8 +885,8 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign printf("%02x",sig[z]); printf(" <- sig[%d]n\n",j); for (z=0; z<33; z++) - printf("%02x",vp->signers[j].pubkey[z]); - printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M);*/ + printf("%02x",vp->signers[j].pubkey[z]);*/ + //printf(" <- pub, SIG.%d.%d VERIFIED numsigs.%d vs M.%d\n",vini,j,numsigs,vp->M); } } if ( numsigs >= vp->M ) @@ -885,7 +896,7 @@ int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *sign iguana_msgtx_Vset(coin,serialized,maxlen,msgtx,V); cJSON *txobj = cJSON_CreateObject(); *signedtx = iguana_rawtxbytes(coin,height,txobj,msgtx,suppress_pubkeys); - printf("SIGNEDTX.(%s)\n",jprint(txobj,1)); + //printf("SIGNEDTX.(%s)\n",jprint(txobj,1)); *signedtxidp = msgtx->txid; return(complete); } @@ -1149,6 +1160,8 @@ int32_t iguana_interpreter(struct iguana_info *coin,cJSON *logarray,int64_t nLoc activescriptlen = V[vini].spendlen; } spendscript = iguana_spendasm(coin,activescript,activescriptlen); + if ( activescriptlen < 16 ) + continue; //printf("interpreter.(%s)\n",jprint(spendscript,0)); if ( (scriptlen= bitcoin_assembler(coin,logarray,script,spendscript,1,nLockTime,&V[vini])) < 0 ) { @@ -1263,7 +1276,7 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf { printf("txobj.(%s)\n",jprint(txobj,0)); } - if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) + if ( 0 && (checkstr= bitcoin_json2hex(myinfo,coin,&txid,txobj,V)) != 0 ) // no guarantee of identical regen { if ( strcmp(rawtx,checkstr) != 0 ) { @@ -1314,17 +1327,6 @@ int32_t iguana_signrawtransaction(struct supernet_info *myinfo,struct iguana_inf *signedtxp = signedtx; return(complete); } -int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin,int32_t vini) -{ - //int32_t i; - if ( vin->vinscript != 0 && vin->scriptlen >= 70 ) - { - //for (i=0; iscriptlen; i++) - // printf("%02x",vin->vinscript[i]); - } - //printf(" vin.[%d] validate len.%d\n",vini,vin->scriptlen); - return(0); -} STRING_ARRAY_OBJ_STRING(bitcoinrpc,signrawtransaction,rawtx,vins,privkeys,sighash) { diff --git a/iguana/iguana_spendvectors.c b/iguana/iguana_spendvectors.c index 3001c969d..54a17bd9f 100755 --- a/iguana/iguana_spendvectors.c +++ b/iguana/iguana_spendvectors.c @@ -793,7 +793,7 @@ void iguana_initfinal(struct supernet_info *myinfo,struct iguana_info *coin,bits if ( (bp= coin->bundles[i]) != 0 && bp->queued == 0 ) { //printf("%d ",i); - iguana_bundleQ(coin,bp,1000); + iguana_bundleQ(myinfo,coin,bp,1000); } } printf("iguana_bundlesQ %d to %d\n",coin->balanceswritten,coin->bundlescount); @@ -1092,7 +1092,7 @@ int32_t iguana_convert(struct iguana_info *coin,int32_t helperid,struct iguana_b return(converted); } -int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag) +int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag) { static int32_t totalerrs,totalvalidated; FILE *fp; char fname[1024]; uint8_t *blockspace; //uint32_t now = (uint32_t)time(NULL); @@ -1127,7 +1127,7 @@ int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp, iguana_volatilesmap(coin,&bp->ramchain); for (i=0; in; i++) { - if ( (len= iguana_peerblockrequest(coin,blockspace,max,0,bp->hashes[i],1)) < 0 ) + if ( (len= iguana_peerblockrequest(myinfo,coin,blockspace,max,0,bp->hashes[i],1)) < 0 ) { errs++; iguana_blockunmark(coin,bp->blocks[i],bp,i,1); diff --git a/iguana/iguana_tx.c b/iguana/iguana_tx.c index 2d4b6407e..b3a04ed60 100755 --- a/iguana/iguana_tx.c +++ b/iguana/iguana_tx.c @@ -196,11 +196,6 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m iguana_vinset(coin,space,height,&vin,tx,i); else vin = vins[i]; len += iguana_rwvin(rwflag,coin,0,&serialized[len],&vin,i); - if ( validatesigs != 0 && iguana_validatesigs(coin,&vin,i) < 0 ) - { - char str[65]; printf("error %s validating vin.%d ht.%d\n",bits256_str(str,tx->txid),i,height); - //return(0); - } } if ( len > maxlen ) { @@ -234,7 +229,7 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m return(len); } -int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs) +int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs) { struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgblock msgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata; if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n ) @@ -249,7 +244,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int { iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,0); msgB.txn_count = block->RO.txn_count; - total = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB,max); + total = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB,max); if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 ) { //static int counter; @@ -320,7 +315,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int for (i=0; i<16; i++) printf("%02x",blockspace[i + sizeof(struct iguana_msghdr)+81]); printf(" txhdr\n"); - if ( (checklen= iguana_gentxarray(coin,&RAWMEM,&txdata,&checklen,&blockspace[sizeof(struct iguana_msghdr)],total)) != total && checklen != total-1 ) + if ( (checklen= iguana_gentxarray(myinfo,coin,&RAWMEM,&txdata,&checklen,&blockspace[sizeof(struct iguana_msghdr)],total)) != total && checklen != total-1 ) printf("Error reconstructing txarray checklen.%d total.%d\n",checklen,total); } return(iguana_queue_send(addr,0,blockspace,"block",total)); @@ -346,7 +341,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int return(-1); } -cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag) +cJSON *iguana_blockjson(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag) { char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgblock msg; bits256 hash2,nexthash2; uint8_t serialized[1024]; cJSON *array,*json = cJSON_CreateObject(); @@ -396,7 +391,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3 msg.zH.solution[i] = block->zRO[0].solution[i]; } else msg.H.nonce = block->RO.nonce; msg.txn_count = 0;//block->RO.txn_count; - len = iguana_rwblock(coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&msg,IGUANA_MAXPACKETSIZE*2); + len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&msg,IGUANA_MAXPACKETSIZE*2); init_hexbytes_noT(hexstr,serialized,len); jaddstr(json,"blockheader",hexstr); if ( txidsflag != 0 ) @@ -410,7 +405,7 @@ cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int3 jadd(json,"tx",array); //printf("add txids[%d]\n",block->txn_count); } - if ( (size= iguana_peerblockrequest(coin,coin->blockspace,coin->blockspacesize,0,block->RO.hash2,0)) < 0 ) + if ( (size= iguana_peerblockrequest(myinfo,coin,coin->blockspace,coin->blockspacesize,0,block->RO.hash2,0)) < 0 ) jaddstr(json,"error","couldnt generate raw bytes for block"); else jaddnum(json,"size",size); return(json); diff --git a/iguana/iguana_wallet.c b/iguana/iguana_wallet.c index 9cc62be75..ce2ec4718 100755 --- a/iguana/iguana_wallet.c +++ b/iguana/iguana_wallet.c @@ -78,7 +78,7 @@ struct iguana_waccount *iguana_waccountcreate(struct supernet_info *myinfo,char wacct = mycalloc('w',1,sizeof(*wacct) + len); strcpy(wacct->account,account); HASH_ADD_KEYPTR(hh,myinfo->wallet,wacct->account,len,wacct); - printf("waccountcreate.(%s) -> wacct.%p\n",account,wacct); + //printf("waccountcreate.(%s) -> wacct.%p\n",account,wacct); if ( (ptr= iguana_waccountfind(myinfo,account)) != wacct ) { printf("ERROR: iguana_waccountcreate verify error %p vs %p\n",ptr,wacct); @@ -815,7 +815,7 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi } printf("persistent address not found in wallet, autoadd.(%s)\n",coinaddr); } - else if ( persistent_flag != 0 ) + else if ( persistent_flag != 0 && 0 ) printf("found persistent address in wallet\n"); } portable_mutex_unlock(&myinfo->bu_mutex); @@ -825,9 +825,8 @@ cJSON *iguana_walletiterate(struct supernet_info *myinfo,struct iguana_info *coi *badp = bad; if ( iguana_waddresssearch(myinfo,&wacct,myinfo->myaddr.BTCD) != 0 ) { - printf("found persistent address.(%s)\n",myinfo->myaddr.BTCD); + //printf("found persistent address.(%s)\n",myinfo->myaddr.BTCD); } - return(array); } @@ -1095,7 +1094,7 @@ ZERO_ARGS(bitcoinrpc,getinfo) jaddnum(retjson,"txfee",dstr(coin->txfee)); if ( coin->bundlescount > 1 ) { - jaddnum(retjson,"bundles",_max100(100. * (double)(iguana_emitfinished(coin,0))/(coin->longestchain/coin->chain->bundlesize))); + jaddnum(retjson,"bundles",_max100(100. * (double)(iguana_emitfinished(myinfo,coin,0))/(coin->longestchain/coin->chain->bundlesize))); jaddnum(retjson,"utxo",_max100(100. * (double)(iguana_utxofinished(coin))/(coin->longestchain/coin->chain->bundlesize))); jaddnum(retjson,"balances",_max100(100. * (double)(iguana_balancefinished(coin))/(coin->longestchain/coin->chain->bundlesize))); jaddnum(retjson,"validated",_max100(100. * (double)(iguana_validated(coin))/(coin->longestchain/coin->chain->bundlesize))); diff --git a/iguana/main.c b/iguana/main.c index d14e9fb4f..1f28ba396 100755 --- a/iguana/main.c +++ b/iguana/main.c @@ -519,7 +519,7 @@ void iguana_appletests(struct supernet_info *myinfo) char genesisblock[1024]; //iguana_chaingenesis("VPN",0,bits256_conv("00000ac7d764e7119da60d3c832b1d4458da9bc9ef9d5dd0d91a15f690a46d99"),genesisblock,"scrypt",1,1409839200,0x1e0fffff,64881664,bits256_conv("698a93a1cacd495a7a4fb3864ad8d06ed4421dedbc57f9aaad733ea53b1b5828")); // VPN - iguana_chaingenesis("LTC",0,0,0,bits256_conv("12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2"),genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC + iguana_chaingenesis(myinfo,"LTC",0,0,0,bits256_conv("12a765e31ffd4059bada1e25190f6e98c99d9714d334efa41a195a7e7e04bfe2"),genesisblock,"sha256",1,1317972665,0x1e0ffff0,2084524493,bits256_conv("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); // LTC //char *Str = "01000000f615f7ce3b4fc6b8f61e8f89aedb1d0852507650533a9e3b10b9bbcc30639f279fcaa86746e1ef52d3edb3c4ad8259920d509bd073605c9bf1d59983752a6b06b817bb4ea78e011d012d59d4"; // https://litecoin.info/Scrypt 0000000110c8357966576df46f3b802ca897deb7ad18b12f1c24ecff6386ebd9 //uint8_t buf[1000]; bits256 shash,hash2; char str[65],str2[65]; diff --git a/iguana/ramchain_api.c b/iguana/ramchain_api.c index 1b451af15..f78a33d2d 100755 --- a/iguana/ramchain_api.c +++ b/iguana/ramchain_api.c @@ -72,7 +72,7 @@ STRING_ARG(iguana,validate,activecoin) for (i=total=validated=0; ibundlescount; i++) if ( (bp= coin->bundles[i]) != 0 ) { - validated += iguana_bundlevalidate(coin,bp,1); + validated += iguana_bundlevalidate(myinfo,coin,bp,1); total += bp->n; } retjson = cJSON_CreateObject(); @@ -138,10 +138,10 @@ HASH_AND_TWOINTS(bitcoinrpc,getblock,blockhash,verbose,remoteonly) if ( remoteonly == 0 && (block= iguana_blockfind("getblockRPC",coin,blockhash)) != 0 ) { if ( verbose != 0 ) - return(jprint(iguana_blockjson(coin,block,1),1)); + return(jprint(iguana_blockjson(myinfo,coin,block,1),1)); else { - if ( (len= iguana_peerblockrequest(coin,coin->blockspace,coin->blockspacesize,0,blockhash,0)) > 0 ) + if ( (len= iguana_peerblockrequest(myinfo,coin,coin->blockspace,coin->blockspacesize,0,blockhash,0)) > 0 ) { datastr = malloc(len*2 + 1); init_hexbytes_noT(datastr,coin->blockspace,len); diff --git a/includes/iguana_funcs.h b/includes/iguana_funcs.h index 164aa5795..4f5d1e760 100755 --- a/includes/iguana_funcs.h +++ b/includes/iguana_funcs.h @@ -41,22 +41,22 @@ int32_t iguana_rwmem(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp); int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p); int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp); -int32_t iguana_rwblock(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen); -int32_t iguana_serialize_block(struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block); +int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen); +int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block); void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height); //void iguana_freetx(struct iguana_msgtx *tx,int32_t n); -int32_t iguana_msgparser(struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache); +int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache); // send message int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H); int32_t iguana_sethdr(struct iguana_msghdr *H,const uint8_t netmagic[4],char *command,uint8_t *data,int32_t datalen); int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); -int32_t iguana_gentxarray(struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txblock,int32_t *lenp,uint8_t *data,int32_t datalen); +int32_t iguana_gentxarray(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txblock,int32_t *lenp,uint8_t *data,int32_t datalen); int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr); int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n); void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count); -int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs); -int32_t iguana_validatesigs(struct iguana_info *coin,struct iguana_msgvin *vin,int32_t vini); +int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs); +int32_t iguana_validatesigs(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t datalen); // ramchain int64_t iguana_verifyaccount(struct iguana_info *coin,struct iguana_account *acct,uint32_t pkind); @@ -65,7 +65,7 @@ void iguana_syncramchain(struct iguana_info *coin); //int32_t iguana_validateramchain(struct iguana_info *coin,int64_t *netp,uint64_t *creditsp,uint64_t *debitsp,int32_t height,struct iguana_block *block,int32_t hwmheight,struct iguana_prevdep *lp); int32_t iguana_calcrmd160(struct iguana_info *coin,char *asmstr,struct vin_info *vp,uint8_t *pk_script,int32_t pk_scriptlen,bits256 debugtxid,int32_t vout,uint32_t sequence); uint32_t iguana_updatescript(struct iguana_info *coin,uint32_t blocknum,uint32_t txidind,uint32_t spendind,uint32_t unspentind,uint64_t value,uint8_t *script,int32_t scriptlen,uint32_t sequence); -void iguana_gotblockM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache); +void iguana_gotblockM(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_txblock *txdata,struct iguana_msgtx *txarray,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache); int32_t iguana_parseblock(struct iguana_info *coin,struct iguana_block *block,struct iguana_msgtx *tx,int32_t numtx); uint32_t iguana_txidind(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,bits256 txid); bits256 iguana_txidstr(struct iguana_info *coin,uint32_t *firstvoutp,uint32_t *firstvinp,char *txidstr,uint32_t txidind); @@ -74,12 +74,12 @@ int32_t iguana_updateramchain(struct iguana_info *coin); // blockchain int32_t iguana_needhdrs(struct iguana_info *coin); -struct iguana_chain *iguana_chainfind(char *name,cJSON *argjson,int32_t createflag); +struct iguana_chain *iguana_chainfind(struct supernet_info *myinfo,char *name,cJSON *argjson,int32_t createflag); int32_t iguana_chainextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *newblock); uint64_t iguana_miningreward(struct iguana_info *coin,uint32_t blocknum); // tx -int32_t iguana_rwtx(uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin); +int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,struct iguana_info *coin,struct OS_memspace *mem,uint8_t *serialized,struct iguana_msgtx *msg,int32_t maxsize,bits256 *txidp,int32_t hastimestamp,int32_t isvpncoin); void iguana_gottxidsM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *txids,int32_t n); void iguana_gotquotesM(struct iguana_info *coin,struct iguana_peer *addr,bits256 *quotes,int32_t n); void iguana_gotunconfirmedM(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msgtx *tx,uint8_t *data,int32_t datalen); @@ -120,7 +120,7 @@ int32_t iguana_avail(struct iguana_info *coin,int32_t height,int32_t n); int32_t iguana_updatebundles(struct iguana_info *coin); uint64_t iguana_utxoaddrtablefind(struct iguana_info *coin,int16_t search_hdrsi,uint32_t search_pkind,uint8_t rmd160[20]); void iguana_bundlestats(struct supernet_info *myinfo,struct iguana_info *coin,char *str,int32_t lag); -void iguana_chaininit(struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson); +void iguana_chaininit(struct supernet_info *myinfo,struct iguana_chain *chain,int32_t hasheaders,cJSON *argjson); void iguana_coinargs(char *symbol,int64_t *maxrecvcachep,int32_t *minconfirmsp,int32_t *maxpeersp,int32_t *initialheightp,uint64_t *servicesp,int32_t *maxrequestsp,int32_t *maxbundlesp,cJSON *json); struct iguana_info *iguana_setcoin(char *symbol,void *launched,int32_t maxpeers,int64_t maxrecvcache,uint64_t services,int32_t initialheight,int32_t maphash,int32_t minconfirms,int32_t maxrequests,int32_t maxbundles,cJSON *json,int32_t virtcoin); @@ -197,7 +197,7 @@ long iguana_ramchain_data(struct iguana_info *coin,struct iguana_peer *addr,stru int32_t iguana_bundlehash2add(struct iguana_info *coin,struct iguana_block **blockp,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2); struct iguana_block *iguana_bundleblockadd(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,struct iguana_block *origblock); int32_t iguana_chainextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *newblock); -int32_t iguana_blockvalidate(struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag); +int32_t iguana_blockvalidate(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *validp,struct iguana_block *block,int32_t dispflag); char *iguana_bundledisp(struct iguana_info *coin,struct iguana_bundle *prevbp,struct iguana_bundle *bp,struct iguana_bundle *nextbp,int32_t m); struct iguana_bundle *iguana_bundlefind(struct iguana_info *coin,struct iguana_bundle **bpp,int32_t *bundleip,bits256 hash2); //int32_t iguana_chainheight(struct iguana_info *coin,struct iguana_block *origblock); @@ -247,7 +247,7 @@ void peggy(); int32_t opreturns_init(uint32_t blocknum,uint32_t blocktimestamp,char *path); struct iguana_info *iguana_coinfind(char *symbol); struct iguana_info *iguana_coinadd(char *symbol,char *nane,cJSON *json,int32_t virtcoin); -struct iguana_ramchain *iguana_bundleload(struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag); +struct iguana_ramchain *iguana_bundleload(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_ramchain *ramchain,struct iguana_bundle *bp,int32_t extraflag); int32_t iguana_sendblockreq(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); int32_t iguana_send_supernet(struct iguana_peer *addr,char *jsonstr,int32_t delay); @@ -261,12 +261,12 @@ cJSON *iguana_peersjson(struct iguana_info *coin,int32_t addronly); //int32_t btc_priv2wif(char *wifstr,uint8_t privkey[32],uint8_t addrtype); //int32_t btc_pub2rmd(uint8_t rmd160[20],uint8_t pubkey[33]); int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json,int32_t virtcoin); -int32_t iguana_bundleinitmap(struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1); +int32_t iguana_bundleinitmap(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t height,bits256 hash2,bits256 hash1); int32_t iguana_jsonQ(struct supernet_info *myinfo,struct iguana_info *coin); int32_t is_bitcoinrpc(struct supernet_info *myinfo,char *method,char *remoteaddr); char *iguana_bitcoinRPC(struct supernet_info *myinfo,char *method,cJSON *json,char *remoteaddr,uint16_t port); cJSON *iguana_pubkeyjson(struct iguana_info *coin,char *pubkeystr); -void iguana_bundleQ(struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit); +void iguana_bundleQ(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t timelimit); int32_t iguana_bundleiters(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct OS_memspace *memB,struct iguana_bundle *bp,int32_t timelimit,int32_t lag); void ramcoder_test(void *data,int64_t len); void iguana_exit(); @@ -278,10 +278,10 @@ int32_t SuperNET_sendmsg(struct supernet_info *myinfo,struct iguana_info *coin,s int32_t category_peer(struct supernet_info *myinfo,struct iguana_peer *addr,bits256 category,bits256 subhash); int32_t bitcoin_wif2priv(uint8_t *addrtypep,bits256 *privkeyp,char *wifstr); int32_t bitcoin_priv2wif(char *wifstr,bits256 privkey,uint8_t addrtype); -bits256 iguana_chaingenesis(char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t bits,uint32_t nonce,bits256 merkle_root); +bits256 iguana_chaingenesis(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t bits,uint32_t nonce,bits256 merkle_root); int32_t iguana_send_ConnectTo(struct iguana_info *coin,struct iguana_peer *addr); cJSON *iguana_txjson(struct iguana_info *coin,struct iguana_txid *tx,int32_t height,struct vin_info *V); -char *iguana_txscan(struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid); +char *iguana_txscan(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid); char *iguana_rawtxbytes(struct iguana_info *coin,int32_t height,cJSON *json,struct iguana_msgtx *msgtx,int32_t suppress_pubkeys); int32_t iguana_send_VPNversion(struct iguana_info *coin,struct iguana_peer *addr,uint64_t myservices); void exchanges777_init(struct supernet_info *myinfo,cJSON *exchanges,int32_t sleepflag); @@ -290,7 +290,7 @@ int32_t iguana_rwvin(int32_t rwflag,struct iguana_info *coin,struct OS_memspace int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJSON *json,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,bits256 *txidp,char *vpnstr,uint8_t *extraspace,int32_t extralen,cJSON *vins,int32_t suppress_pubkeys); int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs); cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid); -cJSON *iguana_blockjson(struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag); +cJSON *iguana_blockjson(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag); int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg); //int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 privkey); //int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey); @@ -315,7 +315,7 @@ char *bitcoin_json2hex(struct supernet_info *myinfo,struct iguana_info *coin,bit int32_t bitcoin_addr2rmd160(uint8_t *addrtypep,uint8_t rmd160[20],char *coinaddr); char *issue_startForging(struct supernet_info *myinfo,char *secret); struct bitcoin_unspent *iguana_unspentsget(struct supernet_info *myinfo,struct iguana_info *coin,char **retstrp,double *balancep,int32_t *numunspentsp,double minconfirms,char *address); -void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson); +void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,cJSON *argjson); int32_t iguana_RTpkhasharray(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *array,int32_t minconf,int32_t maxconf,uint64_t *totalp,struct iguana_pkhash *P,int32_t max,uint8_t rmd160[20],char *coinaddr,uint8_t *pubkey33,int32_t lastheight,struct iguana_outpoint *unspents,int32_t *numunspentsp,int32_t maxunspents,char *remoteaddr,int32_t includespent); long iguana_spentsfile(struct iguana_info *coin,int32_t n); uint8_t *iguana_rmdarray(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *numrmdsp,cJSON *array,int32_t firsti); @@ -325,12 +325,12 @@ void iguana_hhutxo_purge(struct iguana_info *coin); char *iguana_bundleaddrs(struct iguana_info *coin,int32_t hdrsi); uint32_t iguana_sparseaddpk(uint8_t *bits,int32_t width,uint32_t tablesize,uint8_t rmd160[20],struct iguana_pkhash *P,uint32_t pkind,struct iguana_ramchain *ramchain); int32_t iguana_vinscriptparse(struct iguana_info *coin,struct vin_info *vp,uint32_t *sigsizep,uint32_t *pubkeysizep,uint32_t *p2shsizep,uint32_t *suffixp,uint8_t *vinscript,int32_t scriptlen); -void iguana_parsebuf(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache); +void iguana_parsebuf(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct iguana_msghdr *H,uint8_t *buf,int32_t len,int32_t fromcache); int32_t _iguana_calcrmd160(struct iguana_info *coin,struct vin_info *vp); int32_t iguana_spendvectors(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct iguana_ramchain *ramchain,int32_t starti,int32_t numblocks,int32_t convertflag,int32_t iterate); int32_t iguana_balancegen(struct iguana_info *coin,int32_t incremental,struct iguana_bundle *bp,int32_t startheight,int32_t endheight,int32_t startemit); struct iguana_utxoaddr *iguana_utxoaddrfind(int32_t createflag,struct iguana_info *coin,int16_t hdrsi,uint32_t pkind,uint8_t rmd160[20],struct iguana_utxoaddr **prevp); -int32_t iguana_bundlevalidate(struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag); +int32_t iguana_bundlevalidate(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t forceflag); void iguana_validateQ(struct iguana_info *coin,struct iguana_bundle *bp); struct iguana_bloominds iguana_calcbloom(bits256 hash2); int32_t iguana_bloomfind(struct iguana_info *coin,struct iguana_bloom16 *bloom,int32_t incr,struct iguana_bloominds bit); @@ -342,7 +342,7 @@ int32_t iguana_bundleissue(struct iguana_info *coin,struct iguana_bundle *bp,int int32_t iguana_balancecalc(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); int32_t iguana_sendblockreqPT(struct iguana_info *coin,struct iguana_peer *addr,struct iguana_bundle *bp,int32_t bundlei,bits256 hash2,int32_t iamthreadsafe); int32_t iguana_blockreq(struct iguana_info *coin,int32_t height,int32_t priority); -int64_t iguana_bundlecalcs(struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag); +int64_t iguana_bundlecalcs(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t lag); int32_t iguana_ramchain_prefetch(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t txonly); int32_t iguana_realtime_update(struct supernet_info *myinfo,struct iguana_info *coin); int32_t iguana_volatilesmap(struct iguana_info *coin,struct iguana_ramchain *ramchain); @@ -356,7 +356,7 @@ int32_t iguana_ramchain_iterate(struct supernet_info *myinfo,struct iguana_info void *iguana_bundlefile(struct iguana_info *coin,char *fname,long *filesizep,struct iguana_bundle *bp,int32_t bundlei,int32_t renameflag); int32_t iguana_mapchaininit(char *fname,struct iguana_info *coin,struct iguana_ramchain *mapchain,struct iguana_bundle *bp,int32_t bundlei,struct iguana_block *block,void *ptr,long filesize); void iguana_RTdataset_free(struct iguana_info *coin); -void iguana_autoextend(struct iguana_info *coin,struct iguana_bundle *bp); +void iguana_autoextend(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp); //void iguana_RTramchainfree(struct iguana_info *coin,struct iguana_bundle *bp); void iguana_coinpurge(struct iguana_info *coin); void tradebot_liquidity_command(struct supernet_info *myinfo,char *targetcoin,bits256 hash,cJSON *vals); @@ -384,7 +384,7 @@ struct iguana_block *iguana_fastlink(struct iguana_info *coin,int32_t hwmheight) int32_t iguana_balancenormal(struct iguana_info *coin,struct iguana_bundle *bp,int32_t startheight,int32_t endheight); int32_t iguana_spendvectorsaves(struct iguana_info *coin); int32_t iguana_convertfinished(struct iguana_info *coin); -int32_t iguana_emitfinished(struct iguana_info *coin,int32_t queueincomplete); +int32_t iguana_emitfinished(struct supernet_info *myinfo,struct iguana_info *coin,int32_t queueincomplete); int32_t iguana_utxofinished(struct iguana_info *coin); int32_t iguana_balancefinished(struct iguana_info *coin); int32_t iguana_alloctxbits(struct iguana_info *coin,struct iguana_ramchain *ramchain); @@ -402,7 +402,7 @@ int32_t iguana_bundleremove(struct iguana_info *coin,int32_t hdrsi,int32_t tmpfi int32_t iguana_voutsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); int32_t iguana_vinsfname(struct iguana_info *coin,int32_t roflag,char *fname,int32_t slotid); bits256 iguana_merkle(bits256 *tree,int32_t txn_count); -int32_t iguana_bundleready(struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag); +int32_t iguana_bundleready(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,int32_t requiredflag); int32_t iguana_blast(struct iguana_info *coin,struct iguana_peer *addr); int32_t iguana_validated(struct iguana_info *coin); void iguana_volatilesalloc(struct iguana_info *coin,struct iguana_ramchain *ramchain,int32_t copyflag); @@ -439,7 +439,7 @@ struct iguana_txid *iguana_blocktx(struct iguana_info *coin,struct iguana_txid * cJSON *iguana_p2shjson(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *retjson,struct iguana_waddress *waddr); char *setaccount(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_waddress **waddrp,char *account,char *coinaddr,char *redeemScript); char *iguana_APIrequest(struct iguana_info *coin,bits256 blockhash,bits256 txid,int32_t seconds); -int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxsize,struct vin_info *V,int32_t sighash,int32_t signtx,int32_t suppress_pubkeys); +int32_t bitcoin_verifyvins(struct iguana_info *coin,int32_t height,bits256 *signedtxidp,char **signedtx,struct iguana_msgtx *msgtx,uint8_t *serialized,int32_t maxsize,struct vin_info *V,uint32_t sighash,int32_t signtx,int32_t suppress_pubkeys); char *iguana_validaterawtx(struct supernet_info *myinfo,struct iguana_info *coin,int32_t height,struct iguana_msgtx *msgtx,uint8_t *extraspace,int32_t extralen,char *rawtx,int32_t mempool,int32_t suppress_pubkeys); int64_t iguana_fastfindcreate(struct iguana_info *coin); int32_t bitcoin_validaddress(struct iguana_info *coin,char *coinaddr); @@ -533,7 +533,7 @@ char *SuperNET_keysinit(struct supernet_info *myinfo,char *argjsonstr); char *SuperNET_parser(struct supernet_info *myinfo,char *agentstr,char *method,cJSON *json,char *remoteaddr); char *SuperNET_htmlstr(char *fname,char *htmlstr,int32_t maxsize,char *agentstr); void SuperNET_setkeys(struct supernet_info *myinfo,void *pass,int32_t passlen,int32_t dosha256); -int32_t iguana_headerget(struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block); +int32_t iguana_headerget(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block); int32_t iguana_bundlefinalize(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundle *bp,struct OS_memspace *mem,struct OS_memspace *memB); bits256 iguana_parsetxobj(struct supernet_info *myinfo,struct iguana_info *coin,int32_t *txstartp,uint8_t *serialized,int32_t maxsize,struct iguana_msgtx *msg,cJSON *txobj,struct vin_info *V); int32_t iguana_ROallocsize(struct iguana_info *virt); diff --git a/includes/iguana_structs.h b/includes/iguana_structs.h index 2ed6ab30f..dd67f1b6a 100755 --- a/includes/iguana_structs.h +++ b/includes/iguana_structs.h @@ -184,7 +184,7 @@ struct iguana_zblockRO } __attribute__((packed)); #define iguana_blockfields double PoW; \ -int32_t height,fpos; uint32_t fpipbits,issued,lag:19,protected:1,peerid:12; \ +int32_t height,fpos; uint32_t fpipbits,issued,lag:18,sigsvalid:1,protected:1,peerid:12; \ uint16_t hdrsi:15,mainchain:1,bundlei:11,valid:1,queued:1,txvalid:1,newtx:1,processed:1; \ UT_hash_handle hh; struct iguana_bundlereq *req; \ struct iguana_blockRO RO @@ -451,7 +451,7 @@ struct iguana_info struct OS_memspace RTrawmem,RTmem,RThashmem; // struct iguana_ramchain RTramchain; bits256 RThash1; int32_t numremain,numpendings,zcount,recvcount,bcount,pcount,lastbundle,numsaved,pendbalances,numverified,blockdepth; - uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked,lastcheckpoint; + uint32_t recvtime,hdrstime,backstoptime,lastbundletime,numreqsent,numbundlesQ,lastbundleitime,lastdisp,RTgenesis,firstRTgenesis,RTstarti,idletime,stucktime,stuckmonitor,maxstuck,lastreqtime,RThdrstime,nextchecked,lastcheckpoint,sigserrs,sigsvalidated; double bandwidth,maxbandwidth,backstopmillis; bits256 backstophash2; int64_t spaceused; int32_t disableUTXO,initialheight,mapflags,minconfirms,numrecv,bindsock,isRT,backstop,blocksrecv,merging,firstRTheight,polltimeout,numreqtxids,allhashes,balanceflush,basilisk_busy; bits256 reqtxids[64]; void *launched,*started,*rpcloop;