Browse Source

debug flag

release/v0.1
jl777 8 years ago
parent
commit
f550999ae2
  1. 2
      gecko/gecko.c
  2. 2
      gecko/gecko_blocks.c
  3. 2
      iguana/coins/genkmd
  4. 3
      iguana/confs/KMD_peers.txt
  5. 94
      iguana/iguana_blocks.c
  6. 3
      iguana/iguana_chains.c
  7. 16
      iguana/iguana_init.c
  8. 101
      iguana/iguana_msg.c
  9. 4
      iguana/iguana_peers.c
  10. 2
      iguana/iguana_recv.c
  11. 38
      iguana/iguana_tx.c
  12. 48
      includes/iguana_structs.h

2
gecko/gecko.c

@ -181,7 +181,7 @@ struct iguana_info *basilisk_geckochain(struct supernet_info *myinfo,char *symbo
serialized = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr);
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);
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr);
if ( gecko_blocknonce_verify(virt,serialized,hdrsize,virt->chain->nBits,0,0) > 0 )
{
virt->chain->genesishash2 = iguana_calcblockhash(symbol,virt->chain->hashalgo,serialized,hdrsize);

2
gecko/gecko_blocks.c

@ -312,7 +312,7 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a
printf("REJECT: duplicate block %s\n",bits256_str(str,hash2));
return(clonestr("{\"error\":\"duplicate block rejected\"}"));
}
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
hdrsize = (virt->chain->zcash != 0) ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr);
//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 )
{

2
iguana/coins/genkmd

@ -1,2 +1,2 @@
curl --url "http://127.0.0.1:7778" --data "{\"unitval\":\"20\",\"zcash\":1,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":32,\"newcoin\":\"KMD\",\"name\":\"Komodo\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"6df6e755\",\"p2p\":18333,\"rpc\":18332,\"pubval\":111,\"p2shval\":196,\"wifval\":239,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"27d1f4ce03fc473c9dd6e1e307c682c8f802eae1f5a2f61402aa1ae8702ed3b6\",\"protover\":70002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f200000000000000000000000000000000000000000000000000000000000000000209d0900001dc600004fba000024e20100e5660000778100007e190100222f0100720e000056e50100eb12010089920100583d00002e660000844e01001bfe0100cf0c0000892a0000f5230000f9680000976e00009b7b000046770000afd80100bd0d000057650000048f000082b100006a2500004e0601006fef000048410100\"}"
curl --url "http://127.0.0.1:7778" --data "{\"unitval\":\"20\",\"zcash\":1,\"RELAY\":1,\"VALIDATE\":1,\"prefetchlag\":-1,\"poll\":10,\"active\":1,\"agent\":\"iguana\",\"method\":\"addcoin\",\"startpend\":8,\"endpend\":8,\"services\":129,\"maxpeers\":32,\"newcoin\":\"KMD\",\"name\":\"Komodo\",\"hasheaders\":1,\"useaddmultisig\":0,\"netmagic\":\"f9eee48d\",\"p2p\":7770,\"rpc\":7771,\"pubval\":60,\"p2shval\":85,\"wifval\":188,\"txfee_satoshis\":\"10000\",\"isPoS\":0,\"minoutput\":10000,\"minconfirms\":2,\"genesishash\":\"027e3758c3a65b12aa1046462b486d0a63bfa1beae327897f56c5cfb7daaae71\",\"protover\":170002,\"genesisblock\":\"0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a000000000000000000000000000000000000000000000000000000000000000029ab5f490f0f0f200b00000000000000000000000000000000000000000000000000000000000000fd4005000d5ba7cda5d473947263bf194285317179d2b0d307119c2e7cc4bd8ac456f0774bd52b0cd9249be9d40718b6397a4c7bbd8f2b3272fed2823cd2af4bd1632200ba4bf796727d6347b225f670f292343274cc35099466f5fb5f0cd1c105121b28213d15db2ed7bdba490b4cedc69742a57b7c25af24485e523aadbb77a0144fc76f79ef73bd8530d42b9f3b9bed1c135ad1fe152923fafe98f95f76f1615e64c4abb1137f4c31b218ba2782bc15534788dda2cc08a0ee2987c8b27ff41bd4e31cd5fb5643dfe862c9a02ca9f90c8c51a6671d681d04ad47e4b53b1518d4befafefe8cadfb912f3d03051b1efbf1dfe37b56e93a741d8dfd80d576ca250bee55fab1311fc7b3255977558cdda6f7d6f875306e43a14413facdaed2f46093e0ef1e8f8a963e1632dcbeebd8e49fd16b57d49b08f9762de89157c65233f60c8e38a1f503a48c555f8ec45dedecd574a37601323c27be597b956343107f8bd80f3a925afaf30811df83c402116bb9c1e5231c70fff899a7c82f73c902ba54da53cc459b7bf1113db65cc8f6914d3618560ea69abd13658fa7b6af92d374d6eca9529f8bd565166e4fcbf2a8dfb3c9b69539d4d2ee2e9321b85b331925df195915f2757637c2805e1d4131e1ad9ef9bc1bb1c732d8dba4738716d351ab30c996c8657bab39567ee3b29c6d054b711495c0d52e1cd5d8e55b4f0f0325b97369280755b46a02afd54be4ddd9f77c22272b8bbb17ff5118fedbae2564524e797bd28b5f74f7079d532ccc059807989f94d267f47e724b3f1ecfe00ec9e6541c961080d8891251b84b4480bc292f6a180bea089fef5bbda56e1e41390d7c0e85ba0ef530f7177413481a226465a36ef6afe1e2bca69d2078712b3912bba1a99b1fbff0d355d6ffe726d2bb6fbc103c4ac5756e5bee6e47e17424ebcbf1b63d8cb90ce2e40198b4f4198689daea254307e52a25562f4c1455340f0ffeb10f9d8e914775e37d0edca019fb1b9c6ef81255ed86bc51c5391e0591480f66e2d88c5f4fd7277697968656a9b113ab97f874fdd5f2465e5559533e01ba13ef4a8f7a21d02c30c8ded68e8c54603ab9c8084ef6d9eb4e92c75b078539e2ae786ebab6dab73a09e0aa9ac575bcefb29e930ae656e58bcb513f7e3c17e079dce4f05b5dbc18c2a872b22509740ebe6a3903e00ad1abc55076441862643f93606e3dc35e8d9f2caef3ee6be14d513b2e062b21d0061de3bd56881713a1a5c17f5ace05e1ec09da53f99442df175a49bd154aa96e4949decd52fed79ccf7ccbce32941419c314e374e4a396ac553e17b5340336a1a25c22f9e42a243ba5404450b650acfc826a6e432971ace776e15719515e1634ceb9a4a35061b668c74998d3dfb5827f6238ec015377e6f9c94f38108768cf6e5c8b132e0303fb5a200368f845ad9d46343035a6ff94031df8d8309415bb3f6cd5ede9c135fdabcc030599858d803c0f85be7661c88984d88faa3d26fb0e9aac0056a53f1b5d0baed713c853c4a2726869a0a124a8a5bbc0fc0ef80c8ae4cb53636aa02503b86a1eb9836fcc259823e2692d921d88e1ffc1e6cb2bde43939ceb3f32a611686f539f8f7c9f0bf00381f743607d40960f06d347d1cd8ac8a51969c25e37150efdf7aa4c2037a2fd0516fb444525ab157a0ed0a7412b2fa69b217fe397263153782c0f64351fbdf2678fa0dc8569912dcd8e3ccad38f34f23bbbce14c6a26ac24911b308b82c7e43062d180baeac4ba7153858365c72c63dcf5f6a5b08070b730adb017aeae925b7d0439979e2679f45ed2f25a7edcfd2fb77a8794630285ccb0a071f5cce410b46dbf9750b0354aae8b65574501cc69efb5b6a43444074fee116641bb29da56c2b4a7f456991fc92b20101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000\",\"debug\":1}"

3
iguana/confs/KMD_peers.txt

@ -0,0 +1,3 @@
176.9.26.39
5.9.102.210
78.47.196.146

94
iguana/iguana_blocks.c

@ -19,47 +19,71 @@
void iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_block *dest,struct iguana_msgblock *msg,bits256 hash2,int32_t height) //uint32_t numtxids,uint32_t numunspents,uint32_t numspends,double PoW)
{
int32_t i;
memset(dest,0,sizeof(*dest));
dest->RO.version = msg->H.version;
dest->RO.prev_block = msg->H.prev_block;
dest->RO.merkle_root = msg->H.merkle_root;
dest->RO.timestamp = msg->H.timestamp;
dest->RO.bits = msg->H.bits;
dest->RO.txn_count = msg->txn_count;
dest->height = height;
dest->RO.hash2 = hash2;
int32_t i; struct iguana_zblock *zdest; struct iguana_msgzblock *zmsg;
if ( zcash == 0 )
{
memset(dest,0,sizeof(*dest));
dest->RO.version = msg->H.version;
dest->RO.prev_block = msg->H.prev_block;
dest->RO.merkle_root = msg->H.merkle_root;
dest->RO.timestamp = msg->H.timestamp;
dest->RO.bits = msg->H.bits;
dest->RO.txn_count = msg->txn_count;
dest->height = height;
dest->RO.hash2 = hash2;
dest->RO.nonce = msg->H.nonce;
}
else
{
dest->RO.allocsize = (int32_t)(sizeof(*dest) + sizeof(*dest->zRO));
dest->zRO[0].bignonce = msg->zH.bignonce;
zdest = (void *)dest;
zmsg = (void *)msg;
zdest->RO.allocsize = (int32_t)sizeof(struct iguana_zblock);
zdest->RO.version = zmsg->zH.version;
zdest->RO.prev_block = zmsg->zH.prev_block;
zdest->RO.merkle_root = zmsg->zH.merkle_root;
zdest->RO.timestamp = zmsg->zH.timestamp;
zdest->RO.bits = zmsg->zH.bits;
zdest->zRO.bignonce = zmsg->zH.bignonce;
if ( iguana_rwvarint32(0,zmsg->zH.var_numelements,&zdest->zRO.numelements) != sizeof(zmsg->zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zdest->zRO.numelements);
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
dest->zRO[0].solution[i] = msg->zH.solution[i];
zdest->zRO.solution[i] = zmsg->zH.solution[i];
}
}
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count)
{
int32_t i;
memset(msg,0,sizeof(*msg));
msg->H.version = src->RO.version;
msg->H.prev_block = src->RO.prev_block;
msg->H.merkle_root = src->RO.merkle_root;
msg->H.timestamp = src->RO.timestamp;
msg->H.bits = src->RO.bits;
if ( zcash == 0 )
msg->H.nonce = src->RO.nonce;
int32_t i; struct iguana_msgzblock *zmsg; struct iguana_zblock *zsrc;
if ( zcash != 0 )
{
zmsg = (void *)msg;
zsrc = (void *)src;
memset(zmsg,0,sizeof(*zmsg));
zmsg->zH.version = zsrc->RO.version;
zmsg->zH.prev_block = zsrc->RO.prev_block;
zmsg->zH.merkle_root = zsrc->RO.merkle_root;
zmsg->zH.timestamp = zsrc->RO.timestamp;
zmsg->zH.bits = zsrc->RO.bits;
zmsg->zH.bignonce = zsrc->zRO.bignonce;
if ( iguana_rwvarint32(1,zmsg->zH.var_numelements,&zsrc->zRO.numelements) != sizeof(zmsg->zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zsrc->zRO.numelements);
for (i=0; i<zsrc->zRO.numelements; i++)
zmsg->zH.solution[i] = zsrc->zRO.solution[i];
if ( cleartxn_count == 0 )
zmsg->txn_count = src->RO.txn_count;
}
else
{
msg->zH.bignonce = src->zRO[0].bignonce;
msg->zH.numelements = ZCASH_SOLUTION_ELEMENTS;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
msg->zH.solution[i] = src->zRO[0].solution[i];
memset(msg,0,sizeof(*msg));
msg->H.version = src->RO.version;
msg->H.prev_block = src->RO.prev_block;
msg->H.merkle_root = src->RO.merkle_root;
msg->H.timestamp = src->RO.timestamp;
msg->H.bits = src->RO.bits;
msg->H.nonce = src->RO.nonce;
if ( cleartxn_count == 0 )
msg->txn_count = src->RO.txn_count;
}
if ( cleartxn_count == 0 )
msg->txn_count = src->RO.txn_count;
}
void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,struct iguana_block *block,struct iguana_block *origblock)
@ -102,9 +126,12 @@ void iguana_blockcopy(uint8_t zcash,uint8_t auxpow,struct iguana_info *coin,stru
printf("missing space for zcash block.%d origblock.%d\n",block->RO.allocsize,origblock->RO.allocsize);
else
{
block->zRO[0].bignonce = origblock->zRO[0].bignonce;
struct iguana_zblock *zblock = (void *)block;
struct iguana_zblock *origzblock = (void *)origblock;
zblock->zRO.bignonce = origzblock->zRO.bignonce;
zblock->zRO.numelements = origzblock->zRO.numelements;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
block->zRO[0].solution[i] = origblock->zRO[0].solution[i];
zblock->zRO.solution[i] = origzblock->zRO.solution[i];
}
}
}
@ -298,7 +325,7 @@ int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *
int32_t iguana_blockROsize(uint8_t zcash)
{
return((int32_t)(sizeof(struct iguana_blockRO) + zcash*sizeof(struct iguana_msgblockhdr_zcash)));
return((int32_t)(sizeof(struct iguana_blockRO) + zcash*sizeof(struct iguana_msgzblockhdr)));
}
void *iguana_blockzcopyRO(uint8_t zcash,struct iguana_blockRO *dest,int32_t desti,struct iguana_blockRO *src,int32_t srci)
@ -328,6 +355,11 @@ void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_blo
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];
if ( coin->chain->debug != 0 )
{
*validp = 1;
return(0);
}
*validp = 0;
iguana_serialize_block(myinfo,coin->chain,&hash2,serialized,block);
*validp = (memcmp(hash2.bytes,block->RO.hash2.bytes,sizeof(hash2)) == 0);

