From 1775a5dbea16212762b4991659b86b716649717e Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:15:18 +0200 Subject: [PATCH 1/6] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index c5c34b353..d17299573 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -310,7 +310,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { - if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) + if ( 0 && (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); From c871feeb8b57c7d7c6802c840b69da6967767a22 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:19:55 +0200 Subject: [PATCH 2/6] Test --- iguana/exchanges/LP_nativeDEX.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index d17299573..87360c470 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -179,18 +179,15 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson char *retstr=0; if ( jobj(argjson,"result") != 0 || jobj(argjson,"error") != 0 ) return(0); - //double millis = OS_milliseconds(); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) + if ( 0 && (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 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 && //LP_send(pubsock,retstr,(int32_t)strlen(retstr)+1,0); } } //else printf("finished tradecommand (%s)\n",jprint(argjson,0)); - //if ( OS_milliseconds()-millis > 100 ) - // printf("%.3f %s\n",OS_milliseconds()-millis,jprint(argjson,0)); return(retstr); } @@ -310,7 +307,7 @@ char *LP_process_message(void *ctx,char *typestr,char *myipaddr,int32_t pubsock, } else { - if ( 0 && (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) + if ( (retstr= LP_command_process(ctx,myipaddr,pubsock,argjson,&((uint8_t *)ptr)[len],recvlen - len)) != 0 ) { } //printf("%.3f %s LP_command_process\n",OS_milliseconds()-millis,jstr(argjson,"method")); From 1fca97e9e6437a0e6207f8399471cb42e1a0a7f6 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 00:21:16 +0200 Subject: [PATCH 3/6] Test --- iguana/exchanges/LP_nativeDEX.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 87360c470..5969f11a1 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -181,7 +181,7 @@ char *LP_command_process(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson return(0); if ( LP_tradecommand(ctx,myipaddr,pubsock,argjson,data,datalen) <= 0 ) { - if ( 0 && (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 0 ) + if ( (retstr= stats_JSON(ctx,myipaddr,pubsock,argjson,"127.0.0.1",0)) != 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 && From af80a8ed2ff70c3994a7ef29db82ab43902fb4a7 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 11:40:24 +0200 Subject: [PATCH 4/6] mark as spent LP_withdraw --- iguana/exchanges/LP_nativeDEX.c | 5 ++++- iguana/exchanges/LP_transaction.c | 1 + iguana/exchanges/LP_utxo.c | 6 +++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 5969f11a1..6232d159b 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -17,7 +17,10 @@ // LP_nativeDEX.c // marketmaker // -// single utxo allocations alice, reject result, latency +// single utxo allocations alice +// gc cJSON +// more retries for swap sendrawtransaction +// pbca26 unfinished swaps // alice waiting for bestprice //if ( G.LP_pendingswaps != 0 ) //return(-1); diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 4df4b3895..098d2cb84 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -987,6 +987,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_ vp->suppress_pubkeys = suppress_pubkeys; vp->ignore_cltverr = ignore_cltverr; jaddi(vins,LP_inputjson(up->U.txid,up->U.vout,spendscriptstr)); + LP_unavailableset(up->U.txid,up->U.vout,(uint32_t)time(NULL)+600,G.LP_mypub25519); if ( remains <= 0 && i >= numpre-1 ) break; if ( numunspents < 0 ) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index 0f2aee2c3..f8b4d7fac 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -59,7 +59,11 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) struct LP_inuse_info *_LP_inuse_add(uint32_t expiration,bits256 otherpub,bits256 txid,int32_t vout) { struct LP_inuse_info *lp; - if ( bits256_nonz(txid) != 0 && LP_numinuse < sizeof(LP_inuse)/sizeof(*LP_inuse) ) + if ( LP_numinuse >= sizeof(LP_inuse)/sizeof(*LP_inuse) ) + { + + } + if ( bits256_nonz(txid) != 0 && ) { if ( (lp= _LP_inuse_find(txid,vout)) == 0 ) { From 57fd772dfc465dca44cf40e50afe2cb278d25a70 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 11:45:41 +0200 Subject: [PATCH 5/6] Test --- iguana/exchanges/LP_utxo.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index f8b4d7fac..6e49013b0 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -58,12 +58,32 @@ int32_t _LP_inuse_delete(bits256 txid,int32_t vout) struct LP_inuse_info *_LP_inuse_add(uint32_t expiration,bits256 otherpub,bits256 txid,int32_t vout) { - struct LP_inuse_info *lp; + struct LP_inuse_info *lp; int32_t i,n,oldesti; uint32_t now,oldest; if ( LP_numinuse >= sizeof(LP_inuse)/sizeof(*LP_inuse) ) { - + now = (uint32_t)time(NULL); + n = 0; + oldesti = -1; + oldest = 0; + for (i=0; i lp->expiration ) + _LP_inuse_delete(lp->txid,lp->vout), n++; + else if ( oldest == 0 || lp->expiration < oldest ) + { + oldest = lp->expiration; + oldesti = i; + } + } + if ( n == 0 ) + { + printf("_LP_inuse_add out of slots error, pick oldesti %d\n",oldesti); + lp = &LP_inuse[oldesti]; + _LP_inuse_delete(lp->txid,lp->vout); + } else printf("expired %d inuse slots\n",n); } - if ( bits256_nonz(txid) != 0 && ) + if ( bits256_nonz(txid) != 0 ) { if ( (lp= _LP_inuse_find(txid,vout)) == 0 ) { From cb09859e0e8975f2b736628cfa0140cf242fd77c Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 15 Nov 2017 11:59:39 +0200 Subject: [PATCH 6/6] Test --- iguana/exchanges/LP_transaction.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_transaction.c b/iguana/exchanges/LP_transaction.c index 098d2cb84..3f6ff3e43 100644 --- a/iguana/exchanges/LP_transaction.c +++ b/iguana/exchanges/LP_transaction.c @@ -1020,7 +1020,7 @@ char *LP_createrawtransaction(cJSON **txobjp,int32_t *numvinsp,struct iguana_inf } if ( coin->numutxos < LP_MINDESIRED_UTXOS ) dustcombine = 0; - else if ( coin->numutxos >= LP_MINDESIRED_UTXOS ) + else if ( coin->numutxos >= LP_MAXDESIRED_UTXOS ) dustcombine = 2; else dustcombine = 1; amount = txfee;