From be324b6c5fabb94c86a462d9e3fdec26e1b877c5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 12:17:10 +0200 Subject: [PATCH 01/41] Test --- iguana/exchanges/LP_include.h | 4 ++-- iguana/exchanges/LP_nativeDEX.c | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index b7dd79e03b..5e530f9c13 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -53,8 +53,8 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_MIN_PEERS 8 #define LP_MAX_PEERS 32 -#define LP_MAXDESIRED_UTXOS 128 -#define LP_MINDESIRED_UTXOS 32 +#define LP_MAXDESIRED_UTXOS (IAMLP != 0 ? 128 : 64) +#define LP_MINDESIRED_UTXOS (IAMLP != 0 ? 32 : 16) #define LP_DUSTCOMBINE_THRESHOLD 1000000 // RTmetrics diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6232d159bd..ae5fa57a7b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,16 +17,15 @@ // LP_nativeDEX.c // marketmaker // -// single utxo allocations alice // gc cJSON -// more retries for swap sendrawtransaction +// more retries for swap sendrawtransaction? // pbca26 unfinished swaps -// alice waiting for bestprice -//if ( G.LP_pendingswaps != 0 ) -//return(-1); +// if ( G.LP_pendingswaps != 0 ) return(-1); // bot safe to exit? // // BCH signing +// single utxo allocations alice +// alice waiting for bestprice // previously, it used to show amount, kmd equiv, perc // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs From 48ffd56a48f7843f33eb5c043a41d04da7b608b4 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:04:17 +0200 Subject: [PATCH 02/41] Test --- crypto777/cJSON.c | 33 ++++++++++++++++++++++++++++++--- iguana/exchanges/mm.c | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 8bce48b19e..9674910b89 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -578,8 +578,6 @@ cJSON *cJSON_CreateFalse(void) {cJSON *item=cJSON_New_Item();if(item)item->t cJSON *cJSON_CreateBool(int32_t b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;} cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int64_t)num;}return item;} cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;} -cJSON *cJSON_CreateArray(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;} -cJSON *cJSON_CreateObject(void) {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;} /* Create Arrays: */ cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count) {int32_t i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && ichild=n;else suffix_object(p,n);p=n;}return a;} @@ -1129,4 +1127,33 @@ cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num) return(array); } -void free_json(cJSON *json) { if ( json != 0 ) cJSON_Delete(json); } +cJSON *cJSON_CreateArray(void) +{ + cJSON *item = cJSON_New_Item(); + if ( item ) + item->type = cJSON_Array; +#ifdef CJSON_GARBAGECOLLECTION + cJSON_register(item); +#endif + return(item); +} + +cJSON *cJSON_CreateObject(void) +{ + cJSON *item = cJSON_New_Item(); + if ( item ) + item->type = cJSON_Object; +#ifdef CJSON_GARBAGECOLLECTION + cJSON_register(item); +#endif + return item; +} + +void free_json(cJSON *json) +{ +#ifdef CJSON_GARBAGECOLLECTION + cJSON_unregister(item); +#endif + if ( json != 0 ) + cJSON_Delete(json); +} diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 1d2a1bd5e3..8ce073d1f6 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -24,6 +24,7 @@ void PNACL_message(char *arg,...) } #define FROM_MARKETMAKER +#define CJSON_GARBAGECOLLECTION #include #include #ifndef NATIVE_WINDOWS From 7e999953c64612ea58110f01b0aa123621781814 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:16:29 +0200 Subject: [PATCH 03/41] Test --- crypto777/cJSON.c | 2 +- iguana/m_mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 9674910b89..404931fcf1 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1144,7 +1144,7 @@ cJSON *cJSON_CreateObject(void) if ( item ) item->type = cJSON_Object; #ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); + cJSON_register(item); fff #endif return item; } diff --git a/iguana/m_mm b/iguana/m_mm index b5ba405caf..3905b5d84b 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -g -o marketmaker -I../crypto777 exchanges/mm.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -DFROM_MARKETMAKER -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From 32191a3f60704664049426d0242e0bf5753a36c2 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:26:24 +0200 Subject: [PATCH 04/41] Test --- crypto777/cJSON.c | 2 ++ iguana/exchanges/mm.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 404931fcf1..a9bb74dd7b 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -25,6 +25,8 @@ /* JSON parser in C. */ #include +#define CJSON_GARBAGECOLLECTION + #include "../includes/cJSON.h" #ifndef DBL_EPSILON diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 8ce073d1f6..56498394af 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -23,7 +23,10 @@ void PNACL_message(char *arg,...) { } +#ifndef FROM_MARKETMAKER #define FROM_MARKETMAKER +#endif + #define CJSON_GARBAGECOLLECTION #include #include From 3df1acbc3b4bd1470d291f8c36c21d3a29477032 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:28:05 +0200 Subject: [PATCH 05/41] Test --- crypto777/cJSON.c | 2 -- iguana/exchanges/mm.c | 5 +++-- iguana/m_mm | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index a9bb74dd7b..404931fcf1 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -25,8 +25,6 @@ /* JSON parser in C. */ #include -#define CJSON_GARBAGECOLLECTION - #include "../includes/cJSON.h" #ifndef DBL_EPSILON diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index 56498394af..e20b1dcb6d 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -23,11 +23,12 @@ void PNACL_message(char *arg,...) { } -#ifndef FROM_MARKETMAKER #define FROM_MARKETMAKER -#endif +#ifndef CJSON_GARBAGECOLLECTION #define CJSON_GARBAGECOLLECTION +#endif + #include #include #ifndef NATIVE_WINDOWS diff --git a/iguana/m_mm b/iguana/m_mm index 3905b5d84b..0609d842c5 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -DFROM_MARKETMAKER -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -DCJSON_GARBAGECOLLECTION -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From 62ff96b246815feebf2e2d55e39f75d96cec226b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:29:15 +0200 Subject: [PATCH 06/41] Test --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 404931fcf1..9674910b89 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1144,7 +1144,7 @@ cJSON *cJSON_CreateObject(void) if ( item ) item->type = cJSON_Object; #ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); fff + cJSON_register(item); #endif return item; } From 21b83eaf5fc3d5e978d247524c46dd2745834c15 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:31:20 +0200 Subject: [PATCH 07/41] Test --- includes/cJSON.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/cJSON.h b/includes/cJSON.h index 77e0752e64..cd8e6d00f6 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -218,6 +218,8 @@ extern "C" char *nxt64str2(uint64_t nxt64bits); cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num); int32_t myatoi(char *str,int32_t range); + void cJSON_register(cJSON *item); + void cJSON_unregister(cJSON *item); char *stringifyM(char *str); #define replace_backslashquotes unstringify From fc1c161db6650d8cd989ae00d742596606d1116d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:47:36 +0200 Subject: [PATCH 08/41] Test --- iguana/exchanges/LP_nativeDEX.c | 3 ++- iguana/exchanges/LP_utxo.c | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index ae5fa57a7b..c7ba59d0bf 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -82,7 +82,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,LP_gcmutex,LP_inusemutex; +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,LP_inusemutex,LP_cJSONmutex; int32_t LP_canbind; char *Broadcaststr,*Reserved_msgs[2][1000]; int32_t num_Reserved_msgs[2],max_Reserved_msgs[2]; @@ -938,6 +938,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu portable_mutex_init(&LP_reservedmutex); portable_mutex_init(&LP_nanorecvsmutex); portable_mutex_init(&LP_tradebotsmutex); + portable_mutex_init(&LP_cJSONmutex); myipaddr = clonestr("127.0.0.1"); #ifndef _WIN32 #ifndef FROM_JS diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6e49013b04..cdfff09a1b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -27,6 +27,42 @@ struct LP_inuse_info } LP_inuse[1024]; int32_t LP_numinuse; +struct cJSON_list +{ + struct cJSON_list *next,*prev; + cJSON *item; + uint32_t timestamp; +} *LP_cJSONlist; + +void cJSON_register(cJSON *item) +{ + struct cJSON_list *ptr; + ptr = calloc(1,sizeof(*ptr)); + ptr->timestamp = (uint32_t)time(NULL); + ptr->item = item; + portable_mutex_lock(&LP_cJSONmutex); + DL_APPEND(LP_cJSONlist,ptr); + portable_mutex_unlock(&LP_cJSONmutex); +} + +void cJSON_unregister(cJSON *item) +{ + struct cJSON_list *ptr,*tmp; + DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) + { + if ( ptr->item == item ) + break; + ptr = 0; + } + if ( ptr != 0 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_cJSONlist,ptr); + free(ptr); + portable_mutex_unlock(&LP_cJSONmutex); + } +} + struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) { int32_t i; From 5770810c609ab69de70d92bebe61a202bf8fcb5f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:48:38 +0200 Subject: [PATCH 09/41] Test --- crypto777/cJSON.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 9674910b89..28f02bafc6 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1149,11 +1149,11 @@ cJSON *cJSON_CreateObject(void) return item; } -void free_json(cJSON *json) +void free_json(cJSON *item) { #ifdef CJSON_GARBAGECOLLECTION cJSON_unregister(item); #endif if ( json != 0 ) - cJSON_Delete(json); + cJSON_Delete(item); } From b86d13d6b503774c2c54b4c83c02560396b71f1c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 13:49:30 +0200 Subject: [PATCH 10/41] Test --- crypto777/cJSON.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 28f02bafc6..555fdf29cd 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1154,6 +1154,6 @@ void free_json(cJSON *item) #ifdef CJSON_GARBAGECOLLECTION cJSON_unregister(item); #endif - if ( json != 0 ) + if ( item != 0 ) cJSON_Delete(item); } From 2d23ba8dd6bf0d45f5bd5c8cb32d4498b354aa26 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:15:08 +0200 Subject: [PATCH 11/41] Test --- iguana/exchanges/LP_utxo.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index cdfff09a1b..6d22d3fafa 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -45,9 +45,25 @@ void cJSON_register(cJSON *item) portable_mutex_unlock(&LP_cJSONmutex); } +char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { - struct cJSON_list *ptr,*tmp; + static uint32_t lasttime; + char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; + if ( time(NULL) > lasttime+600 ) + { + n = 0; + total = 0; + DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) + { + tmpstr = jprint(ptr->item,0); + total += strlen(tmpstr); + free(tmpstr); + n++; + } + printf("total %d cJSON pending %s\n",n,mbstr(str,total)); + lasttime = (uint32_t)time(NULL); + } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { if ( ptr->item == item ) @@ -60,7 +76,7 @@ void cJSON_unregister(cJSON *item) DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } + } else printf("cJSON_unregister of unknown %p\n",item); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From 19634a3c9afa042ef0b92574c8f608ed3a55770a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:18:04 +0200 Subject: [PATCH 12/41] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 6d22d3fafa..e36afaff5e 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -72,11 +72,12 @@ void cJSON_unregister(cJSON *item) } if ( ptr != 0 ) { + printf("found %p\n",item); portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } else printf("cJSON_unregister of unknown %p\n",item); + } //else printf("cJSON_unregister of unknown %p\n",item); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From ce6caefbed81964237feb6d8715a6ca8dfc41b78 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:24:45 +0200 Subject: [PATCH 13/41] Test --- iguana/exchanges/LP_utxo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e36afaff5e..a807f2fccc 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -37,6 +37,7 @@ struct cJSON_list void cJSON_register(cJSON *item) { struct cJSON_list *ptr; + printf(" register %p\n",item); ptr = calloc(1,sizeof(*ptr)); ptr->timestamp = (uint32_t)time(NULL); ptr->item = item; @@ -50,6 +51,7 @@ void cJSON_unregister(cJSON *item) { static uint32_t lasttime; char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; + printf("unregister %p\n",item); if ( time(NULL) > lasttime+600 ) { n = 0; From 240d250f68c28d0cfe50022e381918f472870639 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:34:25 +0200 Subject: [PATCH 14/41] Test --- iguana/exchanges/LP_utxo.c | 2 +- iguana/exchanges/invreset | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a807f2fccc..ce9c0f4caf 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -52,7 +52,7 @@ void cJSON_unregister(cJSON *item) static uint32_t lasttime; char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; printf("unregister %p\n",item); - if ( time(NULL) > lasttime+600 ) + if ( time(NULL) > lasttime+6 ) { n = 0; total = 0; diff --git a/iguana/exchanges/invreset b/iguana/exchanges/invreset index f0b1c79e32..0304c75036 100755 --- a/iguana/exchanges/invreset +++ b/iguana/exchanges/invreset @@ -1,3 +1,4 @@ +#!/bin/bash source userpass source passphrase curl --url "http://127.0.0.1:7783" --data "{\"userpass\":\"$userpass\",\"method\":\"inventory\",\"coin\":\"KMD\",\"reset\":1,\"passphrase\":\"$passphrase\"}" From d70d5c835db1c4661513f8b3c9b2280154c09b23 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:41:16 +0200 Subject: [PATCH 15/41] Test --- iguana/exchanges/LP_utxo.c | 13 ++++++------- includes/cJSON.h | 1 + 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index ce9c0f4caf..a329aaef54 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -31,16 +31,17 @@ struct cJSON_list { struct cJSON_list *next,*prev; cJSON *item; - uint32_t timestamp; + uint32_t timestamp,cjsonid; } *LP_cJSONlist; void cJSON_register(cJSON *item) { struct cJSON_list *ptr; - printf(" register %p\n",item); ptr = calloc(1,sizeof(*ptr)); ptr->timestamp = (uint32_t)time(NULL); ptr->item = item; + item->cjsonid = rand(); + ptr->cjsonid = item->cjsonid; portable_mutex_lock(&LP_cJSONmutex); DL_APPEND(LP_cJSONlist,ptr); portable_mutex_unlock(&LP_cJSONmutex); @@ -51,8 +52,7 @@ void cJSON_unregister(cJSON *item) { static uint32_t lasttime; char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; - printf("unregister %p\n",item); - if ( time(NULL) > lasttime+6 ) + //if ( time(NULL) > lasttime+6 ) { n = 0; total = 0; @@ -68,18 +68,17 @@ void cJSON_unregister(cJSON *item) } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item == item ) + if ( ptr->cjsonid == item->cjsonid )//ptr->item == item ) break; ptr = 0; } if ( ptr != 0 ) { - printf("found %p\n",item); portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } //else printf("cJSON_unregister of unknown %p\n",item); + } else printf("cJSON_unregister of unknown %p\n",item); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) diff --git a/includes/cJSON.h b/includes/cJSON.h index cd8e6d00f6..3ecdadc694 100755 --- a/includes/cJSON.h +++ b/includes/cJSON.h @@ -73,6 +73,7 @@ extern "C" double valuedouble; /* The item's number, if type==cJSON_Number */ char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ + uint32_t cjsonid; } cJSON; typedef struct cJSON_Hooks { From 006fcdaea0a39052d5ff699b02cb3ea0fcff5639 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:42:32 +0200 Subject: [PATCH 16/41] Test --- iguana/exchanges/LP_utxo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index a329aaef54..8a54d97aea 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -78,7 +78,7 @@ void cJSON_unregister(cJSON *item) DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } else printf("cJSON_unregister of unknown %p\n",item); + } else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From 5e851f41eadad9b2f13beca5ef25db937970b535 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:46:40 +0200 Subject: [PATCH 17/41] Test --- iguana/exchanges/LP_utxo.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8a54d97aea..d785ca9334 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,9 +58,11 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - tmpstr = jprint(ptr->item,0); - total += strlen(tmpstr); - free(tmpstr); + if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + { + total += strlen(tmpstr); + free(tmpstr); + } n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From 86e4295c24ea27dfd2528426d565f0f158bca475 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:50:28 +0200 Subject: [PATCH 18/41] Test --- crypto777/bitcoind_RPC.c | 2 +- iguana/exchanges/LP_utxo.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crypto777/bitcoind_RPC.c b/crypto777/bitcoind_RPC.c index 4f0a9cdd42..98c7e7eb07 100755 --- a/crypto777/bitcoind_RPC.c +++ b/crypto777/bitcoind_RPC.c @@ -56,7 +56,7 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * char *retstr = 0; cJSON *json,*result,*error; #ifdef FROM_MARKETMAKER - usleep(5000); + usleep(3000); #endif //printf("<<<<<<<<<<< bitcoind_RPC: %s post_process_bitcoind_RPC.%s.[%s]\n",debugstr,command,rpcstr); if ( command == 0 || rpcstr == 0 || rpcstr[0] == 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index d785ca9334..c78b475e7b 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,10 +58,13 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + if ( ptr->item != 0 && ptr->item->child != 0 ) { - total += strlen(tmpstr); - free(tmpstr); + if ( (tmpstr= jprint(ptr->item,0)) != 0 ) + { + total += strlen(tmpstr); + free(tmpstr); + } } n++; } From 54a26a1ebad8d4f05dc943e21de0d681cac5b94a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:54:30 +0200 Subject: [PATCH 19/41] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index c78b475e7b..fa1210cfa5 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,14 +58,14 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item != 0 && ptr->item->child != 0 ) + /*if ( ptr->item != 0 && ptr->item->child != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - } + }*/ n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From 66c434d82d697843a93ff2bca53449cc9e7a1353 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 14:55:57 +0200 Subject: [PATCH 20/41] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index fa1210cfa5..de6660b867 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,14 +58,14 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - /*if ( ptr->item != 0 && ptr->item->child != 0 ) + if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - }*/ + } n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From a25ab17cbbe7c727b44469f96794a3e0b56f3832 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:00:04 +0200 Subject: [PATCH 21/41] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index de6660b867..933af800ab 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,14 +58,14 @@ void cJSON_unregister(cJSON *item) total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) + /*if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - } + }*/ n++; } printf("total %d cJSON pending %s\n",n,mbstr(str,total)); From 7c29efc217e67da5540e904df1fd2e96d933c7ed Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:08:29 +0200 Subject: [PATCH 22/41] Test --- iguana/exchanges/LP_utxo.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 933af800ab..8512572e67 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -51,11 +51,10 @@ char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { static uint32_t lasttime; - char *tmpstr,str[65]; int32_t n; uint64_t total; struct cJSON_list *ptr,*tmp; - //if ( time(NULL) > lasttime+6 ) + int32_t n; struct cJSON_list *ptr,*tmp; uint32_t now; + if ( (now= time(NULL)) > lasttime+6 ) { n = 0; - total = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { /*if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) @@ -68,13 +67,21 @@ void cJSON_unregister(cJSON *item) }*/ n++; } - printf("total %d cJSON pending %s\n",n,mbstr(str,total)); + printf("total %d cJSON pending\n",n); lasttime = (uint32_t)time(NULL); } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->cjsonid == item->cjsonid )//ptr->item == item ) + if ( ptr->item == item ) break; + else if ( now > ptr->timestamp+60 ) + { + portable_mutex_lock(&LP_cJSONmutex); + DL_DELETE(LP_cJSONlist,ptr); + portable_mutex_unlock(&LP_cJSONmutex); + cJSON_Delete(ptr->item); + free(ptr); + } ptr = 0; } if ( ptr != 0 ) From 02df7289d30f72ab6d33331aeba4808a012da5ec Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:10:11 +0200 Subject: [PATCH 23/41] Test --- iguana/exchanges/LP_utxo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 8512572e67..4b0828a3b8 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -79,6 +79,7 @@ void cJSON_unregister(cJSON *item) portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); portable_mutex_unlock(&LP_cJSONmutex); + printf("free expired\n"); cJSON_Delete(ptr->item); free(ptr); } @@ -90,7 +91,7 @@ void cJSON_unregister(cJSON *item) DL_DELETE(LP_cJSONlist,ptr); free(ptr); portable_mutex_unlock(&LP_cJSONmutex); - } else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); + } //else printf("cJSON_unregister of unknown %p %u\n",item,item->cjsonid); } struct LP_inuse_info *_LP_inuse_find(bits256 txid,int32_t vout) From 49c0feed90b0686b8210d85d8d808e09f2240e19 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:12:56 +0200 Subject: [PATCH 24/41] Test --- iguana/exchanges/LP_utxo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 4b0828a3b8..1befc1dcfb 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -72,9 +72,9 @@ void cJSON_unregister(cJSON *item) } DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - if ( ptr->item == item ) + if ( ptr->cjsonid == item->cjsonid ) break; - else if ( now > ptr->timestamp+60 ) + else if ( now > ptr->timestamp+60 && item->cjsonid != 0 ) { portable_mutex_lock(&LP_cJSONmutex); DL_DELETE(LP_cJSONlist,ptr); From bea2f74a87beb53592f02099935c6b01a883853b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:16:16 +0200 Subject: [PATCH 25/41] Test --- crypto777/cJSON.c | 18 +++++++++--------- iguana/m_mm | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/crypto777/cJSON.c b/crypto777/cJSON.c index 555fdf29cd..93438fe794 100755 --- a/crypto777/cJSON.c +++ b/crypto777/cJSON.c @@ -1132,9 +1132,9 @@ cJSON *cJSON_CreateArray(void) cJSON *item = cJSON_New_Item(); if ( item ) item->type = cJSON_Array; -#ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); -#endif +//#ifdef CJSON_GARBAGECOLLECTION +// cJSON_register(item); +//#endif return(item); } @@ -1143,17 +1143,17 @@ cJSON *cJSON_CreateObject(void) cJSON *item = cJSON_New_Item(); if ( item ) item->type = cJSON_Object; -#ifdef CJSON_GARBAGECOLLECTION - cJSON_register(item); -#endif +//#ifdef CJSON_GARBAGECOLLECTION +// cJSON_register(item); +//#endif return item; } void free_json(cJSON *item) { -#ifdef CJSON_GARBAGECOLLECTION - cJSON_unregister(item); -#endif +//#ifdef CJSON_GARBAGECOLLECTION +// cJSON_unregister(item); +//#endif if ( item != 0 ) cJSON_Delete(item); } diff --git a/iguana/m_mm b/iguana/m_mm index 0609d842c5..36a0acad11 100755 --- a/iguana/m_mm +++ b/iguana/m_mm @@ -1,3 +1,3 @@ cd secp256k1; ./m_unix; cd .. cd ../crypto777; ./m_LP; cd ../iguana -gcc -DCJSON_GARBAGECOLLECTION -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm +gcc -g -o marketmaker -I../crypto777 exchanges/mm.c ../crypto777/cJSON.c mini-gmp.c secp256k1.o ../agents/libcrypto777.a -lnanomsg -lcurl -lpthread -lm From b435fe804c7af8da3ce399b9320346f851a2cf5c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:18:53 +0200 Subject: [PATCH 26/41] Test --- iguana/exchanges/LP_commands.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 56ed047e45..a241aa4ab9 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,7 +35,9 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; - //printf("stats_JSON(%s)\n",jprint(argjson,0)); + retstr = jprint(argjson,0); + printf("stats_JSON(%s)\n",retstr); + free(retstr), retstr = 0; method = jstr(argjson,"method"); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) { From cd61cdb07f517ed47b0294890917cc67ae8bb53d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:25:35 +0200 Subject: [PATCH 27/41] Test --- iguana/exchanges/LP_commands.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index a241aa4ab9..b06fab289f 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,10 +35,12 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; - retstr = jprint(argjson,0); - printf("stats_JSON(%s)\n",retstr); - free(retstr), retstr = 0; - method = jstr(argjson,"method"); +retstr = jprint(argjson,0); +printf("stats_JSON(%s)\n",retstr); +free(retstr), retstr = 0; +method = jstr(argjson,"method"); +if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ) + return(clonestr("{}")); /*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 ) From db088b68ae6cafedf1e013d802ddc030ec2ecaea Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:28:56 +0200 Subject: [PATCH 28/41] Test --- iguana/exchanges/LP_commands.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index b06fab289f..c583c5346c 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -35,12 +35,12 @@ char *LP_numutxos() char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *remoteaddr,uint16_t port) // from rpc port { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; -retstr = jprint(argjson,0); -printf("stats_JSON(%s)\n",retstr); -free(retstr), retstr = 0; method = jstr(argjson,"method"); if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ) return(clonestr("{}")); +retstr = jprint(argjson,0); +printf("stats_JSON(%s)\n",retstr); +free(retstr), retstr = 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 ) From ecce4d9c0855bc60f49b675836b7ea4ba5272383 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 15:49:57 +0200 Subject: [PATCH 29/41] Test --- iguana/exchanges/LP_commands.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index c583c5346c..d4487782d6 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,7 +36,9 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); -if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 ) +if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 + || strcmp(method,"notify") == 0 || strcmp(method,"postprice") == 0 + ) return(clonestr("{}")); retstr = jprint(argjson,0); printf("stats_JSON(%s)\n",retstr); From 3843e3d1e843b7cc034f8b2fad849016c976f60f Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:02:17 +0200 Subject: [PATCH 30/41] Test --- iguana/exchanges/LP_commands.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index d4487782d6..fdc2bc6ff7 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -37,7 +37,8 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 - || strcmp(method,"notify") == 0 || strcmp(method,"postprice") == 0 + || strcmp(method,"notify") == 0 + //|| strcmp(method,"postprice") == 0 ) return(clonestr("{}")); retstr = jprint(argjson,0); From 48623418bbeafdae3cc01059f872e52811e3a416 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:04:05 +0200 Subject: [PATCH 31/41] Test --- iguana/exchanges/LP_commands.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index fdc2bc6ff7..3fc34e752b 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -36,14 +36,11 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r { char *method,*userpass,*base,*rel,*coin,*retstr = 0; int32_t changed,flag = 0; cJSON *retjson,*reqjson = 0; struct iguana_info *ptr; method = jstr(argjson,"method"); -if ( strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 - || strcmp(method,"notify") == 0 +if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || + strcmp(method,"notify") == 0 //|| strcmp(method,"postprice") == 0 ) return(clonestr("{}")); -retstr = jprint(argjson,0); -printf("stats_JSON(%s)\n",retstr); -free(retstr), retstr = 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 ) From 12a6db1ac053c50ca87cde167292b5df8f11dcfc Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:06:28 +0200 Subject: [PATCH 32/41] Test --- iguana/exchanges/LP_commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_commands.c b/iguana/exchanges/LP_commands.c index 3fc34e752b..40f7151c36 100644 --- a/iguana/exchanges/LP_commands.c +++ b/iguana/exchanges/LP_commands.c @@ -38,7 +38,7 @@ char *stats_JSON(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson,char *r method = jstr(argjson,"method"); if ( //strcmp(method,"uitem") == 0 || strcmp(method,"postutxos") == 0 || strcmp(method,"notify") == 0 - //|| strcmp(method,"postprice") == 0 + || strcmp(method,"postprice") == 0 ) return(clonestr("{}")); /*if ( (ipaddr= jstr(argjson,"ipaddr")) != 0 && (argport= juint(argjson,"port")) != 0 && (method == 0 || strcmp(method,"electrum") != 0) ) From 8743a5701fb5265647f5f03f36e1dccfd9074061 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:37:34 +0200 Subject: [PATCH 33/41] Test --- iguana/exchanges/LP_cache.c | 6 +++--- iguana/exchanges/LP_commands.c | 6 +++--- iguana/exchanges/LP_swap.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/iguana/exchanges/LP_cache.c b/iguana/exchanges/LP_cache.c index a088289662..fdc734fe98 100644 --- a/iguana/exchanges/LP_cache.c +++ b/iguana/exchanges/LP_cache.c @@ -45,10 +45,10 @@ struct LP_transaction *LP_create_transaction(struct iguana_info *coin,bits256 tx vins = jarray(&numvins,txobj,"vin"); vouts = jarray(&numvouts,txobj,"vout"); tx = LP_transactionadd(coin,txid,height,numvouts,numvins); - tx->serialized = serialized; - //free(serialized); + tx->serialized = 0;//serialized; + free(serialized); tx->fpos = fpos; - tx->len = tx->len; + tx->len = 0;//tx->len; tx->SPV = tx->height = height; //printf("tx.%s numvins.%d numvouts.%d\n",bits256_str(str,txid),numvins,numvouts); for (i=0; i= 1000 ) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 03d08d69ef..7e31d21e89 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -895,7 +895,7 @@ void LP_aliceloop(void *_swap) } basilisk_swap_finished(swap); printf("finish swap.%p\n",swap); - //free(swap); + free(swap); G.LP_pendingswaps--; } From 6b98102ea39de321667e0dac15bc985fc70bf047 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 16:39:27 +0200 Subject: [PATCH 34/41] Test --- iguana/exchanges/LP_utxo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 1befc1dcfb..da6f97cc10 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -51,20 +51,20 @@ char *mbstr(char *str,double n); void cJSON_unregister(cJSON *item) { static uint32_t lasttime; - int32_t n; struct cJSON_list *ptr,*tmp; uint32_t now; - if ( (now= time(NULL)) > lasttime+6 ) + int32_t n; char *tmpstr; uint64_t total = 0; struct cJSON_list *ptr,*tmp; uint32_t now; + if ( (now= (uint32_t)time(NULL)) > lasttime+6 ) { n = 0; DL_FOREACH_SAFE(LP_cJSONlist,ptr,tmp) { - /*if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) + if ( ptr->item != 0 && ptr->item->child != 0 && ptr->cjsonid != 0 ) { if ( (tmpstr= jprint(ptr->item,0)) != 0 ) { total += strlen(tmpstr); free(tmpstr); } - }*/ + } n++; } printf("total %d cJSON pending\n",n); From 496a89c6aa32867a7f232aa49df69d26e932927a Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 18:30:29 +0200 Subject: [PATCH 35/41] Test --- iguana/exchanges/LP_nativeDEX.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c7ba59d0bf..6f90ed93c3 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,6 @@ // LP_nativeDEX.c // marketmaker // -// gc cJSON // more retries for swap sendrawtransaction? // pbca26 unfinished swaps // if ( G.LP_pendingswaps != 0 ) return(-1); @@ -327,7 +326,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int32_t sock,char *remoteaddr,int32_t maxdepth) { - int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; + int32_t recvlen=1,nonz = 0; cJSON *argjson; void *ptr,*buf; char methodstr[64],*retstr,*str; struct nn_pollfd pfd; if ( sock >= 0 ) { while ( nonz < maxdepth && recvlen > 0 ) @@ -339,8 +338,11 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int if ( nn_poll(&pfd,1,1) != 1 ) break; ptr = 0; - if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) + buf = malloc(1000000); + if ( (recvlen= nn_recv(sock,buf,1000000,0)) > 0 ) + //if ( (recvlen= nn_recv(sock,&ptr,NN_MSG,0)) > 0 ) { + ptr = buf; methodstr[0] = 0; //printf("%s.(%s)\n",typestr,(char *)ptr); if ( 0 ) @@ -390,7 +392,10 @@ int32_t LP_sock_check(char *typestr,void *ctx,char *myipaddr,int32_t pubsock,int } } if ( ptr != 0 ) - nn_freemsg(ptr), ptr = 0; + { + //nn_freemsg(ptr), ptr = 0; + free(buf); + } } } return(nonz); From 401f4d8a35f67ceeb4ca8a2b134ac1f158f75b84 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 18:58:29 +0200 Subject: [PATCH 36/41] Require requestid/quoteid match --- iguana/exchanges/LP_swap.c | 15 ++++++++++++--- iguana/exchanges/mm.c | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 7e31d21e89..f551b862b1 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -187,6 +187,8 @@ uint32_t basilisk_requestid(struct basilisk_request *rp) int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) { int32_t i,datalen = 0; + datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid); + datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.alicemaxconfirms; @@ -201,9 +203,16 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datalen) { - int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; - if ( datalen == sizeof(swap->otherdeck)+38 ) + uint32_t requestid,quoteid; int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; + if ( datalen == sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2 ) { + datalen += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid); + datalen += iguana_rwnum(0,&data[len],sizeof(quoteid),"eid); + if ( requestid != swap->I.req.requestid || quoteid != swap->I.req.quoteid ) + { + printf("SWAP requestid.%u quoteid.%u mismatch received r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid,requestid,quoteid); + return(-1); + } aliceconfirms = data[len++]; bobconfirms = data[len++]; alicemaxconfirms = data[len++]; @@ -243,7 +252,7 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal len += iguana_rwnum(0,&data[len],sizeof(swap->otherdeck[i>>1][i&1]),&swap->otherdeck[i>>1][i&1]); return(0); } - printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+36); + printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2); return(-1); } diff --git a/iguana/exchanges/mm.c b/iguana/exchanges/mm.c index e20b1dcb6d..f906390b86 100644 --- a/iguana/exchanges/mm.c +++ b/iguana/exchanges/mm.c @@ -19,6 +19,11 @@ // Copyright © 2017 SuperNET. All rights reserved. // +/* +#define malloc(n) LP_alloc(n) +#define calloc(a,b) LP_alloc((uint64_t)(a) * (b)) +#define free(ptr) LP_free(ptr)*/ + void PNACL_message(char *arg,...) { From cb8cdd25980f5f3117d0c97494cf064711df1c5d Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:11:05 +0200 Subject: [PATCH 37/41] Test --- iguana/exchanges/LP_swap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index f551b862b1..1b6a17ab36 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -206,8 +206,8 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal uint32_t requestid,quoteid; int32_t i,nonz=0,alicemaxconfirms,bobmaxconfirms,aliceconfirms,bobconfirms,len = 0; uint8_t other33[33]; if ( datalen == sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2 ) { - datalen += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid); - datalen += iguana_rwnum(0,&data[len],sizeof(quoteid),"eid); + len += iguana_rwnum(0,&data[len],sizeof(requestid),&requestid); + len += iguana_rwnum(0,&data[len],sizeof(quoteid),"eid); if ( requestid != swap->I.req.requestid || quoteid != swap->I.req.quoteid ) { printf("SWAP requestid.%u quoteid.%u mismatch received r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid,requestid,quoteid); @@ -252,7 +252,7 @@ int32_t LP_pubkeys_verify(struct basilisk_swap *swap,uint8_t *data,int32_t datal len += iguana_rwnum(0,&data[len],sizeof(swap->otherdeck[i>>1][i&1]),&swap->otherdeck[i>>1][i&1]); return(0); } - printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2); + printf("pubkeys verify size mismatch %d != %d\n",datalen,(int32_t)(sizeof(swap->otherdeck)+38+sizeof(uint32_t)*2)); return(-1); } From a3d3b00649f363abf262567b47eed4f00cee86f5 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:15:09 +0200 Subject: [PATCH 38/41] Test --- iguana/exchanges/LP_swap.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 1b6a17ab36..616ee46f7d 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -189,6 +189,7 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t i,datalen = 0; datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid); datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); + printf("send >>>>>>>>> r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid); data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.alicemaxconfirms; From 46bd310f62dd4b7ae47ac79ae0079f5602415c3b Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:19:53 +0200 Subject: [PATCH 39/41] Test --- iguana/exchanges/LP_swap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index 616ee46f7d..1002517b04 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -189,7 +189,6 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) int32_t i,datalen = 0; datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.requestid),&swap->I.req.requestid); datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->I.req.quoteid),&swap->I.req.quoteid); - printf("send >>>>>>>>> r.%u q.%u\n",swap->I.req.requestid,swap->I.req.quoteid); data[datalen++] = swap->I.aliceconfirms; data[datalen++] = swap->I.bobconfirms; data[datalen++] = swap->I.alicemaxconfirms; @@ -199,6 +198,7 @@ int32_t LP_pubkeys_data(struct basilisk_swap *swap,uint8_t *data,int32_t maxlen) data[datalen++] = swap->persistent_pubkey33[i]; for (i=0; ideck)/sizeof(swap->deck[0][0]); i++) datalen += iguana_rwnum(1,&data[datalen],sizeof(swap->deck[i>>1][i&1]),&swap->deck[i>>1][i&1]); + printf("send >>>>>>>>> r.%u q.%u datalen.%d\n",swap->I.req.requestid,swap->I.req.quoteid,datalen); return(datalen); } From 3a84ed7eb6ee140ebbab59cb3e0deec871fa1c43 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 19:39:16 +0200 Subject: [PATCH 40/41] Test --- iguana/exchanges/LP_include.h | 2 +- iguana/exchanges/LP_ordermatch.c | 11 ++++++++++ iguana/exchanges/LP_remember.c | 37 ++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 5e530f9c13..b1a78c694c 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -23,7 +23,7 @@ #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" -#define LP_BUILD_NUMBER "14414" +#define LP_BUILD_NUMBER "14498" #ifdef FROM_JS #include diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 0ab6faca0e..7d60f336d1 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -449,6 +449,11 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c if ( bits256_nonz(privkey) != 0 && bits256_cmp(G.LP_mypub25519,qp->srchash) == 0 ) { LP_requestinit(&qp->R,qp->srchash,qp->desthash,base,qp->satoshis-qp->txfee,rel,qp->destsatoshis-qp->desttxfee,qp->timestamp,qp->quotetime,DEXselector); + if ( LP_pendingswap(qp->R.requestid,qp->R.quoteid) > 0 ) + { + printf("requestid.%u quoteid.%u is already in progres\n",qp->R.requestid,qp->R.quoteid); + return(-1); + } if ( (swap= LP_swapinit(1,0,privkey,&qp->R,qp)) == 0 ) { printf("cant initialize swap\n"); @@ -611,6 +616,12 @@ char *LP_connectedalice(cJSON *argjson) // alice { retjson = cJSON_CreateObject(); LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,DEXselector); + if ( LP_pendingswap(Q.R.requestid,Q.R.quoteid) > 0 ) + { + printf("requestid.%u quoteid.%u is already in progres\n",Q.R.requestid,Q.R.quoteid); + jaddstr(retjson,"error","swap already in progress"); + return(jprint(retjson,1)); + } if ( (swap= LP_swapinit(0,0,Q.privkey,&Q.R,&Q)) == 0 ) { jaddstr(retjson,"error","couldnt swapinit"); diff --git a/iguana/exchanges/LP_remember.c b/iguana/exchanges/LP_remember.c index d8b264e7c0..c0ef0efd76 100644 --- a/iguana/exchanges/LP_remember.c +++ b/iguana/exchanges/LP_remember.c @@ -1441,3 +1441,40 @@ char *basilisk_swapentries(char *refbase,char *refrel,int32_t limit) return(jprint(retarray,1)); } +int32_t LP_pendingswap(uint32_t requestid,uint32_t quoteid) +{ + cJSON *retjson,*array,*pending,*item; uint32_t r,q; char *retstr; int32_t i,n,retval = 0; + if ( (retstr= LP_recent_swaps(1000)) != 0 ) + { + if ( (retjson= cJSON_Parse(retstr)) != 0 ) + { + if ( (array= jarray(&n,retjson,"swaps")) != 0 ) + { + for (i=0; i Date: Wed, 15 Nov 2017 19:43:04 +0200 Subject: [PATCH 41/41] Test --- iguana/exchanges/LP_include.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index b1a78c694c..b6c24be52b 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -23,7 +23,7 @@ #define LP_MAJOR_VERSION "0" #define LP_MINOR_VERSION "1" -#define LP_BUILD_NUMBER "14498" +#define LP_BUILD_NUMBER "15000" #ifdef FROM_JS #include