3
iguana/iguana_chains.c

@ -341,6 +341,7 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
chain->rpcport = 14632;
}
chain->zcash = juint(argjson,"zcash");
chain->debug = juint(argjson,"debug");
if ( (chain->normal_txversion= juint(argjson,"normal_txversion")) == 0 )
chain->normal_txversion = IGUANA_NORMAL_TXVERSION;
if ( (chain->locktime_txversion= juint(argjson,"locktime_txversion")) == 0 )
@ -433,7 +434,7 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
if ( (hexstr= jstr(argjson,"genesisblock")) != 0 )
{
uint8_t hexbuf[1024],*ptr,*data; int32_t datalen,hdrsize;
hdrsize = chain->zcash != 0 ? sizeof(struct iguana_msgblockhdr_zcash) : sizeof(struct iguana_msgblockhdr);
hdrsize = chain->zcash != 0 ? sizeof(struct iguana_msgzblockhdr) : sizeof(struct iguana_msgblockhdr);
chain->genesis_hex = clonestr(hexstr);
data = get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,hexbuf,sizeof(hexbuf),hexstr);
chain->genesishash2 = iguana_calcblockhash(chain->symbol,chain->hashalgo,data,hdrsize);

16
iguana/iguana_init.c

@ -92,7 +92,7 @@ void iguana_initcoin(struct iguana_info *coin,cJSON *argjson)
bits256 iguana_genesis(struct supernet_info *myinfo,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;
struct iguana_block *block,*ptr; struct iguana_msgblock msg; bits256 hash2; char str[65],str2[65]; uint8_t buf[8192],blockspace[sizeof(*block)+sizeof(struct iguana_zblock)]; int32_t height,auxback;
if ( coin == 0 || chain == 0 )
return(GENESIS_PUBKEY);
block = (void *)blockspace;
@ -112,19 +112,21 @@ bits256 iguana_genesis(struct supernet_info *myinfo,struct iguana_info *coin,str
coin->chain->auxpow = auxback;
if ( coin->virtualchain == 0 && coin->MAXPEERS > 1 )
{
if ( memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 )
if ( coin->chain->debug == 0 && memcmp(hash2.bytes,chain->genesis_hashdata,sizeof(hash2)) != 0 )
{
bits256_str(str,hash2);
printf("genesis mismatch? zcash.%d calculated %s vs %s\n",coin->chain->zcash,str,bits256_str(str2,*(bits256 *)chain->genesis_hashdata));
memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2));
}
memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2));
} else memcpy(hash2.bytes,chain->genesis_hashdata,sizeof(hash2));
bits256_str(str,hash2);
printf("genesis.(%s) zcash.%d len.%d hash.%s\n",chain->genesis_hex,coin->chain->zcash,(int32_t)sizeof(msg.H),str);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,block,&msg,hash2,0);
block->RO.txn_count = 1;
block->RO.numvouts = 1;
block->RO.allocsize = (int32_t)(sizeof(*block) + coin->chain->zcash*sizeof(*block->zRO));
if ( coin->chain->zcash != 0 )
block->RO.allocsize = sizeof(struct iguana_zblock);
else block->RO.allocsize = (int32_t)sizeof(*block);
iguana_gotdata(coin,0,0);
if ( (ptr= iguana_blockhashset("genesis0",coin,0,hash2,1)) != 0 )
{
@ -294,10 +296,10 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
{
j = (int32_t)strlen(line) - 1;
line[j] = 0;
//printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS);
printf("parse line.(%s) maxpeers.%d\n",line,coin->MAXPEERS);
if ( iter == 0 )
{
if ( (rand() % 2) == 0 && (m < 32 || m < coin->MAXPEERS/2) )//&& m < 77.7 )
if ( (m < 8 || (rand() % 2) == 0) && (m < 32 || m < coin->MAXPEERS/2) )//&& m < 77.7 )
{
if ( 0 && m == 0 )
{
@ -309,7 +311,7 @@ void iguana_parseline(struct supernet_info *myinfo,struct iguana_info *coin,int3
#ifndef IGUANA_DISABLEPEERS
addr = &coin->peers->active[m++];
iguana_initpeer(coin,addr,(uint32_t)calc_ipbits(line));
//printf("call initpeer.(%s)\n",addr->ipaddr);
printf("call initpeer.(%s)\n",addr->ipaddr);
iguana_launch(coin,"connection",iguana_startconnection,addr,IGUANA_CONNTHREAD);
#endif
}

101
iguana/iguana_msg.c

@ -101,31 +101,42 @@ int32_t iguana_rwzsolution(int32_t rwflag,uint8_t *serialized,uint32_t *solution
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg)
{
uint32_t tmp; int32_t len = 0;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.prev_block),msg->H.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.merkle_root),msg->H.merkle_root.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.timestamp),&msg->H.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.bits),&msg->H.bits);
uint32_t tmp; struct iguana_msgzblock *zmsg; int32_t len = 0;
if ( zcash == 0 )
{
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.prev_block),msg->H.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->H.merkle_root),msg->H.merkle_root.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.timestamp),&msg->H.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.bits),&msg->H.bits);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.nonce),&msg->H.nonce);
}
else
{
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(msg->zH.bignonce),msg->zH.bignonce.bytes);
zmsg = (void *)msg;
len += iguana_rwnum(rwflag,&serialized[len],sizeof(zmsg->zH.version),&zmsg->zH.version);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.prev_block),zmsg->zH.prev_block.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.merkle_root),zmsg->zH.merkle_root.bytes);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.reserved),zmsg->zH.reserved.bytes);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(zmsg->zH.timestamp),&zmsg->zH.timestamp);
len += iguana_rwnum(rwflag,&serialized[len],sizeof(zmsg->zH.bits),&zmsg->zH.bits);
len += iguana_rwbignum(rwflag,&serialized[len],sizeof(zmsg->zH.bignonce),zmsg->zH.bignonce.bytes);
//char str[65]; printf("prev.(%s) len.%d [%d %d %d]\n",bits256_str(str,msg->H.prev_block),len,serialized[len],serialized[len+1],serialized[len+2]);
printf("numelements: (%02x %02x %02x)\n",serialized[len],serialized[len+1],serialized[len+2]);
if ( rwflag != 0 )
tmp = msg->zH.numelements;
len += iguana_rwvarint32(rwflag,&serialized[len],(uint32_t *)&tmp);
if ( rwflag == 0 )
msg->zH.numelements = tmp;
if ( msg->zH.numelements != ZCASH_SOLUTION_ELEMENTS )
memcpy(&serialized[len],zmsg->zH.var_numelements,sizeof(zmsg->zH.var_numelements));
else memcpy(zmsg->zH.var_numelements,&serialized[len],sizeof(zmsg->zH.var_numelements));
len += sizeof(zmsg->zH.var_numelements);
if ( iguana_rwvarint32(rwflag,zmsg->zH.var_numelements,(uint32_t *)&tmp) != sizeof(zmsg->zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d %d %d\n",zmsg->zH.var_numelements[0],zmsg->zH.var_numelements[1],zmsg->zH.var_numelements[2]);
if ( tmp != ZCASH_SOLUTION_ELEMENTS )
{
int32_t i; for (i=0; i<157; i++)
printf("%02x",serialized[i]);
printf(" unexpected ZCASH_SOLUTION_ELEMENTS, got %d vs %d len.%d\n",msg->zH.numelements,ZCASH_SOLUTION_ELEMENTS,len);
//int32_t i; for (i=0; i<157; i++)
// printf("%02x",serialized[i]);
printf(" unexpected ZCASH_SOLUTION_ELEMENTS, (%02x %02x %02x) expected %d tmp.%d len.%d\n",zmsg->zH.var_numelements[0],zmsg->zH.var_numelements[1],zmsg->zH.var_numelements[2],ZCASH_SOLUTION_ELEMENTS,tmp,len);
return(-1);
}
len += iguana_rwzsolution(rwflag,&serialized[len],msg->zH.solution,ZCASH_SOLUTION_ELEMENTS);
len += iguana_rwzsolution(rwflag,&serialized[len],zmsg->zH.solution,tmp);
}
return(len);
}
@ -164,7 +175,7 @@ int32_t iguana_eatauxpow(struct supernet_info *myinfo,int32_t rwflag,char *symbo
return(len);
}
int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)//,uint8_t *serialized,int32_t maxlen)
int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)
{
int32_t len = 0;
if ( zcash == 0 )
@ -175,7 +186,7 @@ int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)//,uint8_t
return(sizeof(struct iguana_msgblockhdr) + len);
//else
return(-1);
} else return((int32_t)(sizeof(struct iguana_msgblockhdr) - sizeof(uint32_t) + sizeof(struct iguana_msgblockhdr_zcash) + auxpow*sizeof(bits256)));
} else return((int32_t)(sizeof(struct iguana_msgzblockhdr) + auxpow*sizeof(bits256)));
}
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)
@ -183,7 +194,10 @@ int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,u
int32_t len = 0; uint64_t x;
if ( (len= iguana_rwblockhdr(rwflag,zcash,serialized,msg)) < 0 )
{
printf("error rw.%d blockhdr zcash.%d\n",rwflag,zcash);
int32_t i;
for (i=0; i<maxlen; i++)
printf("%02x",serialized[i]);
printf(" error rw.%d blockhdr zcash.%d\n",rwflag,zcash);
return(-1);
}
*hash2p = iguana_calcblockhash(symbol,hashalgo,serialized,len);
@ -205,29 +219,38 @@ int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,u
return(len);
}
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)
int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgzblock)],struct iguana_block *block)
{
struct iguana_msgblock msg; int32_t i,len;
memset(&msg,0,sizeof(msg));
msg.H.version = block->RO.version;
msg.H.prev_block = block->RO.prev_block;
msg.H.merkle_root = block->RO.merkle_root;
msg.H.timestamp = block->RO.timestamp;
msg.H.bits = block->RO.bits;
struct iguana_msgblock msg; struct iguana_zblock *zblock;struct iguana_msgzblock zmsg; int32_t i,len;
if ( chain->zcash == 0 )
{
memset(&msg,0,sizeof(msg));
msg.H.version = block->RO.version;
msg.H.prev_block = block->RO.prev_block;
msg.H.merkle_root = block->RO.merkle_root;
msg.H.timestamp = block->RO.timestamp;
msg.H.bits = block->RO.bits;
msg.H.nonce = block->RO.nonce;
msg.txn_count = block->RO.txn_count;
len = iguana_rwblock(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,&msg,IGUANA_MAXPACKETSIZE);
}
else
{
if ( block->RO.allocsize == sizeof(struct iguana_zblock) )
{
msg.zH.bignonce = block->zRO[0].bignonce;
msg.zH.numelements = ZCASH_SOLUTION_ELEMENTS;
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
msg.zH.solution[i] = block->zRO[0].solution[i];
} else printf("iguana_serialize_block has missing zRO\n");
memset(&zmsg,0,sizeof(zmsg));
zblock = (void *)block;
zmsg.zH.version = zblock->RO.version;
zmsg.zH.prev_block = zblock->RO.prev_block;
zmsg.zH.merkle_root = zblock->RO.merkle_root;
zmsg.zH.timestamp = zblock->RO.timestamp;
zmsg.zH.bits = zblock->RO.bits;
zmsg.zH.bignonce = zblock->zRO.bignonce;
if ( iguana_rwvarint32(1,zmsg.zH.var_numelements,(uint32_t *)&zblock->zRO.numelements) != sizeof(zmsg.zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d %d %d\n",zmsg.zH.var_numelements[0],zmsg.zH.var_numelements[1],zmsg.zH.var_numelements[2]);
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
zmsg.zH.solution[i] = zblock->zRO.solution[i];
msg.txn_count = block->RO.txn_count;
len = iguana_rwblock(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,(void *)&zmsg,IGUANA_MAXPACKETSIZE);
}
msg.txn_count = block->RO.txn_count;
len = iguana_rwblock(myinfo,chain->symbol,chain->zcash,chain->auxpow,chain->hashalgo,1,hash2p,serialized,&msg,IGUANA_MAXPACKETSIZE);
return(len);
}
@ -704,7 +727,7 @@ int32_t iguana_rwtx(struct supernet_info *myinfo,uint8_t zcash,int32_t rwflag,st
char *iguana_txscan(struct supernet_info *myinfo,struct iguana_info *coin,cJSON *json,uint8_t *data,int32_t recvlen,bits256 txid)
{
struct iguana_msgtx tx; bits256 hash2; struct iguana_block *block; struct iguana_msgblock msg;
int32_t i,n,len,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(*block->zRO)];
int32_t i,n,len,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(struct iguana_zblock)];
block = (void *)blockspace;
memset(&msg,0,sizeof(msg));
vpnstr[0] = 0;
@ -905,11 +928,11 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
memset(&txdata,0,sizeof(txdata));
if ( ishost == 0 )
{
if ( 0 && coin->chain->auxpow != 0 )
if ( coin->chain->zcash != 0 )
{
int32_t i; for (i=0; i<recvlen; i++)
printf("%02x",data[i]);
printf(" auxblock\n");
printf(" zblock.[%d]\n",recvlen);
}
addr->msgcounts.block++;
if ( (n= iguana_gentxarray(myinfo,coin,rawmem,&txdata,&len,data,recvlen)) == recvlen || n == recvlen-1 )

4
iguana/iguana_peers.c

@ -737,7 +737,7 @@ void iguana_startconnection(void *arg)
printf("avoid self-loopback\n");
return;
}
//printf(">>>>>>>> startconnection.(%s) pending.%u usock.%d addrind.%d\n",addr->ipaddr,addr->pending,addr->usock,addr->addrind);
printf(">>>>>>>> startconnection.(%s) pending.%u usock.%d addrind.%d\n",addr->ipaddr,addr->pending,addr->usock,addr->addrind);
addr->pending = (uint32_t)time(NULL);
if ( (port= (uint16_t)(addr->ipbits >> 32)) == 0 )
port = coin->chain->portp2p;
@ -746,7 +746,7 @@ void iguana_startconnection(void *arg)
if ( addr->usock < 0 || (coin->peers != 0 && coin->peers->shuttingdown != 0) )
{
strcpy(ipaddr,addr->ipaddr);
//printf("%s refused PEER KILLED. slot.%d for %s:%d usock.%d\n",coin->symbol,addr->addrind,ipaddr,coin->chain->portp2p,addr->usock);
printf("%s refused PEER KILLED. slot.%d for %s:%d usock.%d\n",coin->symbol,addr->addrind,ipaddr,coin->chain->portp2p,addr->usock);
iguana_iAkill(coin,addr,1);
}
else

2
iguana/iguana_recv.c

@ -1303,7 +1303,7 @@ void iguana_checklongestchain(struct iguana_info *coin,struct iguana_bundle *bp,
struct iguana_bundlereq *iguana_recvblockhdrs(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_bundlereq *req,struct iguana_zblock *zblocks,int32_t n,int32_t *newhwmp)
{
int32_t i,bundlei,match; struct iguana_block *block; bits256 prevhash2; uint8_t serialized[sizeof(struct iguana_msgblock) + sizeof(struct iguana_msgblockhdr_zcash)]; struct iguana_peer *addr; struct iguana_bundle *bp,*firstbp = 0;
int32_t i,bundlei,match; struct iguana_block *block; bits256 prevhash2; uint8_t serialized[sizeof(struct iguana_msgblock) + sizeof(struct iguana_msgzblockhdr)]; struct iguana_peer *addr; struct iguana_bundle *bp,*firstbp = 0;
if ( zblocks == 0 )
{
printf("iguana_recvblockhdrs null blocks?\n");

38
iguana/iguana_tx.c

@ -336,7 +336,7 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
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;
char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgblock msg; struct iguana_msgzblock zmsg; struct iguana_zblock *zblock;
bits256 hash2,nexthash2; uint8_t serialized[1024]; cJSON *array,*json = cJSON_CreateObject();
jaddstr(json,"result","success");
jaddstr(json,"hash",bits256_str(str,block->RO.hash2));
@ -371,20 +371,34 @@ cJSON *iguana_blockjson(struct supernet_info *myinfo,struct iguana_info *coin,st
serialized[3] = ((uint8_t *)&block->RO.bits)[0];
init_hexbytes_noT(hexstr,serialized,sizeof(uint32_t));
jaddstr(json,"nBitshex",hexstr);
memset(&msg,0,sizeof(msg));
msg.H.version = block->RO.version;
msg.H.merkle_root = block->RO.merkle_root;
msg.H.timestamp = block->RO.timestamp;
msg.H.bits = block->RO.bits;
if ( block->RO.allocsize == sizeof(struct iguana_zblock) )
{
msg.zH.bignonce = block->zRO[0].bignonce;
msg.zH.numelements = ZCASH_SOLUTION_ELEMENTS;
zblock = (void *)block;
memset(&zmsg,0,sizeof(zmsg));
zmsg.zH.version = zblock->RO.version;
zmsg.zH.merkle_root = zblock->RO.merkle_root;
zmsg.zH.timestamp = zblock->RO.timestamp;
zmsg.zH.bits = zblock->RO.bits;
zmsg.zH.bignonce = zblock->zRO.bignonce;
if ( iguana_rwvarint32(1,zmsg.zH.var_numelements,&zblock->zRO.numelements) != sizeof(zmsg.zH.var_numelements) )
printf("unexpected varint size for zmsg.zH.numelements <- %d\n",zblock->zRO.numelements);
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
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(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&msg,IGUANA_MAXPACKETSIZE*2);
zmsg.zH.solution[i] = zblock->zRO.solution[i];
zmsg.txn_count = 0;//block->RO.txn_count;
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&msg,IGUANA_MAXPACKETSIZE*2);
}
else
{
memset(&msg,0,sizeof(msg));
msg.H.version = block->RO.version;
msg.H.prev_block = block->RO.prev_block;
msg.H.merkle_root = block->RO.merkle_root;
msg.H.timestamp = block->RO.timestamp;
msg.H.bits = block->RO.bits;
msg.H.nonce = block->RO.nonce;
msg.txn_count = 0;//block->RO.txn_count;
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 )

48
includes/iguana_structs.h

@ -55,7 +55,7 @@ struct iguana_chain
char use_addmultisig,do_opreturn;
int32_t estblocktime,protover;
bits256 genesishash2,PoWtarget,PoStargets[16]; int32_t numPoStargets,PoSheights[16];
uint8_t zcash,auxpow,havecltv,alertpubkey[65];
uint8_t zcash,auxpow,debug,havecltv,alertpubkey[65];
uint16_t targetspacing,targettimespan; uint32_t nBits,normal_txversion,locktime_txversion;
};
@ -104,18 +104,37 @@ struct iguana_msgblockhdr
uint32_t version;
bits256 prev_block,merkle_root;
uint32_t timestamp,bits,nonce;
}PACKEDSTRUCT;
} PACKEDSTRUCT;
#define ZKSNARK_PROOF_SIZE 584
#define ZCASH_SOLUTION_ELEMENTS 32
#define ZCASH_SOLUTION_ELEMENTS 1344
struct iguana_msgzblockhdr
{
uint32_t version;
bits256 prev_block,merkle_root,reserved;
uint32_t timestamp,bits;
bits256 bignonce;
uint8_t var_numelements[3];
uint32_t solution[ZCASH_SOLUTION_ELEMENTS];
} PACKEDSTRUCT;
struct iguana_msgblockhdr_zcash
/*int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
uint256 hashReserved;
uint32_t nTime;
uint32_t nBits;
uint256 nNonce;
std::vector<unsigned char> nSolution;*/
/*struct iguana_msgblockhdr_zcash
{
bits256 bignonce;
uint8_t numelements;
uint32_t solution[ZCASH_SOLUTION_ELEMENTS];
//bits256 reserved; // only here if auxpow is set
}PACKEDSTRUCT;
}PACKEDSTRUCT;*/
struct iguana_msgmerkle
{
@ -127,9 +146,14 @@ struct iguana_msgmerkle
struct iguana_msgblock
{
struct iguana_msgblockhdr H; // double hashed for blockhash
struct iguana_msgblockhdr_zcash zH;
uint32_t txn_count;
}PACKEDSTRUCT;
} PACKEDSTRUCT;
struct iguana_msgzblock
{
struct iguana_msgzblockhdr zH; // double hashed for blockhash
uint32_t txn_count;
} PACKEDSTRUCT;
struct iguana_msgvin { bits256 prev_hash; uint8_t *vinscript,*userdata,*spendscript,*redeemscript; uint32_t prev_vout,sequence; uint16_t scriptlen,p2shlen,userdatalen,spendlen; }PACKEDSTRUCT;
@ -181,13 +205,13 @@ struct iguana_blockRO
uint16_t txn_count,numvouts,numvins,allocsize;
}PACKEDSTRUCT;
struct iguana_zcashRO { bits256 bignonce; uint32_t solution[ZCASH_SOLUTION_ELEMENTS]; }PACKEDSTRUCT;
struct iguana_zcashRO { bits256 bignonce; uint32_t numelements,solution[ZCASH_SOLUTION_ELEMENTS]; }PACKEDSTRUCT;
struct iguana_zblockRO
{
struct iguana_blockRO RO;
struct iguana_zcashRO zRO;
}PACKEDSTRUCT;
} PACKEDSTRUCT;
#define iguana_blockfields double PoW; \
int32_t height,fpos; uint32_t fpipbits,issued,lag:18,sigsvalid:1,protected:1,peerid:12; \
@ -198,14 +222,14 @@ struct iguana_blockRO RO
struct iguana_block
{
iguana_blockfields;
struct iguana_zcashRO zRO[];
}PACKEDSTRUCT;
//struct iguana_zcashRO zRO[];
} PACKEDSTRUCT;
struct iguana_zblock // mu
{
iguana_blockfields;
struct iguana_zcashRO zRO;
}PACKEDSTRUCT;
} PACKEDSTRUCT;
#define IGUANA_LHASH_BLOCKS 0
#define IGUANA_LHASH_TXIDS 1 //

Loading…
Cancel
Save