Browse Source

test

release/v0.1
jl777 9 years ago
parent
commit
379235b5c9
  1. 16
      basilisk/basilisk.c
  2. 32
      gecko/gecko_blocks.c
  3. 9
      gecko/gecko_miner.c
  4. 2
      includes/iguana_funcs.h

16
basilisk/basilisk.c

@ -114,7 +114,7 @@ uint8_t *basilisk_jsondata(int32_t extraoffset,uint8_t **ptrp,uint8_t *space,int
return(data); return(data);
} }
char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr) char *basilisk_finish(struct supernet_info *myinfo,struct basilisk_item *ptr,int32_t besti,char *errstr)
{ {
char *str,*retstr = 0; int32_t i; struct basilisk_item *parent; cJSON *retarray,*item; char *str,*retstr = 0; int32_t i; struct basilisk_item *parent; cJSON *retarray,*item;
if ( ptr->retstr != 0 ) if ( ptr->retstr != 0 )
@ -133,11 +133,15 @@ char *basilisk_finish(struct basilisk_item *ptr,int32_t besti,char *errstr)
{ {
ptr->results[i] = 0; ptr->results[i] = 0;
if ( (item= cJSON_Parse(str)) != 0 ) if ( (item= cJSON_Parse(str)) != 0 )
{
if ( jobj(item,"myip") == 0 )
jaddstr(item,"myip",myinfo->ipaddr);
jaddi(retarray,item); jaddi(retarray,item);
}
free(str); free(str);
} }
retstr = jprint(retarray,1); retstr = jprint(retarray,1);
} else retstr = ptr->results[0], ptr->results[0] = 0; }
if ( retstr == 0 ) if ( retstr == 0 )
retstr = clonestr(errstr); retstr = clonestr(errstr);
ptr->retstr = retstr; ptr->retstr = retstr;
@ -336,7 +340,7 @@ char *basilisk_waitresponse(struct supernet_info *myinfo,char *CMD,char *symbol,
usleep(50000); usleep(50000);
} }
if ( retstr == 0 ) if ( retstr == 0 )
retstr = basilisk_finish(ptr,-1,"[{\"error\":\"basilisk timeout\"}]"); retstr = basilisk_finish(myinfo,ptr,-1,"[{\"error\":\"basilisk timeout\"}]");
} }
basilisk_sendback(myinfo,CMD,symbol,remoteaddr,ptr->basilisktag,retstr); basilisk_sendback(myinfo,CMD,symbol,remoteaddr,ptr->basilisktag,retstr);
return(retstr); return(retstr);
@ -496,7 +500,7 @@ int32_t basilisk_besti(struct basilisk_item *ptr)
return(besti); return(besti);
} }
char *basilisk_iscomplete(struct basilisk_item *ptr) char *basilisk_iscomplete(struct supernet_info *myinfo,struct basilisk_item *ptr)
{ {
int32_t i,numvalid,besti=-1; char *errstr = 0,*retstr = 0; int32_t i,numvalid,besti=-1; char *errstr = 0,*retstr = 0;
if ( ptr->childrendone < ptr->numchildren ) if ( ptr->childrendone < ptr->numchildren )
@ -520,7 +524,7 @@ char *basilisk_iscomplete(struct basilisk_item *ptr)
besti = -1, errstr = "[{\"error\":\"basilisk non-consensus results\"}]"; besti = -1, errstr = "[{\"error\":\"basilisk non-consensus results\"}]";
else besti = basilisk_besti(ptr), errstr = "[{\"error\":\"basilisk no valid results\"}]"; else besti = basilisk_besti(ptr), errstr = "[{\"error\":\"basilisk no valid results\"}]";
//printf("%u complete besti.%d\n",ptr->basilisktag,besti); //printf("%u complete besti.%d\n",ptr->basilisktag,besti);
retstr = basilisk_finish(ptr,besti,errstr); retstr = basilisk_finish(myinfo,ptr,besti,errstr);
//printf("%u besti.%d numexact.%d numresults.%d -> (%s)\n",ptr->basilisktag,besti,ptr->numexact,ptr->numresults,retstr); //printf("%u besti.%d numexact.%d numresults.%d -> (%s)\n",ptr->basilisktag,besti,ptr->numexact,ptr->numresults,retstr);
return(retstr); return(retstr);
} }
@ -870,7 +874,7 @@ int32_t basilisk_issued_iteration(struct supernet_info *myinfo,struct basilisk_i
flag++; flag++;
} }
} }
basilisk_iscomplete(pending); basilisk_iscomplete(myinfo,pending);
if ( OS_milliseconds() > pending->expiration ) if ( OS_milliseconds() > pending->expiration )
{ {
if ( pending->finished == 0 ) if ( pending->finished == 0 )

32
gecko/gecko_blocks.c

@ -276,9 +276,9 @@ char *basilisk_respond_geckoblock(struct supernet_info *myinfo,char *CMD,void *a
return(0); return(0);
} }
int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,char *blockstr,bits256 hash2) int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,char *blockstr,bits256 hash2,int32_t height)
{ {
int32_t datalen; uint8_t *data,space[16384],*allocptr; cJSON *valsobj=0,*retjson; char *str,*str2; int32_t i,datalen,num,numerrs,numresults=-1; uint8_t *data,space[16384],*allocptr; cJSON *valsobj=0,*retjson,*retarray,*item; char *str,*str2,*othercoin; bits256 othertip;
if ( (data= get_dataptr(sizeof(struct iguana_msghdr) + BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),blockstr)) != 0 ) if ( (data= get_dataptr(sizeof(struct iguana_msghdr) + BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),blockstr)) != 0 )
{ {
if ( (str= gecko_blockarrived(myinfo,virt,"127.0.0.1",data,datalen,hash2)) != 0 ) if ( (str= gecko_blockarrived(myinfo,virt,"127.0.0.1",data,datalen,hash2)) != 0 )
@ -294,7 +294,31 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *bt
jaddstr(valsobj,"symbol",virt->symbol); jaddstr(valsobj,"symbol",virt->symbol);
if ( (str2= basilisk_standardservice("BLK",myinfo,hash2,valsobj,blockstr,1)) != 0 ) if ( (str2= basilisk_standardservice("BLK",myinfo,hash2,valsobj,blockstr,1)) != 0 )
{ {
printf("got responses.(%s)\n",str2); if ( (retarray= cJSON_Parse(str2)) != 0 )
{
numerrs = numresults = 0;
if ( (num= cJSON_GetArraySize(retarray)) > 0 )
{
for (i=0; i<num; i++)
{
item = jitem(retarray,i);
if ( jobj(item,"error") != 0 )
numerrs++;
else if ( jstr(item,"result") != 0 )
{
if ( (othercoin= jstr(item,"symbol")) != 0 && strcmp(othercoin,virt->symbol) == 0 && juint(item,"hwm") == height )
{
othertip = jbits256(item,"chaintip");
if ( bits256_cmp(hash2,othertip) == 0 )
numresults++;
else numerrs++;
} else numerrs++;
}
}
}
printf("%s got responses.%d good.%d errs.%d (%s)\n","BLK",num,numresults,numerrs,str2);
free_json(retjson);
}
free(str2); free(str2);
} }
free_json(valsobj); free_json(valsobj);
@ -306,7 +330,7 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *bt
} }
if ( allocptr != 0 ) if ( allocptr != 0 )
free(allocptr); free(allocptr);
return(0); return(numresults);
} }
int32_t basilisk_respond_geckogetblock(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *serialized,int32_t maxsize,cJSON *valsobj,bits256 hash2) int32_t basilisk_respond_geckogetblock(struct supernet_info *myinfo,struct iguana_info *virt,uint8_t *serialized,int32_t maxsize,cJSON *valsobj,bits256 hash2)

