Browse Source

Sane stop, reduce redundancy

dev
jl777 7 years ago
parent
commit
11b63d1bf3
  1. 3
      iguana/exchanges/LP_commands.c
  2. 22
      iguana/exchanges/LP_nativeDEX.c
  3. 4
      iguana/exchanges/LP_network.c
  4. 10
      iguana/exchanges/LP_ordermatch.c
  5. 14
      iguana/exchanges/LP_peers.c
  6. 2
      iguana/exchanges/LP_portfolio.c
  7. 2
      iguana/exchanges/LP_remember.c
  8. 2
      iguana/exchanges/LP_scan.c
  9. 1
      iguana/exchanges/LP_signatures.c
  10. 6
      iguana/exchanges/stats.c

3
iguana/exchanges/LP_commands.c

@ -268,7 +268,8 @@ jpg(srcfile, destfile, power2=7, passphrase, data="", required)\n\
else if ( strcmp(method,"stop") == 0 ) else if ( strcmp(method,"stop") == 0 )
{ {
printf("DEBUG stop\n"); printf("DEBUG stop\n");
exit(0); LP_STOP_RECEIVED = 1;
return(clonestr("{\"result\":\"success\"}"));
} }
else if ( strcmp(method,"millis") == 0 ) else if ( strcmp(method,"millis") == 0 )
{ {

22
iguana/exchanges/LP_nativeDEX.c

@ -100,7 +100,7 @@ struct LP_trade *LP_trades,*LP_tradesQ;
//uint32_t LP_deadman_switch; //uint32_t LP_deadman_switch;
uint16_t LP_fixed_pairport,LP_publicport; uint16_t LP_fixed_pairport,LP_publicport;
uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount; uint32_t LP_lastnonce,LP_swap_endcritical,LP_swap_critical,LP_RTcount,LP_swapscount;
int32_t LP_mybussock = -1; int32_t LP_STOP_RECEIVED,LP_numactive_LP,LP_mybussock = -1;
int32_t LP_mypubsock = -1; int32_t LP_mypubsock = -1;
int32_t LP_mypullsock = -1; int32_t LP_mypullsock = -1;
int32_t LP_numfinished,LP_showwif,IAMLP = 0; int32_t LP_numfinished,LP_showwif,IAMLP = 0;
@ -480,7 +480,7 @@ void command_rpcloop(void *ctx)
int32_t nonz = 0; int32_t nonz = 0;
strcpy(command_rpcloop_stats.name,"command_rpcloop"); strcpy(command_rpcloop_stats.name,"command_rpcloop");
command_rpcloop_stats.threshold = 2500.; command_rpcloop_stats.threshold = 2500.;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
LP_millistats_update(&command_rpcloop_stats); LP_millistats_update(&command_rpcloop_stats);
nonz = LP_nanomsg_recvs(ctx); nonz = LP_nanomsg_recvs(ctx);
@ -515,7 +515,7 @@ void LP_coinsloop(void *_coins)
strcpy(LP_coinsloop_stats.name,"other coins loop"); strcpy(LP_coinsloop_stats.name,"other coins loop");
LP_coinsloop_stats.threshold = 5000.; LP_coinsloop_stats.threshold = 5000.;
} }
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( strcmp("BTC",coins) == 0 ) if ( strcmp("BTC",coins) == 0 )
LP_millistats_update(&LP_coinsloopBTC_stats); LP_millistats_update(&LP_coinsloopBTC_stats);
@ -874,7 +874,7 @@ void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint
//LP_addpeer(mypeer,pubsock,"51.15.86.136",myport,pushport,subport,0,G.LP_sessionid); //LP_addpeer(mypeer,pubsock,"51.15.86.136",myport,pushport,subport,0,G.LP_sessionid);
OS_randombytes((void *)&r,sizeof(r)); OS_randombytes((void *)&r,sizeof(r));
//r = 0; //r = 0;
for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes); j++) for (j=0; j<sizeof(default_LPnodes)/sizeof(*default_LPnodes)&&j<5; j++)
{ {
i = (r + j) % (sizeof(default_LPnodes)/sizeof(*default_LPnodes)); i = (r + j) % (sizeof(default_LPnodes)/sizeof(*default_LPnodes));
LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid); LP_addpeer(mypeer,pubsock,default_LPnodes[i],myport,pushport,subport,0,G.LP_sessionid);
@ -891,7 +891,7 @@ void LP_pubkeysloop(void *ctx)
strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop"); strcpy(LP_pubkeysloop_stats.name,"LP_pubkeysloop");
LP_pubkeysloop_stats.threshold = 15000.; LP_pubkeysloop_stats.threshold = 15000.;
sleep(10); sleep(10);
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
LP_millistats_update(&LP_pubkeysloop_stats); LP_millistats_update(&LP_pubkeysloop_stats);
if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 ) if ( time(NULL) > lasttime+LP_ORDERBOOK_DURATION*0.5 )
@ -910,7 +910,7 @@ void LP_swapsloop(void *ctx)
strcpy(LP_swapsloop_stats.name,"LP_swapsloop"); strcpy(LP_swapsloop_stats.name,"LP_swapsloop");
LP_swapsloop_stats.threshold = 605000.; LP_swapsloop_stats.threshold = 605000.;
sleep(50); sleep(50);
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
LP_millistats_update(&LP_swapsloop_stats); LP_millistats_update(&LP_swapsloop_stats);
if ( (retstr= basilisk_swapentry(0,0,0)) != 0 ) if ( (retstr= basilisk_swapentry(0,0,0)) != 0 )
@ -924,7 +924,7 @@ void gc_loop(void *ctx)
uint32_t now; struct LP_address_utxo *up,*utmp; struct rpcrequest_info *req,*rtmp; int32_t flag = 0; uint32_t now; struct LP_address_utxo *up,*utmp; struct rpcrequest_info *req,*rtmp; int32_t flag = 0;
strcpy(LP_gcloop_stats.name,"gc_loop"); strcpy(LP_gcloop_stats.name,"gc_loop");
LP_gcloop_stats.threshold = 11000.; LP_gcloop_stats.threshold = 11000.;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
flag = 0; flag = 0;
LP_millistats_update(&LP_gcloop_stats); LP_millistats_update(&LP_gcloop_stats);
@ -959,7 +959,7 @@ void queue_loop(void *ctx)
struct LP_queue *ptr,*tmp; cJSON *json; uint8_t linebuf[32768]; int32_t k,sentbytes,nonz,flag,duplicate,n=0; struct LP_queue *ptr,*tmp; cJSON *json; uint8_t linebuf[32768]; int32_t k,sentbytes,nonz,flag,duplicate,n=0;
strcpy(queue_loop_stats.name,"queue_loop"); strcpy(queue_loop_stats.name,"queue_loop");
queue_loop_stats.threshold = 1000.; queue_loop_stats.threshold = 1000.;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
LP_millistats_update(&queue_loop_stats); LP_millistats_update(&queue_loop_stats);
//printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0); //printf("LP_Q.%p next.%p prev.%p\n",LP_Q,LP_Q!=0?LP_Q->next:0,LP_Q!=0?LP_Q->prev:0);
@ -1068,7 +1068,7 @@ void LP_reserved_msgs(void *ignore)
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
strcpy(LP_reserved_msgs_stats.name,"LP_reserved_msgs"); strcpy(LP_reserved_msgs_stats.name,"LP_reserved_msgs");
LP_reserved_msgs_stats.threshold = 150.; LP_reserved_msgs_stats.threshold = 150.;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
nonz = 0; nonz = 0;
LP_millistats_update(&LP_reserved_msgs_stats); LP_millistats_update(&LP_reserved_msgs_stats);
@ -1362,7 +1362,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
int32_t nonz; int32_t nonz;
LP_statslog_parse(); LP_statslog_parse();
bitcoind_RPC_inittime = 0; bitcoind_RPC_inittime = 0;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
nonz = 0; nonz = 0;
G.waiting = 1; G.waiting = 1;
@ -1379,6 +1379,8 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
usleep(1000); usleep(1000);
} }
#endif #endif
sleep(5);
printf("marketmaker exiting in 5 seconds\n");
} }
#ifdef FROM_JS #ifdef FROM_JS

