Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
c47b0bb731
  1. 3
      basilisk/basilisk.c
  2. 10
      basilisk/basilisk.h
  3. 27
      basilisk/basilisk_CMD.c
  4. 207
      basilisk/basilisk_privatechains.c
  5. 2
      iguana/iguana.sources
  6. 166
      iguana/iguana777.c
  7. 11
      iguana/iguana777.h
  8. 2
      iguana/iguana_blocks.c
  9. 2
      iguana/iguana_bundles.c
  10. 25
      iguana/iguana_chains.c
  11. 70
      iguana/iguana_init.c
  12. 2
      iguana/iguana_msg.c
  13. 41
      iguana/iguana_peers.c
  14. 4
      iguana/iguana_ramchain.c
  15. 4
      iguana/iguana_recv.c
  16. 2
      iguana/iguana_tx.c
  17. 1
      iguana/tests/new

3
basilisk/basilisk.c

@ -16,7 +16,7 @@
#include "../iguana/iguana777.h"
typedef char *basilisk_coinfunc(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen);
typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk);
typedef char *basilisk_servicefunc(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk);
typedef struct basilisk_item *basilisk_requestfunc(struct basilisk_item *Lptr,struct supernet_info *myinfo,bits256 pubkey,cJSON *valsobj,uint8_t *data,int32_t datalen);
uint32_t basilisk_calcnonce(struct supernet_info *myinfo,uint8_t *data,int32_t datalen,uint32_t nBits)
@ -446,7 +446,6 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,bits256 ha
#include "basilisk_waves.c"
#include "basilisk_lisk.c"
#include "basilisk_CMD.c"
#include "basilisk_privatechains.c"
void basilisk_functions(struct iguana_info *coin,int32_t protocol)
{

10
basilisk/basilisk.h

@ -64,7 +64,17 @@ uint8_t *basilisk_jsondata(void **ptrp,uint8_t *space,int32_t spacesize,int32_t
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);
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
char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk);
char *basilisk_respond_newprivatechain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk);
char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk);
char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk);
void basilisk_request_goodbye(struct supernet_info *myinfo);
int32_t basilisk_update(char *symbol,uint32_t reftimestamp);
void basilisk_seqresult(struct supernet_info *myinfo,char *retstr);
#endif

27
basilisk/basilisk_CMD.c