9
gecko/gecko_miner.c

@ -303,12 +303,15 @@ cJSON *gecko_paymentsobj(struct supernet_info *myinfo,cJSON *txjson,cJSON *valso
return(txjson); return(txjson);
} }
void gecko_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,char *blockstr,bits256 hash2) void gecko_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,char *blockstr,bits256 hash2,int32_t height)
{ {
uint8_t *data,space[16384],*allocptr=0; int32_t i,len,numranked=0; struct iguana_peers *peers; struct iguana_peer *addr; uint8_t *data,space[16384],*allocptr=0; int32_t i,len,numranked=0; struct iguana_peers *peers; struct iguana_peer *addr;
//printf("submit.(%s)\n",blockstr); //printf("submit.(%s)\n",blockstr);
if ( (peers= virt->peers) == 0 || (numranked= peers->numranked) == 0 ) if ( (peers= virt->peers) == 0 || (numranked= peers->numranked) == 0 )
basilisk_blocksubmit(myinfo,btcd,virt,blockstr,hash2); {
while ( basilisk_blocksubmit(myinfo,btcd,virt,blockstr,hash2,height) < myinfo->numrelays-1 )
sleep(1);
}
else // physical node for geckochain else // physical node for geckochain
{ {
if ( (data= get_dataptr(sizeof(struct iguana_msghdr),&allocptr,&len,space,sizeof(space),blockstr)) != 0 ) if ( (data= get_dataptr(sizeof(struct iguana_msghdr),&allocptr,&len,space,sizeof(space),blockstr)) != 0 )
@ -343,7 +346,7 @@ void gecko_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct ig
if ( (blockstr= gecko_createblock(myinfo,virt->chain->estblocktime,prevtimestamp,btcd,virt->chain->isPoS,(void *)&newblock,virt->symbol,txptrs,txn_count,maxmillis,minerpubkey33,reward)) != 0 ) if ( (blockstr= gecko_createblock(myinfo,virt->chain->estblocktime,prevtimestamp,btcd,virt->chain->isPoS,(void *)&newblock,virt->symbol,txptrs,txn_count,maxmillis,minerpubkey33,reward)) != 0 )
{ {
char str[65]; printf(">>>>>>>>>>>>>>>>> MINED %s.%x %s %u %d %.8f %d\n",virt->symbol,newblock.RO.bits,bits256_str(str,newblock.RO.hash2),newblock.RO.timestamp,newblock.height,dstr(reward),newblock.RO.txn_count); char str[65]; printf(">>>>>>>>>>>>>>>>> MINED %s.%x %s %u %d %.8f %d\n",virt->symbol,newblock.RO.bits,bits256_str(str,newblock.RO.hash2),newblock.RO.timestamp,newblock.height,dstr(reward),newblock.RO.txn_count);
gecko_blocksubmit(myinfo,btcd,virt,blockstr,newblock.RO.hash2); gecko_blocksubmit(myinfo,btcd,virt,blockstr,newblock.RO.hash2,newblock.height);
free(blockstr); free(blockstr);
} }
if ( txptrs != (void *)space ) if ( txptrs != (void *)space )

2
includes/iguana_funcs.h

@ -487,7 +487,7 @@ void iguana_blockzcopy(uint8_t zcash,struct iguana_block *dest,struct iguana_blo
int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block); int32_t iguana_blocksizecheck(char *debugstr,uint8_t zcash,struct iguana_block *block);
void basilisk_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr); void basilisk_miner(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,int32_t maxmillis,char *mineraddr);
int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]); int32_t bitcoin_pubkeyspend(uint8_t *script,int32_t n,uint8_t pubkey[66]);
int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,char *blockstr,bits256 hash2); int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *btcd,struct iguana_info *virt,char *blockstr,bits256 hash2,int32_t height);
struct supernet_info *SuperNET_MYINFO(char *passphrase); struct supernet_info *SuperNET_MYINFO(char *passphrase);
bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory); bits256 calc_categoryhashes(bits256 *subhashp,char *category,char *subcategory);
struct gecko_chain *category_find(bits256 categoryhash,bits256 subhash); struct gecko_chain *category_find(bits256 categoryhash,bits256 subhash);

Loading…
Cancel
Save