Browse Source

voting

release/v0.1
jl777 8 years ago
parent
commit
fac139728e
  1. 1160
      basilisk/basilisk copy.c
  2. 57
      basilisk/basilisk.c
  3. 75
      basilisk/basilisk_CMD.c
  4. 12
      basilisk/basilisk_DEX.c
  5. 10
      basilisk/basilisk_MSG.c
  6. 14
      basilisk/basilisk_bitcoin.c
  7. 24
      basilisk/basilisk_ping.c
  8. 405
      basilisk/basilisk_vote.c
  9. 2
      datachain/datachain.c
  10. 2
      gecko/gecko_blocks.c
  11. 16
      gecko/gecko_mempool.c
  12. 4
      iguana/iguana777.c
  13. 9
      iguana/iguana777.h
  14. 6
      iguana/iguana_chains.c
  15. 8
      iguana/iguana_init.c
  16. 26
      iguana/main.c
  17. 2
      includes/iguana_apideclares.h
  18. 1
      includes/iguana_defines.h
  19. 4
      includes/iguana_funcs.h
  20. 4
      includes/iguana_globals.h

1160
basilisk/basilisk copy.c

File diff suppressed because it is too large

57
basilisk/basilisk.c

@ -17,7 +17,7 @@
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 hash,int32_t from_basilisk);
int32_t basilisk_specialcmd(char *cmd)
int32_t basilisk_notarycmd(char *cmd)
{
//&& strcmp(cmd,"DEX") != 0 && strcmp(cmd,"ACC") != 0 && strcmp(cmd,"RID") != 0 &&
if ( strcmp(cmd,"PIN") != 0 && strcmp(cmd,"OUT") != 0 && strcmp(cmd,"MSG") != 0 )
@ -149,7 +149,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{
int32_t i,l,s,valid,val,n=0,retval = -1; char cmd[12]; struct iguana_info *coin,*tmp; struct iguana_peer *addr; bits256 hash; uint32_t *alreadysent,r,r2;
if ( fanout <= 0 )
fanout = sqrt(NUMRELAYS) + 1;
fanout = sqrt(myinfo->NOTARY.NUMRELAYS) + 1;
else if ( fanout > BASILISK_MAXFANOUT )
fanout = BASILISK_MAXFANOUT;
if ( type == 0 )
@ -205,7 +205,7 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
}
return(-1);
}
if ( basilisk_specialcmd(type) != 0 && NUMRELAYS == 0 )
if ( basilisk_notarycmd(type) != 0 && myinfo->NOTARY.NUMRELAYS == 0 )
return(-1);
//portable_mutex_lock(&myinfo->allcoins_mutex);
alreadysent = calloc(IGUANA_MAXPEERS * IGUANA_MAXCOINS,sizeof(*alreadysent));
@ -228,19 +228,19 @@ int32_t basilisk_sendcmd(struct supernet_info *myinfo,char *destipaddr,char *typ
{
s = 0;
valid = (addr->supernet != 0);
if ( basilisk_specialcmd(type) != 0 )
if ( basilisk_notarycmd(type) != 0 )
{
valid = 0;
OS_randombytes((void *)&r2,sizeof(r2));
if ( (r2 % NUMRELAYS) >= sqrt(NUMRELAYS) )
if ( (r2 % myinfo->NOTARY.NUMRELAYS) >= sqrt(myinfo->NOTARY.NUMRELAYS) )
{
//printf("fanout.%d s.%d n.%d skip %s\n",fanout,s,n,addr->ipaddr);
continue;
}
for (s=0; s<NUMRELAYS; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && RELAYS[s].ipbits == addr->ipbits )
for (s=0; s<myinfo->NOTARY.NUMRELAYS; s++)
if ( addr->ipbits != myinfo->myaddr.myipbits && myinfo->NOTARY.RELAYS[s].ipbits == addr->ipbits )
break;
if ( s == NUMRELAYS )
if ( s == myinfo->NOTARY.NUMRELAYS )
{
//printf("skip non-relay.(%s)\n",addr->ipaddr);
continue;
@ -394,7 +394,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc
}
if ( (timeoutmillis= jint(valsobj,"timeout")) == 0 )
timeoutmillis = BASILISK_TIMEOUT;
minfanout = sqrt(NUMRELAYS)+1;
minfanout = sqrt(myinfo->NOTARY.NUMRELAYS)+1;
if ( minfanout < 5 )
minfanout = 5;
if ( jobj(valsobj,"fanout") == 0 )
@ -403,7 +403,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc
if ( fanout < minfanout )
fanout = minfanout;
if ( (numrequired= jint(valsobj,"numrequired")) <= 0 )
numrequired = MAX(fanout,sqrt(NUMRELAYS)+1);
numrequired = MAX(fanout,sqrt(myinfo->NOTARY.NUMRELAYS)+1);
if ( (symbol= jstr(valsobj,"coin")) != 0 || (symbol= jstr(valsobj,"symbol")) != 0 )
{
if ( (virt= iguana_coinfind(symbol)) != 0 )
@ -424,7 +424,7 @@ struct basilisk_item *basilisk_requestservice(struct supernet_info *myinfo,struc
char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_addr,bits256 hash,cJSON *valsobj,char *hexstr,int32_t blockflag) // client side
{
uint32_t nBits = 0; uint8_t space[4096],*allocptr=0,*data = 0; struct basilisk_item *ptr; int32_t datalen = 0; cJSON *retjson; char *retstr=0;
if ( RELAYID >= 0 && basilisk_specialcmd(CMD) == 0 )
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 && basilisk_notarycmd(CMD) == 0 )
return(clonestr("{\"error\":\"unsupported special relay command\"}"));
data = get_dataptr(BASILISK_HDROFFSET,&allocptr,&datalen,space,sizeof(space),hexstr);
//printf("request.(%s)\n",jprint(valsobj,0));
@ -456,8 +456,8 @@ char *basilisk_standardservice(char *CMD,struct supernet_info *myinfo,void *_add
int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits)
{
int32_t j;
for (j=0; j<NUMRELAYS; j++)
if ( RELAYS[j].ipbits == ipbits )
for (j=0; j<myinfo->NOTARY.NUMRELAYS; j++)
if ( myinfo->NOTARY.RELAYS[j].ipbits == ipbits )
return(j);
return(-1);
}
@ -473,6 +473,7 @@ int32_t basilisk_relayid(struct supernet_info *myinfo,uint32_t ipbits)
#include "basilisk_swap.c"
#include "basilisk_DEX.c"
#include "basilisk_ping.c"
#include "basilisk_vote.c"
#include "basilisk_CMD.c"
void basilisk_functions(struct iguana_info *coin,int32_t protocol)
@ -625,7 +626,10 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{ (void *)"OUT", &basilisk_respond_OUT }, // send MSG to hash/id/num
{ (void *)"MSG", &basilisk_respond_MSG }, // get MSG (hash, id, num)
{ (void *)"ADD", &basilisk_respond_addrelay }, // relays register with each other bus
{ (void *)"VOT", &basilisk_respond_VOT }, // VOTE handler for something
//{ (void *)"PIN", &basilisk_respond_PIN },
// encrypted data for jumblr
{ (void *)"HOP", &basilisk_respond_forward }, // message forwarding
{ (void *)"BOX", &basilisk_respond_mailbox }, // create/send/check mailbox pubkey
@ -666,12 +670,11 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
CMD[i] = toupper((int32_t)CMD[i]);
cmd[i] = tolower((int32_t)CMD[i]);
}
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 )//RELAYID >= 0 )
{
if ( basilisk_specialcmd(CMD) == 0 )
if ( basilisk_notarycmd(CMD) == 0 )
return;
}
else if ( basilisk_specialcmd(CMD) != 0 )
} else if ( basilisk_notarycmd(CMD) != 0 )
return;
symbol = "BTCD";
if ( senderipbits == 0 )
@ -729,7 +732,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
hash = jbits256(valsobj,"hash");
timeoutmillis = jint(valsobj,"timeout");
if ( (numrequired= jint(valsobj,"numrequired")) == 0 )
numrequired = sqrt(NUMRELAYS)+1;
numrequired = sqrt(myinfo->NOTARY.NUMRELAYS)+1;
if ( senderipbits != 0 )
expand_ipbits(remoteaddr,senderipbits);
else remoteaddr[0] = 0;
@ -737,7 +740,7 @@ void basilisk_msgprocess(struct supernet_info *myinfo,void *_addr,uint32_t sende
{
if ( strcmp((char *)basilisk_services[i][0],type) == 0 )
{
if ( coin->FULLNODE != 0 || RELAYID >= 0 ) // iguana node
if ( coin->FULLNODE != 0 || myinfo->NOTARY.RELAYID >= 0 ) // iguana node
{
//printf("FULL.%d RELAYID.%d NUMRELAYS.%d services %s\n",coin->FULLNODE,RELAYID,NUMRELAYS,type);
if ( (retstr= (*basilisk_services[i][1])(myinfo,type,addr,remoteaddr,basilisktag,valsobj,data,datalen,hash,from_basilisk)) != 0 )
@ -777,7 +780,7 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
else ipbits = myinfo->myaddr.myipbits;
if ( type[0] == 'P' && type[1] == 'I' && type[2] == 'N' )
{
if ( strcmp(type,"PIN") == 0 && RELAYID >= 0 )
if ( strcmp(type,"PIN") == 0 && myinfo->NOTARY.RELAYID >= 0 )
{
basilisk_ping_process(myinfo,_addr,ipbits,data,datalen);
}
@ -787,8 +790,8 @@ void basilisk_p2p(void *_myinfo,void *_addr,char *senderip,uint8_t *data,int32_t
len += iguana_rwnum(0,data,sizeof(basilisktag),&basilisktag);
//int32_t i; for (i=0; i<datalen-len; i++)
// printf("%02x",data[len+i]);
if ( RELAYID >= 0 )
printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag);
if ( myinfo->NOTARY.RELAYID >= 0 )
printf("RELAYID.%d ->received.%d basilisk_p2p.(%s) from %s tag.%u\n",myinfo->NOTARY.RELAYID,datalen,type,senderip!=0?senderip:"?",basilisktag);
basilisk_msgprocess(myinfo,_addr,ipbits,type,basilisktag,&data[len],datalen - len);
}
if ( ptr != 0 )
@ -865,7 +868,7 @@ void basilisks_loop(void *arg)
}
}
//portable_mutex_unlock(&myinfo->allcoins_mutex);
if ( RELAYID >= 0 )
if ( myinfo->NOTARY.RELAYID >= 0 )
{
basilisk_ping_send(myinfo,btcd);
}
@ -883,7 +886,7 @@ void basilisks_loop(void *arg)
}
}
}
if ( RELAYID < 0 && myinfo->expiration != 0 )
if ( myinfo->NOTARY.RELAYID < 0 && myinfo->expiration != 0 )
basilisk_requests_poll(myinfo);
now = (uint32_t)time(NULL);
portable_mutex_lock(&myinfo->messagemutex);
@ -898,7 +901,7 @@ void basilisks_loop(void *arg)
}
}
portable_mutex_unlock(&myinfo->messagemutex);
if ( RELAYID >= 0 )
if ( myinfo->NOTARY.RELAYID >= 0 )
usleep(100000);
else usleep(3000000);
}
@ -925,7 +928,7 @@ void basilisks_init(struct supernet_info *myinfo)
HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis;
if ( RELAYID >= 0 )
if ( myinfo->NOTARY.RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
if ( vals == 0 )
return(clonestr("{\"error\":\"need vals object\"}"));
@ -934,7 +937,7 @@ HASH_ARRAY_STRING(basilisk,balances,hash,vals,hexstr)
if ( jobj(vals,"history") == 0 )
jaddnum(vals,"history",3);
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",juint(vals,"fanout"));
if ( jobj(vals,"addresses") == 0 )

75
basilisk/basilisk_CMD.c

@ -24,25 +24,25 @@
return(-1);
}*/
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits)
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits)
{
struct iguana_peer *addr; int32_t i;
if ( btcd == 0 )
if ( notaries == 0 )
return(0);
if ( (addr= iguana_peerfindipbits(btcd,ipbits,0)) == 0 )
if ( (addr= iguana_peerfindipbits(notaries,ipbits,0)) == 0 )
{
if ( (addr= iguana_peerslot(btcd,ipbits,0)) != 0 )
if ( (addr= iguana_peerslot(notaries,ipbits,0)) != 0 )
{
printf("launch peer for relay\n");
addr->isrelay = 1;
RELAYID = -1;
for (i=0; i<NUMRELAYS; i++)
if ( RELAYS[i].ipbits == myinfo->myaddr.myipbits )
myinfo->NOTARY.RELAYID = -1;
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
if ( myinfo->NOTARY.RELAYS[i].ipbits == myinfo->myaddr.myipbits )
{
RELAYID = i;
myinfo->NOTARY.RELAYID = i;
break;
}
iguana_launch(btcd,"addrelay",iguana_startconnection,addr,IGUANA_CONNTHREAD);
iguana_launch(notaries,"addrelay",iguana_startconnection,addr,IGUANA_CONNTHREAD);
} else printf("error getting peerslot\n");
} else addr->isrelay = 1;
return(addr);
@ -65,30 +65,30 @@ void basilisk_relay_remap(struct supernet_info *myinfo,struct basilisk_relay *rp
{
int32_t i; struct basilisk_relaystatus tmp[BASILISK_MAXRELAYS];
// need to verify this works
for (i=0; i<NUMRELAYS; i++)
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
tmp[i] = rp->reported[i];
for (i=0; i<NUMRELAYS; i++)
rp->reported[RELAYS[i].relayid] = tmp[RELAYS[i].oldrelayid];
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
rp->reported[myinfo->NOTARY.RELAYS[i].relayid] = tmp[myinfo->NOTARY.RELAYS[i].oldrelayid];
}
void basilisk_setmyid(struct supernet_info *myinfo)
{
int32_t i; char ipaddr[64]; struct iguana_info *btcd = iguana_coinfind("BTCD");
for (i=0; i<NUMRELAYS; i++)
int32_t i; char ipaddr[64]; struct iguana_info *notaries = iguana_coinfind("NOTARY");
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
{
expand_ipbits(ipaddr,RELAYS[i].ipbits);
if ( myinfo->myaddr.myipbits == RELAYS[i].ipbits )
RELAYID = i;
basilisk_ensurerelay(myinfo,btcd,RELAYS[i].ipbits);
expand_ipbits(ipaddr,myinfo->NOTARY.RELAYS[i].ipbits);
if ( myinfo->myaddr.myipbits == myinfo->NOTARY.RELAYS[i].ipbits )
myinfo->NOTARY.RELAYID = i;
basilisk_ensurerelay(myinfo,notaries,myinfo->NOTARY.RELAYS[i].ipbits);
}
}
char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint32_t ipbits,bits256 pubkey)
{
int32_t i; struct basilisk_relay *rp;
for (i=0; i<NUMRELAYS; i++)
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
{
rp = &RELAYS[i];
rp = &myinfo->NOTARY.RELAYS[i];
if ( ipbits == rp->ipbits )
{
if ( bits256_cmp(GENESIS_PUBKEY,pubkey) != 0 && bits256_nonz(pubkey) != 0 )
@ -99,24 +99,24 @@ char *basilisk_addrelay_info(struct supernet_info *myinfo,uint8_t *pubkey33,uint
return(clonestr("{\"error\":\"relay already there\"}"));
}
}
if ( i >= sizeof(RELAYS)/sizeof(*RELAYS) )
i = (rand() % (sizeof(RELAYS)/sizeof(*RELAYS)));
if ( i >= sizeof(myinfo->NOTARY.RELAYS)/sizeof(*myinfo->NOTARY.RELAYS) )
i = (rand() % (sizeof(myinfo->NOTARY.RELAYS)/sizeof(*myinfo->NOTARY.RELAYS)));
printf("add relay[%d] <- %x\n",i,ipbits);
for (i=0; i<NUMRELAYS; i++)
RELAYS[i].oldrelayid = i;
rp = &RELAYS[i];
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
myinfo->NOTARY.RELAYS[i].oldrelayid = i;
rp = &myinfo->NOTARY.RELAYS[i];
rp->ipbits = ipbits;
rp->relayid = NUMRELAYS;
basilisk_ensurerelay(myinfo,iguana_coinfind("BTCD"),rp->ipbits);
if ( NUMRELAYS < sizeof(RELAYS)/sizeof(*RELAYS) )
NUMRELAYS++;
qsort(RELAYS,NUMRELAYS,sizeof(RELAYS[0]),_increasing_ipbits);
for (i=0; i<NUMRELAYS; i++)
RELAYS[i].relayid = i;
rp->relayid = myinfo->NOTARY.NUMRELAYS;
basilisk_ensurerelay(myinfo,iguana_coinfind("NOTARY"),rp->ipbits);
if ( myinfo->NOTARY.NUMRELAYS < sizeof(myinfo->NOTARY.RELAYS)/sizeof(*myinfo->NOTARY.RELAYS) )
myinfo->NOTARY.NUMRELAYS++;
qsort(myinfo->NOTARY.RELAYS,myinfo->NOTARY.NUMRELAYS,sizeof(myinfo->NOTARY.RELAYS[0]),_increasing_ipbits);
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
myinfo->NOTARY.RELAYS[i].relayid = i;
basilisk_setmyid(myinfo);
printf("sorted MYRELAYID.%d\n",RELAYID);
for (i=0; i<NUMRELAYS; i++)
basilisk_relay_remap(myinfo,&RELAYS[i]);
printf("sorted MYRELAYID.%d\n",myinfo->NOTARY.RELAYID);
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
basilisk_relay_remap(myinfo,&myinfo->NOTARY.RELAYS[i]);
return(clonestr("{\"result\":\"relay added\"}"));
}
@ -254,6 +254,11 @@ char *basilisk_respond_getinfo(struct supernet_info *myinfo,char *CMD,void *addr
#include "../includes/iguana_apidefs.h"
#include "../includes/iguana_apideclares.h"
HASH_ARRAY_STRING(basilisk,vote,hash,vals,hexstr)
{
return(basilisk_standardservice("VOT",myinfo,0,hash,vals,hexstr,0));
}
HASH_ARRAY_STRING(basilisk,addrelay,hash,vals,hexstr)
{
return(basilisk_standardservice("ADD",myinfo,0,hash,vals,hexstr,1));

12
basilisk/basilisk_DEX.c

@ -247,7 +247,7 @@ struct basilisk_relay *basilisk_request_ensure(struct supernet_info *myinfo,uint
int32_t j; struct basilisk_relay *relay = 0;
if ( (j= basilisk_relayid(myinfo,senderipbits)) >= 0 )
{
relay = &RELAYS[j];
relay = &myinfo->NOTARY.RELAYS[j];
if ( numrequests > relay->maxrequests )
{
relay->maxrequests = numrequests;
@ -284,14 +284,14 @@ static int _cmp_requests(const void *a,const void *b)
struct basilisk_request *_basilisk_requests_uniq(struct supernet_info *myinfo,int32_t *nump,uint8_t *space,int32_t spacesize)
{
int32_t i,j,n,k,m; struct basilisk_relay *relay; struct basilisk_request *requests,*rp;
for (j=m=0; j<NUMRELAYS; j++)
m += RELAYS[j].numrequests;
for (j=m=0; j<myinfo->NOTARY.NUMRELAYS; j++)
m += myinfo->NOTARY.RELAYS[j].numrequests;
if ( m*sizeof(*requests) <= spacesize )
requests = (void *)space;
else requests = calloc(m,sizeof(*requests));
for (j=m=0; j<NUMRELAYS; j++)
for (j=m=0; j<myinfo->NOTARY.NUMRELAYS; j++)
{
relay = &RELAYS[j];
relay = &myinfo->NOTARY.RELAYS[j];
if ( (n= relay->numrequests) > 0 )
{
for (i=0; i<n; i++)
@ -471,7 +471,7 @@ HASH_ARRAY_STRING(InstantDEX,request,hash,vals,hexstr)
if ( basilisk_request_create(&R,vals,hash,juint(vals,"timestamp")) == 0 )
{
printf("R.requestid.%u vs calc %u, q.%u\n",R.requestid,basilisk_requestid(&R),R.quoteid);
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
R.relaybits = myinfo->myaddr.myipbits;
if ( (reqjson= basilisk_requestjson(&R)) != 0 )
free_json(reqjson);

10
basilisk/basilisk_MSG.c

@ -167,7 +167,7 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
jdelete(vals,"msgid");
jaddnum(vals,"msgid",msgid);
}
if ( RELAYID >= 0 )
if ( myinfo->NOTARY.RELAYID >= 0 )
{
channel = juint(vals,"channel");
width = juint(vals,"width");
@ -178,7 +178,7 @@ HASH_ARRAY_STRING(basilisk,getmessage,hash,vals,hexstr)
HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
{
int32_t keylen,datalen; uint8_t key[BASILISK_KEYSIZE],space[16384],*data,*ptr = 0; char *retstr=0;
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 )
{
keylen = basilisk_messagekey(key,juint(vals,"channel"),juint(vals,"msgid"),jbits256(vals,"sender"),hash);
if ( (data= get_dataptr(BASILISK_HDROFFSET,&ptr,&datalen,space,sizeof(space),hexstr)) != 0 )
@ -189,7 +189,7 @@ HASH_ARRAY_STRING(basilisk,sendmessage,hash,vals,hexstr)
free(retstr);
}
if ( vals != 0 && juint(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+2));
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
return(basilisk_standardservice("OUT",myinfo,0,hash,vals,hexstr,0));
}
#include "../includes/iguana_apiundefs.h"
@ -203,7 +203,7 @@ int32_t basilisk_channelsend(struct supernet_info *myinfo,bits256 hash,uint32_t
jaddnum(valsobj,"channel",channel);
if ( msgid == 0 )
msgid = (uint32_t)time(NULL);
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+2));
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+2));
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"duration",duration);
jaddbits256(valsobj,"sender",myinfo->myaddr.persistent);
@ -252,7 +252,7 @@ cJSON *basilisk_channelget(struct supernet_info *myinfo,bits256 hash,uint32_t ch
jaddnum(valsobj,"msgid",msgid);
jaddnum(valsobj,"width",width);
jaddnum(valsobj,"timeout",2500);
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jaddnum(valsobj,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
jaddnum(valsobj,"numrequired",1);
if ( (retstr= basilisk_getmessage(myinfo,0,0,0,hash,valsobj,0)) != 0 )
{

14
basilisk/basilisk_bitcoin.c

@ -383,7 +383,7 @@ double basilisk_bitcoin_valuemetric(struct supernet_info *myinfo,struct basilisk
void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
int32_t i,height,vout,numsent; struct basilisk_item *ptr; char coinaddr[64],str[65]; struct basilisk_value *v; uint64_t value = 0; bits256 txid; struct iguana_outpoint outpt;
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 )
return(0);
txid = jbits256(valsobj,"txid");
vout = jint(valsobj,"vout");
@ -424,7 +424,7 @@ void *basilisk_bitcoinvalue(struct basilisk_item *Lptr,struct supernet_info *myi
void *basilisk_getinfo(struct basilisk_item *Lptr,struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
struct basilisk_item *ptr; cJSON *infojson; int32_t numsent,fanout,numrequired;
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
return(0);
if ( coin->VALIDATENODE != 0 || coin->FULLNODE != 0 )
{
@ -516,7 +516,7 @@ int32_t basilisk_vins_validate(struct supernet_info *myinfo,struct iguana_info *
char *basilisk_bitcoinrawtx(struct supernet_info *myinfo,struct iguana_info *coin,char *remoteaddr,uint32_t basilisktag,int32_t timeoutmillis,cJSON *valsobj)
{
uint8_t buf[4096]; int32_t oplen,offset,minconf,spendlen; cJSON *vins,*addresses,*txobj = 0; uint32_t locktime; char *opreturn,*spendscriptstr,*changeaddr,*rawtx = 0; int64_t amount,txfee,burnamount;
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
vins = 0;
changeaddr = jstr(valsobj,"changeaddr");
@ -815,7 +815,7 @@ cJSON *BTC_makeclaimfunc(struct supernet_info *myinfo,struct exchange_info *exch
HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
{
char *retstr=0,*symbol; uint32_t basilisktag; struct basilisk_item *ptr,Lptr; int32_t timeoutmillis;
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 || myinfo->NOTARY.RELAYID >= 0 )
return(clonestr("{\"error\":\"special relays only do OUT and MSG\"}"));
//if ( coin == 0 )
{
@ -823,7 +823,7 @@ HASH_ARRAY_STRING(basilisk,value,hash,vals,hexstr)
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( coin != 0 )
{
if ( (basilisktag= juint(vals,"basilisktag")) == 0 )
@ -849,9 +849,9 @@ HASH_ARRAY_STRING(basilisk,rawtx,hash,vals,hexstr)
coin = iguana_coinfind(symbol);
}
if ( jobj(vals,"numrequired") == 0 )
jaddnum(vals,"numrequired",NUMRELAYS);
jaddnum(vals,"numrequired",myinfo->NOTARY.NUMRELAYS);
if ( jobj(vals,"fanout") == 0 )
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(NUMRELAYS)+1));
jaddnum(vals,"fanout",MAX(5,(int32_t)sqrt(myinfo->NOTARY.NUMRELAYS)+1));
if ( coin != 0 )
{
//if ( juint(vals,"burn") == 0 )

24
basilisk/basilisk_ping.c

@ -212,9 +212,9 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
int32_t diff,i,n,len = 0; struct iguana_info *btcd; char ipbuf[64]; struct basilisk_relay *rp; uint8_t numrelays; uint16_t sn; uint32_t now = (uint32_t)time(NULL);
expand_ipbits(ipbuf,senderipbits);
btcd = iguana_coinfind("BTCD");
for (i=0; i<NUMRELAYS; i++)
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
{
rp = &RELAYS[i];
rp = &myinfo->NOTARY.RELAYS[i];
rp->direct.pingdelay = 0;
if ( rp->ipbits == senderipbits )
rp->lastping = now;
@ -231,7 +231,7 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
//len += basilisk_ping_processvirts(myinfo,btcd,addr,&data[len],datalen - len);
for (i=0; i<numrelays; i++)
{
rp = &RELAYS[i];
rp = &myinfo->NOTARY.RELAYS[i];
if ( len > datalen )
break;
if ( (n= basilisk_ping_processrelay(myinfo,&data[len],datalen-len,rp,i)) < 0 )
@ -253,10 +253,10 @@ void basilisk_ping_process(struct supernet_info *myinfo,struct iguana_peer *addr
int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t maxlen)
{
int32_t i,datalen = 0;
data[datalen++] = NUMRELAYS;
data[datalen++] = myinfo->NOTARY.NUMRELAYS;
//datalen += basilisk_ping_genvirts(myinfo,&data[datalen],maxlen - datalen);
for (i=0; i<NUMRELAYS; i++)
datalen += basilisk_ping_genrelay(myinfo,&data[datalen],maxlen - datalen,&RELAYS[i]);
for (i=0; i<myinfo->NOTARY.NUMRELAYS; i++)
datalen += basilisk_ping_genrelay(myinfo,&data[datalen],maxlen - datalen,&myinfo->NOTARY.RELAYS[i]);
//datalen += basilisk_ping_genDEX(myinfo,&data[datalen],maxlen - datalen);
datalen += basilisk_ping_genMSG(myinfo,&data[datalen],maxlen - datalen);
//for (i=0; i<datalen; i++)
@ -271,25 +271,25 @@ int32_t basilisk_ping_gen(struct supernet_info *myinfo,uint8_t *data,int32_t max
void basilisk_ping_send(struct supernet_info *myinfo,struct iguana_info *btcd)
{
struct iguana_peer *addr; char ipaddr[64]; struct basilisk_relay *rp; uint32_t r; int32_t i,j,incr,datalen=0; uint64_t alreadysent;
if ( btcd == 0 || NUMRELAYS <= 0 )
if ( btcd == 0 || myinfo->NOTARY.NUMRELAYS <= 0 )
return;
if ( myinfo->pingbuf == 0 )
myinfo->pingbuf = malloc(IGUANA_MAXPACKETSIZE);
datalen = basilisk_ping_gen(myinfo,&myinfo->pingbuf[sizeof(struct iguana_msghdr)],IGUANA_MAXPACKETSIZE-sizeof(struct iguana_msghdr));
incr = sqrt(NUMRELAYS) + 1;
incr = sqrt(myinfo->NOTARY.NUMRELAYS) + 1;
for (alreadysent=j=0; j<=incr; j++)
{
OS_randombytes((void *)&r,sizeof(r));
i = (j == 0) ? RELAYID : (r % NUMRELAYS);
if ( j != 0 && i == RELAYID )
i = (RELAYID + 1) % NUMRELAYS;
i = (j == 0) ? myinfo->NOTARY.RELAYID : (r % myinfo->NOTARY.NUMRELAYS);
if ( j != 0 && i == myinfo->NOTARY.RELAYID )
i = (myinfo->NOTARY.RELAYID + 1) % myinfo->NOTARY.NUMRELAYS;
if ( (((uint64_t)1 << i) & alreadysent) != 0 )
{
j--;
continue;
}
alreadysent |= ((uint64_t)1 << i);
rp = &RELAYS[i];
rp = &myinfo->NOTARY.RELAYS[i];
addr = 0;
expand_ipbits(ipaddr,rp->ipbits);
if ( rp->ipbits == myinfo->myaddr.myipbits )

405
basilisk/basilisk_vote.c

@ -0,0 +1,405 @@
/******************************************************************************
* Copyright © 2014-2016 The SuperNET Developers. *
* *
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at *
* the top-level directory of this distribution for the individual copyright *
* holder information and the developer policies on copyright and licensing. *
* *
* Unless otherwise agreed in a custom licensing agreement, no part of the *
* SuperNET software, including this file may be copied, modified, propagated *
* or distributed except according to the terms contained in the LICENSE file *
* *
* Removal or modification of this copyright notice is prohibited. *
* *
******************************************************************************/
#define MAX_ELECTIONS 64
struct vote_info
{
bits256 commit,vote;
uint64_t stake,repstake;
int32_t repid;
uint8_t sig[74],siglen;
uint8_t pubkey[33],rmd160[20];
};
struct election_info
{
bits256 hash;
char name[64];
uint32_t expiration,duration,numcandidates,numvotes;
cJSON *ballot;
struct vote_info *votes;
} Elections[MAX_ELECTIONS];
int64_t basilisk_voter_stake(struct supernet_info *myinfo,uint8_t *rmd160,struct iguana_info *coin,uint8_t *pubkey)
{
char coinaddr[64]; int64_t stake = 1;
calc_rmd160_sha256(rmd160,pubkey,33);
bitcoin_address(coinaddr,coin->chain->pubtype,pubkey,33);
// get stake of address
return(stake);
}
int32_t basilisk_voter_process(struct supernet_info *myinfo,uint8_t *rmd160,struct iguana_info *coin,struct election_info *ep,struct vote_info *vp)
{
int32_t i;
if ( vp->stake == 0 )
vp->stake = 1;
if ( bits256_nonz(vp->vote) != 0 )
{
for (i=1; i<8; i++)
if ( vp->vote.uints[i] != 0 )
break;
if ( i == 8 )
return(vp->vote.uints[0]);
else
{
for (i=0; i<20; i++)
rmd160[i] = vp->vote.bytes[i + 4];
return(ep->numcandidates);
}
}
return(-1);
}
int32_t basilisk_election_process(struct supernet_info *myinfo,int64_t *tally,struct iguana_info *coin,struct election_info *ep)
{
int32_t i,j,pending = 0; struct vote_info *vp; uint8_t rmd160[20];
for (i=0; i<ep->numvotes; i++)
ep->votes[i].repstake = 0;
for (i=0; i<ep->numvotes; i++)
{
vp = &ep->votes[i];
if ( basilisk_voter_process(myinfo,rmd160,coin,ep,vp) == ep->numcandidates && vp->repid < 0 )
{
for (j=0; j<ep->numvotes; j++)
{
if ( i != j && memcmp(rmd160,ep->votes[j].rmd160,20) == 0 )
{
vp->repid = j;
ep->votes[j].repstake += vp->stake;
break;
}
}
}
}
if ( tally != 0 )
{
memset(tally,0,ep->numcandidates*sizeof(*tally));
for (i=0; i<ep->numvotes; i++)
{
vp = &ep->votes[i];
if ( vp->repid < 0 && vp->vote.uints[0] > 0 && vp->vote.uints[0] <= ep->numcandidates )
tally[vp->vote.uints[0]] += (vp->stake + vp->repstake);
else if ( vp->repid < 0 )
pending++;
}
}
return(pending);
}
cJSON *basilisk_voterjson(struct supernet_info *myinfo,struct iguana_info *coin,struct election_info *ep,struct vote_info *vp)
{
char coinaddr[64],sigstr[74*2+1]; int32_t i; uint8_t rmd160[20]; cJSON *item;
item = cJSON_CreateObject();
basilisk_voter_process(myinfo,rmd160,coin,ep,vp);
bitcoin_address(coinaddr,5,vp->pubkey,sizeof(vp->pubkey));
jaddstr(item,"coinaddr",coinaddr);
jaddnum(item,"stake",dstr(vp->stake));
if ( vp->repstake != 0 )
jaddnum(item,"repstake",dstr(vp->repstake));
if ( bits256_nonz(vp->vote) != 0 )
{
for (i=1; i<8; i++)
if ( vp->vote.uints[i] != 0 )
break;
if ( i == 8 )
{
if ( vp->vote.uints[0] <= ep->numcandidates )
jaddnum(item,"vote",vp->vote.uints[0]);
else jaddstr(item,"error","illegal vote");
}
else
{
for (i=0; i<20; i++)
rmd160[i] = vp->vote.bytes[i + 4];
bitcoin_address(coinaddr,5,rmd160,20);
jaddstr(item,"delegated",coinaddr);
}
}
else if ( bits256_nonz(vp->commit) != 0 )
jaddbits256(item,"commit",vp->commit);
init_hexbytes_noT(sigstr,vp->sig,vp->siglen);
jaddstr(item,"sig",sigstr);
return(item);
}
cJSON *basilisk_electionjson(struct supernet_info *myinfo,struct iguana_info *coin,struct election_info *ep)
{
int32_t i; cJSON *array,*obj = cJSON_CreateObject();
jaddstr(obj,"name",ep->name);
jaddbits256(obj,"hash",ep->hash);
jaddnum(obj,"expiration",ep->expiration);
jaddnum(obj,"numcandidates",ep->numcandidates);
jaddnum(obj,"numvotes",ep->numvotes);
jadd(obj,"ballot",jduplicate(ep->ballot));
array = cJSON_CreateArray();
for (i=0; i<ep->numvotes; i++)
jaddi(array,basilisk_voterjson(myinfo,coin,ep,&ep->votes[i]));
jadd(obj,"votes",array);
return(obj);
}
int32_t basilisk_electionsave(struct election_info *ep)
{
char fname[512],str[65],*ballotstr; int32_t n; FILE *fp;
OS_ensure_directory("elections");
sprintf(fname,"elections/%s",bits256_str(str,ep->hash));
OS_compatible_path(fname);
if ( (fp= fopen(fname,"wb")) != 0 )
{
if ( fwrite(ep,1,sizeof(*ep),fp) != sizeof(*ep) )
printf("error saving election.(%s) to %s\n",ep->name,fname);
else
{
if ( fwrite(&ep->numvotes,1,sizeof(ep->numvotes),fp) != sizeof(ep->numvotes) )
printf("error saving numvotes.%d to %s\n",ep->numvotes,fname);
else if ( ep->numvotes > 0 )
{
if ( fwrite(ep->votes,sizeof(*ep->votes),ep->numvotes,fp) != ep->numvotes )
printf("error saving votes.%d for %s to %s\n",ep->numvotes,ep->name,fname);
else
{
if ( (ballotstr= jprint(ep->ballot,0)) != 0 )
{
n = (int32_t)strlen(ballotstr) + 1;
if ( fwrite(&n,1,sizeof(n),fp) != sizeof(n) )
printf("error saving n.%d for (%s) to %s\n",n,ballotstr,fname);
else if ( fwrite(ballotstr,1,n,fp) != n )
printf("error saving election.(%s) to %s\n",ballotstr,fname);
free(ballotstr);
}
}
}
}
fclose(fp);
return(0);
}
return(-1);
}
struct vote_info *basilisk_vote_find(struct election_info *ep,struct vote_info *vote)
{
int32_t i;
for (i=0; i<ep->numvotes; i++)
{
if ( memcmp(ep->votes[i].pubkey,vote->pubkey,33) == 0 )
return(&ep->votes[i]);
}
return(0);
}
struct election_info *basilisk_election_find(int32_t createflag,bits256 hash)
{
int32_t i; uint32_t now = (uint32_t)time(NULL);
for (i=0; i<sizeof(Elections)/sizeof(*Elections); i++)
{
if ( Elections[i].expiration != 0 && now > Elections[i].expiration )
{
basilisk_electionsave(&Elections[i]);
memset(&Elections[i],0,sizeof(Elections[i]));
}
if ( bits256_nonz(hash) != 0 )
{
if ( bits256_nonz(Elections[i].hash) == 0 )
return(&Elections[i]);
else if ( bits256_cmp(Elections[i].hash,hash) == 0 )
return(0);
}
}
return(0);
}
int32_t basilisk_vote_extract(struct supernet_info *myinfo,char *coinaddr,struct vote_info *vote,cJSON *item)
{
char str[65],str2[65],str3[65]; uint8_t *sig,*pubkey; int32_t action,siglen,plen; bits256 data,hash;
memset(vote,0,sizeof(*vote));
if ( get_dataptr(0,&sig,&siglen,vote->sig,sizeof(vote->sig),jstr(item,"sig")) != 0 )
{
vote->siglen = siglen;
action = juint(item,"action");
if ( get_dataptr(0,&pubkey,&plen,vote->pubkey,sizeof(vote->pubkey),jstr(item,"pubkey")) != 0 )
{
bitcoin_address(coinaddr,5,pubkey,33);
data = jbits256(item,"data");
if ( bitcoin_verify(myinfo->ctx,vote->sig,vote->siglen,data,vote->pubkey,33) == 0 )
{
if ( (action & 0xff) == 'c' )
{
vote->commit = data;
printf("%s commits to %s\n",coinaddr,bits256_str(str,data));
return(action);
}
else if ( (action & 0xff) == 'r' )
{
if ( bits256_nonz(vote->commit) != 0 )
{
vcalc_sha256(0,hash.bytes,data.bytes,sizeof(data));
if ( bits256_cmp(hash,vote->commit) == 0 )
{
printf("%s vote %s -> %s matches commit %s\n",coinaddr,bits256_str(str,data),bits256_str(str2,hash),bits256_str(str3,vote->commit));
vote->vote = data;
// error check vote
return(action);
}
else
{
printf("%s vote %s -> %s doesnt match commit %s\n",coinaddr,bits256_str(str,data),bits256_str(str2,hash),bits256_str(str3,vote->commit));
return(-2);
}
}
}
} else return(-1);
}
}
return(-1);
}
char *basilisk_respond_VOT(struct supernet_info *myinfo,char *CMD,void *addr,char *remoteaddr,uint32_t basilisktag,cJSON *valsobj,uint8_t *data,int32_t datalen,bits256 hash,int32_t from_basilisk)
{
int32_t i,duration,winner,pending,action,numcandidates; char coinaddr[64],*symbol,*votemethod,*ballotstr; cJSON *item,*array,*electionobj,*ballot,*retjson; struct election_info *ep; struct vote_info vote,*vp; struct iguana_info *coin; int64_t *tally,max;
retjson = cJSON_CreateObject();
if ( (symbol= jstr(valsobj,"coin")) == 0 )
symbol = "BTCD";
coin = iguana_coinfind(symbol);
if ( (votemethod= jstr(valsobj,"votemethod")) != 0 )
{
if ( strcmp(votemethod,"create") == 0 )
{
if ( (ballot= jarray(&numcandidates,valsobj,"ballot")) != 0 && numcandidates > 0 )
{
if ( (duration= juint(valsobj,"duration")) == 0 )
duration = 3600;
ballotstr = jprint(ballot,0);
vcalc_sha256(0,hash.bytes,(uint8_t *)ballotstr,(int32_t)strlen(ballotstr));
free(ballotstr);
if ( (ep= basilisk_election_find(1,hash)) != 0 )
{
ep->hash = hash;
ep->duration = duration;
ep->expiration = (uint32_t)time(NULL) + duration;
ep->ballot = jduplicate(ballot);
ep->numcandidates = numcandidates;
safecopy(ep->name,jstr(valsobj,"name"),sizeof(ep->name));
if ( (electionobj= basilisk_electionjson(myinfo,coin,ep)) != 0 )
{
jaddstr(retjson,"result","success");
jadd(retjson,"election",electionobj);
} else jaddstr(retjson,"error","couldnt create election object");
} else jaddstr(retjson,"error","couldnt allocate election slot");
}
}
else if ( strcmp(votemethod,"list") == 0 )
{
array = cJSON_CreateArray();
for (i=0; i<sizeof(Elections)/sizeof(*Elections); i++)
{
if ( bits256_nonz(Elections[i].hash) != 0 )
{
item = cJSON_CreateObject();
jaddstr(item,"name",Elections[i].name);
jaddbits256(item,"hash",Elections[i].hash);
jaddi(array,item);
}
}
jaddstr(retjson,"result","success");
jadd(retjson,"elections",array);
}
if ( (ep= basilisk_election_find(0,hash)) != 0 )
{
if ( strcmp(votemethod,"info") == 0 )
{
jaddstr(retjson,"result","success");
tally = calloc(ep->numcandidates+1,sizeof(*tally));
pending = basilisk_election_process(myinfo,tally,coin,ep);
if ( pending != 0 )
jaddnum(retjson,"pending",pending);
jadd(retjson,"election",basilisk_electionjson(myinfo,coin,ep));
array = cJSON_CreateArray();
max = 0;
winner = -1;
for (i=1; i<=ep->numcandidates; i++)
{
if ( tally[i] > max )
{
max = tally[i];
winner = i;
}
jaddinum(array,dstr(tally[i]));
}
jadd(retjson,"tally",array);
if ( winner > 0 )
{
item = jitem(ep->ballot,winner-1);
jadd(retjson,"winner",item);
}
free(tally);
}
else if ( strcmp(votemethod,"ratify") == 0 )
{
// record ratification of tally
}
else if ( (action= basilisk_vote_extract(myinfo,coinaddr,&vote,valsobj)) > 0 )
{
vp = basilisk_vote_find(ep,&vote);
if ( strcmp(votemethod,"vote") == 0 )
{
if ( vp == 0 )
{
ep->votes = realloc(ep->votes,sizeof(*ep->votes) + (ep->numvotes + 1));
vote.repid = -1;
vote.stake = basilisk_voter_stake(myinfo,vote.rmd160,coin,vote.pubkey);
ep->votes[ep->numvotes++] = vote;
jaddstr(retjson,"result","success");
}
else if ( action == 'c' )
{
*vp = vote;
jaddstr(retjson,"result","success");
}
else if ( action == 'r' )
{
*vp = vote;
jaddstr(retjson,"result","success");
} else jaddstr(retjson,"error","illegal vote action");
}
else if ( strcmp(votemethod,"verify") == 0 )
{
if ( vp == 0 )
jaddstr(retjson,"error","cant find voter");
else if ( action == 'c' )
{
if ( bits256_cmp(vote.commit,vp->commit) == 0 )
jaddstr(retjson,"result","success");
else jaddstr(retjson,"error","mismatched commit");
jaddbits256(retjson,"oldcommit",vp->commit);
jaddbits256(retjson,"newcommit",vote.commit);
}
else if ( action == 'r' )
{
if ( bits256_cmp(vote.vote,vp->vote) == 0 )
jaddstr(retjson,"result","success");
else jaddstr(retjson,"error","mismatched vote");
jaddbits256(retjson,"oldvote",vp->vote);
jaddbits256(retjson,"newvote",vote.vote);
} else jaddstr(retjson,"error","illegal vote action");
} else jaddstr(retjson,"error","illegal vote method");
} else jaddstr(retjson,"error","couldnt extract vote info");
}
}
return(jprint(retjson,1));
}

2
datachain/datachain.c

@ -20,7 +20,7 @@ uint32_t datachain_checkpoint(struct supernet_info *myinfo,struct iguana_info *c
{
char str[65],str2[65]; struct iguana_info *btc = iguana_coinfind("BTC");
printf("datachain_checkpoint.%s for %s.%u to %u lastheight.%d %s\n",bits256_str(str,merkle),coin->symbol,lastcheckpoint,timestamp,lastheight,bits256_str(str2,lasthash2));
if ( (lastheight % NUMRELAYS) == RELAYID )
if ( (lastheight % myinfo->NOTARY.NUMRELAYS) == myinfo->NOTARY.RELAYID )
{
// if designated relay, submit checkpoint -> add ip/relayid to opreturn
//

2
gecko/gecko_blocks.c

@ -341,7 +341,7 @@ int32_t basilisk_blocksubmit(struct supernet_info *myinfo,struct iguana_info *bt
if ( jobj(retjson,"error") == 0 )
{
valsobj = cJSON_CreateObject();
jaddnum(valsobj,"numrequired",NUMRELAYS - 1);
jaddnum(valsobj,"numrequired",myinfo->NOTARY.NUMRELAYS - 1);
jaddnum(valsobj,"timeout",3000);
jaddnum(valsobj,"fanout",-1);
jaddnum(valsobj,"height",height);

16
gecko/gecko_mempool.c

@ -21,7 +21,7 @@ struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct igua
int32_t j,firstz,numother; bits256 *othertxids; struct gecko_mempool *otherpool = 0;
othertxids = 0;
numother = firstz = 0;
for (j=0; j<NUMRELAYS; j++)
for (j=0; j<myinfo->NOTARY.NUMRELAYS; j++)
{
if ( (otherpool= virt->mempools[j]) != 0 )
{
@ -44,22 +44,22 @@ struct gecko_mempool *gecko_mempoolfind(struct supernet_info *myinfo,struct igua
void gecko_mempool_sync(struct supernet_info *myinfo,struct iguana_info *virt,bits256 *reftxids,int32_t numtx)
{
int32_t i,j,k,n,num,numother; struct iguana_peer *addr; bits256 txid,*txids; struct gecko_mempool *pool,*otherpool; struct iguana_info *coin;
if ( (pool= virt->mempool) == 0 || NUMRELAYS <= 0 )
if ( (pool= virt->mempool) == 0 || myinfo->NOTARY.NUMRELAYS <= 0 )
return;
n = sqrt(NUMRELAYS) + 2;
if ( n > NUMRELAYS )
NUMRELAYS = n;
n = sqrt(myinfo->NOTARY.NUMRELAYS) + 2;
if ( n > myinfo->NOTARY.NUMRELAYS )
myinfo->NOTARY.NUMRELAYS = n;
i = (myinfo->myaddr.myipbits % n);
txids = calloc(pool->numtx,sizeof(bits256));
if ( virt->peers == 0 )
coin = iguana_coinfind("BTCD");
else coin = virt;
for (; i<NUMRELAYS; i+=n)
for (; i<myinfo->NOTARY.NUMRELAYS; i+=n)
{
printf("mempool_sync.%d\n",i);
if ( (addr= iguana_peerfindipbits(coin,RELAYS[i].ipbits,1)) != 0 )
if ( (addr= iguana_peerfindipbits(coin,myinfo->NOTARY.RELAYS[i].ipbits,1)) != 0 )
{
if ( (otherpool= gecko_mempoolfind(myinfo,virt,&numother,RELAYS[i].ipbits)) != 0 )
if ( (otherpool= gecko_mempoolfind(myinfo,virt,&numother,myinfo->NOTARY.RELAYS[i].ipbits)) != 0 )
{
for (j=num=0; j<pool->numtx; j++)
{

4
iguana/iguana777.c

@ -785,7 +785,7 @@ void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin)
}
sprintf(dirname,"%s/%s",GLOBAL_TMPDIR,symbol), OS_ensure_directory(dirname);
sprintf(dirname,"%s/%s/RT",GLOBAL_TMPDIR,coin->symbol), OS_ensure_directory(dirname);
iguana_coinstart(coin,coin->initialheight,coin->mapflags);
iguana_coinstart(myinfo,coin,coin->initialheight,coin->mapflags);
coin->chain->minconfirms = coin->minconfirms;
coin->started = coin;
coin->startutc = (uint32_t)time(NULL);
@ -846,7 +846,7 @@ void iguana_coinloop(void *arg)
if ( coin->MAXPEERS > IGUANA_MINPEERS )
coin->MAXPEERS = IGUANA_MINPEERS;
}
if ( RELAYID < 0 )
if ( myinfo->NOTARY.RELAYID < 0 )
{
if ( coin->bindsock >= 0 )
{

9
iguana/iguana777.h

@ -63,6 +63,12 @@ struct supernet_address
struct liquidity_info { char base[64],rel[64]; double profit,refprice; };
struct message_info { int32_t msgcount; bits256 refhash,msghashes[64]; uint32_t timestamps[64]; };
struct komodo_notaries
{
struct basilisk_relay RELAYS[BASILISK_MAXRELAYS];
int32_t NUMRELAYS,RELAYID;
};
struct supernet_info
{
struct supernet_address myaddr;
@ -70,7 +76,7 @@ struct supernet_info
uint8_t persistent_pubkey33[33];
char ipaddr[64],NXTAPIURL[512],secret[4096],password[4096],rpcsymbol[64],handle[1024],permanentfile[1024];
char *decryptstr;
int32_t maxdelay,IAMRELAY,IAMLP,publicRPC,basilisk_busy,genesisresults;
int32_t maxdelay,IAMRELAY,IAMNOTARY,IAMLP,publicRPC,basilisk_busy,genesisresults;
uint32_t expiration,dirty,DEXactive,DEXpoll;
uint16_t argport,rpcport;
struct basilisk_info basilisks;
@ -87,6 +93,7 @@ struct supernet_info
struct basilisk_spend *spends; int32_t numspends;
struct peggy_info *PEGS;
struct liquidity_info linfos[64];
struct komodo_notaries NOTARY;
// compatibility
bits256 pangea_category,instantdex_category;
uint8_t logs[256],exps[510];

6
iguana/iguana_chains.c

@ -321,7 +321,7 @@ void iguana_chainparms(struct supernet_info *myinfo,struct iguana_chain *chain,c
if ( juint(argjson,"p2p") != 0 )
chain->portp2p = juint(argjson,"p2p");
else chain->portp2p = juint(argjson,"portp2p");
if ( (chain->rpcport= juint(argjson,"rpc")) == 0 )
if ( (chain->rpcport= juint(argjson,"rpc")) == 0 && strcmp(chain->symbol,"NOTARY") != 0 )
{
if ( chain->portp2p != 0 )
chain->rpcport = chain->portp2p-1;
@ -504,7 +504,7 @@ void iguana_chaininit(struct supernet_info *myinfo,struct iguana_chain *chain,in
if ( strcmp(chain->symbol,"BTC") == 0 )
chain->bundlesize = 100;
decode_hex((uint8_t *)chain->genesis_hashdata,32,(char *)chain->genesis_hash);
if ( chain->rpcport == 0 )
if ( chain->rpcport == 0 && strcmp(chain->symbol,"NOTARY") != 0 )
chain->rpcport = chain->portp2p + 1;
}
@ -531,6 +531,8 @@ struct iguana_chain *iguana_chainfind(struct supernet_info *myinfo,char *name,cJ
}
}
chain = calloc(1,sizeof(*chain));
strcpy(chain->name,name);
strcpy(chain->symbol,name);
iguana_chaininit(myinfo,chain,1,argjson);
return(chain);
}

8
iguana/iguana_init.c

@ -515,9 +515,9 @@ void iguana_coinpurge(struct iguana_info *coin)
coin->active = saved;
}
struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags)
struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,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);
FILE *fp; char fname[512],*symbol; int32_t iter; long fpos; bits256 lastbundle;
/*if ( coin->peers == 0 )
{
printf("cant start privatechain directly\n");
@ -540,7 +540,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
printf("%s MYSERVICES.%llx\n",coin->symbol,(long long)coin->myservices);
if ( coin->virtualchain == 0 && coin->peers != 0 )
{
if ( (coin->myservices & NODE_NETWORK) != 0 || (coin->FULLNODE != 0 || coin->VALIDATENODE != 0) )
if ( myinfo->IAMNOTARY != 0 || (coin->myservices & NODE_NETWORK) != 0 || (coin->FULLNODE != 0 || coin->VALIDATENODE != 0) )
{
if ( coin->peers->acceptloop == 0 && coin->peers->localaddr == 0 )
{
@ -553,7 +553,7 @@ struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialhei
}
}
}
if ( coin->rpcloop == 0 )
if ( coin->rpcloop == 0 && strcmp(coin->chain->symbol,"NOTARY") != 0 )
{
myinfo->argport = coin->chain->rpcport;
coin->rpcloop = malloc(sizeof(pthread_t));

26
iguana/main.c

@ -80,7 +80,7 @@ struct supernet_info *SuperNET_MYINFO(char *passphrase)
OS_randombytes(MYINFO.privkey.bytes,sizeof(MYINFO.privkey));
MYINFO.myaddr.pubkey = curve25519(MYINFO.privkey,curve25519_basepoint9());
printf("SuperNET_MYINFO: generate session keypair\n");
RELAYID = -1;
MYINFO.NOTARY.RELAYID = -1;
}
if ( passphrase == 0 || passphrase[0] == 0 )
return(&MYINFO);
@ -1345,7 +1345,7 @@ STRING_ARG(SuperNET,priv2wif,priv)
STRING_ARG(SuperNET,myipaddr,ipaddr)
{
cJSON *retjson = cJSON_CreateObject();
RELAYID = -1;
myinfo->NOTARY.RELAYID = -1;
if ( myinfo->ipaddr[0] == 0 )
{
if ( is_ipaddr(ipaddr) != 0 )
@ -1356,10 +1356,10 @@ STRING_ARG(SuperNET,myipaddr,ipaddr)
}
}
jaddstr(retjson,"result",myinfo->ipaddr);
if ( RELAYID >= 0 )
if ( myinfo->IAMNOTARY != 0 && myinfo->NOTARY.RELAYID >= 0 )
{
jaddnum(retjson,"relayid",RELAYID);
jaddnum(retjson,"numrelays",NUMRELAYS);
jaddnum(retjson,"relayid",myinfo->NOTARY.RELAYID);
jaddnum(retjson,"numrelays",myinfo->NOTARY.NUMRELAYS);
}
return(jprint(retjson,1));
}
@ -1551,7 +1551,7 @@ FOUR_STRINGS(SuperNET,login,handle,password,permanentfile,passphrase)
void iguana_relays_init(struct supernet_info *myinfo)
{
static char *ipaddrs[] = { "89.248.160.237", "89.248.160.238", "89.248.160.239", "89.248.160.240", "89.248.160.241", "89.248.160.242", "89.248.160.243", "89.248.160.244" };
static char *ipaddrs[] = { "78.47.196.146", "5.9.102.210" };//"89.248.160.237", "89.248.160.238", "89.248.160.239", "89.248.160.240", "89.248.160.241", "89.248.160.242", "89.248.160.243", "89.248.160.244" };
char *str; int32_t i;
for (i=0; i<sizeof(ipaddrs)/sizeof(*ipaddrs); i++)
if ( (str= basilisk_addrelay_info(myinfo,0,(uint32_t)calc_ipbits(ipaddrs[i]),GENESIS_PUBKEY)) != 0 )
@ -1573,8 +1573,17 @@ void iguana_main(void *arg)
iguana_Qinit();
myinfo = SuperNET_MYINFO(0);
libgfshare_init(myinfo,myinfo->logs,myinfo->exps);
if ( arg != 0 && strcmp((char *)arg,"OStests") == 0 )
do_OStests = 1;
myinfo->rpcport = IGUANA_RPCPORT;
if ( arg != 0 )
{
if ( strcmp((char *)arg,"OStests") == 0 )
do_OStests = 1;
else if ( strcmp((char *)arg,"notary") == 0 )
{
myinfo->rpcport = IGUANA_NOTARYPORT;
myinfo->IAMNOTARY = 1;
}
}
#ifdef IGUANA_OSTESTS
do_OStests = 1;
#endif
@ -1585,7 +1594,6 @@ void iguana_main(void *arg)
printf("OStests retval %d\n",retval);
return;
}
myinfo->rpcport = IGUANA_RPCPORT;
strcpy(myinfo->rpcsymbol,"BTCD");
iguana_urlinit(myinfo,ismainnet,usessl);
#if LIQUIDITY_PROVIDER

2
includes/iguana_apideclares.h

@ -63,6 +63,8 @@ HASH_ARRAY_STRING(basilisk,VPNbroadcast,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNreceive,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,VPNlogout,hash,vals,hexstr);
HASH_ARRAY_STRING(basilisk,vote,hash,vals,hexstr);
ZERO_ARGS(bitcoinrpc,getinfo);
ZERO_ARGS(bitcoinrpc,getblockcount);
ZERO_ARGS(bitcoinrpc,getdifficulty);

1
includes/iguana_defines.h

@ -49,6 +49,7 @@
#define IGUANA_MINPENDBUNDLES 4
#define IGUANA_MAXPENDBUNDLES 64
#define IGUANA_RPCPORT 7778
#define IGUANA_NOTARYPORT 7776
#define IGUANA_MAXRAMCHAINSIZE ((uint64_t)1024L * 1024L * 1024L * 16)
#define IGUANA_MAPHASHTABLES 1

4
includes/iguana_funcs.h

@ -124,7 +124,7 @@ void iguana_coinargs(char *symbol,int64_t *maxrecvcachep,int32_t *minconfirmsp,i
struct iguana_info *iguana_setcoin(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,int32_t virtcoin);
// init
struct iguana_info *iguana_coinstart(struct iguana_info *coin,int32_t initialheight,int32_t mapflags);
struct iguana_info *iguana_coinstart(struct supernet_info *myinfo,struct iguana_info *coin,int32_t initialheight,int32_t mapflags);
void iguana_callcoinstart(struct supernet_info *myinfo,struct iguana_info *coin);
void iguana_initcoin(struct iguana_info *coin,cJSON *argjson);
void iguana_coinloop(void *arg);
@ -558,7 +558,7 @@ struct iguana_peer *iguana_peerfindipbits(struct iguana_info *coin,uint32_t ipbi
int32_t basilisk_hashes_send(struct supernet_info *myinfo,struct iguana_info *virt,struct iguana_peer *addr,char *CMD,bits256 *txids,int32_t num);
int32_t iguana_opreturn(struct supernet_info *myinfo,int32_t ordered,struct iguana_info *coin,uint32_t timestamp,struct iguana_bundle *bp,int64_t crypto777_payment,int32_t height,uint64_t hdrsi_unspentind,int64_t payment,uint32_t fileid,uint64_t scriptpos,uint32_t scriptlen);
int32_t iguana_scriptdata(struct iguana_info *coin,uint8_t *scriptspace,long fileptr[2],char *fname,uint64_t scriptpos,int32_t scriptlen);
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *btcd,uint32_t ipbits);
struct iguana_peer *basilisk_ensurerelay(struct supernet_info *myinfo,struct iguana_info *notaries,uint32_t ipbits);
int32_t iguana_datachain_scan(struct supernet_info *myinfo,struct iguana_info *coin,uint8_t rmd160[20]);
void iguana_RTreset(struct iguana_info *coin);

4
includes/iguana_globals.h

@ -54,8 +54,8 @@ int32_t IGUANA_NUMHELPERS = 1;
// ALL globals must be here!
CONDEXTERN struct basilisk_relay RELAYS[BASILISK_MAXRELAYS];
CONDEXTERN int32_t NUMRELAYS,RELAYID;
//CONDEXTERN struct basilisk_relay RELAYS[BASILISK_MAXRELAYS];
//CONDEXTERN int32_t NUMRELAYS,RELAYID;
CONDEXTERN char *COMMANDLINE_ARGFILE;
CONDEXTERN char *Iguana_validcommands[];

Loading…
Cancel
Save