4
iguana/exchanges/LP_network.c

@ -213,7 +213,7 @@ int32_t LP_magic_check(uint8_t *msg,int32_t recvlen,char *remoteaddr)
int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32) int32_t LP_crc32find(int32_t *duplicatep,int32_t ind,uint32_t crc32)
{ {
static uint32_t crcs[4096]; static unsigned long dup,total; static uint32_t crcs[16384]; static unsigned long dup,total;
int32_t i; int32_t i;
*duplicatep = 0; *duplicatep = 0;
if ( ind < 0 ) if ( ind < 0 )
@ -416,7 +416,7 @@ void LP_psockloop(void *_ptr) // printouts seem to be needed for forwarding to w
int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512]; int32_t i,n,nonz,iter,retval,sentbytes,size=0,sendsock = -1; uint32_t now; struct psock *ptr=0; void *buf=0; char keepalive[512];
strcpy(LP_psockloop_stats.name,"LP_psockloop"); strcpy(LP_psockloop_stats.name,"LP_psockloop");
LP_psockloop_stats.threshold = 200.; LP_psockloop_stats.threshold = 200.;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
LP_millistats_update(&LP_psockloop_stats); LP_millistats_update(&LP_psockloop_stats);
now = (uint32_t)time(NULL); now = (uint32_t)time(NULL);

10
iguana/exchanges/LP_ordermatch.c

@ -481,11 +481,9 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,char *base,char *rel,double
bits256 zero; bits256 zero;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,base,rel,zero,jprint(reqjson,0)); LP_reserved_msg(1,base,rel,zero,jprint(reqjson,0));
//if ( IAMLP == 0 )
{
sleep(1); sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
} sleep(1);
LP_reserved_msg(0,base,rel,zero,jprint(reqjson,0)); LP_reserved_msg(0,base,rel,zero,jprint(reqjson,0));
free_json(reqjson); free_json(reqjson);
LP_importaddress(qp->destcoin,qp->destaddr); LP_importaddress(qp->destcoin,qp->destaddr);
@ -910,12 +908,12 @@ struct LP_quoteinfo *LP_trades_gotrequest(void *ctx,struct LP_quoteinfo *qp,stru
bits256 zero; bits256 zero;
memset(zero.bytes,0,sizeof(zero)); memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
//if ( IAMLP == 0 ) if ( 0 )//if ( IAMLP == 0 )
{ {
sleep(1); sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,qp->desthash,jprint(reqjson,0));
} }
LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0)); //LP_reserved_msg(0,qp->srccoin,qp->destcoin,zero,jprint(reqjson,0));
free_json(reqjson); free_json(reqjson);
return(qp); return(qp);
} else printf("request processing selected ineligible utxos?\n"); } else printf("request processing selected ineligible utxos?\n");
@ -1016,7 +1014,7 @@ void LP_tradesloop(void *ctx)
strcpy(LP_tradesloop_stats.name,"LP_tradesloop"); strcpy(LP_tradesloop_stats.name,"LP_tradesloop");
LP_tradesloop_stats.threshold = 10000; LP_tradesloop_stats.threshold = 10000;
sleep(5); sleep(5);
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
LP_millistats_update(&LP_tradesloop_stats); LP_millistats_update(&LP_tradesloop_stats);
nonz = 0; nonz = 0;

