From 053bb32ce7bf881216e7293389ee63ea61b3edc3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 06:32:38 +0200 Subject: [PATCH 01/20] Pub key -> destpubkey --- iguana/exchanges/LP_bitcoin.c | 12 ++++++++++++ iguana/exchanges/LP_commands.c | 8 ++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_bitcoin.c b/iguana/exchanges/LP_bitcoin.c index 1c2c5d0c5..0eef539d1 100644 --- a/iguana/exchanges/LP_bitcoin.c +++ b/iguana/exchanges/LP_bitcoin.c @@ -1959,6 +1959,18 @@ int32_t bitcoin_timelockspend(uint8_t *script,int32_t n,uint8_t rmd160[20],uint3 return(n); } +int32_t bitcoin_performancebond(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,uint32_t unlocktimestamp,uint8_t cltv_rmd160[20],uint8_t anytime_rmd160[20]) +{ + script[n++] = SCRIPT_OP_IF; + n = bitcoin_checklocktimeverify(script,n,unlocktimestamp); + n = bitcoin_standardspend(script,n,cltv_rmd160); + script[n++] = SCRIPT_OP_ELSE; + n = bitcoin_standardspend(script,n,anytime_rmd160); + script[n++] = SCRIPT_OP_ENDIF; + calc_rmd160_sha256(p2sh_rmd160,script,n); + return(n); +} + int32_t bitcoin_MofNspendscript(uint8_t p2sh_rmd160[20],uint8_t *script,int32_t n,const struct vin_info *vp) { int32_t i,plen; diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index fe60a38a3..831f81ccb 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -111,8 +111,8 @@ getrawtransaction(coin, txid)\n\ inventory(coin)\n\ bestfit(rel, relvolume)\n\ lastnonce()\n\ -buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, pubkey="")\n\ -sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce, pubkey="")\n\ +buy(base, rel, price, relvolume, timeout=10, duration=3600, nonce, destpubkey="")\n\ +sell(base, rel, price, basevolume, timeout=10, duration=3600, nonce, destpubkey="")\n\ withdraw(coin, outputs[])\n\ sendrawtransaction(coin, signedtx)\n\ swapstatus()\n\ @@ -306,7 +306,7 @@ bot_resume(botid)\n\ //* if ( price > SMALLVAL ) { - return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"pubkey"),0)); + return(LP_autobuy(ctx,myipaddr,pubsock,base,rel,price,jdouble(argjson,"relvolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0)); } else return(clonestr("{\"error\":\"no price set\"}")); } else if ( strcmp(method,"sell") == 0 ) @@ -314,7 +314,7 @@ bot_resume(botid)\n\ //* if ( price > SMALLVAL ) { - return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"pubkey"),0)); + return(LP_autobuy(ctx,myipaddr,pubsock,rel,base,1./price,jdouble(argjson,"basevolume"),jint(argjson,"timeout"),jint(argjson,"duration"),jstr(argjson,"gui"),juint(argjson,"nonce"),jbits256(argjson,"destpubkey"),0)); } else return(clonestr("{\"error\":\"no price set\"}")); } } From ef30184405157ccf78b77d670b858c386653e6ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 10:50:26 +0200 Subject: [PATCH 02/20] Test --- iguana/exchanges/LP_nativeDEX.c | 8 +++++++- iguana/exchanges/LP_network.c | 26 ++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 8a4109323..9a6809a04 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -29,7 +29,7 @@ struct LP_millistats double lastmilli,millisum,threshold; uint32_t count; char name[64]; -} LP_psockloop_stats,LP_reserved_msgs_stats,utxosQ_loop_stats,command_rpcloop_stats,queue_loop_stats,prices_loop_stats,LP_coinsloop_stats,LP_coinsloopBTC_stats,LP_coinsloopKMD_stats,LP_pubkeysloop_stats,LP_privkeysloop_stats,LP_swapsloop_stats; +} LP_psockloop_stats,LP_reserved_msgs_stats,utxosQ_loop_stats,command_rpcloop_stats,queue_loop_stats,prices_loop_stats,LP_coinsloop_stats,LP_coinsloopBTC_stats,LP_coinsloopKMD_stats,LP_pubkeysloop_stats,LP_privkeysloop_stats,LP_swapsloop_stats,LP_gcloop_stats; extern int32_t IAMLP; void LP_millistats_update(struct LP_millistats *mp) @@ -52,6 +52,7 @@ void LP_millistats_update(struct LP_millistats *mp) mp = &LP_pubkeysloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count); mp = &LP_privkeysloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count); mp = &LP_swapsloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count); + mp = &LP_gcloop_stats, printf("%32s lag %10.2f millis, threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,OS_milliseconds() - mp->lastmilli,mp->threshold,mp->millisum/(mp->count > 0 ? mp->count: 1),mp->count); } else { @@ -1112,6 +1113,11 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu printf("error launching queue_loop for port.%u\n",myport); exit(-1); } + if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)gc_loop,(void *)myipaddr) != 0 ) + { + printf("error launching gc_loop for port.%u\n",myport); + exit(-1); + } if ( OS_thread_create(malloc(sizeof(pthread_t)),NULL,(void *)prices_loop,ctx) != 0 ) { printf("error launching prices_loop for port.%u\n",myport); diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 797c31d04..1e207c2dc 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -265,23 +265,37 @@ int32_t LP_peerindsock(int32_t *peerindp) return(-1); } -void queue_loop(void *arg) +void gc_loop(void *arg) { - struct rpcrequest_info *req,*rtmp; struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; - strcpy(queue_loop_stats.name,"queue_loop"); - queue_loop_stats.threshold = 500.; + struct rpcrequest_info *req,*rtmp; int32_t flag = 0; + strcpy(queue_loop_stats.name,"gc_loop"); + queue_loop_stats.threshold = 50.; while ( 1 ) { - LP_millistats_update(&queue_loop_stats); + flag = 0; + LP_millistats_update(&LP_gcloop_stats); portable_mutex_lock(&LP_networkmutex); DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) { DL_DELETE(LP_garbage_collector,req); //printf("garbage collect ipbits.%x\n",req->ipbits); free(req); + flag++; } portable_mutex_unlock(&LP_networkmutex); + if ( flag == 0 ) + usleep(25000); + } +} +void queue_loop(void *arg) +{ + struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; + strcpy(queue_loop_stats.name,"queue_loop"); + queue_loop_stats.threshold = 500.; + while ( 1 ) + { + LP_millistats_update(&queue_loop_stats); nonz = 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); n = 0; @@ -291,7 +305,7 @@ void queue_loop(void *arg) flag = 0; if ( ptr->sock >= 0 ) { - if ( LP_sockcheck(ptr->sock) > 0 ) + //if ( LP_sockcheck(ptr->sock) > 0 ) { bits256 magic; magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256))); From eb1207676cbc8a09e096881f5495805e117bf44b Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 10:50:58 +0200 Subject: [PATCH 03/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 1e207c2dc..fa803467d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,7 +269,7 @@ void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(queue_loop_stats.name,"gc_loop"); - queue_loop_stats.threshold = 50.; + queue_loop_stats.threshold = 27.; while ( 1 ) { flag = 0; From 84475181967899fd98a6826d0c55decd6fadfd7d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 10:51:27 +0200 Subject: [PATCH 04/20] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index fa803467d..9d8bbb46d 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,7 +269,7 @@ void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(queue_loop_stats.name,"gc_loop"); - queue_loop_stats.threshold = 27.; + queue_loop_stats.threshold = 26.; while ( 1 ) { flag = 0; @@ -292,7 +292,7 @@ void queue_loop(void *arg) { struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; strcpy(queue_loop_stats.name,"queue_loop"); - queue_loop_stats.threshold = 500.; + queue_loop_stats.threshold = 50.; while ( 1 ) { LP_millistats_update(&queue_loop_stats); From e73be6059706d121d7ca89c5a486ec5447915cee Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 10:52:58 +0200 Subject: [PATCH 05/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 9d8bbb46d..a2d4ae860 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -305,7 +305,7 @@ void queue_loop(void *arg) flag = 0; if ( ptr->sock >= 0 ) { - //if ( LP_sockcheck(ptr->sock) > 0 ) + if ( LP_sockcheck(ptr->sock) > 0 ) { bits256 magic; magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256))); From 2e036b4873247db8128c9b99ef36c9204ac819fe Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 10:58:12 +0200 Subject: [PATCH 06/20] Test --- iguana/exchanges/LP_network.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index a2d4ae860..bccc03ce0 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,7 +269,7 @@ void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(queue_loop_stats.name,"gc_loop"); - queue_loop_stats.threshold = 26.; + queue_loop_stats.threshold = 6.; while ( 1 ) { flag = 0; @@ -284,7 +284,8 @@ void gc_loop(void *arg) } portable_mutex_unlock(&LP_networkmutex); if ( flag == 0 ) - usleep(25000); + usleep(5000); + else printf("gc_loop.%d\n",flag); } } @@ -292,15 +293,15 @@ void queue_loop(void *arg) { struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; strcpy(queue_loop_stats.name,"queue_loop"); - queue_loop_stats.threshold = 50.; + queue_loop_stats.threshold = 11.; while ( 1 ) { LP_millistats_update(&queue_loop_stats); - nonz = 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); - n = 0; + n = nonz = 0; DL_FOREACH_SAFE(LP_Q,ptr,tmp) { + nonz = 0; n++; flag = 0; if ( ptr->sock >= 0 ) @@ -348,6 +349,7 @@ void queue_loop(void *arg) portable_mutex_unlock(&LP_networkmutex); free(ptr); ptr = 0; + break; } } if ( arg == 0 ) @@ -355,10 +357,7 @@ void queue_loop(void *arg) //if ( n != 0 ) // printf("LP_Q.[%d]\n",n); if ( nonz == 0 ) - usleep(25000); - else if ( IAMLP == 0 ) usleep(10000); - else usleep(1000); } } From 8dadab25e5dcb4ae2e49532f418e71135da6c869 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:00:13 +0200 Subject: [PATCH 07/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index bccc03ce0..6aee50faf 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,7 +269,7 @@ void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(queue_loop_stats.name,"gc_loop"); - queue_loop_stats.threshold = 6.; + queue_loop_stats.threshold = 12.; while ( 1 ) { flag = 0; From a1316241883868afbad3e19b618561124622bd40 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:19:01 +0200 Subject: [PATCH 08/20] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_network.c | 15 +++++++-------- iguana/exchanges/stats.c | 12 +++++------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 9a6809a04..24f1cf450 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -75,7 +75,7 @@ void LP_millistats_update(struct LP_millistats *mp) } #include "LP_include.h" -portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex; +portable_mutex_t LP_peermutex,LP_UTXOmutex,LP_utxomutex,LP_commandmutex,LP_cachemutex,LP_swaplistmutex,LP_forwardmutex,LP_pubkeymutex,LP_networkmutex,LP_psockmutex,LP_coinmutex,LP_messagemutex,LP_portfoliomutex,LP_electrummutex,LP_butxomutex,LP_reservedmutex,LP_nanorecvsmutex,LP_tradebotsmutex,LP_gcmutex; int32_t LP_canbind; char *Broadcaststr,*Reserved_msgs[2][1000]; int32_t num_Reserved_msgs[2],max_Reserved_msgs[2]; @@ -995,6 +995,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_swaplistmutex); portable_mutex_init(&LP_cachemutex); portable_mutex_init(&LP_networkmutex); + portable_mutex_init(&LP_gcmutex); portable_mutex_init(&LP_forwardmutex); portable_mutex_init(&LP_psockmutex); portable_mutex_init(&LP_coinmutex); diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 6aee50faf..596f7ba75 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -274,7 +274,7 @@ void gc_loop(void *arg) { flag = 0; LP_millistats_update(&LP_gcloop_stats); - portable_mutex_lock(&LP_networkmutex); + portable_mutex_lock(&LP_gcmutex); DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) { DL_DELETE(LP_garbage_collector,req); @@ -282,10 +282,10 @@ void gc_loop(void *arg) free(req); flag++; } - portable_mutex_unlock(&LP_networkmutex); + portable_mutex_unlock(&LP_gcmutex); if ( flag == 0 ) usleep(5000); - else printf("gc_loop.%d\n",flag); + //else printf("gc_loop.%d\n",flag); } } @@ -301,7 +301,6 @@ void queue_loop(void *arg) n = nonz = 0; DL_FOREACH_SAFE(LP_Q,ptr,tmp) { - nonz = 0; n++; flag = 0; if ( ptr->sock >= 0 ) @@ -313,10 +312,10 @@ void queue_loop(void *arg) memcpy(&ptr->msg[ptr->msglen - sizeof(bits256)],&magic,sizeof(magic)); if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); + else flag++; ptr->sock = -1; if ( ptr->peerind > 0 ) ptr->starttime = (uint32_t)time(NULL); - else flag = 1; } //else printf("sock not ready to send.%d\n",ptr->msglen); } else if ( 0 && time(NULL) > ptr->starttime+13 ) @@ -327,7 +326,7 @@ void queue_loop(void *arg) LP_Qfound++; if ( (LP_Qfound % 100) == 0 ) printf("found.%u Q.%d err.%d match.%d\n",ptr->crc32,LP_Qenqueued,LP_Qerrors,LP_Qfound); - flag = 1; + flag++; } else if ( 0 ) // too much beyond duplicate filter when network is busy { @@ -336,7 +335,7 @@ void queue_loop(void *arg) if ( (ptr->sock= LP_peerindsock(&ptr->peerind)) < 0 ) { printf("%d no more peers to try at peerind.%d %p Q_LP.%p\n",n,ptr->peerind,ptr,LP_Q); - flag = 1; + flag++; LP_Qerrors++; } } @@ -349,7 +348,6 @@ void queue_loop(void *arg) portable_mutex_unlock(&LP_networkmutex); free(ptr); ptr = 0; - break; } } if ( arg == 0 ) @@ -358,6 +356,7 @@ void queue_loop(void *arg) // printf("LP_Q.[%d]\n",n); if ( nonz == 0 ) usleep(10000); + else printf("queue_loop nonz.%d flag.%d n.%d\n",nonz,flag,n); } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 37514e596..2cc747ae0 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -589,7 +589,7 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) } uint16_t RPC_port; -extern portable_mutex_t LP_commandmutex,LP_networkmutex; +extern portable_mutex_t LP_commandmutex,LP_gcmutex; extern struct rpcrequest_info *LP_garbage_collector; void LP_rpc_processreq(void *_ptr) @@ -608,9 +608,7 @@ void LP_rpc_processreq(void *_ptr) jsonbuf = calloc(1,size); remains = size-1; buf = jsonbuf; - portable_mutex_lock(&LP_networkmutex); spawned++; - portable_mutex_unlock(&LP_networkmutex); if ( spawned > maxspawned ) { printf("max rpc threads spawned and alive %d <- %d\n",maxspawned,spawned); @@ -735,10 +733,10 @@ void LP_rpc_processreq(void *_ptr) free(space); free(jsonbuf); closesocket(sock); - portable_mutex_lock(&LP_networkmutex); + portable_mutex_lock(&LP_gcmutex); DL_APPEND(LP_garbage_collector,req); spawned--; - portable_mutex_unlock(&LP_networkmutex); + portable_mutex_unlock(&LP_gcmutex); } extern int32_t IAMLP; @@ -779,13 +777,13 @@ continue; printf("error launching rpc handler on port %d, retval.%d\n",port,retval); close(bindsock); bindsock = -1; - portable_mutex_lock(&LP_networkmutex); + portable_mutex_lock(&LP_gcmutex); DL_FOREACH_SAFE(LP_garbage_collector,req2,rtmp) { DL_DELETE(LP_garbage_collector,req2); free(req2); } - portable_mutex_unlock(&LP_networkmutex); + portable_mutex_unlock(&LP_gcmutex); if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 ) { printf("error2 launching rpc handler on port %d, retval.%d\n",port,retval); From 1b363373b7ee389e66597747ed0073f22162886a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:25:24 +0200 Subject: [PATCH 09/20] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- iguana/exchanges/LP_network.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 24f1cf450..395ba7ffc 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -66,7 +66,7 @@ void LP_millistats_update(struct LP_millistats *mp) mp->millisum += elapsed; if ( mp->threshold != 0. && elapsed > mp->threshold ) { - if ( IAMLP == 0 ) + //if ( IAMLP == 0 ) printf("%32s elapsed %10.2f millis > threshold %10.2f, ave %10.2f millis, count.%u\n",mp->name,elapsed,mp->threshold,mp->millisum/mp->count,mp->count); } mp->lastmilli = millis; diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 596f7ba75..5284bac2c 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -298,7 +298,7 @@ void queue_loop(void *arg) { 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); - n = nonz = 0; + n = nonz = flag = 0; DL_FOREACH_SAFE(LP_Q,ptr,tmp) { n++; @@ -356,7 +356,7 @@ void queue_loop(void *arg) // printf("LP_Q.[%d]\n",n); if ( nonz == 0 ) usleep(10000); - else printf("queue_loop nonz.%d flag.%d n.%d\n",nonz,flag,n); + else printf("queue_loop nonz.%d n.%d\n",nonz,n); } } From 5219d88727a03efe0a5b317bdfc191a449994783 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:28:05 +0200 Subject: [PATCH 10/20] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 5284bac2c..eb3c0d7ea 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -275,7 +275,7 @@ void gc_loop(void *arg) flag = 0; LP_millistats_update(&LP_gcloop_stats); portable_mutex_lock(&LP_gcmutex); - DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) + DL_FOREACH(LP_garbage_collector,req) { DL_DELETE(LP_garbage_collector,req); //printf("garbage collect ipbits.%x\n",req->ipbits); @@ -285,7 +285,7 @@ void gc_loop(void *arg) portable_mutex_unlock(&LP_gcmutex); if ( flag == 0 ) usleep(5000); - //else printf("gc_loop.%d\n",flag); + else printf("gc_loop.%d\n",flag); } } From 7aabcd1ae94ded0872462ddbcc841ec2ffc8efa3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:30:47 +0200 Subject: [PATCH 11/20] test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index eb3c0d7ea..eef7658b7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -275,7 +275,7 @@ void gc_loop(void *arg) flag = 0; LP_millistats_update(&LP_gcloop_stats); portable_mutex_lock(&LP_gcmutex); - DL_FOREACH(LP_garbage_collector,req) + DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) { DL_DELETE(LP_garbage_collector,req); //printf("garbage collect ipbits.%x\n",req->ipbits); From 3d49071cb011a88f5abdae1cdbad0f0e04e0f653 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:33:10 +0200 Subject: [PATCH 12/20] Test --- iguana/exchanges/LP_network.c | 4 ++-- iguana/exchanges/stats.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index eef7658b7..38f03ede7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -274,7 +274,7 @@ void gc_loop(void *arg) { flag = 0; LP_millistats_update(&LP_gcloop_stats); - portable_mutex_lock(&LP_gcmutex); + //portable_mutex_lock(&LP_gcmutex); DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) { DL_DELETE(LP_garbage_collector,req); @@ -282,7 +282,7 @@ void gc_loop(void *arg) free(req); flag++; } - portable_mutex_unlock(&LP_gcmutex); + //portable_mutex_unlock(&LP_gcmutex); if ( flag == 0 ) usleep(5000); else printf("gc_loop.%d\n",flag); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 2cc747ae0..b4d680e03 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -733,10 +733,10 @@ void LP_rpc_processreq(void *_ptr) free(space); free(jsonbuf); closesocket(sock); - portable_mutex_lock(&LP_gcmutex); + //portable_mutex_lock(&LP_gcmutex); DL_APPEND(LP_garbage_collector,req); spawned--; - portable_mutex_unlock(&LP_gcmutex); + //portable_mutex_unlock(&LP_gcmutex); } extern int32_t IAMLP; From 9452e4c9891ae01c18e2e9627278057177c85a64 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:35:20 +0200 Subject: [PATCH 13/20] Test --- iguana/exchanges/LP_network.c | 8 ++++---- iguana/exchanges/stats.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 38f03ede7..e869759b2 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,12 +269,12 @@ void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(queue_loop_stats.name,"gc_loop"); - queue_loop_stats.threshold = 12.; + queue_loop_stats.threshold = 1001.; while ( 1 ) { flag = 0; LP_millistats_update(&LP_gcloop_stats); - //portable_mutex_lock(&LP_gcmutex); + portable_mutex_lock(&LP_gcmutex); DL_FOREACH_SAFE(LP_garbage_collector,req,rtmp) { DL_DELETE(LP_garbage_collector,req); @@ -282,9 +282,9 @@ void gc_loop(void *arg) free(req); flag++; } - //portable_mutex_unlock(&LP_gcmutex); + portable_mutex_unlock(&LP_gcmutex); if ( flag == 0 ) - usleep(5000); + sleep(1); else printf("gc_loop.%d\n",flag); } } diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index b4d680e03..2cc747ae0 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -733,10 +733,10 @@ void LP_rpc_processreq(void *_ptr) free(space); free(jsonbuf); closesocket(sock); - //portable_mutex_lock(&LP_gcmutex); + portable_mutex_lock(&LP_gcmutex); DL_APPEND(LP_garbage_collector,req); spawned--; - //portable_mutex_unlock(&LP_gcmutex); + portable_mutex_unlock(&LP_gcmutex); } extern int32_t IAMLP; From f8651e0e312105f785be05e115a45c012640a4b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:37:32 +0200 Subject: [PATCH 14/20] Test --- iguana/exchanges/LP_network.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index e869759b2..64f1905bc 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -283,9 +283,9 @@ void gc_loop(void *arg) flag++; } portable_mutex_unlock(&LP_gcmutex); - if ( flag == 0 ) - sleep(1); - else printf("gc_loop.%d\n",flag); + if ( flag != 0 ) + printf("gc_loop.%d\n",flag); + sleep(1); } } From be8d3eae2d1bdd51b4bc9f1a48ffc5a6a5dc9a54 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:40:08 +0200 Subject: [PATCH 15/20] Test --- iguana/exchanges/LP_network.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 64f1905bc..8896a8c70 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -293,7 +293,7 @@ void queue_loop(void *arg) { struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; strcpy(queue_loop_stats.name,"queue_loop"); - queue_loop_stats.threshold = 11.; + queue_loop_stats.threshold = 51.; while ( 1 ) { LP_millistats_update(&queue_loop_stats); @@ -354,9 +354,9 @@ void queue_loop(void *arg) break; //if ( n != 0 ) // printf("LP_Q.[%d]\n",n); - if ( nonz == 0 ) - usleep(10000); - else printf("queue_loop nonz.%d n.%d\n",nonz,n); + if ( n != 0 ) + printf("queue_loop nonz.%d n.%d\n",nonz,n); + usleep(50000); } } From f8253540feca225b96c08a6db6f65c35be51307c Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:45:34 +0200 Subject: [PATCH 16/20] Test --- iguana/exchanges/LP_network.c | 38 ++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 8896a8c70..d314b3d85 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -140,7 +140,7 @@ struct LP_queue { struct LP_queue *next,*prev; int32_t sock,peerind,msglen; - uint32_t starttime,crc32; + uint32_t starttime,crc32,notready; uint8_t msg[]; } *LP_Q; int32_t LP_Qenqueued,LP_Qerrors,LP_Qfound; @@ -305,18 +305,26 @@ void queue_loop(void *arg) flag = 0; if ( ptr->sock >= 0 ) { - if ( LP_sockcheck(ptr->sock) > 0 ) + if ( ptr->notready == 0 || (rand() % ptr->notready) == 0 ) { - bits256 magic; - magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256))); - memcpy(&ptr->msg[ptr->msglen - sizeof(bits256)],&magic,sizeof(magic)); - if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) - printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); - else flag++; - ptr->sock = -1; - if ( ptr->peerind > 0 ) - ptr->starttime = (uint32_t)time(NULL); - } //else printf("sock not ready to send.%d\n",ptr->msglen); + if ( LP_sockcheck(ptr->sock) > 0 ) + { + bits256 magic; + magic = LP_calc_magic(ptr->msg,(int32_t)(ptr->msglen - sizeof(bits256))); + memcpy(&ptr->msg[ptr->msglen - sizeof(bits256)],&magic,sizeof(magic)); + if ( (sentbytes= nn_send(ptr->sock,ptr->msg,ptr->msglen,0)) != ptr->msglen ) + printf("%d LP_send sent %d instead of %d\n",n,sentbytes,ptr->msglen); + else flag++; + ptr->sock = -1; + if ( ptr->peerind > 0 ) + ptr->starttime = (uint32_t)time(NULL); + } + else + { + if ( ptr->notready++ > 1000 ) + flag = 1; + } + } } else if ( 0 && time(NULL) > ptr->starttime+13 ) { @@ -352,11 +360,9 @@ void queue_loop(void *arg) } if ( arg == 0 ) break; - //if ( n != 0 ) - // printf("LP_Q.[%d]\n",n); - if ( n != 0 ) + if ( n+nonz != 0 ) printf("queue_loop nonz.%d n.%d\n",nonz,n); - usleep(50000); + else usleep(50000); } } From 97ba511f73c943ba887bbae13128468a95fbc30f Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:48:25 +0200 Subject: [PATCH 17/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index d314b3d85..12b626bb7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -360,7 +360,7 @@ void queue_loop(void *arg) } if ( arg == 0 ) break; - if ( n+nonz != 0 ) + if ( nonz != 0 ) printf("queue_loop nonz.%d n.%d\n",nonz,n); else usleep(50000); } From 17a822dc9f646ce53d20bdba7918c67e2a0b9079 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:50:59 +0200 Subject: [PATCH 18/20] Test --- iguana/exchanges/LP_network.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 12b626bb7..bf212278b 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -268,8 +268,8 @@ int32_t LP_peerindsock(int32_t *peerindp) void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; - strcpy(queue_loop_stats.name,"gc_loop"); - queue_loop_stats.threshold = 1001.; + strcpy(LP_gcloop_stats.name,"gc_loop"); + LP_gcloop_stats.threshold = 1001.; while ( 1 ) { flag = 0; From 957d87387953c4a9ada808303d345bf20bff3114 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 11:54:36 +0200 Subject: [PATCH 19/20] Test --- iguana/exchanges/LP_network.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index bf212278b..9bf43463c 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -283,7 +283,7 @@ void gc_loop(void *arg) flag++; } portable_mutex_unlock(&LP_gcmutex); - if ( flag != 0 ) + if ( 0 && flag != 0 ) printf("gc_loop.%d\n",flag); sleep(1); } @@ -293,7 +293,7 @@ void queue_loop(void *arg) { struct LP_queue *ptr,*tmp; int32_t sentbytes,nonz,flag,duplicate,n=0; strcpy(queue_loop_stats.name,"queue_loop"); - queue_loop_stats.threshold = 51.; + queue_loop_stats.threshold = 100.; while ( 1 ) { LP_millistats_update(&queue_loop_stats); @@ -360,9 +360,12 @@ void queue_loop(void *arg) } if ( arg == 0 ) break; - if ( nonz != 0 ) - printf("queue_loop nonz.%d n.%d\n",nonz,n); - else usleep(50000); + if ( nonz == 0 ) + { + if ( IAMLP == 0 ) + usleep(50000); + else usleep(10000); + } } } From 4c2897ea4ea2cac6d35cee2de033e5b848571b6e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 6 Nov 2017 12:08:38 +0200 Subject: [PATCH 20/20] Test --- iguana/exchanges/LP_network.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 9bf43463c..9a52b86d4 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -269,7 +269,7 @@ void gc_loop(void *arg) { struct rpcrequest_info *req,*rtmp; int32_t flag = 0; strcpy(LP_gcloop_stats.name,"gc_loop"); - LP_gcloop_stats.threshold = 1001.; + LP_gcloop_stats.threshold = 1100.; while ( 1 ) { flag = 0;