From 6b76aa8b849d653f0af2f8cfe1e98feae3f80095 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 May 2018 16:48:57 +0300 Subject: [PATCH 1/3] Test --- iguana/exchanges/LP_ordermatch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 9eb27ee33..5e5ff0707 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1389,7 +1389,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } LP_tradecommand_log(argjson); qprice = (double)Q.destsatoshis / (Q.satoshis - Q.txfee); //jdouble(argjson,"price"); - //printf("%s\n",jprint(argjson,0)); + printf("%s\n",jprint(argjson,0)); printf("%-4d uuid.%32s %12s %5s/%-5s %12.8f -> %12.8f (%11.8f) | RT.%d %d n%d\n",(uint32_t)time(NULL) % 3600,Q.uuidstr+32,method,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),qprice,LP_RTcount,LP_swapscount,G.netid); retval = 1; aliceid = j64bits(argjson,"aliceid"); From 53fe03e358bc2655f8bd3d5c0162d518a557c665 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 May 2018 17:05:47 +0300 Subject: [PATCH 2/3] Prevent duplicate utxo[] --- iguana/exchanges/LP_utxo.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/iguana/exchanges/LP_utxo.c b/iguana/exchanges/LP_utxo.c index e7c8c463e..eb4b37131 100644 --- a/iguana/exchanges/LP_utxo.c +++ b/iguana/exchanges/LP_utxo.c @@ -357,7 +357,7 @@ int32_t LP_address_minmax(int32_t iambob,uint64_t *medianp,uint64_t *minp,uint64 int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_address_utxo **utxos,int32_t max,struct LP_address *ap,char *coinaddr) { - struct LP_address_utxo *up,*tmp; struct LP_transaction *tx; cJSON *txout; int32_t n = 0; + struct LP_address_utxo *up,*tmp; struct LP_transaction *tx; cJSON *txout; int32_t i,n = 0; if ( strcmp(ap->coinaddr,coinaddr) != 0 ) printf("UNEXPECTED coinaddr mismatch (%s) != (%s)\n",ap->coinaddr,coinaddr); //portable_mutex_lock(&LP_utxomutex); @@ -402,9 +402,15 @@ int32_t LP_address_utxo_ptrs(struct iguana_info *coin,int32_t iambob,struct LP_a } if ( LP_allocated(up->U.txid,up->U.vout) == 0 ) { - utxos[n++] = up; - if ( n >= max ) - break; + for (i=0; iU.vout == up->U.vout && bits256_cmp(utxos[i]->U.txid,up->U.txid) == 0 ) + break; + if ( i == n ) + { + utxos[n++] = up; + if ( n >= max ) + break; + } } //else printf("LP_allocated skip %u\n",LP_allocated(up->U.txid,up->U.vout)); } else From 2cfd45c39860c4a4f492924a5015e490f286e8b3 Mon Sep 17 00:00:00 2001 From: jl777 Date: Tue, 8 May 2018 17:40:44 +0300 Subject: [PATCH 3/3] Add more guards against identical utxo in the utxopair --- iguana/exchanges/LP_ordermatch.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/iguana/exchanges/LP_ordermatch.c b/iguana/exchanges/LP_ordermatch.c index 5e5ff0707..7d3a239f9 100644 --- a/iguana/exchanges/LP_ordermatch.c +++ b/iguana/exchanges/LP_ordermatch.c @@ -1410,7 +1410,7 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, } else printf("got reserved response from destpubkey %s\n",bits256_str(str,Q.srchash)); } } - if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 ) // alice + if ( bits256_cmp(G.LP_mypub25519,Q.desthash) == 0 && bits256_cmp(G.LP_mypub25519,Q.srchash) != 0 && (Q.vout != Q.vout2 || bits256_cmp(Q.txid,Q.txid2) != 0) ) // alice { if ( Qtrades == 0 ) { @@ -1466,10 +1466,13 @@ int32_t LP_tradecommand(void *ctx,char *myipaddr,int32_t pubsock,cJSON *argjson, { //if ( LP_Alicemaxprice != 0. ) // return(retval); - bestprice = LP_bob_competition(&counter,aliceid,qprice,-1); - if ( Qtrades == 0 )//|| (bits256_cmp(Q.srchash,G.LP_mypub25519) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0) ) - LP_trades_gotrequest(ctx,&Q,&Q2,jstr(argjson,"pair")); - else LP_tradecommandQ(&Q,jstr(argjson,"pair"),LP_REQUEST); + if ( Q.destvout != Q.feevout || bits256_cmp(Q.desttxid,Q.feetxid) != 0 ) + { + bestprice = LP_bob_competition(&counter,aliceid,qprice,-1); + if ( Qtrades == 0 )//|| (bits256_cmp(Q.srchash,G.LP_mypub25519) == 0 && bits256_cmp(G.LP_mypub25519,Q.desthash) != 0) ) + LP_trades_gotrequest(ctx,&Q,&Q2,jstr(argjson,"pair")); + else LP_tradecommandQ(&Q,jstr(argjson,"pair"),LP_REQUEST); + } } else if ( strcmp(method,"connect") == 0 ) {