14
iguana/exchanges/LP_peers.c

@ -68,8 +68,11 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
{ {
if ( (peer= LP_peerfind(ipbits,port)) != 0 ) if ( (peer= LP_peerfind(ipbits,port)) != 0 )
{ {
if ( isLP != 0 ) if ( isLP != 0 && peer->isLP == 0 )
peer->isLP = isLP; {
if ( (peer->isLP= isLP) != 0 )
LP_numactive_LP++;
}
/*if ( numpeers > peer->numpeers ) /*if ( numpeers > peer->numpeers )
peer->numpeers = numpeers; peer->numpeers = numpeers;
if ( numutxos > peer->numutxos ) if ( numutxos > peer->numutxos )
@ -77,7 +80,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( peer->sessionid == 0 ) if ( peer->sessionid == 0 )
peer->sessionid = sessionid;*/ peer->sessionid = sessionid;*/
} }
else else if ( IAMLP != 0 || LP_numactive_LP < 3 )
{ {
//printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport); //printf("addpeer (%s:%u) pushport.%u subport.%u\n",ipaddr,port,pushport,subport);
peer = calloc(1,sizeof(*peer)); peer = calloc(1,sizeof(*peer));
@ -88,7 +91,8 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
strcpy(peer->ipaddr,ipaddr); strcpy(peer->ipaddr,ipaddr);
//peer->profitmargin = profitmargin; //peer->profitmargin = profitmargin;
peer->ipbits = ipbits; peer->ipbits = ipbits;
peer->isLP = isLP; if ( (peer->isLP= isLP) != 0 )
LP_numactive_LP++;
peer->port = port; peer->port = port;
peer->ip_port = ((uint64_t)port << 32) | ipbits; peer->ip_port = ((uint64_t)port << 32) | ipbits;
if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 ) if ( pushport != 0 && subport != 0 && (pushsock= nn_socket(AF_SP,NN_PUSH)) >= 0 )
@ -124,7 +128,7 @@ struct LP_peerinfo *LP_addpeer(struct LP_peerinfo *mypeer,int32_t mypubsock,char
if ( valid > 0 ) if ( valid > 0 )
{ {
peer->subsock = subsock; peer->subsock = subsock;
printf("connected to sub.(%s) subsock.%d valid.%d\n",subaddr,peer->subsock,valid); printf("connected to sub.(%s) subsock.%d valid.%d numactive.%d\n",subaddr,peer->subsock,valid,LP_numactive_LP);
} }
else else
{ {

2
iguana/exchanges/LP_portfolio.c

@ -869,7 +869,7 @@ void prices_loop(void *ctx)
char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp; char *retstr; cJSON *retjson,*array; char *buycoin,*sellcoin; struct iguana_info *buy,*sell; uint32_t requestid,quoteid; int32_t i,n,m; struct LP_portfoliotrade trades[256]; struct LP_priceinfo *btcpp;
strcpy(prices_loop_stats.name,"prices_loop"); strcpy(prices_loop_stats.name,"prices_loop");
prices_loop_stats.threshold = 191000.; prices_loop_stats.threshold = 191000.;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
//printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs); //printf("prices loop autoprices.%d autorefs.%d\n",LP_autoprices,num_LP_autorefs);
LP_millistats_update(&prices_loop_stats); LP_millistats_update(&prices_loop_stats);

2
iguana/exchanges/LP_remember.c

@ -489,7 +489,7 @@ cJSON *LP_swap_json(struct LP_swap_remember *rswap)
item = cJSON_CreateObject(); item = cJSON_CreateObject();
if ( LP_swap_endcritical < LP_swap_critical ) if ( LP_swap_endcritical < LP_swap_critical )
{ {
jaddstr(item,"warning","swaps in critical section"); jaddstr(item,"warning","swaps in critical section, dont exit now");
jaddnum(item,"critical",LP_swap_critical); jaddnum(item,"critical",LP_swap_critical);
jaddnum(item,"endcritical",LP_swap_endcritical); jaddnum(item,"endcritical",LP_swap_endcritical);
} }

2
iguana/exchanges/LP_scan.c

@ -453,7 +453,7 @@ int32_t LP_waitmempool(char *symbol,char *coinaddr,bits256 txid,int32_t vout,int
return(-1); return(-1);
} }
expiration = (uint32_t)time(NULL) + duration; expiration = (uint32_t)time(NULL) + duration;
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( LP_gettx_presence(symbol,txid) != 0 ) if ( LP_gettx_presence(symbol,txid) != 0 )
numconfirms = 0; numconfirms = 0;

1
iguana/exchanges/LP_signatures.c

@ -676,6 +676,7 @@ void LP_query(void *ctx,char *myipaddr,int32_t mypubsock,char *method,struct LP_
memset(&zero,0,sizeof(zero)); memset(&zero,0,sizeof(zero));
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));
//if ( strcmp(method,"request") == 0 ) //if ( strcmp(method,"request") == 0 )
if ( 0 )
{ {
sleep(1); sleep(1);
LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg)); LP_reserved_msg(1,qp->srccoin,qp->destcoin,zero,clonestr(msg));

6
iguana/exchanges/stats.c

@ -771,7 +771,7 @@ void LP_rpc_processreq(void *_ptr)
spawned--; spawned--;
} }
extern int32_t IAMLP; extern int32_t IAMLP,LP_STOP_RECEIVED;
//int32_t LP_bindsock_reset,LP_bindsock = -1; //int32_t LP_bindsock_reset,LP_bindsock = -1;
void stats_rpcloop(void *args) void stats_rpcloop(void *args)
@ -782,7 +782,7 @@ void stats_rpcloop(void *args)
printf("Start stats_rpcloop.%u\n",port); printf("Start stats_rpcloop.%u\n",port);
localhostbits = (uint32_t)calc_ipbits("127.0.0.1"); localhostbits = (uint32_t)calc_ipbits("127.0.0.1");
//initial_bindsock_reset = LP_bindsock_reset; //initial_bindsock_reset = LP_bindsock_reset;
while ( 1 )//LP_bindsock_reset == initial_bindsock_reset ) while ( LP_STOP_RECEIVED == 0 )//LP_bindsock_reset == initial_bindsock_reset )
{ {
//printf("LP_bindsock.%d\n",LP_bindsock); //printf("LP_bindsock.%d\n",LP_bindsock);
if ( bindsock < 0 ) if ( bindsock < 0 )
@ -1196,7 +1196,7 @@ int main(int argc, const char * argv[])
exit(-1); exit(-1);
} }
printf("DEX stats running\n"); printf("DEX stats running\n");
while ( 1 ) while ( LP_STOP_RECEIVED == 0 )
{ {
if ( (filestr= stats_update(logfp,STATS_DEST,statefname,komodofile)) != 0 ) if ( (filestr= stats_update(logfp,STATS_DEST,statefname,komodofile)) != 0 )
{ {

Loading…
Cancel
Save