From 268f386b815d72094bf1d4277a4248f56c656751 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Apr 2018 12:04:46 +0300 Subject: [PATCH 01/13] Activate maintain MoM and 0.0001 --- iguana/dPoW.h | 4 ++-- iguana/dpow/dpow_fsm.c | 2 +- iguana/dpow/dpow_rpc.c | 2 +- iguana/dpow/dpow_tx.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/iguana/dPoW.h b/iguana/dPoW.h index 7862fe36d..49461af75 100755 --- a/iguana/dPoW.h +++ b/iguana/dPoW.h @@ -23,8 +23,8 @@ #define DPOW_MIN_ASSETCHAIN_SIGS 11 //#define DPOW_M(bp) ((bp)->minsigs) // (((bp)->numnotaries >> 1) + 1) #define DPOW_MODIND(bp,offset) (((((bp)->height / DPOW_CHECKPOINTFREQ) % (bp)->numnotaries) + (offset)) % (bp)->numnotaries) -#define DPOW_VERSION 0x1781 -#define DPOW_UTXOSIZE 50000 +#define DPOW_VERSION 0x1782 +#define DPOW_UTXOSIZE 10000//50000 #define DPOW_MINOUTPUT 6000 #define DPOW_DURATION 600 #define DPOW_RATIFYDURATION (3600 * 24) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index ccd30bbec..34516c3d1 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -271,7 +271,7 @@ int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supe decode_hex(script,len,hexstr); if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len) > 0 ) { - if ( Notaries_port != DPOW_SOCKPORT ) + //if ( Notaries_port != DPOW_SOCKPORT ) { if ( bits256_nonz(MoM) == 0 || MoMdepth == 0 || *nothtp >= height || *nothtp < 0 ) *nothtp = 0; diff --git a/iguana/dpow/dpow_rpc.c b/iguana/dpow/dpow_rpc.c index 07822f642..a44e02fbc 100755 --- a/iguana/dpow/dpow_rpc.c +++ b/iguana/dpow/dpow_rpc.c @@ -230,7 +230,7 @@ int32_t dpow_paxpending(uint8_t *hex,uint32_t *paxwdcrcp,bits256 MoM,uint32_t Mo { struct iguana_info *coin; char *retstr,*hexstr; cJSON *retjson; int32_t n=0; uint32_t paxwdcrc; paxwdcrc = 0; - if ( Notaries_port != DPOW_SOCKPORT ) + //if ( Notaries_port != DPOW_SOCKPORT ) { n += iguana_rwbignum(1,&hex[n],sizeof(MoM),MoM.bytes); n += iguana_rwnum(1,&hex[n],sizeof(MoMdepth),(uint32_t *)&MoMdepth); diff --git a/iguana/dpow/dpow_tx.c b/iguana/dpow/dpow_tx.c index dad95859c..e2e6f5798 100755 --- a/iguana/dpow/dpow_tx.c +++ b/iguana/dpow/dpow_tx.c @@ -232,7 +232,7 @@ int32_t dpow_voutstandard(struct dpow_block *bp,uint8_t *serialized,int32_t m,in printf("%02x",extras[i]); printf(" <- withdraw.%d %08x\n",n,paxwdcrc); } - else if ( Notaries_port != DPOW_SOCKPORT && bp->MoMdepth > 0 && strcmp(bp->destcoin->symbol,"KMD") == 0 ) // only testnets for now + else if ( bp->MoMdepth > 0 && strcmp(bp->destcoin->symbol,"KMD") == 0 ) // Notaries_port != DPOW_SOCKPORT && { n = dpow_paxpending(extras,&paxwdcrc,bp->MoM,bp->MoMdepth); //n += iguana_rwbignum(1,&extras[n],sizeof(bp->MoM),bp->MoM.bytes); From 6daf3584eab9b8c19cbe8c8a44422ea563e32261 Mon Sep 17 00:00:00 2001 From: jl777 Date: Sun, 1 Apr 2018 12:15:13 +0300 Subject: [PATCH 02/13] Test --- iguana/dpow/dpow_fsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/dpow/dpow_fsm.c b/iguana/dpow/dpow_fsm.c index 34516c3d1..ccd30bbec 100755 --- a/iguana/dpow/dpow_fsm.c +++ b/iguana/dpow/dpow_fsm.c @@ -271,7 +271,7 @@ int32_t dpow_txhasnotarization(uint64_t *signedmaskp,int32_t *nothtp,struct supe decode_hex(script,len,hexstr); if ( dpow_opreturn_parsesrc(&blockhash,nothtp,&txid,symbol,&MoM,&MoMdepth,script,len) > 0 ) { - //if ( Notaries_port != DPOW_SOCKPORT ) + if ( Notaries_port != DPOW_SOCKPORT ) { if ( bits256_nonz(MoM) == 0 || MoMdepth == 0 || *nothtp >= height || *nothtp < 0 ) *nothtp = 0; From 07ea47522f2ffcfed0f876f99e83adb5c15dc234 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 12:24:31 +0300 Subject: [PATCH 03/13] Getfee --- iguana/exchanges/LP_commands.c | 14 ++++++++++++++ iguana/exchanges/getfee | 3 +++ 2 files changed, 17 insertions(+) create mode 100755 iguana/exchanges/getfee diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index aa105413d..f859aea5e 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -168,6 +168,7 @@ timelock(coin, duration, destaddr=(tradeaddr), amount)\n\ unlockedspend(coin, txid)\n\ opreturndecrypt(coin, txid, passphrase)\n\ getendpoint(port=5555)\n\ +getfee(coin)\n\ listtransactions(coin, address, count=10, skip=0)\n\ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ \"}")); @@ -579,6 +580,19 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ return(jprint(LP_address_balance(ptr,jstr(argjson,"address"),1),1)); else return(clonestr("{\"error\":\"cant find coind\"}")); } + else if ( strcmp(method,"getfee") == 0 ) + { + uint64_t txfee; + if ( (ptr= LP_coinsearch(coin)) != 0 ) + { + txfee = LP_txfeecalc(ptr,0,0); + retjson = cJSON_CreateObject(); + jaddstr(retjson,"result","success"); + jaddstr(retjson,"coin",coin); + jaddnum(retjson,"txfee",dstr(txfee)); + return(jprint(retjson,1)); + } else return(clonestr("{\"error\":\"cant find coind\"}")); + } else if ( strcmp(method,"electrum") == 0 ) { if ( (ptr= LP_coinsearch(coin)) != 0 ) diff --git a/iguana/exchanges/getfee b/iguana/exchanges/getfee new file mode 100755 index 000000000..147bd344f --- /dev/null +++ b/iguana/exchanges/getfee @@ -0,0 +1,3 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"getfee\",\"coin\":\"BTC\"}" From 26b73f73852b1b92e5b1ccb24d0ed50754aac19a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 13:46:00 +0300 Subject: [PATCH 04/13] Fastflag --- iguana/exchanges/DEXstats.h | 2 +- iguana/exchanges/LP_commands.c | 10 +++++++++- iguana/exchanges/LP_nativeDEX.c | 4 ++-- iguana/exchanges/fasttest | 6 ++++++ iguana/exchanges/mm.c | 2 +- iguana/exchanges/stats.c | 14 +++++++------- 6 files changed, 26 insertions(+), 12 deletions(-) create mode 100755 iguana/exchanges/fasttest diff --git a/iguana/exchanges/DEXstats.h b/iguana/exchanges/DEXstats.h index dc1f89864..3758a4e55 100644 --- a/iguana/exchanges/DEXstats.h +++ b/iguana/exchanges/DEXstats.h @@ -928,7 +928,7 @@ char *stats_prices(char *symbol,char *dest,struct DEXstats_disp *prices,int32_t #ifndef FROM_MARKETMAKER #ifndef FROM_PRIVATEBET -char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port) +char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port) { char *method,*agent,*retstr,*source,*dest; struct tai T; uint32_t endtimestamp; struct DEXstats_disp prices[365]; int32_t leftdatenum,seconds,numdates; if ( (method= jstr(argjson,"method")) == 0 ) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index f859aea5e..b65fa9556 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -32,7 +32,7 @@ char *LP_numutxos() return(jprint(retjson,1)); } -char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port +char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*passphrase,*retstr = 0; int32_t authenticated=0,changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); @@ -169,6 +169,7 @@ unlockedspend(coin, txid)\n\ opreturndecrypt(coin, txid, passphrase)\n\ getendpoint(port=5555)\n\ getfee(coin)\n\ +sleep(seconds=60)\n\ listtransactions(coin, address, count=10, skip=0)\n\ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ \"}")); @@ -318,6 +319,13 @@ jpg(srcfile, destfile, power2=7, password, data="", required, ind=0)\n\ LP_millistats_update(0); return(clonestr("{\"result\":\"success\"}")); } + else if ( strcmp(method,"sleep") == 0 ) + { + if ( jint(argjson,"seconds") == 0 ) + sleep(60); + else sleep(jint(argjson,"seconds")); + return(clonestr("{\"result\":\"success\",\"status\":\"feeling good after sleeping\"}")); + } else if ( strcmp(method,"getprices") == 0 ) return(LP_prices()); else if ( strcmp(method,"getpeers") == 0 ) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6ad01bd30..d715efc8c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -204,7 +204,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(0); if ( stats_JSONonly != 0 || LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",stats_JSONonly)) != 0 ) + if ( (retstr= stats_JSON(ctx,0,myipaddr,pubsock,argjson,"127.0.0.1",stats_JSONonly)) != 0 ) { //printf("%s PULL.[%d]-> (%s)\n",myipaddr != 0 ? myipaddr : "127.0.0.1",datalen,retstr); //if ( pubsock >= 0 ) //strncmp("{\"error\":",retstr,strlen("{\"error\":")) != 0 && @@ -425,7 +425,7 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int //portable_mutex_lock(&LP_commandmutex); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,0,0) <= 0 ) { - if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) + if ( (retstr= stats_JSON(ctx,0,myipaddr,pubsock,argjson,remoteaddr,0)) != 0 ) free(retstr); } //portable_mutex_unlock(&LP_commandmutex); diff --git a/iguana/exchanges/fasttest b/iguana/exchanges/fasttest new file mode 100755 index 000000000..bdfb417db --- /dev/null +++ b/iguana/exchanges/fasttest @@ -0,0 +1,6 @@ +#!/bin/bash +source userpass +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sleep\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 234565e32..c35046538 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -37,7 +37,7 @@ void PNACL_message(char *arg,...) uint32_t DOCKERFLAG; #define MAX(a,b) ((a) > (b) ? (a) : (b)) -char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); +char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port); #include "stats.c" void LP_priceupdate(char *base,char *rel,double price,double avebid,double aveask,double highbid,double lowask,double PAXPRICES[32]); diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 6c8daa4f5..7649ea627 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -28,7 +28,7 @@ #define STATS_DESTDIR "/var/www/html" #define STATS_DEST "/var/www/html/DEXstats.json" #include "DEXstats.h" -char *stats_JSON(void *ctx,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port); +char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t mypubsock,cJSON *argjson,char *remoteaddr,uint16_t port); void LP_queuecommand(char **retstrp,char *buf,int32_t responsesock,int32_t stats_JSONonly,uint32_t queueid); extern uint32_t DOCKERFLAG; @@ -530,7 +530,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po //free(buf); //while ( retstr == 0 ) // usleep(10000); - if ( (retstr= stats_JSON(ctx,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 ) + if ( (retstr= stats_JSON(ctx,0,"127.0.0.1",-1,argjson,remoteaddr,port)) != 0 ) { if ( (retitem= cJSON_Parse(retstr)) != 0 ) jaddi(retarray,retitem); @@ -543,7 +543,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po //free(buf); //while ( retstr == 0 ) // usleep(10000); - if ( (retstr= stats_JSON(ctx,myipaddr,-1,argjson,remoteaddr,port)) != 0 ) + if ( (retstr= stats_JSON(ctx,0,myipaddr,-1,argjson,remoteaddr,port)) != 0 ) { if ( (retitem= cJSON_Parse(retstr)) != 0 ) jaddi(retarray,retitem); @@ -576,7 +576,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); free(buf); retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); - } else retstr = stats_JSON(ctx,"127.0.0.1",-1,arg,remoteaddr,port); + } else retstr = stats_JSON(ctx,jint(arg,"fast"),"127.0.0.1",-1,arg,remoteaddr,port); } else retstr = clonestr("{\"error\":\"invalid remote method\"}"); #else if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) @@ -584,7 +584,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po buf = jprint(arg,0); LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); free(buf); - } else retstr = stats_JSON(ctx,myipaddr,-1,arg,remoteaddr,port); + } else retstr = stats_JSON(ctx,jint(arg,"fast"),myipaddr,-1,arg,remoteaddr,port); #endif } free_json(argjson); @@ -626,7 +626,7 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) } uint16_t RPC_port; -extern portable_mutex_t LP_commandmutex,LP_gcmutex; +extern portable_mutex_t LP_gcmutex; extern struct rpcrequest_info *LP_garbage_collector; void LP_rpc_processreq(void *_ptr) @@ -884,7 +884,7 @@ void stats_rpcloop(void *args) #ifndef FROM_MARKETMAKER -portable_mutex_t LP_commandmutex; +//portable_mutex_t LP_commandmutex; uint16_t LP_RPCPORT = 7763; void stats_kvjson(FILE *logfp,int32_t height,int32_t savedheight,uint32_t timestamp,char *key,cJSON *kvjson,bits256 pubkey,bits256 sigprev) From eaefc5cb2fac16d459fbe988e53d297b27a0f295 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 13:47:32 +0300 Subject: [PATCH 05/13] Fasttest --- iguana/exchanges/fasttest | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/fasttest b/iguana/exchanges/fasttest index bdfb417db..b876291f8 100755 --- a/iguana/exchanges/fasttest +++ b/iguana/exchanges/fasttest @@ -1,6 +1,6 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sleep\"}" +curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"sleep\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" -curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" From c25001512e0ea41db35b25db821b100d44769107 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 13:58:28 +0300 Subject: [PATCH 06/13] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/LP_network.c | 3 ++- iguana/exchanges/stats.c | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b65fa9556..1345b2431 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -38,7 +38,7 @@ char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON method = jstr(argjson,"method"); if ( method != 0 && (strcmp(method,"addr_unspents") == 0 || strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) ) return(0); -//printf("stats_JSON.(%s)\n",jprint(argjson,0)); +printf("stats_JSON.(%s)\n",jprint(argjson,0)); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index f5fb75a26..78a6cd8a8 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -445,7 +445,7 @@ void LP_commandQ_loop(void *ctx) portable_mutex_unlock(&LP_commandQmutex); if ( ptr->stats_JSONonly < 0 ) // broadcast passthrough { - if ( 1 && ptr->responsesock >= 0 ) + if ( ptr->responsesock >= 0 ) { if ( (result= cJSON_Parse(ptr->msg)) != 0 ) { @@ -461,6 +461,7 @@ void LP_commandQ_loop(void *ctx) } else if ( (argjson= cJSON_Parse(ptr->msg)) != 0 ) { + printf("deQ.(%s)\n",jprint(argjson,0)); if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 ) { if ( ptr->retstrp != 0 ) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 7649ea627..d2cc0cab5 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -564,7 +564,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( is_cJSON_Array(arg) != 0 && cJSON_GetArraySize(arg) == 1 ) arg = jitem(arg,0); } else arg = argjson; - //printf("ARGJSON.(%s)\n",jprint(arg,0)); + printf("ARGJSON.(%s)\n",jprint(arg,0)); if ( userpass != 0 && jstr(arg,"userpass") == 0 ) jaddstr(arg,"userpass",userpass); #ifdef FROM_MARKETMAKER @@ -573,6 +573,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) { buf = jprint(arg,0); + printf("Q command\n"); LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); free(buf); retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); @@ -854,7 +855,7 @@ void stats_rpcloop(void *args) continue; } req = calloc(1,sizeof(*req)); - //printf("alloc req.%p\n",req); + printf("LP_rpc_processreq req.%p\n",req); req->sock = sock; req->ipbits = ipbits; req->port = port; From 32ff4a3915eed95e8b565c1e89e7c1a1ce6a7f0a Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:02:56 +0300 Subject: [PATCH 07/13] Test --- iguana/exchanges/LP_network.c | 2 +- iguana/exchanges/fasttest | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_network.c b/iguana/exchanges/LP_network.c index 78a6cd8a8..85b9467a7 100644 --- a/iguana/exchanges/LP_network.c +++ b/iguana/exchanges/LP_network.c @@ -461,7 +461,7 @@ void LP_commandQ_loop(void *ctx) } else if ( (argjson= cJSON_Parse(ptr->msg)) != 0 ) { - printf("deQ.(%s)\n",jprint(argjson,0)); + //printf("deQ.(%s)\n",jprint(argjson,0)); if ( (retstr= LP_command_process(ctx,"127.0.0.1",ptr->responsesock,argjson,(uint8_t *)ptr->msg,ptr->msglen,ptr->stats_JSONonly)) != 0 ) { if ( ptr->retstrp != 0 ) diff --git a/iguana/exchanges/fasttest b/iguana/exchanges/fasttest index b876291f8..0e156a4c3 100755 --- a/iguana/exchanges/fasttest +++ b/iguana/exchanges/fasttest @@ -1,6 +1,6 @@ #!/bin/bash source userpass curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"sleep\"}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7782" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7782" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" From aa762acf84d76896f8f4c6ec782dd0e4095f2eb5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:05:06 +0300 Subject: [PATCH 08/13] Test --- iguana/exchanges/fasttest | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/fasttest b/iguana/exchanges/fasttest index 0e156a4c3..46aaf1120 100755 --- a/iguana/exchanges/fasttest +++ b/iguana/exchanges/fasttest @@ -1,6 +1,6 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"sleep\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sleep\"}" & curl --url "http://127.0.0.1:7782" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" curl --url "http://127.0.0.1:7782" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" -curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" From cb7dee4e2faa8e59d6c80bd336dec3c8824a1e82 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:06:21 +0300 Subject: [PATCH 09/13] Test --- iguana/exchanges/LP_commands.c | 2 +- iguana/exchanges/stats.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 1345b2431..b65fa9556 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -38,7 +38,7 @@ char *stats_JSON(void *ctx,int32_t fastflag,char *myipaddr,int32_t pubsock,cJSON method = jstr(argjson,"method"); if ( method != 0 && (strcmp(method,"addr_unspents") == 0 || strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0) ) return(0); -printf("stats_JSON.(%s)\n",jprint(argjson,0)); +//printf("stats_JSON.(%s)\n",jprint(argjson,0)); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { if ( strcmp(ipaddr,"127.0.0.1") != 0 && argport >= 1000 ) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index d2cc0cab5..fcfe70904 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -564,7 +564,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( is_cJSON_Array(arg) != 0 && cJSON_GetArraySize(arg) == 1 ) arg = jitem(arg,0); } else arg = argjson; - printf("ARGJSON.(%s)\n",jprint(arg,0)); + //printf("ARGJSON.(%s)\n",jprint(arg,0)); if ( userpass != 0 && jstr(arg,"userpass") == 0 ) jaddstr(arg,"userpass",userpass); #ifdef FROM_MARKETMAKER @@ -573,7 +573,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po if ( IPC_ENDPOINT >= 0 && (queueid= juint(arg,"queueid")) > 0 ) { buf = jprint(arg,0); - printf("Q command\n"); + //printf("Q command\n"); LP_queuecommand(&retstr,buf,IPC_ENDPOINT,1,queueid); free(buf); retstr = clonestr("{\"result\":\"success\",\"status\":\"queued\"}"); @@ -855,7 +855,7 @@ void stats_rpcloop(void *args) continue; } req = calloc(1,sizeof(*req)); - printf("LP_rpc_processreq req.%p\n",req); + //printf("LP_rpc_processreq req.%p\n",req); req->sock = sock; req->ipbits = ipbits; req->port = port; From 552ba77ba4f026d037b2fc4bb793ba196aca33fb Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:13:22 +0300 Subject: [PATCH 10/13] Test --- iguana/exchanges/fasttest | 6 +++--- iguana/exchanges/stats.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/iguana/exchanges/fasttest b/iguana/exchanges/fasttest index 46aaf1120..f4ef15e87 100755 --- a/iguana/exchanges/fasttest +++ b/iguana/exchanges/fasttest @@ -1,6 +1,6 @@ #!/bin/bash source userpass -curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"sleep\"}" & -curl --url "http://127.0.0.1:7782" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" -curl --url "http://127.0.0.1:7782" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"sleep\",\"seconds\":10}" & curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index fcfe70904..140753f6d 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -629,10 +629,10 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) uint16_t RPC_port; extern portable_mutex_t LP_gcmutex; extern struct rpcrequest_info *LP_garbage_collector; +static int32_t spawned,maxspawned; void LP_rpc_processreq(void *_ptr) { - static uint32_t spawned,maxspawned; char filetype[128],content_type[128]; int32_t recvlen,flag,postflag=0,contentlen,remains,sock,numsent,jsonflag=0,hdrsize,len; char helpname[512],remoteaddr[64],*buf,*retstr,space[8192],space2[32786],*jsonbuf; struct rpcrequest_info *req = _ptr; @@ -647,6 +647,8 @@ void LP_rpc_processreq(void *_ptr) //printf("alloc jsonbuf.%p\n",jsonbuf); remains = size-1; buf = jsonbuf; + if ( spawned < 0 ) + spawned = 0; spawned++; if ( spawned > maxspawned ) { @@ -796,7 +798,8 @@ void LP_rpc_processreq(void *_ptr) //printf("free req.%p\n",req); free(req); } - spawned--; + if ( spawned > 0 ) + spawned--; } extern int32_t IAMLP,LP_STOP_RECEIVED; @@ -859,10 +862,10 @@ void stats_rpcloop(void *args) req->sock = sock; req->ipbits = ipbits; req->port = port; - LP_rpc_processreq(req); - continue; + if ( spawned > 1 ) + LP_rpc_processreq(req); // this might lead to "cant open file errors" - if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 ) + else if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 ) { printf("error launching rpc handler on port %d, retval.%d\n",port,retval); LP_rpc_processreq(req); From a09179d63f3691372a817138135ed05a8298b79e Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:17:02 +0300 Subject: [PATCH 11/13] Test --- iguana/exchanges/fasttest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/fasttest b/iguana/exchanges/fasttest index f4ef15e87..a420ed864 100755 --- a/iguana/exchanges/fasttest +++ b/iguana/exchanges/fasttest @@ -3,4 +3,4 @@ source userpass curl --url "http://127.0.0.1:7783" --data "{\"queueid\":1,\"userpass\":\"$userpass\",\"method\":\"sleep\",\"seconds\":10}" & curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" -curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"orderbook\",\"base\":\"REVS\",\"rel\":\"KMD\"}" +curl --url "http://127.0.0.1:7783" --data "{\"queueid\":2,\"userpass\":\"$userpass\",\"method\":\"getcoin\",\"coin\":\"REVS\",\"rel\":\"KMD\"}" From 092c71c3aa79c6a0b6374c42f9cbcfc449f1237d Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:19:38 +0300 Subject: [PATCH 12/13] Test --- iguana/exchanges/stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index 140753f6d..cdce20561 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -862,7 +862,7 @@ void stats_rpcloop(void *args) req->sock = sock; req->ipbits = ipbits; req->port = port; - if ( spawned > 1 ) + if ( spawned > 0 ) LP_rpc_processreq(req); // this might lead to "cant open file errors" else if ( (retval= OS_thread_create(&req->T,NULL,(void *)LP_rpc_processreq,req)) != 0 ) From 4e289f1e8f325d279ffaa78c467bc1762f0ddeb6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Mon, 2 Apr 2018 14:26:33 +0300 Subject: [PATCH 13/13] Test --- iguana/exchanges/stats.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/iguana/exchanges/stats.c b/iguana/exchanges/stats.c index cdce20561..5d50c6a52 100644 --- a/iguana/exchanges/stats.c +++ b/iguana/exchanges/stats.c @@ -331,6 +331,10 @@ cJSON *SuperNET_urlconv(char *value,int32_t bufsize,char *urlstr) extern void *bitcoin_ctx(); extern int32_t IPC_ENDPOINT; +extern portable_mutex_t LP_gcmutex,LP_commandmutex; +extern struct rpcrequest_info *LP_garbage_collector; +uint16_t RPC_port; +static int32_t spawned,maxspawned; char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *postflagp,char *urlstr,char *remoteaddr,char *filetype,uint16_t port) { @@ -557,7 +561,7 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po } else { - cJSON *arg; char *buf; + cJSON *arg; char *buf,*method; int32_t fastflag; if ( jstr(argjson,"agent") != 0 && strcmp(jstr(argjson,"agent"),"bitcoinrpc") != 0 && jobj(argjson,"params") != 0 ) { arg = jobj(argjson,"params"); @@ -567,6 +571,13 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po //printf("ARGJSON.(%s)\n",jprint(arg,0)); if ( userpass != 0 && jstr(arg,"userpass") == 0 ) jaddstr(arg,"userpass",userpass); + if ( (fastflag= jint(arg,"fast")) == 0 ) + { + if ( (method= jstr(arg,"method")) != 0 && (strcmp(method,"orderbook") == 0 || strcmp(method,"portfolio") == 0) ) + fastflag = 1; + } + if ( fastflag == 0 ) + portable_mutex_lock(&LP_commandmutex); #ifdef FROM_MARKETMAKER if ( strcmp(remoteaddr,"127.0.0.1") == 0 || LP_valid_remotemethod(arg) > 0 ) { @@ -587,6 +598,8 @@ char *stats_rpcparse(char *retbuf,int32_t bufsize,int32_t *jsonflagp,int32_t *po free(buf); } else retstr = stats_JSON(ctx,jint(arg,"fast"),myipaddr,-1,arg,remoteaddr,port); #endif + if ( fastflag == 0 ) + portable_mutex_unlock(&LP_commandmutex); } free_json(argjson); } @@ -626,11 +639,6 @@ int32_t iguana_getheadersize(char *buf,int32_t recvlen) return(recvlen); } -uint16_t RPC_port; -extern portable_mutex_t LP_gcmutex; -extern struct rpcrequest_info *LP_garbage_collector; -static int32_t spawned,maxspawned; - void LP_rpc_processreq(void *_ptr) { char filetype[128],content_type[128]; @@ -642,9 +650,7 @@ void LP_rpc_processreq(void *_ptr) sock = req->sock; recvlen = flag = 0; retstr = 0; - //space = calloc(1,size); jsonbuf = calloc(1,size); - //printf("alloc jsonbuf.%p\n",jsonbuf); remains = size-1; buf = jsonbuf; if ( spawned < 0 ) @@ -711,9 +717,7 @@ void LP_rpc_processreq(void *_ptr) if ( recvlen > 0 ) { jsonflag = postflag = 0; - //portable_mutex_lock(&LP_commandmutex); retstr = stats_rpcparse(space,size,&jsonflag,&postflag,jsonbuf,remoteaddr,filetype,req->port); - //portable_mutex_unlock(&LP_commandmutex); if ( filetype[0] != 0 ) { static cJSON *mimejson; char *tmp,*typestr=0; long tmpsize; @@ -888,7 +892,7 @@ void stats_rpcloop(void *args) #ifndef FROM_MARKETMAKER -//portable_mutex_t LP_commandmutex; +portable_mutex_t LP_commandmutex; uint16_t LP_RPCPORT = 7763; void stats_kvjson(FILE *logfp,int32_t height,int32_t savedheight,uint32_t timestamp,char *key,cJSON *kvjson,bits256 pubkey,bits256 sigprev)