Browse Source

fix basilisk native coin port timeout

release/v0.1
jl777 8 years ago
parent
commit
78d40efae3
  1. 24
      datachain/datachain_KOMODO.c
  2. 2
      gecko/gecko_blocks.c
  3. 10
      gecko/gecko_headers.c
  4. 18
      gecko/gecko_miner.c
  5. 6
      iguana/iguana_accept.c
  6. 11
      iguana/iguana_blocks.c
  7. 16
      iguana/iguana_chains.c
  8. 62
      iguana/iguana_msg.c
  9. 30
      iguana/iguana_tx.c
  10. 7
      iguana/main.c
  11. 2
      iguana/tests/getinfo2
  12. 6
      includes/iguana_funcs.h
  13. 4
      includes/iguana_structs.h

24
datachain/datachain_KOMODO.c

@ -78,12 +78,12 @@ bits256 datachain_opreturn_convert(uint8_t *txidbytes,int32_t *txlenp,struct igu
int32_t datachain_genesis_verify(struct gecko_genesis_opreturn *opret)
{
int32_t txlen,datalen; bits256 txid,threshold,hash2; uint8_t serialized[1024],txidbytes[1024]; struct iguana_msgblock msg; char str[65],str2[65];
txid = datachain_opreturn_convert(txidbytes,&txlen,&msg,opret);
int32_t txlen,datalen; bits256 txid,threshold,hash2; uint8_t serialized[1024],txidbytes[1024]; struct iguana_msgzblock zmsg; char str[65],str2[65];
txid = datachain_opreturn_convert(txidbytes,&txlen,(void *)&zmsg,opret);
if ( opret->nBits >= GECKO_EASIESTDIFF )
threshold = bits256_from_compact(GECKO_EASIESTDIFF);
else threshold = bits256_from_compact(opret->nBits);
datalen = iguana_rwblockhdr(1,0,serialized,&msg);
datalen = iguana_rwblockhdr(1,0,serialized,&zmsg);
hash2 = iguana_calcblockhash("virtual",blockhash_sha256,serialized,datalen);
//for (i=0; i<datalen; i++)
// printf("%02x",serialized[i]);
@ -101,7 +101,7 @@ int32_t datachain_genesis_verify(struct gecko_genesis_opreturn *opret)
int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,char *coinaddr,int64_t PoSvalue,uint32_t nBits,uint16_t blocktime,uint16_t port,uint8_t p2shval,uint8_t wifval)
{
int32_t i,len,datalen,txlen; struct gecko_genesis_opreturn opret; bits256 threshold,txid,hash2; struct iguana_info *btcd; struct iguana_msgblock msg; uint8_t txidbytes[1024];
int32_t i,len,datalen,txlen; struct gecko_genesis_opreturn opret; bits256 threshold,txid,hash2; struct iguana_info *btcd; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; uint8_t txidbytes[1024];
btcd = iguana_coinfind("BTCD");
memset(&opret,0,sizeof(opret));
opret.type[0] = 'N', opret.type[1] = 'E', opret.type[2] = 'W';
@ -117,14 +117,14 @@ int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,ch
opret.timestamp = (uint32_t)time(NULL);
OS_randombytes((void *)&opret.netmagic,sizeof(opret.netmagic));
bitcoin_addr2rmd160(&opret.pubval,opret.rmd160,coinaddr);
txid = datachain_opreturn_convert(txidbytes,&txlen,&msg,&opret);
txid = datachain_opreturn_convert(txidbytes,&txlen,msg,&opret);
if ( nBits >= GECKO_EASIESTDIFF )
threshold = bits256_from_compact(GECKO_EASIESTDIFF);
else threshold = bits256_from_compact(nBits);
for (i=0; i<100000000; i++)
{
opret.nonce = msg.H.nonce = i;
datalen = iguana_rwblockhdr(1,0,serialized,&msg);
opret.nonce = msg->H.nonce = i;
datalen = iguana_rwblockhdr(1,0,serialized,&zmsg);
hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen);
if ( bits256_cmp(threshold,hash2) > 0 )
break;
@ -140,7 +140,7 @@ int32_t datachain_opreturn_create(uint8_t *serialized,char *symbol,char *name,ch
void datachain_events_processKOMODO(struct supernet_info *myinfo,struct datachain_info *dPoW,struct datachain_event *event)
{
struct gecko_chain *chain; bits256 hash2,threshold; struct gecko_genesis_opreturn opret; int32_t datalen,i,j,len,txlen; char symbol[16],name[64],magicstr[16],blockstr[8192],nbitstr[16],issuer[64],hashstr[65],str2[65],argbuf[1024],chainname[GECKO_MAXNAMELEN]; cJSON *valsobj; struct iguana_msgblock msg; uint8_t serialized[256],txidbytes[1024],buf[4]; struct iguana_info *virt,*btcd;
struct gecko_chain *chain; bits256 hash2,threshold; struct gecko_genesis_opreturn opret; int32_t datalen,i,j,len,txlen; char symbol[16],name[64],magicstr[16],blockstr[8192],nbitstr[16],issuer[64],hashstr[65],str2[65],argbuf[1024],chainname[GECKO_MAXNAMELEN]; cJSON *valsobj; struct iguana_msgzblock zmsg; uint8_t serialized[256],txidbytes[1024],buf[4]; struct iguana_info *virt,*btcd;
if ( (btcd= iguana_coinfind("BTCD")) != 0 && memcmp(event->opreturn,"NEW",3) == 0 )
{
//int32_t i; for (i=0; i<76; i++)
@ -151,13 +151,13 @@ void datachain_events_processKOMODO(struct supernet_info *myinfo,struct datachai
datachain_genesis_verify(&opret);
memset(symbol,0,sizeof(symbol)), memcpy(symbol,opret.symbol,sizeof(opret.symbol));
memset(name,0,sizeof(name)), memcpy(name,opret.name,sizeof(opret.name));
hash2 = datachain_opreturn_convert(txidbytes,&txlen,&msg,&opret);
hash2 = datachain_opreturn_convert(txidbytes,&txlen,(void *)&zmsg,&opret);
if ( opret.nBits >= GECKO_EASIESTDIFF )
threshold = bits256_from_compact(GECKO_EASIESTDIFF);
else threshold = bits256_from_compact(opret.nBits);
msg.txn_count = 1;
zmsg.txn_count = 1;
//n = iguana_serialize_block(virt->chain,&hash2,serialized,newblock);
datalen = iguana_rwblockhdr(1,0,serialized,&msg);
datalen = iguana_rwblockhdr(1,0,serialized,&zmsg);
hash2 = iguana_calcblockhash(symbol,btcd->chain->hashalgo,serialized,datalen);
for (i=0; i<datalen; i++)
printf("%02x",serialized[i]);
@ -179,7 +179,7 @@ void datachain_events_processKOMODO(struct supernet_info *myinfo,struct datachai
init_hexbytes_noT(blockstr,serialized,datalen);
strcat(blockstr,"01"), datalen++;
init_hexbytes_noT(&blockstr[datalen << 1],txidbytes,txlen);
sprintf(argbuf,"{\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%02x\",\"p2shval\":\"%02x\",\"wifval\":\"%02x\",\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",name,symbol,magicstr,opret.port,opret.blocktime,opret.pubval,opret.p2shval,opret.wifval,(opret.nBits >> 24) & 0xff,hashstr,opret.timestamp,nbitstr,opret.nonce,bits256_str(str2,msg.H.merkle_root),blockstr);
sprintf(argbuf,"{\"name\":\"%s\",\"symbol\":\"%s\",\"netmagic\":\"%s\",\"port\":%u,\"blocktime\":%u,\"pubval\":\"%02x\",\"p2shval\":\"%02x\",\"wifval\":\"%02x\",\"unitval\":\"%02x\",\"genesishash\":\"%s\",\"genesis\":{\"version\":1,\"timestamp\":%u,\"nBits\":\"%s\",\"nonce\":%d,\"merkle_root\":\"%s\"},\"genesisblock\":\"%s\"}",name,symbol,magicstr,opret.port,opret.blocktime,opret.pubval,opret.p2shval,opret.wifval,(opret.nBits >> 24) & 0xff,hashstr,opret.timestamp,nbitstr,opret.nonce,bits256_str(str2,zmsg.zH.merkle_root),blockstr);
if ( (valsobj= cJSON_Parse(argbuf)) != 0 )
{
printf("datachain.NEW (%s/%s port.%u blocktime.%d) issuer.%s (%s)\n",opret.symbol,opret.name,opret.port,opret.blocktime,issuer,jprint(valsobj,0));

2
gecko/gecko_blocks.c

@ -316,7 +316,7 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a
//nBits = gecko_nBits(virt,&prevtimestamp,(struct iguana_block *)&virt->blocks.hwmchain,GECKO_DIFFITERS);
//if ( gecko_blocknonce_verify(virt,data,hdrsize,nBits,virt->blocks.hwmchain.RO.timestamp,prevtimestamp) > 0 )
{
iguana_rwblock(myinfo,symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,&msg,datalen);
iguana_rwblock(myinfo,symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&checkhash2,data,(void *)&msg,datalen);
if ( bits256_cmp(hash2,checkhash2) == 0 )
{
if ( gecko_blocknonce_verify(virt,data,hdrsize,msg.H.bits,0,0) > 0 )

10
gecko/gecko_headers.c

@ -53,7 +53,7 @@ void gecko_blockhashupdate(struct iguana_info *virt,bits256 hash2,int32_t height
char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt,char *remoteaddr,uint8_t *data,int32_t datalen,bits256 firsthash2)
{
bits256 hash2,prevhash2; struct iguana_block *block; int32_t height,firstheight,i,len=0,n,num; struct iguana_msgblock msgB; char str[65],str2[65];
bits256 hash2,prevhash2; struct iguana_block *block; int32_t height,firstheight,i,len=0,n,num; struct iguana_msgzblock zmsgB; char str[65],str2[65];
num = (int32_t)(datalen / 84);
printf("headers.%s arrived.%d from %s\n",virt->symbol,num,bits256_str(str,firsthash2));
if ( (block= iguana_blockfind("geckohdrs",virt,firsthash2)) != 0 && (firstheight= block->height) >= 0 )
@ -62,14 +62,14 @@ char *gecko_headersarrived(struct supernet_info *myinfo,struct iguana_info *virt
prevhash2 = firsthash2;
for (i=0; i<num; i++)
{
if ( (n= iguana_rwblock(myinfo,virt->symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&hash2,&data[len],&msgB,datalen-len)) > 0 )
if ( (n= iguana_rwblock(myinfo,virt->symbol,virt->chain->zcash,virt->chain->auxpow,virt->chain->hashalgo,0,&hash2,&data[len],&zmsgB,datalen-len)) > 0 )
{
if ( bits256_cmp(msgB.H.prev_block,prevhash2) == 0 )
if ( bits256_cmp(zmsgB.zH.prev_block,prevhash2) == 0 )
{
height = (firstheight + i + 1);
gecko_blockhashupdate(virt,hash2,height);
printf("ht.%d %s %08x t.%u\n",height,bits256_str(str,hash2),msgB.H.bits,msgB.H.timestamp);
} else printf("ht.%d non prevhash i.%d %s %s\n",height,i,bits256_str(str,prevhash2),bits256_str(str2,msgB.H.prev_block));
printf("ht.%d %s\n",height,bits256_str(str,hash2));
} else printf("ht.%d non prevhash i.%d %s %s\n",height,i,bits256_str(str,prevhash2),bits256_str(str2,zmsgB.zH.prev_block));
len += n;
prevhash2 = hash2;
}

18
gecko/gecko_miner.c

@ -215,20 +215,20 @@ char *gecko_blockconstruct(struct supernet_info *myinfo,struct iguana_info *virt
threshold = bits256_from_compact(newblock->RO.bits);
if ( (newblock->RO.nonce= *noncep) == 0 )
{
struct iguana_msgblock msg;
memset(&msg,0,sizeof(msg));
msg.H.version = newblock->RO.version;
msg.H.prev_block = newblock->RO.prev_block;
msg.H.merkle_root = newblock->RO.merkle_root;
msg.H.timestamp = newblock->RO.timestamp;
msg.H.bits = newblock->RO.bits;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg;
memset(&zmsg,0,sizeof(zmsg));
msg->H.version = newblock->RO.version;
msg->H.prev_block = newblock->RO.prev_block;
msg->H.merkle_root = newblock->RO.merkle_root;
msg->H.timestamp = newblock->RO.timestamp;
msg->H.bits = newblock->RO.bits;
for (i=0; i<GECKO_MAXMINERITERS; i++)
{
OS_randombytes((void *)noncep,sizeof(*noncep));
msg.H.nonce = *noncep;
msg->H.nonce = *noncep;
//n = iguana_serialize_block(virt->chain,&hash2,serialized,newblock);
//char str[65]; printf("nonce.%08x %s\n",newblock->RO.nonce,bits256_str(str,newblock->RO.hash2));
len = iguana_rwblockhdr(1,virt->chain->zcash,serialized,&msg);
len = iguana_rwblockhdr(1,virt->chain->zcash,serialized,&zmsg);
hash2 = iguana_calcblockhash(virt->symbol,virt->chain->hashalgo,serialized,len);
if ( bits256_cmp(threshold,hash2) > 0 )
{

6
iguana/iguana_accept.c

@ -293,9 +293,9 @@ int32_t iguana_inv2packet(uint8_t *serialized,int32_t maxsize,int32_t type,bits2
int32_t iguana_headerget(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t maxsize,struct iguana_block *block)
{
bits256 checkhash2; struct iguana_msgblock msgB; int32_t len = 0;
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,1);
if ( (len= iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&msgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 )
bits256 checkhash2; struct iguana_msgzblock zmsgB; int32_t len = 0;
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&zmsgB,(void *)block,1);
if ( (len= iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&serialized[sizeof(struct iguana_msghdr)],&zmsgB,(int32_t)(maxsize-sizeof(struct iguana_msghdr)))) < 0 )
return(-1);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{

11
iguana/iguana_blocks.c

@ -37,6 +37,9 @@ int32_t iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdes
else
{
zdest->RO.allocsize = (int32_t)sizeof(struct iguana_zblock);
zdest->RO.txn_count = zmsg->txn_count;
zdest->RO.hash2 = hash2;
zdest->height = height;
zdest->RO.version = zmsg->zH.version;
zdest->RO.prev_block = zmsg->zH.prev_block;
zdest->RO.merkle_root = zmsg->zH.merkle_root;
@ -51,13 +54,11 @@ int32_t iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdes
}
}
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count)
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgzblock *zmsg,struct iguana_zblock *zsrc,int32_t cleartxn_count)
{
int32_t i; struct iguana_msgzblock *zmsg; struct iguana_zblock *zsrc;
int32_t i; struct iguana_msgblock *msg = (void *)zmsg; struct iguana_block *src = (void *)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;
@ -70,7 +71,7 @@ void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg
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;
zmsg->txn_count = zsrc->RO.txn_count;
}
else
{

16
iguana/iguana_chains.c

@ -163,19 +163,19 @@ bits256 iguana_calcblockhash(char *symbol,int32_t (*hashalgo)(uint8_t *blockhash
bits256 iguana_chaingenesis(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),bits256 genesishash,char *genesisblock,char *hashalgostr,int32_t version,uint32_t timestamp,uint32_t nBits,uint32_t nonce,bits256 merkle_root)
{
struct iguana_msgblock msg; int32_t len; bits256 hash2; char blockhashstr[256]; uint8_t serialized[8192];
memset(&msg,0,sizeof(msg));
msg.H.version = version;
msg.H.merkle_root = merkle_root;
msg.H.timestamp = timestamp;
msg.H.bits = nBits;
msg.H.nonce = nonce;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; int32_t len; bits256 hash2; char blockhashstr[256]; uint8_t serialized[8192];
memset(&zmsg,0,sizeof(zmsg));
msg->H.version = version;
msg->H.merkle_root = merkle_root;
msg->H.timestamp = timestamp;
msg->H.bits = nBits;
msg->H.nonce = nonce;
if ( zcash != 0 )
printf("need to handle zcash genesis\n");
if ( hashalgostr != 0 && strcmp(hashalgostr,"sha256") != 0 )
hashalgo = iguana_hashalgo(hashalgostr);
else hashalgo = blockhash_sha256;
len = iguana_rwblock(myinfo,symbol,zcash,auxpow,hashalgo,1,&hash2,serialized,&msg,sizeof(1024));
len = iguana_rwblock(myinfo,symbol,zcash,auxpow,hashalgo,1,&hash2,serialized,&zmsg,sizeof(1024));
blockhashstr[0] = 0;
init_hexbytes_noT(blockhashstr,hash2.bytes,sizeof(hash2));
char str[65],str2[65];

62
iguana/iguana_msg.c

@ -99,9 +99,9 @@ int32_t iguana_rwzsolution(int32_t rwflag,uint8_t *serialized,uint8_t *solution,
return(len);
}
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg)
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgzblock *zmsg)
{
uint32_t tmp; struct iguana_msgzblock *zmsg; int32_t len = 0;
uint32_t tmp; struct iguana_msgblock *msg = (void *)zmsg; int32_t len = 0;
if ( zcash == 0 )
{
len += iguana_rwnum(rwflag,&serialized[len],sizeof(msg->H.version),&msg->H.version);
@ -125,7 +125,7 @@ int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struc
if ( rwflag != 0 )
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));
printf("numelements: (%02x %02x %02x)\n",serialized[len],serialized[len+1],serialized[len+2]);
//printf("numelements: (%02x %02x %02x)\n",serialized[len],serialized[len+1],serialized[len+2]);
len += sizeof(zmsg->zH.var_numelements);
if ( iguana_rwvarint32(0,zmsg->zH.var_numelements,(uint32_t *)&tmp) != sizeof(zmsg->zH.var_numelements) )
printf("rw.%d unexpected varint size for zmsg.zH.numelements <- %d %d %d\n",rwflag,zmsg->zH.var_numelements[0],zmsg->zH.var_numelements[1],zmsg->zH.var_numelements[2]);
@ -165,7 +165,7 @@ int32_t iguana_eatauxpow(struct supernet_info *myinfo,int32_t rwflag,char *symbo
len += iguana_rwmerklebranch(rwflag,&serialized[len],blockchain_branch);
if ( len > maxlen )
return(-1);
len += iguana_rwblockhdr(rwflag,zcash,&serialized[len],&parentblock);
len += iguana_rwblockhdr(rwflag,zcash,&serialized[len],(void *)&parentblock);
if ( len > maxlen )
return(-1);
free(ptr);
@ -189,10 +189,10 @@ int32_t iguana_blockhdrsize(char *symbol,uint8_t zcash,uint8_t auxpow)
} 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)
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_msgzblock *zmsg,int32_t maxlen)
{
int32_t len = 0; uint64_t x;
if ( (len= iguana_rwblockhdr(rwflag,zcash,serialized,msg)) < 0 )
int32_t len = 0; uint64_t x; struct iguana_msgblock *msg = (void *)zmsg;
if ( (len= iguana_rwblockhdr(rwflag,zcash,serialized,zmsg)) < 0 )
{
int32_t i;
for (i=0; i<maxlen&&i<sizeof(struct iguana_zblock); i++)
@ -201,18 +201,26 @@ int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,u
return(-1);
}
*hash2p = iguana_calcblockhash(symbol,hashalgo,serialized,len);
if ( auxpow != 0 && (msg->H.version & 0x100) != 0 )
if ( auxpow != 0 && (zmsg->zH.version & 0x100) != 0 )
len += iguana_eatauxpow(myinfo,rwflag,symbol,zcash,&serialized[len],maxlen-len);
if ( rwflag == 1 )
{
if ( zcash == 0 )
x = msg->txn_count;
char str[65],str2[65]; printf("zcash.%d len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx hash2.%s zlen.%d\n",zcash,len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,bits256_str(str2,*hash2p),(int32_t)sizeof(struct iguana_msgzblockhdr));
else x = zmsg->txn_count;
}
//char str[65],str2[65]; printf("zcash.%d len.%d: block version.%d timestamp.%u bits.%x nonce.%u prev.(%s) %llx hash2.%s zlen.%d\n",zcash,len,msg->H.version,msg->H.timestamp,msg->H.bits,msg->H.nonce,bits256_str(str,msg->H.prev_block),(long long)msg->H.merkle_root.txid,bits256_str(str2,*hash2p),(int32_t)sizeof(struct iguana_msgzblockhdr));
len += iguana_rwvarint(rwflag,&serialized[len],&x);
if ( rwflag == 0 )
{
char str[65];
bits256_str(str,*hash2p);
if ( x < 65536 )
{
if ( zcash != 0 )
msg->txn_count = (uint16_t)x;
else zmsg->txn_count = (uint16_t)x;
}
else printf("txn_count overflow.%lld for %s\n",(long long)x,str);
}
// ? txns tx[] Block transactions, in format of "tx" command
@ -221,18 +229,18 @@ int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,u
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; struct iguana_zblock *zblock;struct iguana_msgzblock zmsg; int32_t i,len;
struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg; struct iguana_zblock *zblock; 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);
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,&zmsg,IGUANA_MAXPACKETSIZE);
}
else
{
@ -246,10 +254,9 @@ int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain
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]);
printf("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;
zmsg.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);
}
return(len);
@ -727,25 +734,24 @@ 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_zblock *zblock; struct iguana_block *block; struct iguana_msgzblock zmsg; struct iguana_msgblock msg;
struct iguana_msgtx tx; bits256 hash2; struct iguana_zblock *zblock; struct iguana_block *block; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&zmsg;
int32_t i,n,len,txn_count,extralen = 65356; char *txbytes,vpnstr[64]; uint8_t *extraspace,blockspace[sizeof(*block)+sizeof(struct iguana_zblock)];
zblock = (void *)blockspace;
block = (void *)blockspace;
memset(&zmsg,0,sizeof(zmsg));
memset(&msg,0,sizeof(msg));
vpnstr[0] = 0;
extraspace = calloc(1,extralen);
if ( coin->chain->zcash == 0 )
{
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&msg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,(void *)block,(void *)&msg,hash2,-1);
txn_count = msg.txn_count;
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,&zmsg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,zblock,&zmsg,hash2,-1);
txn_count = msg->txn_count;
}
else
{
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,0,&hash2,data,(void *)&zmsg,recvlen);
iguana_blockconv(coin->chain->zcash,coin->chain->auxpow,zblock,&zmsg,hash2,-1);
txn_count = msg.txn_count;
txn_count = zmsg.txn_count;
}
for (i=0; i<txn_count; i++)
{
@ -1021,7 +1027,7 @@ int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,s
len += iguana_rwbignum(0,&data[len],sizeof(auxhash2),auxhash2.bytes);
len += iguana_rwmerklebranch(0,&data[len],coinbase_branch);
len += iguana_rwmerklebranch(0,&data[len],blockchain_branch);
len += iguana_rwblockhdr(0,coin->chain->zcash,&data[len],&parentblock);
len += iguana_rwblockhdr(0,coin->chain->zcash,&data[len],(void *)&parentblock);
}
len += iguana_rwvarint32(0,&data[len],&tmp);
char str[65],str2[65];

30
iguana/iguana_tx.c

@ -224,7 +224,7 @@ int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t m
int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs)
{
struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgblock msgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata;
struct iguana_txid *tx,T; bits256 checktxid; int32_t i,len,total,bundlei=-2; struct iguana_block *block; struct iguana_msgzblock zmsgB; bits256 *tree,checkhash2,merkle_root; struct iguana_bundle *bp=0; long tmp; char str[65]; struct iguana_ramchaindata *rdata;
if ( (bp= iguana_bundlefind(coin,&bp,&bundlei,hash2)) != 0 && bundlei >= 0 && bundlei < bp->n )
{
if ( (rdata= bp->ramchain.H.data) == 0 )//&& bp == coin->current )
@ -235,9 +235,9 @@ int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info
}
if ( (block= bp->blocks[bundlei]) != 0 && rdata != 0 )
{
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&msgB,block,0);
msgB.txn_count = block->RO.txn_count;
total = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&msgB,max);
iguana_blockunconv(coin->chain->zcash,coin->chain->auxpow,&zmsgB,(void *)block,0);
zmsgB.txn_count = block->RO.txn_count;
total = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&checkhash2,&blockspace[sizeof(struct iguana_msghdr) + 0],&zmsgB,max);
if ( bits256_cmp(checkhash2,block->RO.hash2) != 0 )
{
//static int counter;
@ -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; struct iguana_msgzblock zmsg; struct iguana_zblock *zblock;
char str[65],hexstr[1024]; int32_t i,len,size; struct iguana_txid *tx,T; struct iguana_msgzblock zmsg; struct iguana_msgblock *msg = (void *)&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));
@ -385,19 +385,19 @@ cJSON *iguana_blockjson(struct supernet_info *myinfo,struct iguana_info *coin,st
for (i=0; i<ZCASH_SOLUTION_ELEMENTS; i++)
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);
len = iguana_rwblock(myinfo,coin->symbol,coin->chain->zcash,coin->chain->auxpow,coin->chain->hashalgo,1,&hash2,serialized,&zmsg,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);
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,&zmsg,IGUANA_MAXPACKETSIZE*2);
}
init_hexbytes_noT(hexstr,serialized,len);
jaddstr(json,"blockheader",hexstr);

7
iguana/main.c

@ -219,7 +219,7 @@ int32_t iguana_jsonQ(struct supernet_info *myinfo,struct iguana_info *coin)
char *iguana_blockingjsonstr(struct supernet_info *myinfo,struct iguana_info *coin,char *jsonstr,uint64_t tag,int32_t maxmillis,char *remoteaddr,uint16_t port)
{
struct iguana_jsonitem *ptr; int32_t len,allocsize; double expiration;
queue_t *Q; struct iguana_jsonitem *ptr; int32_t len,allocsize; double expiration;
expiration = OS_milliseconds() + maxmillis;
//printf("blocking case.(%s) %.0f maxmillis.%d\n",jsonstr,OS_milliseconds(),maxmillis);
len = (int32_t)strlen(jsonstr);
@ -231,7 +231,10 @@ char *iguana_blockingjsonstr(struct supernet_info *myinfo,struct iguana_info *co
ptr->retjsonstr = 0;
safecopy(ptr->remoteaddr,remoteaddr,sizeof(ptr->remoteaddr));
memcpy(ptr->jsonstr,jsonstr,len+1);
queue_enqueue("jsonQ",coin != 0 ? &coin->jsonQ : &JSON_Q,&ptr->DL,0);
if ( coin == 0 || (coin->FULLNODE == 0 && coin->VALIDATENODE == 0) )
Q = &JSON_Q;
else Q = &coin->jsonQ;
queue_enqueue("jsonQ",Q,&ptr->DL,0);
while ( OS_milliseconds() < expiration )
{
usleep(100);

2
iguana/tests/getinfo2

@ -1 +1 @@
curl --url "http://127.0.0.1:7778" --data "{\"coin\":\"BTC\",\"method\":\"getinfo\",\"params\":[]}"
curl --url "http://127.0.0.1:14632" --data "{\"coin\":\"BTCD\",\"method\":\"getinfo\",\"params\":[]}"

6
includes/iguana_funcs.h

@ -41,7 +41,7 @@ int32_t iguana_rwmem(int32_t rwflag,uint8_t *serialized,int32_t len,void *endian
int32_t iguana_rwnum(int32_t rwflag,uint8_t *serialized,int32_t len,void *endianedp);
int32_t iguana_rwvarint32(int32_t rwflag,uint8_t *serialized,uint32_t *int32p);
int32_t iguana_rwbignum(int32_t rwflag,uint8_t *serialized,int32_t len,uint8_t *endianedp);
int32_t iguana_rwblock(struct supernet_info *myinfo,char *symbol,uint8_t zcash,uint8_t auxpow,int32_t (*hashalgo)(uint8_t *blockhashp,uint8_t *serialized,int32_t len),int32_t rwflag,bits256 *hash2p,uint8_t *serialized,struct iguana_msgblock *msg,int32_t maxlen);
int32_t iguana_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_msgzblock *zmsg,int32_t maxlen);
int32_t iguana_serialize_block(struct supernet_info *myinfo,struct iguana_chain *chain,bits256 *hash2p,uint8_t serialized[sizeof(struct iguana_msgblock)],struct iguana_block *block);
int32_t iguana_blockconv(uint8_t zcash,uint8_t auxpow,struct iguana_zblock *zdest,struct iguana_msgzblock *zmsg,bits256 hash2,int32_t height);
int32_t iguana_msgparser(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_peer *addr,struct OS_memspace *rawmem,struct OS_memspace *txmem,struct OS_memspace *hashmem,struct iguana_msghdr *H,uint8_t *data,int32_t datalen,int32_t fromcache);
@ -53,7 +53,7 @@ int32_t iguana_send_version(struct iguana_info *coin,struct iguana_peer *addr,ui
int32_t iguana_gentxarray(struct supernet_info *myinfo,struct iguana_info *coin,struct OS_memspace *mem,struct iguana_txblock *txblock,int32_t *lenp,uint8_t *data,int32_t datalen);
int32_t iguana_gethdrs(struct iguana_info *coin,uint8_t *serialized,char *cmd,char *hashstr);
int32_t iguana_getdata(struct iguana_info *coin,uint8_t *serialized,int32_t type,bits256 *hashes,int32_t n);
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgblock *msg,struct iguana_block *src,int32_t cleartxn_count);
void iguana_blockunconv(uint8_t zcash,uint8_t auxpow,struct iguana_msgzblock *zmsg,struct iguana_zblock *zsrc,int32_t cleartxn_count);
int32_t iguana_peerblockrequest(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *blockspace,int32_t max,struct iguana_peer *addr,bits256 hash2,int32_t validatesigs);
int32_t iguana_validatesigs(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t *serialized,int32_t datalen);
@ -294,7 +294,7 @@ int32_t iguana_rwmsgtx(struct iguana_info *coin,int32_t height,int32_t rwflag,cJ
int32_t iguana_ramtxbytes(struct iguana_info *coin,uint8_t *serialized,int32_t maxlen,bits256 *txidp,struct iguana_txid *tx,int32_t height,struct iguana_msgvin *vins,struct iguana_msgvout *vouts,int32_t validatesigs);
cJSON *bitcoin_txtest(struct iguana_info *coin,char *rawtxstr,bits256 txid);
cJSON *iguana_blockjson(struct supernet_info *myinfo,struct iguana_info *coin,struct iguana_block *block,int32_t txidsflag);
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgblock *msg);
int32_t iguana_rwblockhdr(int32_t rwflag,uint8_t zcash,uint8_t *serialized,struct iguana_msgzblock *zmsg);
//int32_t iguana_sig(uint8_t *sig,int32_t maxsize,uint8_t *data,int32_t datalen,bits256 privkey);
//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,bits256 pubkey);
//int32_t iguana_ver(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen,uint8_t *pubkey);

4
includes/iguana_structs.h

@ -227,8 +227,8 @@ struct iguana_block
struct iguana_zblock // mu
{
iguana_blockfields;
struct iguana_zcashRO zRO;
iguana_blockfields; // this is to minimize code needed to support both types
struct iguana_zcashRO zRO; // if zRO is changed, the RO part must also be updated
} PACKEDSTRUCT;
#define IGUANA_LHASH_BLOCKS 0

Loading…
Cancel
Save