diff --git a/basilisk/basilisk.c b/basilisk/basilisk.c index a86c42cff..d255cdf19 100755 --- a/basilisk/basilisk.c +++ b/basilisk/basilisk.c @@ -60,21 +60,21 @@ char *basilisk_addhexstr(char **ptrp,cJSON *valsobj,char *strbuf,int32_t strsize return(strbuf); } -uint8_t *get_dataptr(uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr) +uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr) { - *ptrp = 0; uint8_t *data = 0; uint32_t basilisktag; + *ptrp = 0; uint8_t *data = 0; if ( hexstr != 0 && (*datalenp= is_hexstr(hexstr,0)) > 0 ) { *datalenp >>= 1; - if ( (*datalenp+BASILISK_HDROFFSET) <= spacesize ) + if ( (*datalenp+hdroffset) <= spacesize ) { - memset(space,0,BASILISK_HDROFFSET); - data = &space[BASILISK_HDROFFSET]; - } else *ptrp = data = calloc(1,*datalenp + BASILISK_HDROFFSET); - decode_hex(&data[BASILISK_HDROFFSET],*datalenp,hexstr); + memset(space,0,hdroffset); + data = &space[hdroffset]; + } else *ptrp = data = calloc(1,*datalenp + hdroffset); + decode_hex(&data[hdroffset],*datalenp,hexstr); } if ( data != 0 ) - return(&data[BASILISK_HDROFFSET]); + return(&data[hdroffset]); else return(data); } @@ -269,14 +269,15 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *vi if ( virt->TXMEM.ptr == 0 ) iguana_meminit(&virt->TXMEM,virt->name,0,IGUANA_MAXPACKETSIZE * 2,0); iguana_memreset(&virt->TXMEM); - if ( (data= get_dataptr(&allocptr,&recvlen,space,sizeof(space),blockstr)) != 0 ) + if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&recvlen,space,sizeof(space),blockstr)) != 0 ) { memset(&txdata,0,sizeof(txdata)); if ( (n= iguana_gentxarray(virt,&virt->TXMEM,&txdata,&len,data,recvlen)) == recvlen ) { len = n; memset(&H,0,sizeof(H)); - iguana_gotblockM(virt,&virt->internaladdr,&txdata,virt->TXMEM.ptr,&H,data,recvlen); + gecko_blockarrived(myinfo,&virt->internaladdr,0,data,recvlen); + //iguana_gotblockM(virt,&virt->internaladdr,&txdata,virt->TXMEM.ptr,&H,data,recvlen); } } if ( allocptr != 0 ) @@ -407,7 +408,7 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 ha { uint32_t nBits = 0; uint8_t space[8192],*allocptr=0,*data = 0; struct basilisk_item *ptr,Lptr; int32_t datalen = 0; cJSON *retjson; retjson = cJSON_CreateObject(); - data = get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr); + data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr); ptr = basilisk_requestservice(myinfo,CMD,valsobj,hash,data,datalen,nBits); if ( allocptr != 0 ) free(allocptr); @@ -738,9 +739,6 @@ HASH_ARRAY_STRING(basilisk,VPNlogout,pubkey,vals,hexstr) void basilisks_loop(void *arg) { basilisk_metricfunc metricfunc; struct iguana_info *btcd,*virt,*hhtmp; struct basilisk_item *ptr,*tmp,*pending,*parent; int32_t i,iter,maxmillis,done,flag,n; cJSON *valsobj,*retjson; uint32_t now; struct supernet_info *myinfo = arg; - //uint8_t *blockspace; struct OS_memspace RAWMEM; - //memset(&RAWMEM,0,sizeof(RAWMEM)); - //blockspace = calloc(1,IGUANA_MAXPACKETSIZE); iter = 0; while ( 1 ) { @@ -919,7 +917,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *addr,uint32_t sender // gecko chains { (void *)"NEW", &basilisk_respond_newgeckochain }, // creates new virtual gecko chain { (void *)"SEQ", &basilisk_respond_hashstamps }, // BTCD and BTC recent hashes from timestamp - { (void *)"VTX", &basilisk_respond_geckotx }, + { (void *)"GTX", &basilisk_respond_geckotx }, { (void *)"BLK", &basilisk_respond_geckoblock }, { (void *)"GEN", &basilisk_respond_geckogenesis }, diff --git a/basilisk/basilisk.h b/basilisk/basilisk.h index 18c8d00de..0e6e6287b 100755 --- a/basilisk/basilisk.h +++ b/basilisk/basilisk.h @@ -25,7 +25,7 @@ #define BASILISK_MAXFUTUREBLOCK 60 #define BASILISK_MAXBLOCKLAG 600 -#define BASILISK_HDROFFSET ((int32_t)(sizeof(struct iguana_msghdr)+sizeof(basilisktag))) +#define BASILISK_HDROFFSET ((int32_t)(sizeof(struct iguana_msghdr)+sizeof(uint32_t))) struct basilisk_value { bits256 txid; int64_t value; int32_t height; int16_t vout; char coinaddr[64]; }; @@ -53,7 +53,7 @@ uint8_t *basilisk_jsondata(uint8_t **ptrp,uint8_t *space,int32_t spacesize,int32 uint8_t *SuperNET_ciphercalc(void **ptrp,int32_t *cipherlenp,bits256 *privkeyp,bits256 *destpubkeyp,uint8_t *data,int32_t datalen,uint8_t *space2,int32_t space2size); void *SuperNET_deciphercalc(void **ptrp,int32_t *msglenp,bits256 privkey,bits256 srcpubkey,uint8_t *cipher,int32_t cipherlen,uint8_t *buf,int32_t bufsize); -uint8_t *get_dataptr(uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr); +uint8_t *get_dataptr(int32_t hdroffset,uint8_t **ptrp,int32_t *datalenp,uint8_t *space,int32_t spacesize,char *hexstr); char *basilisk_addhexstr(char **ptrp,cJSON *valsobj,char *strbuf,int32_t strsize,uint8_t *data,int32_t datalen); char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag); // client side diff --git a/gecko/gecko.c b/gecko/gecko.c index 381fbeac4..c437681a7 100755 --- a/gecko/gecko.c +++ b/gecko/gecko.c @@ -16,6 +16,7 @@ #include "../iguana/iguana777.h" #include "gecko_delayedPoW.c" #include "gecko_miner.c" +#include "gecko_blocks.c" bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory) { @@ -233,7 +234,7 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo safecopy(virt->name,chainname,sizeof(virt->name)); virt->chain = calloc(1,sizeof(*virt->chain)); virt->enableCACHE = 1; - serialized = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); + serialized = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); iguana_chaininit(virt->chain,1,valsobj); 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 ) @@ -390,7 +391,7 @@ char *basilisk_respond_geckotx(struct supernet_info *myinfo,char *CMD,void *addr char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash2,int32_t from_basilisk) { - char *symbol; struct iguana_info *virt; bits256 checkhash2; int32_t hdrsize; uint32_t nBits; struct iguana_msgblock msg; struct iguana_block newblock; + char *symbol; struct iguana_info *virt; bits256 checkhash2; int32_t hdrsize; uint32_t nBits; struct iguana_msgblock msg; printf("got geckoblock len.%d from (%s) %s\n",datalen,remoteaddr!=0?remoteaddr:"",jprint(valsobj,0)); if ( (symbol= jstr(valsobj,"coin")) != 0 && (virt= iguana_coinfind(symbol)) != 0 ) { @@ -401,11 +402,12 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a iguana_rwblock(symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen); if ( bits256_cmp(hash2,checkhash2) == 0 ) { - iguana_blockconv(virt->chain->zcash,virt->chain->auxpow,&newblock,&msg,hash2,jint(valsobj,"ht")); + /*iguana_blockconv(virt->chain->zcash,virt->chain->auxpow,&newblock,&msg,hash2,jint(valsobj,"ht")); if ( _iguana_chainlink(virt,&newblock) != 0 ) { return(clonestr("{\"result\":\"gecko chain extended\"}")); - } else return(clonestr("{\"result\":\"block not HWM\"}")); + } else return(clonestr("{\"result\":\"block not HWM\"}"));*/ + return(gecko_blockarrived(myinfo,addr,valsobj,data,datalen)); } else return(clonestr("{\"error\":\"block error with checkhash2\"}")); } else return(clonestr("{\"error\":\"block nonce didnt verify\"}")); } @@ -476,16 +478,16 @@ HASH_ARRAY_STRING(basilisk,geckotx,pubkey,vals,hexstr) { if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 ) { - if ( (data= get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) + if ( (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { txid = bits256_doublesha256(0,data,datalen); - retstr = basilisk_respond_geckotx(myinfo,"VTX",0,0,0,vals,data,datalen,txid,0); + retstr = basilisk_respond_geckotx(myinfo,"GTX",0,0,0,vals,data,datalen,txid,0); } if ( allocptr != 0 ) free(allocptr); if ( retstr == 0 ) retstr = clonestr("{\"error\":\"couldnt create geckotx\"}"); - } else retstr = basilisk_standardservice("VTX",myinfo,txid,vals,hexstr,1); + } else retstr = basilisk_standardservice("GTX",myinfo,txid,vals,hexstr,1); return(retstr); } else return(clonestr("{\"error\":\"couldnt find geckochain\"}")); } diff --git a/gecko/gecko.h b/gecko/gecko.h index 1bd30e258..4ac37b4f4 100755 --- a/gecko/gecko.h +++ b/gecko/gecko.h @@ -28,6 +28,8 @@ #define GECKO_MAXNAMELEN 64 #define GECKO_MAXMINERITERS 10000000 +struct iguana_peer; + struct hashstamp { bits256 hash2; uint32_t timestamp; int32_t height; }; struct gecko_sequence { struct hashstamp *stamps; int32_t lastupdate,maxstamps,numstamps,lasti,longestchain; }; struct gecko_sequences { struct gecko_sequence BTC,BTCD; }; @@ -50,5 +52,6 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a void gecko_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr); void gecko_seqresult(struct supernet_info *myinfo,char *retstr); int32_t gecko_sequpdate(char *symbol,uint32_t reftimestamp); +char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_peer *addr,cJSON *valsobj,uint8_t *data,int32_t datalen); #endif diff --git a/gecko/gecko_blocks.c b/gecko/gecko_blocks.c new file mode 100755 index 000000000..29eb9709f --- /dev/null +++ b/gecko/gecko_blocks.c @@ -0,0 +1,21 @@ +/****************************************************************************** + * Copyright © 2014-2016 The SuperNET Developers. * + * * + * See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * + * the top-level directory of this distribution for the individual copyright * + * holder information and the developer policies on copyright and licensing. * + * * + * Unless otherwise agreed in a custom licensing agreement, no part of the * + * SuperNET software, including this file may be copied, modified, propagated * + * or distributed except according to the terms contained in the LICENSE file * + * * + * Removal or modification of this copyright notice is prohibited. * + * * + ******************************************************************************/ + +// included from gecko.c + +char *gecko_blockarrived(struct supernet_info *myinfo,struct iguana_peer *addr,cJSON *valsobj,uint8_t *data,int32_t datalen) +{ + return(clonestr("{\"result\":\"gecko block queued\"}")); +} diff --git a/gecko/gecko_delayedPoW.c b/gecko/gecko_delayedPoW.c index ac9268871..4d94cec6b 100755 --- a/gecko/gecko_delayedPoW.c +++ b/gecko/gecko_delayedPoW.c @@ -13,7 +13,7 @@ * * ******************************************************************************/ -// included from gecko_chains.c +// included from gecko.c int32_t gecko_hashstampsfind(struct hashstamp *stamps,int32_t max,struct gecko_sequence *seq,bits256 hash,uint32_t reftimestamp) { @@ -202,7 +202,7 @@ void gecko_seqresult(struct supernet_info *myinfo,char *retstr) longestchain = jint(resultjson,"longest"); hexstr = jstr(resultjson,"data"); printf("got startheight.%d num.%d lastupdate.%d longest.%d (%s)\n",startheight,num,lastupdate,longestchain,hexstr!=0?hexstr:""); - if ( hexstr != 0 && (data= get_dataptr(&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) + if ( hexstr != 0 && (data= get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr)) != 0 ) { gecko_ensure(seq,ind + num); for (i=0; ipeers) == 0 || (numranked= peers->numranked) == 0 ) + basilisk_blocksubmit(myinfo,virt,blockstr); + else + { + if ( (data= get_dataptr(sizeof(struct iguana_msghdr),&allocptr,&len,space,sizeof(space),blockstr)) != 0 ) + { + for (i=0; iranked[i]) != 0 && addr->usock >= 0 && addr->supernet != 0 ) + iguana_queue_send(addr,0,data,"block",len); + } + } + if ( allocptr != 0 ) + free(allocptr); + } } void gecko_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr) diff --git a/iguana/iguana_chains.c b/iguana/iguana_chains.c index 2b5b503fe..8bb682685 100755 --- a/iguana/iguana_chains.c +++ b/iguana/iguana_chains.c @@ -386,7 +386,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson) uint8_t hexbuf[1024],*ptr,*data; int32_t datalen,hdrsize; hdrsize = chain->zcash != 0 ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr); chain->genesis_hex = clonestr(hexstr); - data = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); + data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr); chain->genesishash2 = iguana_calcblockhash(chain->symbol,chain->hashalgo,data,hdrsize); memcpy(chain->genesis_hashdata,chain->genesishash2.bytes,32); //char str[65]; printf("%s -> calculated %s from %d datalen\n",hexstr,bits256_str(str,chain->genesishash2),hdrsize); diff --git a/iguana/iguana_init.c b/iguana/iguana_init.c index dcd9048f4..efbad5508 100755 --- a/iguana/iguana_init.c +++ b/iguana/iguana_init.c @@ -516,6 +516,15 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei } //coin->firstblock = coin->blocks.parsedblocks + 1; iguana_genesis(coin,coin->chain); + int32_t bundlei = -2; + static const bits256 zero; + iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1); + _iguana_chainlink(coin,iguana_blockfind("genesis",coin,*(bits256 *)coin->chain->genesis_hashdata)); + if ( coin->blocks.hwmchain.height != 0 || memcmp(coin->blocks.hwmchain.RO.hash2.bytes,coin->chain->genesis_hashdata,sizeof(coin->chain->genesis_hashdata)) != 0 ) + { + char str[65]; printf("%s genesis values mismatch hwmheight.%d %.15f %.15f %s\n",coin->name,coin->blocks.hwmchain.height,coin->blocks.hwmchain.PoW,coin->blocks.hwmchain.PoW,bits256_str(str,coin->blocks.hwmchain.RO.hash2)); + getchar(); + } memset(&lastbundle,0,sizeof(lastbundle)); if ( coin->peers == 0 ) iter = 2; @@ -588,15 +597,6 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei fclose(fp); } else fpos = -1; } - int32_t bundlei = -2; - static const bits256 zero; - iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1); - _iguana_chainlink(coin,iguana_blockfind("genesis",coin,*(bits256 *)coin->chain->genesis_hashdata)); - if ( coin->blocks.hwmchain.height != 0 || memcmp(coin->blocks.hwmchain.RO.hash2.bytes,coin->chain->genesis_hashdata,sizeof(coin->chain->genesis_hashdata)) != 0 ) - { - char str[65]; printf("%s genesis values mismatch hwmheight.%d %.15f %.15f %s\n",coin->name,coin->blocks.hwmchain.height,coin->blocks.hwmchain.PoW,coin->blocks.hwmchain.PoW,bits256_str(str,coin->blocks.hwmchain.RO.hash2)); - getchar(); - } #ifndef IGUANA_DEDICATED_THREADS coin->peers->peersloop = iguana_launch("peersloop",iguana_peersloop,coin,IGUANA_PERMTHREAD); #endif