@ -15,8 +15,9 @@
#include "../iguana/iguana777.h"
char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_goodbye(struct supernet_info *myinfo,char *CMD,void *_addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
struct iguana_peer *addr = _addr;
printf("(%s) sends goodbye\n",remoteaddr);
addr->dead = (uint32_t)time(NULL);
addr->rank = 0;
@ -31,75 +32,75 @@ void basilisk_request_goodbye(struct supernet_info *myinfo)
free_json(valsobj);
}
char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_publish(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
printf("from.(%s) PUB.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen);
return(retstr);
}
char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_subscribe(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
printf("from.(%s) SUB.(%s) datalen.%d\n",remoteaddr,jprint(valsobj,0),datalen);
return(retstr);
}
char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_dispatch(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_addrelay(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_addrelay(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_forward(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_forward(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_mailbox(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_mailbox(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_VPNcreate(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_VPNcreate(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_VPNjoin(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_VPNjoin(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_VPNlogout(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_VPNlogout(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_VPNbroadcast(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_VPNbroadcast(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_VPNreceive(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_VPNreceive(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);
}
char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
char *basilisk_respond_VPNmessage(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 pubkey,int32_t from_basilisk)
{
char *retstr=0;
return(retstr);

207
basilisk/basilisk_privatechains.c

@ -13,6 +13,7 @@
* *
******************************************************************************/
#include "../iguana/iguana777.h"
/*int32_t basilist_validateblock(cJSON *valsobj)
{
@ -64,8 +65,7 @@ int32_t basilisk_hashstampsfind(struct hashstamp *stamps,int32_t max,struct basi
bits256 basilisk_hashstampscalc(struct iguana_info *btcd,bits256 *btchashp,uint32_t reftimestamp)
{
struct hashstamp BTCDstamps[BASILISK_MAXBTCDGAP],BTCstamps[BASILISK_MAXBTCGAP]; bits256 btcdhash;
memset(btcdhash.bytes,0,sizeof(btcdhash));
memset(btchashp,0,sizeof(*btchashp));
btcdhash = *btchashp = GENESIS_PUBKEY;
if ( basilisk_hashstampsfind(BTCDstamps,BASILISK_MAXBTCDGAP,&btcd->SEQ.BTCD,btcdhash,reftimestamp) < 0 )
{
btcdhash = BTCDstamps[BASILISK_MAXBTCDGAP >> 1].hash2;
@ -238,7 +238,7 @@ void basilisk_seqresult(struct supernet_info *myinfo,char *retstr)
}
}
char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{
int32_t startheight; struct iguana_info *btcd; cJSON *retjson = cJSON_CreateObject();
if ( (btcd= iguana_coinfind("BTCD")) != 0 )
@ -251,14 +251,15 @@ char *basilisk_respond_hashstamps(struct supernet_info *myinfo,char *CMD,struct
return(jprint(retjson,1));
}
char *basilisk_coinbase(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,uint8_t *data,int32_t datalen,bits256 coinbasespend,cJSON *txjson)
char *basilisk_coinbase(struct supernet_info *myinfo,struct iguana_info *coin,bits256 *txidp,uint8_t *data,int32_t datalen,bits256 coinbasespend,cJSON *origtxjson)
{
char *rawtx; struct vin_info V;
if ( txjson == 0 )
char *rawtx; struct vin_info V; cJSON *txjson;
if ( (txjson= origtxjson) == 0 )
txjson = bitcoin_txcreate(1,0);
bitcoin_txinput(coin,txjson,coinbasespend,-1,0xffffffff,0,0,data,datalen,0,0);
rawtx = bitcoin_json2hex(myinfo,coin,txidp,txjson,&V);
free_json(txjson);
if ( txjson != origtxjson )
free_json(txjson);
return(rawtx);
}
@ -331,7 +332,7 @@ int32_t basilisk_privatechainvals(struct supernet_info *myinfo,char *CMD,cJSON *
return(-1);
}
char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block,int32_t version,uint32_t timestamp,uint32_t *noncep,bits256 prevblock,uint32_t nBits,int32_t height,char **txptrs,int32_t txn_count,uint8_t *coinbase,int32_t coinbaselen,bits256 coinbasespend,cJSON *txjson)
char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_block *block,int32_t version,uint32_t timestamp,uint32_t *noncep,bits256 prevblock,uint32_t nBits,int32_t height,char **txptrs,int32_t txn_count,uint8_t *coinbase,int32_t coinbaselen,bits256 coinbasespend,cJSON *txjson)
{
struct iguana_info *btcd; uint8_t serialized[sizeof(*block)],space[16384],*txdata,*allocptr = 0; int32_t i,n,totaltxlen=0,txlen,numiters=1000000; char *coinbasestr,*blockstr=0; bits256 *txids=0,txspace[256],threshold;
if ( (btcd= iguana_coinfind("BTCD")) == 0 )
@ -361,7 +362,7 @@ char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *coin,struc
free(allocptr);
}
}
if ( (coinbasestr= basilisk_coinbase(myinfo,coin,&txids[0],coinbase,coinbaselen,coinbasespend,txjson)) != 0 )
if ( (coinbasestr= basilisk_coinbase(myinfo,virt,&txids[0],coinbase,coinbaselen,coinbasespend,txjson)) != 0 )
{
memset(block,0,sizeof(*block));
block->RO.version = version;
@ -372,18 +373,21 @@ char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *coin,struc
block->RO.txn_count = (txn_count + 1);
block->height = height;
threshold = bits256_from_compact(nBits);
//offset = (int32_t)((long)&block->RO.bits - (long)block);
//n = iguana_serialize_block(virt->chain,&block->RO.hash2,serialized,block);
if ( (block->RO.nonce= *noncep) == 0 )
{
for (i=0; i<numiters; i++)
{
block->RO.nonce = rand();
n = iguana_serialize_block(coin->chain,&block->RO.hash2,serialized,block);
n = iguana_serialize_block(virt->chain,&block->RO.hash2,serialized,block);
//char str[65]; printf("nonce.%08x %s\n",block->RO.nonce,bits256_str(str,block->RO.hash2));
if ( bits256_cmp(threshold,block->RO.hash2) > 0 )
break;
}
}
*noncep = block->RO.nonce;
n = iguana_serialize_block(coin->chain,&block->RO.hash2,serialized,block);
n = iguana_serialize_block(virt->chain,&block->RO.hash2,serialized,block);
if ( bits256_cmp(threshold,block->RO.hash2) > 0 )
{
blockstr = calloc(1,strlen(coinbasestr) + (totaltxlen+n)*2 + 1);
@ -393,13 +397,50 @@ char *basilisk_block(struct supernet_info *myinfo,struct iguana_info *coin,struc
strcat(blockstr,txptrs[i]);
}
free(coinbasestr);
/*
if ( (block->RO.nonce= *noncep) == 0 )
{
for (i=0; i<numiters; i++)
{
block->RO.nonce = rand();
iguana_rwnum(1,&serialized[offset],sizeof(block->RO.nonce),&block->RO.nonce);
block->RO.hash2 = iguana_calcblockhash(virt->symbol,virt->chain->hashalgo,serialized,sizeof(struct iguana_msgblockhdr));
char str[65]; printf("nonce.%08x %s\n",block->RO.nonce,bits256_str(str,block->RO.hash2));
if ( bits256_cmp(threshold,block->RO.hash2) > 0 )
{
printf("found kernel\n");
break;
}
}
}
*noncep = block->RO.nonce;
n = iguana_serialize_block(virt->chain,&block->RO.hash2,serialized,block);
if ( bits256_cmp(threshold,block->RO.hash2) > 0 )
{
blockstr = calloc(1,strlen(coinbasestr) + (totaltxlen+n)*2 + 1);
init_hexbytes_noT(blockstr,serialized,n);
strcat(blockstr,coinbasestr);
for (i=0; i<txn_count; i++)
strcat(blockstr,txptrs[i]);
} else printf("nonce failure\n");
free(coinbasestr);*/
}
if ( txids != txspace )
free(txids);
return(blockstr);
}
char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
int32_t basilisk_blocknonce_verify(struct iguana_info *virt,uint8_t *serialized,int32_t datalen,uint32_t nBits)
{
bits256 threshold,hash2;
threshold = bits256_from_compact(nBits);
hash2 = iguana_calcblockhash(virt->symbol,virt->chain->hashalgo,serialized,datalen);
if ( bits256_cmp(threshold,hash2) > 0 )
return(0);
else return(0);
}
char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{
struct iguana_info *virt; struct iguana_block *prevblock,*prev2,*newblock,block; char chainname[BASILISK_MAXNAMELEN],str[65],*blocktx; uint32_t nBits,timestamp,nonce; cJSON *retjson; bits256 btcdhash;
if ( datalen <= 0 )
@ -429,7 +470,7 @@ char *basilisk_respond_setfield(struct supernet_info *myinfo,char *CMD,struct ig
return(jprint(retjson,1));
}
char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{
struct iguana_info *coin; cJSON *retjson; char chainname[BASILISK_MAXNAMELEN];
if ( (coin= basilisk_chain(myinfo,chainname,valsobj)) == 0 )
@ -441,14 +482,19 @@ char *basilisk_respond_getfield(struct supernet_info *myinfo,char *CMD,struct ig
cJSON *basilisk_genesisjson(struct supernet_info *myinfo,struct iguana_info *btcd,char *chainname,cJSON *valsobj)
{
char str[64],str2[64],argbuf[1024],*nbitstr,*blockstr; bits256 btchash,btcdhash,zero; uint8_t coinbase[512],buf[4]; int32_t i,coinbaselen; uint32_t nonce,nbits; struct iguana_block genesis; uint32_t timestamp; cJSON *txjson;
char str2[64],hashstr[64],argbuf[1024],*nbitstr,*blockstr; bits256 btchash,btcdhash,zero; uint8_t coinbase[512],buf[4]; int32_t i,coinbaselen; uint32_t nonce,nbits; struct iguana_block genesis; uint32_t timestamp; cJSON *txjson;
timestamp = (uint32_t)time(NULL);
btcdhash = basilisk_hashstampscalc(btcd,(bits256 *)coinbase,timestamp);
if ( bits256_cmp(btcdhash,GENESIS_PUBKEY) == 0 || bits256_cmp(*(bits256 *)coinbase,GENESIS_PUBKEY) == 0 )
{
printf("no hashstamps\n");
return(cJSON_Parse("{\"error\":\"no up to date hashstamps\"}"));
}
coinbaselen = (int32_t)strlen(chainname);
memcpy(&coinbase[sizeof(btchash)],chainname,coinbaselen);
memset(zero.bytes,0,sizeof(zero));
nonce = 0;
if ( (nbitstr= jstr(valsobj,"nBits")) == 0 )
if ( (nbitstr= jstr(valsobj,"nbits")) == 0 )
{
nbits = BASILISK_DEFAULTDIFF;
nbitstr = BASILISK_DEFAULTDIFFSTR;
@ -461,37 +507,90 @@ cJSON *basilisk_genesisjson(struct supernet_info *myinfo,struct iguana_info *btc
}
txjson = basilisk_paymentsobj(0,jobj(valsobj,"payments"));
blockstr = basilisk_block(myinfo,btcd,&genesis,BASILISK_DEFAULTVERSION,timestamp,&nonce,zero,nbits,0,0,0,coinbase,coinbaselen,btcdhash,txjson);
sprintf(argbuf,"(\"name\":\"%s\",\"unitval\":%02x,\"genesishash\":\"%s\",\"genesis\":{\"hashalgo\":\"sha256\",\"version\":1,\"timestamp\":%u,\"nbits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesis_block\":\"%s\"}",chainname,(nbits >> 24) & 0xff,bits256_str(str,genesis.RO.hash2),timestamp,nbitstr,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr);
bits256_str(hashstr,genesis.RO.hash2);
sprintf(argbuf,"{\"name\":\"%s\",\"unitval\":%02x,\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nbits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",chainname,(nbits >> 24) & 0xff,hashstr,timestamp,nbitstr,genesis.RO.nonce,bits256_str(str2,genesis.RO.merkle_root),blockstr);
free(blockstr);
//printf("argbuf.(%s) hash.%s\n",argbuf,hashstr);
return(cJSON_Parse(argbuf));
}
char *basilisk_respond_newprivatechain(struct supernet_info *myinfo,char *CMD,struct iguana_peer *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
struct iguana_info *basilisk_privatechain(struct supernet_info *myinfo,char *symbol,char *chainname,cJSON *valsobj)
{
int32_t datalen,maxpeers,initialheight,minconfirms,maxrequests,maxbundles,hdrsize; int64_t maxrecvcache; uint64_t services; struct iguana_info *virt=0; char *hexstr; uint8_t hexbuf[1024],*ptr,*serialized;
if ( (hexstr= jstr(valsobj,"genesisblock")) != 0 && (virt= iguana_coinadd(symbol,valsobj)) == 0 )
{
safecopy(virt->name,chainname,sizeof(virt->name));
virt->chain = calloc(1,sizeof(*virt->chain));
virt->chain->hashalgo = blockhash_sha256;
serialized = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr);
iguana_chaininit(virt->chain,1,valsobj);
iguana_coinargs(symbol,&maxrecvcache,&minconfirms,&maxpeers,&initialheight,&services,&maxrequests,&maxbundles,valsobj);
iguana_setcoin(myinfo,symbol,virt,maxpeers,maxrecvcache,services,initialheight,0,minconfirms,maxrequests,maxbundles,valsobj);
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
if ( basilisk_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits) == 0 )
{
virt->chain->genesishash2 = iguana_calcblockhash(symbol,virt->chain->hashalgo,serialized,hdrsize);
memcpy(virt->chain->genesis_hashdata,virt->chain->genesishash2.bytes,sizeof(virt->chain->genesishash2));
if ( ptr != 0 )
free(ptr);
virt->chain->genesis_hex = clonestr(hexstr);
virt->MAXPEERS = 0;
iguana_callcoinstart(virt);
printf("nonce verified\n");
} else printf("error validating nonce\n");
}
return(virt);
}
cJSON *basilisk_genesisargs(char *symbol,char *chainname,char *chain,char *keystr,char *genesishash,char *genesisblock,char *magicstr,uint16_t port,uint16_t blocktime,char *nbitstr)
{
struct iguana_info *virt,*btcd; char chainname[BASILISK_MAXNAMELEN]; cJSON *argjson; uint16_t port,targetspacing;
int32_t timespan,targetspacing; cJSON *argvals = cJSON_CreateObject();
if ( genesishash != 0 && genesishash[0] != 0 )
jaddstr(argvals,"genesishash",genesishash);
if ( genesisblock != 0 && genesisblock[0] != 0 )
jaddstr(argvals,"genesisblock",genesisblock);
jaddstr(argvals,"netmagic",magicstr);
jaddstr(argvals,"symbol",symbol);
jaddstr(argvals,"name",chainname);
if ( nbitstr == 0 || nbitstr[0] == 0 )
nbitstr = BASILISK_DEFAULTDIFFSTR;
jaddstr(argvals,"nbits",nbitstr);
jaddstr(argvals,"chain",chain);
if ( keystr != 0 )
jaddstr(argvals,"key",keystr);
if ( port == 0 )
jaddstr(argvals,"privatechain",chainname);
else
{
jaddnum(argvals,"services",129);
jaddnum(argvals,"portp2p",port);
if ( blocktime == 0xffff )
targetspacing = 24 * 60 * 60; // one day
else targetspacing = 60; // one minute
jaddnum(argvals,"targetspacing",targetspacing);
if ( (timespan= sqrt(604800 / targetspacing)) < 7 )
timespan = 7;
jaddnum(argvals,"targettimespan",targetspacing * timespan);
}
return(argvals);
}
char *basilisk_respond_newprivatechain(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 prevhash,int32_t from_basilisk)
{
struct iguana_info *virt,*btcd; char *symbol,*chain,chainname[BASILISK_MAXNAMELEN]; cJSON *retjson;
if ( (virt= basilisk_chain(myinfo,chainname,valsobj)) != 0 )
{
printf("%s already exists\n",chainname);
return(clonestr("{\"error\":\"cant create duplicate privatechain\"}"));
}
if ( (btcd= iguana_coinfind("BTCD")) != 0 )
if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(valsobj,"symbol")) != 0 && (chain= jstr(valsobj,"chain")) != 0 )
{
if ( (port= juint(valsobj,"port")) == 0 )
jaddstr(argjson,"privatechain",chainname);
else
if ( (virt= basilisk_privatechain(myinfo,symbol,chainname,valsobj)) != 0 )
{
jaddnum(argjson,"portp2p",port);
if ( (targetspacing= juint(valsobj,"blocktime")) == 0 )
targetspacing = 60;
jaddnum(argjson,"targetspacing",targetspacing);
jaddnum(argjson,"targettimespan",targetspacing * 60);
retjson = basilisk_genesisargs(symbol,chainname,chain,jstr(valsobj,"key"),jstr(valsobj,"genesishash"),jstr(valsobj,"genesisblock"),jstr(valsobj,"netmagic"),juint(valsobj,"port"),juint(valsobj,"blocktime"),jstr(valsobj,"nbits"));
jaddstr(retjson,"result","success");
return(jprint(retjson,1));
}
if ( (virt= iguana_coinadd(chainname,argjson)) != 0 )
{
iguana_genesis(virt,virt->chain);
}
if ( argjson != 0 )
free_json(argjson);
}
return(clonestr("{\"error\":-22}"));
}
@ -501,18 +600,46 @@ char *basilisk_respond_newprivatechain(struct supernet_info *myinfo,char *CMD,st
HASH_ARRAY_STRING(basilisk,newprivatechain,pubkey,vals,hexstr)
{
char chainname[BASILISK_MAXNAMELEN]; struct iguana_info *virt,*btcd; cJSON *argjson;
if ( (btcd= iguana_coinfind("BTCD")) != 0 )
char chainname[BASILISK_MAXNAMELEN],magicstr[9],*retstr,*symbol,*chain; struct iguana_info *virt,*btcd; cJSON *argjson,*argvals,*retjson=0; int32_t i; uint32_t magic;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && (symbol= jstr(vals,"symbol")) != 0 && (chain= jstr(vals,"chain")) != 0 )
{
if ( (virt= basilisk_chain(myinfo,chainname,vals)) != 0 )
if ( iguana_coinfind(symbol) == 0 && (virt= basilisk_chain(myinfo,chainname,vals)) != 0 )
{
printf("%s already exists\n",chainname);
return(clonestr("{\"error\":\"cant create duplicate privatechain\"}"));
}
argjson = basilisk_genesisjson(myinfo,btcd,chainname,vals);
return(basilisk_standardservice("NEW",myinfo,pubkey,vals,hexstr,1));
} else return(clonestr("{\"error\":\"need BTCD to create private chain\"}"));
if ( jobj(vals,"netmagic") == 0 )
{
OS_randombytes((void *)&magic,sizeof(magic));
for (i=0; i<sizeof(magic); i++)
((uint8_t *)&magic)[i] |= 0x80;
init_hexbytes_noT(magicstr,(void *)&magic,sizeof(magic));
} else safecopy(magicstr,jstr(vals,"netmagic"),sizeof(magicstr));
if ( (argjson= basilisk_genesisjson(myinfo,btcd,chainname,vals)) != 0 )
{
argvals = basilisk_genesisargs(symbol,chainname,chain,jstr(argjson,"key"),jstr(argjson,"genesishash"),jstr(argjson,"genesisblock"),jstr(argjson,"netmagic"),juint(argjson,"port"),juint(argjson,"blocktime"),jstr(argjson,"nbits"));
if ( btcd->RELAYNODE != 0 || btcd->VALIDATENODE != 0 )
retstr = basilisk_respond_newprivatechain(myinfo,"NEW",0,0,0,argvals,0,0,GENESIS_PUBKEY,0);
else retstr = basilisk_standardservice("NEW",myinfo,GENESIS_PUBKEY,argvals,0,1);
free_json(argvals);
if ( (argvals= cJSON_Parse(retstr)) != 0 )
{
if ( jobj(argvals,"result") != 0 && strcmp(jstr(argvals,"result"),"success") == 0 )
{
if ( basilisk_privatechain(myinfo,symbol,chainname,argvals) != 0 )
jaddstr(argvals,"status","active");
//free_json(argvals);
} else jaddstr(argvals,"error","couldnt initialize privatechain");
free(retstr);
return(jprint(argvals,1));
}
if ( retjson != 0 )
free_json(retjson);
free_json(argvals);
return(retstr);
} else return(clonestr("{\"error\":\"couldnt create genesis_block\"}"));
}
return(clonestr("{\"error\":\"need symbol and chain and BTCD to create new private chain\"}"));
}
HASH_ARRAY_STRING(basilisk,sequence,pubkey,vals,hexstr)

2
iguana/iguana.sources

@ -1,2 +1,2 @@
SOURCES := SuperNET.c iguana_bundles.c iguana_stake.c iguana_interpreter.c mini-gmp.c main.c iguana_payments.c iguana_spendvectors.c iguana_sign.c iguana_txidfind.c iguana_realtime.c iguana_volatiles.c peggy_price.c SuperNET_category.c iguana_chains.c iguana_ramchain.c iguana_secp.c pangea_api.c peggy_ramkv.c SuperNET_hexmsg.c iguana_exchanges.c iguana_recv.c pangea_bets.c peggy_serdes.c SuperNET_keys.c iguana_rpc.c pangea_hand.c peggy_tx.c cards777.c iguana_init.c iguana_scripts.c pangea_json.c peggy_txind.c iguana777.c iguana_instantdex.c iguana_tradebots.c pangea_summary.c peggy_update.c iguana_accept.c iguana_json.c iguana_tx.c peggy.c poker.c iguana_bitmap.c iguana_msg.c iguana_unspents.c peggy_accts.c ramchain_api.c iguana_blocks.c iguana_peers.c iguana_wallet.c peggy_consensus.c ../basilisk/basilisk.c secp256k1/src/secp256k1.c
SOURCES := SuperNET.c iguana_bundles.c iguana_stake.c iguana_interpreter.c mini-gmp.c main.c iguana_payments.c iguana_spendvectors.c iguana_sign.c iguana_txidfind.c iguana_realtime.c iguana_volatiles.c peggy_price.c SuperNET_category.c iguana_chains.c iguana_ramchain.c iguana_secp.c pangea_api.c peggy_ramkv.c SuperNET_hexmsg.c iguana_exchanges.c iguana_recv.c pangea_bets.c peggy_serdes.c SuperNET_keys.c iguana_rpc.c pangea_hand.c peggy_tx.c cards777.c iguana_init.c iguana_scripts.c pangea_json.c peggy_txind.c iguana777.c iguana_instantdex.c iguana_tradebots.c pangea_summary.c peggy_update.c iguana_accept.c iguana_json.c iguana_tx.c peggy.c poker.c iguana_bitmap.c iguana_msg.c iguana_unspents.c peggy_accts.c ramchain_api.c iguana_blocks.c iguana_peers.c iguana_wallet.c peggy_consensus.c ../basilisk/basilisk.c ../basilisk/basilisk_privatechains.c secp256k1/src/secp256k1.c

166
iguana/iguana777.c

@ -80,8 +80,8 @@ struct iguana_info *iguana_coinadd(const char *symbol,cJSON *argjson)
safecopy(coin->name,jstr(argjson,"name"),sizeof(coin->name));
else strcpy(coin->name,symbol);
}
if ( jstr(argjson,"privatechain") == 0 )
coin->peers = calloc(1,sizeof(*coin->peers));
if ( jstr(argjson,"privatechain") != 0 )
coin->virtualchain = 1;
coin->chain = iguana_chainfind((char *)symbol,argjson,1);
coin->ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
secp256k1_pedersen_context_initialize(coin->ctx);
@ -676,17 +676,30 @@ void iguana_helper(void *arg)
}
}
void iguana_callcoinstart(struct iguana_info *coin)
{
struct iguana_bundle *bp; int32_t bundlei; bits256 zero;
iguana_rwiAddrind(coin,0,0,0);
//for (i=0; i<sizeof(*coin->chain); i++)
// printf("%02x",((uint8_t *)coin->chain)[i]);
char str[65]; printf(" netmagic.%08x init.(%s) maxpeers.%d maxrecvcache.%s services.%llx MAXMEM.%s polltimeout.%d cache.%d pend.(%d -> %d)\n",*(uint32_t *)coin->chain->netmagic,coin->symbol,coin->MAXPEERS,mbstr(str,coin->MAXRECVCACHE),(long long)coin->myservices,mbstr(str,coin->MAXMEM),coin->polltimeout,coin->enableCACHE,coin->startPEND,coin->endPEND);
iguana_coinstart(coin,coin->initialheight,coin->mapflags);
coin->chain->minconfirms = coin->minconfirms;
coin->started = coin;
coin->startutc = (uint32_t)time(NULL);
memset(zero.bytes,0,sizeof(zero));
if ( (bp= iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1)) != 0 )
bp->bundleheight = 0;
}
void iguana_coinloop(void *arg)
{
struct iguana_info *coin,**coins = arg;
struct iguana_bundle *bp; struct supernet_info *myinfo; int32_t flag,i,n,bundlei;
bits256 zero; char str[2065]; uint32_t now;
struct supernet_info *myinfo; int32_t flag,i,j,n; bits256 zero; uint32_t now; struct iguana_info *coin,**coins = arg;
myinfo = SuperNET_MYINFO(0);
n = (int32_t)(long)coins[0];
coins++;
printf("begin coinloop[%d]\n",n);
coin = coins[0];
iguana_launchpeer(coin,"127.0.0.1");
memset(zero.bytes,0,sizeof(zero));
while ( 1 )
{
@ -695,27 +708,26 @@ void iguana_coinloop(void *arg)
{
if ( (coin= coins[i]) != 0 )
{
if ( coin->MAXPEERS > IGUANA_MAXPEERS )
coin->MAXPEERS = IGUANA_MAXPEERS;
if ( coin->MAXPEERS > 1 && coin->MAXPEERS < IGUANA_MINPEERS )
coin->MAXPEERS = IGUANA_MAXPEERS;
if ( coin->peers == 0 )
{
coin->peers = calloc(1,sizeof(*coin->peers));
for (j=0; j<IGUANA_MAXPEERS; j++)
coin->peers->active[j].usock = -1;
iguana_launchpeer(coin,"127.0.0.1");
}
if ( coin->virtualchain == 0 )
{
if ( coin->MAXPEERS > IGUANA_MAXPEERS )
coin->MAXPEERS = IGUANA_MAXPEERS;
if ( coin->MAXPEERS > 1 && coin->MAXPEERS < IGUANA_MINPEERS )
coin->MAXPEERS = IGUANA_MAXPEERS;
#ifdef __PNACL__
if ( coin->MAXPEERS > 64 )
coin->MAXPEERS = 64;
if ( coin->MAXPEERS > 64 )
coin->MAXPEERS = 64;
#endif
if ( coin->started == 0 && coin->active != 0 )
{
iguana_rwiAddrind(coin,0,0,0);
//for (i=0; i<sizeof(*coin->chain); i++)
// printf("%02x",((uint8_t *)coin->chain)[i]);
printf(" netmagic.%08x init.(%s) maxpeers.%d maxrecvcache.%s services.%llx MAXMEM.%s polltimeout.%d cache.%d pend.(%d -> %d)\n",*(uint32_t *)coin->chain->netmagic,coin->symbol,coin->MAXPEERS,mbstr(str,coin->MAXRECVCACHE),(long long)coin->myservices,mbstr(str,coin->MAXMEM),coin->polltimeout,coin->enableCACHE,coin->startPEND,coin->endPEND);
iguana_coinstart(coin,coin->initialheight,coin->mapflags);
coin->chain->minconfirms = coin->minconfirms;
coin->started = coin;
coin->startutc = (uint32_t)time(NULL);
if ( (bp= iguana_bundlecreate(coin,&bundlei,0,*(bits256 *)coin->chain->genesis_hashdata,zero,1)) != 0 )
bp->bundleheight = 0;
}
if ( coin->started == 0 && coin->active != 0 )
iguana_callcoinstart(coin);
now = (uint32_t)time(NULL);
coin->idletime = 0;
if ( coin->started != 0 && coin->active != 0 )
@ -796,65 +808,61 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi
mapflags = IGUANA_MAPRECVDATA | maphash*IGUANA_MAPTXIDITEMS | maphash*IGUANA_MAPPKITEMS | maphash*IGUANA_MAPBLOCKITEMS | maphash*IGUANA_MAPPEERITEMS;
if ( (coin= iguana_coinfind(symbol)) == 0 )
coin = iguana_coinadd(symbol,json);
if ( (coin->MAXPEERS= maxpeers) <= 0 )
coin->MAXPEERS = (strcmp(symbol,"BTC") == 0) ? 128 : 64;
if ( (coin->MAXRECVCACHE= maxrecvcache) == 0 )
coin->MAXRECVCACHE = IGUANA_MAXRECVCACHE;
if ( (coin->MAXPENDINGREQUESTS= maxrequests) <= 0 )
coin->MAXPENDINGREQUESTS = (strcmp(symbol,"BTC") == 0) ? IGUANA_MAXPENDINGREQUESTS : IGUANA_PENDINGREQUESTS;
mult = (strcmp("BTC",coin->symbol) != 0) ? 8 : 32;
maxval = IGUANA_MAXPENDBUNDLES;
if ( coin->virtualchain == 0 )
{
if ( (coin->MAXPEERS= maxpeers) <= 0 )
coin->MAXPEERS = (strcmp(symbol,"BTC") == 0) ? 128 : 64;
if ( (coin->MAXRECVCACHE= maxrecvcache) == 0 )
coin->MAXRECVCACHE = IGUANA_MAXRECVCACHE;
if ( (coin->MAXPENDINGREQUESTS= maxrequests) <= 0 )
coin->MAXPENDINGREQUESTS = (strcmp(symbol,"BTC") == 0) ? IGUANA_MAXPENDINGREQUESTS : IGUANA_PENDINGREQUESTS;
if ( jobj(json,"prefetchlag") != 0 )
coin->PREFETCHLAG = jint(json,"prefetchlag");
else if ( strcmp("BTC",coin->symbol) == 0 )
coin->PREFETCHLAG = 13;
else coin->PREFETCHLAG = -1;
if ( (coin->MAXSTUCKTIME= juint(json,"maxstuck")) == 0 )
coin->MAXSTUCKTIME = _IGUANA_MAXSTUCKTIME;
if ( (coin->startPEND= juint(json,"startpend")) == 0 )
{
if ( strcmp("BTCD",coin->symbol) == 0 )
coin->startPEND = 500;
else coin->startPEND = IGUANA_MAXPENDBUNDLES*mult;
}
if ( coin->startPEND > maxval*mult )
coin->startPEND = maxval*mult;
else if ( coin->startPEND < 2 )
coin->startPEND = 2;
coin->MAXBUNDLES = coin->startPEND;
if ( (coin->endPEND= juint(json,"endpend")) == 0 )
{
if ( strcmp("BTCD",coin->symbol) == 0 )
coin->endPEND = 500;
else coin->endPEND = IGUANA_MINPENDBUNDLES*mult;
}
if ( coin->endPEND > maxval*mult )
coin->endPEND = maxval*mult;
else if ( coin->endPEND < 2 )
coin->endPEND = 2;
#ifdef __PNACL__
coin->startPEND = coin->endPEND = 1;
#endif
} else coin->MAXPEERS = 0;
coin->myservices = services;
coin->initialheight = initialheight;
coin->mapflags = mapflags;
coin->protocol = IGUANA_PROTOCOL_BITCOIN;
mult = (strcmp("BTC",coin->symbol) != 0) ? 8 : 32;
maxval = IGUANA_MAXPENDBUNDLES;
if ( (coin->txfee= jdouble(json,"txfee") * SATOSHIDEN) == 0 )
coin->txfee = 10000;
if ( (coin->txfee_perkb= j64bits(json,"txfee_perkb")) < coin->txfee/8 )
coin->txfee_perkb = coin->txfee / 8;
coin->MAXMEM = juint(json,"RAM");
if ( jobj(json,"prefetchlag") != 0 )
coin->PREFETCHLAG = jint(json,"prefetchlag");
else if ( strcmp("BTC",coin->symbol) == 0 )
coin->PREFETCHLAG = 13;
else coin->PREFETCHLAG = -1;
if ( (coin->MAXSTUCKTIME= juint(json,"maxstuck")) == 0 )
coin->MAXSTUCKTIME = _IGUANA_MAXSTUCKTIME;
if ( coin->MAXMEM == 0 )
coin->MAXMEM = IGUANA_DEFAULTRAM;
//if ( strcmp("BTC",coin->symbol) == 0 && coin->MAXMEM < 4 )
// maxval = (int32_t)coin->MAXMEM;
coin->MAXMEM *= (1024L * 1024 * 1024);
#ifdef __PNACL__
//maxval = 1;// * (strcmp("BTC",coin->symbol) != 0) + 8;
//if ( mult > 1 )
// mult /= 2;
#endif
if ( (coin->startPEND= juint(json,"startpend")) == 0 )
{
if ( strcmp("BTCD",coin->symbol) == 0 )
coin->startPEND = 500;
else coin->startPEND = IGUANA_MAXPENDBUNDLES*mult;
}
if ( coin->startPEND > maxval*mult )
coin->startPEND = maxval*mult;
else if ( coin->startPEND < 2 )
coin->startPEND = 2;
coin->MAXBUNDLES = coin->startPEND;
if ( (coin->endPEND= juint(json,"endpend")) == 0 )
{
if ( strcmp("BTCD",coin->symbol) == 0 )
coin->endPEND = 500;
else coin->endPEND = IGUANA_MINPENDBUNDLES*mult;
}
if ( coin->endPEND > maxval*mult )
coin->endPEND = maxval*mult;
else if ( coin->endPEND < 2 )
coin->endPEND = 2;
#ifdef __PNACL__
coin->startPEND = coin->endPEND = 1;
#endif
coin->enableCACHE = (strcmp("BTCD",coin->symbol) == 0);
coin->enableCACHE = 0;//(strcmp("BTCD",coin->symbol) == 0);
if ( jobj(json,"cache") != 0 )
coin->enableCACHE = juint(json,"cache");
if ( (coin->polltimeout= juint(json,"poll")) <= 0 )
@ -862,7 +870,7 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi
coin->active = juint(json,"active");
if ( (coin->minconfirms = minconfirms) == 0 )
coin->minconfirms = (strcmp(symbol,"BTC") == 0) ? 3 : 10;
printf("ensure directories maxval.%d mult.%d start.%d end.%d\n",maxval,mult,coin->startPEND,coin->endPEND);
//printf("ensure directories maxval.%d mult.%d start.%d end.%d\n",maxval,mult,coin->startPEND,coin->endPEND);
sprintf(dirname,"%s/ro",GLOBAL_DBDIR), OS_ensure_directory(dirname);
sprintf(dirname,"%s/ro/%s",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s",GLOBAL_DBDIR,symbol), OS_ensure_directory(dirname);
@ -883,15 +891,15 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi
strcpy(coin->name,"illegalcoin");
coin->symbol[0] = 0;
return(0);
} else iguana_chainparms(coin->chain,json);
} //else iguana_chainparms(coin->chain,json);
if ( jobj(json,"RELAY") != 0 )
coin->RELAYNODE = juint(json,"RELAY");
else coin->RELAYNODE = 1;
else coin->RELAYNODE = (strcmp(coin->symbol,"BTCD") == 0);
if ( jobj(json,"VALIDATE") != 0 )
coin->VALIDATENODE = juint(json,"VALIDATE");
else coin->VALIDATENODE = 1;
else coin->VALIDATENODE = (strcmp(coin->symbol,"BTCD") == 0);
if ( coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
myinfo->IAMRELAY = 1;
myinfo->IAMRELAY++;
#ifdef __PNACL
coin->VALIDATENODE = coin->RELAYNODE = 0;
#endif
@ -907,7 +915,9 @@ struct iguana_info *iguana_setcoin(struct supernet_info *myinfo,char *symbol,voi
}
printf("addnodes.%d\n",m);
}
char str[65]; printf("pend.(%d -> %d) MAXMEM.%s enablecache.%d VALIDATEDIR.(%s) VALIDATE.%d RELAY.%d\n",coin->startPEND,coin->endPEND,mbstr(str,coin->MAXMEM),coin->enableCACHE,coin->VALIDATEDIR,coin->VALIDATENODE,coin->RELAYNODE);
char str[65];
if ( coin->virtualchain == 0 )
printf("pend.(%d -> %d) MAXMEM.%s enablecache.%d VALIDATEDIR.(%s) VALIDATE.%d RELAY.%d\n",coin->startPEND,coin->endPEND,mbstr(str,coin->MAXMEM),coin->enableCACHE,coin->VALIDATEDIR,coin->VALIDATENODE,coin->RELAYNODE);
return(coin);
}
@ -936,8 +946,6 @@ int32_t iguana_launchcoin(struct supernet_info *myinfo,char *symbol,cJSON *json)
coins[0] = (void *)((long)1);
coins[1] = coin;
printf("launch coinloop for.%s services.%llx started.%p peers.%p\n",coin->symbol,(long long)services,coin->started,coin->peers);
if ( coin->peers == 0 )
coin->peers = calloc(1,sizeof(*coin->peers));
coin->launched = iguana_launch(coin,"iguana_coinloop",iguana_coinloop,coins,IGUANA_PERMTHREAD);
coin->active = 1;
coin->started = 0;

11
iguana/iguana777.h

@ -227,9 +227,9 @@ struct iguana_chain
char userhome[512],serverport[128],userpass[1024];
char use_addmultisig,do_opreturn;
int32_t estblocktime,protover;
bits256 PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16];
bits256 genesishash2,PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16];
uint8_t zcash,auxpow,alertpubkey[65];
int32_t targetspacing,targettimespan;
uint16_t targetspacing,targettimespan; uint32_t nBits;
};
struct iguana_msgaddress { uint32_t nTime; uint64_t nServices; uint8_t ip[16]; uint16_t port; } __attribute__((packed));
@ -563,7 +563,7 @@ struct iguana_info
int32_t MAXPEERS,MAXPENDINGREQUESTS,MAXBUNDLES,MAXSTUCKTIME,active,closestbundle,numemitted,lastsweep,numemit,startutc,newramchain,numcached,cachefreed,helperdepth,startPEND,endPEND,enableCACHE,RELAYNODE,VALIDATENODE,origbalanceswritten,balanceswritten,RTheight,RTdatabad;
bits256 balancehash,allbundles;
uint32_t lastsync,parsetime,numiAddrs,lastpossible,bundlescount,savedblocks,backlog,spendvectorsaved,laststats,lastinv2; char VALIDATEDIR[512];
int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy,emitbusy,stuckiters;
int32_t longestchain,badlongestchain,longestchain_strange,RTramchain_busy,emitbusy,stuckiters,virtualchain;
struct tai starttime; double startmillis;
struct iguana_chain *chain;
struct iguana_iAddr *iAddrs;
@ -719,9 +719,13 @@ int32_t iguana_pollQsPT(struct iguana_info *coin,struct iguana_peer *addr);
int32_t iguana_avail(struct iguana_info *coin,int32_t height,int32_t n);
int32_t iguana_updatebundles(struct iguana_info *coin);
void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag);
void iguana_chaininit(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(struct supernet_info *myinfo,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);
// init
struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags);
void iguana_callcoinstart(struct iguana_info *coin);
void iguana_initcoin(struct iguana_info *coin,cJSON *argjson);
void iguana_coinloop(void *arg);
@ -835,6 +839,7 @@ void iguana_dedicatedglue(void *arg);
void SuperNET_remotepeer(struct supernet_info *myinfo,struct iguana_info *coin,char *symbol,char *ipaddr,int32_t supernetflag);
void SuperNET_yourip(struct supernet_info *myinfo,char *yourip);
void iguana_peerkill(struct iguana_info *coin);
int32_t blockhash_sha256(uint8_t *blockhashp,uint8_t *serialized,int32_t len);
char *busdata_sync(uint32_t *noncep,char *jsonstr,char *broadcastmode,char *destNXTaddr);
void peggy();

2
iguana/iguana_blocks.c

@ -670,7 +670,7 @@ struct iguana_block *_iguana_chainlink(struct iguana_info *coin,struct iguana_bl
return(block);
}
}
} else printf("chainlink error from block.%p\n",block);
} //else printf("chainlink error from block.%p\n",block);
return(0);
}

2
iguana/iguana_bundles.c

@ -1313,7 +1313,7 @@ void iguana_bundlestats(struct iguana_info *coin,char *str,int32_t lag)
coin->blocksrecv = numrecv;
uint64_t tmp; int32_t diff,p = 0; struct tai difft,t = tai_now();
for (i=0; i<IGUANA_MAXPEERS; i++)
if ( coin->peers->active[i].usock >= 0 )
if ( coin->peers->active[i].usock > 0 )
p++;
diff = (int32_t)time(NULL) - coin->startutc;
difft.x = (t.x - coin->starttime.x), difft.millis = (t.millis - coin->starttime.millis);

25
iguana/iguana_chains.c

@ -238,7 +238,7 @@ uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *us
{
FILE *fp; uint16_t port = 0;
char fname[2048],line[1024],*rpcuser,*rpcpassword,*rpcport,*str;
if ( strcmp(coinstr,"NXT") == 0 )
if ( strcmp(coinstr,"NXT") == 0 || coindir == 0 || confname == 0 || coindir[0] == 0 || confname[0] == 0 )
return(0);
serverport[0] = userpass[0] = 0;
set_coinconfname(fname,coinstr,userhome,coindir,confname);
@ -286,7 +286,7 @@ uint16_t extract_userpass(char *serverport,char *userpass,char *coinstr,char *us
void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
{
extern char Userhome[];
char *path,conf[512],*hexstr,genesisblock[1024]; bits256 hash; uint16_t port; cJSON *rpair,*genesis,*rewards,*item; int32_t i,n,m; uint32_t nBits; uint8_t tmp[4];
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];
if ( strcmp(chain->symbol,"NXT") != 0 )
{
if ( strcmp(chain->symbol,"BTCD") == 0 )
@ -311,7 +311,8 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
if ( jobj(argjson,"conf") == 0 )
conf[0] = 0;
else safecopy(conf,jstr(argjson,"conf"),sizeof(conf));
printf("CONF.(%s)\n",conf);
if ( conf[0] != 0 )
printf("CONF.(%s)\n",conf);
safecopy(chain->name,jstr(argjson,"name"),sizeof(chain->name));
//chain->dust = j64bits(argjson,"dust");
if ( jobj(argjson,"txfee_satoshis") != 0 )
@ -326,7 +327,10 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
if ( (chain->ramchainport= juint(argjson,"ramchain")) == 0 )
chain->ramchainport = chain->portp2p - 1;
if ( (chain->rpcport= juint(argjson,"rpc")) == 0 )
chain->rpcport = chain->portp2p - 1;
{
if ( chain->portp2p != 0 )
chain->rpcport = chain->portp2p-1;
}
chain->zcash = juint(argjson,"zcash");
if ( jobj(argjson,"isPoS") != 0 )
chain->txhastimestamp = juint(argjson,"isPoS");
@ -373,7 +377,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
if ( (genesis= jobj(argjson,"genesis")) != 0 )
{
chain->hashalgo = iguana_hashalgo(jstr(genesis,"hashalgo"));
decode_hex(hash.bytes,sizeof(hash),chain->genesis_hash);
decode_hex(chain->genesishash2.bytes,sizeof(chain->genesishash2),chain->genesis_hash);
if ( jstr(genesis,"nBits") != 0 )
{
decode_hex((void *)&tmp,sizeof(tmp),jstr(genesis,"nBits"));
@ -383,8 +387,8 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
((uint8_t *)&nBits)[3] = tmp[0];
}
else nBits = 0x1e00ffff;
hash = iguana_chaingenesis(chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,hash,genesisblock,jstr(genesis,"hashalgo"),juint(genesis,"version"),juint(genesis,"timestamp"),nBits,juint(genesis,"nonce"),jbits256(genesis,"merkle_root"));
memcpy(chain->genesis_hashdata,hash.bytes,32);
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"));
memcpy(chain->genesis_hashdata,chain->genesishash2.bytes,32);
char str[65]; init_hexbytes_noT(str,chain->genesis_hashdata,32);
chain->genesis_hash = clonestr(str);
//chain->genesis_hash = clonestr(bits256_str(str,hash));
@ -394,8 +398,13 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
{
if ( (hexstr= jstr(argjson,"genesisblock")) != 0 )
{
uint8_t hexbuf[1024],*ptr,*data; int32_t datalen,hdrsize = (chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
chain->genesis_hex = mycalloc('G',1,strlen(hexstr)+1);
strcpy(chain->genesis_hex,hexstr);
data = get_dataptr(&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr);
memcpy(chain->genesis_hashdata,data,hdrsize);
if ( ptr != 0 )
free(ptr);
}
}
if ( (rewards= jarray(&n,argjson,"rewards")) != 0 )
@ -411,7 +420,7 @@ void iguana_chainparms(struct iguana_chain *chain,cJSON *argjson)
}
}
sprintf(chain->messagemagic,"%s Signed Message:\n",chain->name);
printf("COIN.%s serverport.(%s) userpass.(%s) port.%u magic.%08x\n",chain->symbol,chain->serverport,chain->userpass,chain->rpcport,*(uint32_t *)chain->netmagic);
printf("COIN.%s serverport.(%s) userpass.(%s) RPCport.%u magic.%08x\n",chain->symbol,chain->serverport,chain->userpass,chain->rpcport,*(uint32_t *)chain->netmagic);
}
}

70
iguana/iguana_init.c

@ -27,7 +27,7 @@ void iguana_initQ(queue_t *Q,char *name)
void iguana_initQs(struct iguana_info *coin)
{
int32_t i; struct iguana_info *btcd;
int32_t i;
iguana_initQ(&coin->acceptQ,"acceptQ");
iguana_initQ(&coin->hdrsQ,"hdrsQ");
iguana_initQ(&coin->blocksQ,"blocksQ");
@ -36,7 +36,7 @@ void iguana_initQs(struct iguana_info *coin)
iguana_initQ(&coin->msgrequestQ,"msgrequestQ");
iguana_initQ(&coin->cacheQ,"cacheQ");
iguana_initQ(&coin->recvQ,"recvQ");
if ( (btcd= iguana_coinfind("BTCD")) == 0 || coin->peers != btcd->peers )
if ( coin->MAXPEERS > 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
iguana_initQ(&coin->peers->active[i].sendQ,"addrsendQ");
@ -74,7 +74,7 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
coin->startmillis = OS_milliseconds(), coin->starttime = tai_now();
coin->avetime = 1 * 100;
//coin->R.maxrecvbundles = IGUANA_INITIALBUNDLES;
if ( coin->peers != 0 )
if ( coin->MAXPEERS > 0 )
{
for (i=0; i<IGUANA_MAXPEERS; i++)
coin->peers->active[i].usock = -1;
@ -84,9 +84,12 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
{
struct iguana_block *block,*ptr; struct iguana_msgblock msg; bits256 hash2; char str[65],str2[65]; uint8_t buf[8192],blockspace[sizeof(*block)+sizeof(*block->zRO)]; int32_t height,auxback;
if ( coin == 0 || chain == 0 )
return(GENESIS_PUBKEY);
block = (void *)blockspace;
memset(block,0,sizeof(blockspace));
iguana_blocksizecheck("genesis",coin->chain->zcash,block);
block->RO.allocsize = chain->zcash != 0 ? sizeof(struct iguana_zblock) : sizeof(struct iguana_block);
iguana_blocksizecheck("genesis",chain->zcash,block);
if ( chain->genesis_hex == 0 )
{
printf("no genesis_hex for %s\n",coin->symbol);
@ -98,7 +101,7 @@ bits256 iguana_genesis(struct iguana_info *coin,struct iguana_chain *chain)
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));
coin->chain->auxpow = auxback;
if ( coin->MAXPEERS == 0 || coin->MAXPEERS > 1 )
if ( coin->virtualchain != 0 || coin->MAXPEERS > 1 )
{
if ( memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 )
{
@ -462,14 +465,14 @@ void iguana_coinpurge(struct iguana_info *coin)
struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags)
{
FILE *fp; char fname[512],*symbol; int32_t iter; long fpos; bits256 lastbundle; struct supernet_info *myinfo = SuperNET_MYINFO(0);
if ( coin->peers == 0 )
/*if ( coin->peers == 0 )
{
printf("cant start privatechain directly\n");
return(0);
}
}*/
coin->sleeptime = 10000;
symbol = coin->symbol;
if ( iguana_peerslotinit(coin,&coin->internaladdr,IGUANA_MAXPEERS,calc_ipbits("127.0.0.1:7777")) < 0 )
if ( coin->peers != 0 && iguana_peerslotinit(coin,&coin->internaladdr,IGUANA_MAXPEERS,calc_ipbits("127.0.0.1:7777")) < 0 )
{
printf("iguana_coinstart: error creating peerslot\n");
return(0);
@ -482,28 +485,31 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
memset(&coin->blocks.hwmchain,0,sizeof(coin->blocks.hwmchain));
coin->blocks.hwmchain.height = 0;
printf("%s MYSERVICES.%llx\n",coin->symbol,(long long)coin->myservices);
if ( (coin->myservices & NODE_NETWORK) != 0 )
if ( coin->virtualchain == 0 )
{
if ( coin->peers->acceptloop == 0 && coin->peers->localaddr == 0 )
if ( (coin->myservices & NODE_NETWORK) != 0 )
{
coin->peers->acceptloop = malloc(sizeof(pthread_t));
if ( OS_thread_create(coin->peers->acceptloop,NULL,(void *)iguana_acceptloop,(void *)coin) != 0 )
if ( coin->peers->acceptloop == 0 && coin->peers->localaddr == 0 )
{
free(coin->peers->acceptloop);
coin->peers->acceptloop = 0;
printf("error launching accept thread for port.%u\n",coin->chain->portp2p);
coin->peers->acceptloop = malloc(sizeof(pthread_t));
if ( OS_thread_create(coin->peers->acceptloop,NULL,(void *)iguana_acceptloop,(void *)coin) != 0 )
{
free(coin->peers->acceptloop);
coin->peers->acceptloop = 0;
printf("error launching accept thread for port.%u\n",coin->chain->portp2p);
}
}
}
}
if ( coin->RELAYNODE != 0 && coin->rpcloop == 0 )
{
myinfo->argport = coin->chain->rpcport;
coin->rpcloop = malloc(sizeof(pthread_t));
if ( OS_thread_create(coin->rpcloop,NULL,(void *)iguana_rpcloop,(void *)myinfo) != 0 )
if ( coin->RELAYNODE != 0 && coin->rpcloop == 0 )
{
free(coin->rpcloop);
coin->rpcloop = 0;
printf("error launching rpcloop for %s port.%u\n",coin->symbol,coin->chain->rpcport);
myinfo->argport = coin->chain->rpcport;
coin->rpcloop = malloc(sizeof(pthread_t));
if ( OS_thread_create(coin->rpcloop,NULL,(void *)iguana_rpcloop,(void *)myinfo) != 0 )
{
free(coin->rpcloop);
coin->rpcloop = 0;
printf("error launching rpcloop for %s port.%u\n",coin->symbol,coin->chain->rpcport);
}
}
}
//coin->firstblock = coin->blocks.parsedblocks + 1;
@ -518,7 +524,10 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
getchar();
}
memset(&lastbundle,0,sizeof(lastbundle));
for (iter=coin->peers->numranked>8; iter<2; iter++)
if ( coin->peers == 0 )
iter = 2;
else iter = (coin->peers->numranked > 8);
for (; iter<2; iter++)
{
#ifdef __PNACL__
if ( iter == 0 )
@ -530,7 +539,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
ipaddrs = BTCD_ipaddrs, num = (int32_t)(sizeof(BTCD_ipaddrs)/sizeof(*BTCD_ipaddrs));
else if ( strcmp(coin->symbol,"BTC") == 0 )
ipaddrs = BTC_ipaddrs, num = (int32_t)(sizeof(BTC_ipaddrs)/sizeof(*BTC_ipaddrs));
if ( ipaddrs != 0 )
if ( ipaddrs != 0 && coin->virtualchain == 0 )
{
for (j=0; j<num; j++)
{
@ -574,14 +583,17 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
//sprintf(fname,"confs/%s_%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
//sprintf(fname,"tmp/%s/%s.txt",coin->symbol,(iter == 0) ? "peers" : "hdrs");
OS_compatible_path(fname);
printf("parsefile.%d %s\n",iter,fname);
if ( (fp= fopen(fname,"r")) != 0 )
{
iguana_parseline(coin,iter,fp);
if ( coin->virtualchain == 0 || iter > 0 )
{
printf("parsefile.%d %s\n",iter,fname);
iguana_parseline(coin,iter,fp);
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
}
fpos = ftell(fp);
fclose(fp);
} else fpos = -1;
printf("done parsefile.%d (%s) size.%ld\n",iter,fname,fpos);
}
#ifndef IGUANA_DEDICATED_THREADS
coin->peers->peersloop = iguana_launch("peersloop",iguana_peersloop,coin,IGUANA_PERMTHREAD);

2
iguana/iguana_msg.c

@ -328,7 +328,7 @@ void iguana_gotversion(struct iguana_info *coin,struct iguana_peer *addr,struct
}
else if ( 0 && addr->supernet == 0 && addr->basilisk == 0 )//|| (addr->basilisk != 0 && myinfo->IAMRELAY == 0) )
addr->dead = (uint32_t)time(NULL);
//if ( addr->supernet != 0 || addr->basilisk != 0 )
if ( addr->supernet != 0 || addr->basilisk != 0 )
printf("height.%d nServices.%lld nonce.%llu %srelay node.(%s) supernet.%d basilisk.%d longest.%u\n",vers->nStartingHeight,(long long)vers->nServices,(long long)vers->nonce,addr->relayflag==0?"non-":"",addr->ipaddr,addr->supernet,addr->basilisk,vers->nStartingHeight);
if ( (int32_t)vers->nStartingHeight > coin->longestchain )
{

41
iguana/iguana_peers.c

@ -48,6 +48,8 @@ int32_t iguana_validatehdr(char *symbol,struct iguana_msghdr *H)
struct iguana_iAddr *_iguana_hashset(struct iguana_info *coin,uint32_t ipbits,int32_t itemind)
{
struct iguana_iAddr *ptr = 0; int32_t allocsize; char str[65]; struct OS_memspace *mem = 0;
if ( coin->virtualchain != 0 )
return(0);
expand_ipbits(str,ipbits);
HASH_FIND(hh,coin->iAddrs,&ipbits,sizeof(ipbits),ptr);
//printf("%p hashset.(%s) -> ptr.%p itemind.%d keylen.%ld %x\n",coin->iAddrs,str,ptr,itemind,sizeof(ipbits),ipbits);
@ -81,6 +83,8 @@ struct iguana_iAddr *_iguana_hashset(struct iguana_info *coin,uint32_t ipbits,in
struct iguana_iAddr *iguana_iAddrhashset(struct iguana_info *coin,struct iguana_iAddr *iA,int32_t ind)
{
struct iguana_iAddr *tmp,*item;
if ( coin->virtualchain != 0 )
return(0);
if ( iA == 0 || iA->ipbits == 0 )
{
printf("null iA.%p or ipbits.%llx ind.%d status.%d\n",iA,iA!=0?(long long)iA->ipbits:0,iA!=0?iA->hh.itemind:0,iA!=0?iA->status:0);
@ -117,6 +121,8 @@ struct iguana_iAddr *iguana_iAddrhashset(struct iguana_info *coin,struct iguana_
struct iguana_iAddr *iguana_iAddrhashfind(struct iguana_info *coin,uint64_t ipbits,int32_t createflag)
{
int32_t ind; struct iguana_iAddr *item = 0;
if ( coin->virtualchain != 0 )
return(0);
portable_mutex_lock(&coin->peers_mutex);
if ( ipbits != 0 )
{
@ -135,6 +141,8 @@ struct iguana_iAddr *iguana_iAddrhashfind(struct iguana_info *coin,uint64_t ipbi
uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana_iAddr *iA,uint32_t ind)
{
FILE *fp; char fname[512],hexstr[65],ipaddr[64]; uint32_t ipbits; int32_t i,n,m,retval = 0; struct iguana_iAddr tmp,*ptr;
if ( coin->virtualchain != 0 )
return(0);
sprintf(fname,"%s/%s_peers.dat",GLOBAL_DBDIR,coin->symbol), OS_compatible_path(fname);
if ( rwflag < 0 || iA == 0 )
{
@ -260,6 +268,8 @@ uint32_t iguana_rwiAddrind(struct iguana_info *coin,int32_t rwflag,struct iguana
void iguana_iAconnected(struct iguana_info *coin,struct iguana_peer *addr)
{
struct iguana_iAddr *iA;
if ( coin->virtualchain != 0 )
return;
if ( (iA= iguana_iAddrhashfind(coin,addr->ipbits,1)) != 0 )
{
iA->status = IGUANA_PEER_READY;
@ -276,6 +286,8 @@ void iguana_iAconnected(struct iguana_info *coin,struct iguana_peer *addr)
void iguana_iAkill(struct iguana_info *coin,struct iguana_peer *addr,int32_t markflag)
{
struct iguana_iAddr *iA; int32_t rank; char ipaddr[64];
if ( coin->virtualchain != 0 )
return;
if ( addr->ipbits == 0 )
{
printf("cant iAkill null ipbits\n");
@ -627,6 +639,8 @@ void iguana_gotdata(struct iguana_info *coin,struct iguana_peer *addr,int32_t he
int32_t iguana_iAddrheight(struct iguana_info *coin,uint64_t ipbits)
{
struct iguana_iAddr *iA;
if ( coin->virtualchain != 0 )
return(0);
if ( (iA= iguana_iAddrhashfind(coin,ipbits,0)) != 0 )
return(iA->height);
return(0);
@ -640,6 +654,8 @@ void iguana_startconnection(void *arg)
printf("iguana_startconnection nullptrs addr.%p coin.%p\n",addr,coin);
return;
}
if ( coin->virtualchain != 0 )
return;
addr->addrind = (int32_t)(((long)addr - (long)&coin->peers->active[0]) / sizeof(*addr));
if ( addr->usock >= 0 )
{
@ -700,6 +716,8 @@ void iguana_startconnection(void *arg)
void iguana_peerkill(struct iguana_info *coin)
{
struct iguana_peer *addr;
if ( coin->virtualchain != 0 )
return;
if ( coin->peers->numranked > 0 && (addr= coin->peers->ranked[coin->peers->numranked-1]) != 0 )
{
printf("mark rank.%d as dead.(%s)\n",coin->peers->numranked,addr->ipaddr);
@ -710,8 +728,10 @@ void iguana_peerkill(struct iguana_info *coin)
struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int32_t forceflag)
{
int32_t i; struct iguana_peer *addr; char ipaddr[64];
if ( coin->virtualchain != 0 )
return(0);
for (i=0; i<IGUANA_MAXPEERS; i++)
if ( ipbits == coin->peers->active[i].ipbits )
if ( (uint32_t)ipbits == (uint32_t)coin->peers->active[i].ipbits )
return(forceflag!=0 ? &coin->peers->active[i] : 0);
expand_ipbits(ipaddr,ipbits);
#ifdef IGUANA_DISABLEPEERS
@ -727,7 +747,7 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int
addr->addrind = i;
if ( addr->usock >= 0 || addr->pending != 0 || addr->ipbits == ipbits || strcmp(ipaddr,addr->ipaddr) == 0 )
{
//printf("skip.(%s) usock.%d pending.%d ipbits.%x vs %x lag.%ld\n",addr->ipaddr,addr->usock,addr->pending,addr->ipbits,iA->ipbits,time(NULL)-addr->pending);
//printf("i.%d skip.(%s) usock.%d pending.%d ipbits.%llx lag.%ld\n",i,addr->ipaddr,addr->usock,addr->pending,(long long)addr->ipbits,time(NULL)-addr->pending);
continue;
}
portable_mutex_lock(&coin->peers_mutex);
@ -747,6 +767,8 @@ struct iguana_peer *iguana_peerslot(struct iguana_info *coin,uint64_t ipbits,int
void iguana_launchpeer(struct iguana_info *coin,char *ipaddr)
{
struct iguana_peer *addr; uint32_t ipbits = (uint32_t)calc_ipbits(ipaddr);
if ( coin->virtualchain != 0 )
return;
if ( (addr= iguana_peerslot(coin,ipbits,0)) != 0 )
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
}
@ -754,12 +776,15 @@ void iguana_launchpeer(struct iguana_info *coin,char *ipaddr)
void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
{
struct iguana_peer *addr = 0;
if ( coin->virtualchain != 0 )
return(0);
if ( iA != 0 && iA->ipbits != 0 && iguana_numthreads(coin,1 << IGUANA_CONNTHREAD) < IGUANA_MAXCONNTHREADS && iA->status == IGUANA_PEER_ELIGIBLE )
{
//printf("%x\n",iA->ipbits);
//portable_mutex_unlock(&coin->peers_mutex);
if ( (addr= iguana_peerslot(coin,iA->ipbits,0)) != 0 )
{
addr->ipbits = iA->ipbits;
//printf("pend.%d status.%d possible peer.(%s).%x threads %d %d %d %d\n",addr->pending,iA->status,addr->ipaddr,(uint32_t)addr->ipbits,iguana_numthreads(coin,0),iguana_numthreads(coin,1),iguana_numthreads(coin,2),iguana_numthreads(coin,3));
if ( addr->pending == 0 && iA->status != IGUANA_PEER_CONNECTING && (iA->status != IGUANA_PEER_KILLED || time(NULL) > iA->lastkilled+600) )
{
@ -788,6 +813,8 @@ void *iguana_iAddriterator(struct iguana_info *coin,struct iguana_iAddr *iA)
uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
{
char checkaddr[64]; uint64_t ipbits; uint32_t now = (uint32_t)time(NULL); int32_t i,n; struct iguana_iAddr *iA;
if ( coin->virtualchain != 0 )
return(0);
if ( ipaddr != 0 && ipaddr[0] != 0 )
{
if ( strcmp(ipaddr,"0.0.0.0") == 0 || strcmp(ipaddr,"127.0.0.1") == 0 )
@ -813,7 +840,10 @@ uint32_t iguana_possible_peer(struct iguana_info *coin,char *ipaddr)
return((uint32_t)time(NULL));
}
#endif
ipbits = (uint32_t)calc_ipbits(ipaddr);
//printf("check possible peer.(%s)\n",ipaddr);
if ( iguana_peerslot(coin,(uint32_t)ipbits,0) != 0 )
return((uint32_t)time(NULL));
for (i=n=0; i<coin->MAXPEERS; i++)
{
if ( strcmp(ipaddr,coin->peers->active[i].ipaddr) == 0 )
@ -1004,6 +1034,7 @@ int64_t iguana_peerfree(struct iguana_info *coin,struct iguana_peer *addr,void *
return(-1);
}
#else
void *iguana_peeralloc(struct iguana_info *coin,struct iguana_peer *addr,int32_t datalen)
{
addr->allocated += datalen;
@ -1048,7 +1079,7 @@ int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,in
fseek(addr->voutsfp,0,SEEK_END);
else if ( (addr->voutsfp= fopen(fname,"wb+")) == 0 )
{
printf("cant create.(%s)\n",fname);
printf("iguana_peerslotinit cant create.(%s)\n",fname);
return(-1);
}
if ( coin->MAXPEERS == 1 || coin->VALIDATENODE != 0 || coin->RELAYNODE != 0 )
@ -1058,7 +1089,7 @@ int32_t iguana_peerslotinit(struct iguana_info *coin,struct iguana_peer *addr,in
fseek(addr->vinsfp,0,SEEK_END);
else if ( (addr->vinsfp= fopen(fname,"wb+")) == 0 )
{
printf("cant create.(%s)\n",fname);
printf("iguana_peerslotinit cant create.(%s)\n",fname);
return(-1);
}
}
@ -1070,6 +1101,8 @@ void iguana_dedicatedloop(struct supernet_info *myinfo,struct iguana_info *coin,
static uint32_t lastping;
struct pollfd fds; struct iguana_bundlereq *req; uint8_t *buf; uint32_t ipbits;
int32_t bufsize,flag,run,timeout = coin->polltimeout == 0 ? 10 : coin->polltimeout;
if ( coin->virtualchain != 0 )
return;
if ( iguana_peerslotinit(coin,addr,(int32_t)(((long)addr - (long)&coin->peers->active[0]) / sizeof(*addr)),calc_ipbits(addr->ipaddr)) < 0 )
{
printf("error creating peer's files\n");

4
iguana/iguana_ramchain.c

@ -1369,8 +1369,6 @@ int32_t iguana_Xspendmap(struct iguana_info *coin,struct iguana_ramchain *ramcha
struct iguana_ramchain *_iguana_ramchain_map(struct iguana_info *coin,char *fname,struct iguana_bundle *bp,int32_t numblocks,struct iguana_ramchain *ramchain,struct OS_memspace *hashmem,uint32_t ipbits,bits256 hash2,bits256 prevhash2,int32_t bundlei,long fpos,int32_t allocextras,int32_t expanded,uint8_t zcash)
{
RAMCHAIN_DECLARE; int32_t valid,iter,i,checki,hdrsi; long filesize; void *ptr; char str[65],str2[65],dirstr[64]; struct iguana_block *block; struct iguana_blockRO *bRO; struct iguana_ramchaindata *rdata;
if ( (rdata= ramchain->H.data) == 0 )
return(0);
/*if ( ramchain->expanded != 0 && (ramchain->sigsfileptr == 0 || ramchain->sigsfilesize == 0) )
{
sprintf(sigsfname,"sigs/%s/%s",coin->symbol,bits256_str(str,hash2));
@ -1408,7 +1406,7 @@ struct iguana_ramchain *_iguana_ramchain_map(struct iguana_info *coin,char *fnam
if ( ramchain->fileptr != 0 && ramchain->filesize > 0 )
{
// verify hashes
ramchain->H.data = (void *)(long)((long)ramchain->fileptr + fpos);
ramchain->H.data = rdata = (void *)(long)((long)ramchain->fileptr + fpos);
ramchain->H.ROflag = 1;
ramchain->expanded = expanded;
ramchain->numblocks = (bp == 0) ? 1 : bp->n;

4
iguana/iguana_recv.c

@ -235,7 +235,9 @@ int32_t iguana_speculativefind(struct iguana_info *coin,struct iguana_bundle *bp
continue;
}
if ( memcmp(&recvlen,tmp,sizeof(recvlen)) != 0 || memcmp(&tmp[sizeof(recvlen)],data,recvlen) != 0 )
printf("cachedata ERROR [%d:%d] already has recvlen.%d vs %d for %s\n",bp->hdrsi,i,recvlen,cachelen,bits256_str(str,block->RO.hash2));
{
//printf("cachedata ERROR [%d:%d] already has recvlen.%d vs %d for %s\n",bp->hdrsi,i,recvlen,cachelen,bits256_str(str,block->RO.hash2));
}
return(0);
}
bp->speculativecache[i] = calloc(1,recvlen + sizeof(recvlen));

2
iguana/iguana_tx.c

@ -317,7 +317,7 @@ int32_t iguana_peerblockrequest(struct iguana_info *coin,uint8_t *blockspace,int
else
{
if ( block != 0 )
printf("iguana_peerblockrequest: block.%p ht.%d mainchain.%d [%d:%d]\n",block,block->height,block->mainchain,bp->hdrsi,bundlei);
printf("iguana_peerblockrequest: block.%p ht.%d mainchain.%d [%d:%d] from %s\n",block,block->height,block->mainchain,bp->hdrsi,bundlei,addr!=0?addr->ipaddr:"local");
else printf("iguana_peerblockrequest: block.%p [%d:%d]\n",block,bp->hdrsi,bundlei);
}
} //else printf("iguana_peerblockrequest: cant find %s\n",bits256_str(str,hash2));

1
iguana/tests/new

@ -0,0 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"agent\":\"basilisk\",\"method\":\"newprivatechain\",\"vals\":{\"chain\":\"InstantDEX\",\"symbol\":\"DEX\"}}"
Loading…
Cancel
Save