Browse Source

Merge pull request #501 from jl777/spvdex

fix deadlock
etomic
jl777 7 years ago
committed by GitHub
parent
commit
d650cf8c50
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      iguana/exchanges/LP_commands.c
  2. 13
      iguana/exchanges/LP_nativeDEX.c
  3. 2
      iguana/exchanges/LP_ordermatch.c
  4. 2
      iguana/exchanges/LP_stats.c
  5. 2
      iguana/exchanges/LP_transaction.c
  6. 5
      iguana/exchanges/LP_utxo.c

25
iguana/exchanges/LP_commands.c

@ -109,7 +109,6 @@ myprice(base, rel)\n\
enable(coin)\n\
disable(coin)\n\
notarizations(coin)\n\
parselog()\n\
statsdisp(starttime=0, endtime=0, gui="", pubkey="", base="", rel="")\n\
tradesarray(base, rel, starttime=<now>-timescale*1024, endtime=<now>, timescale=60) -> [timestamp, high, low, open, close, relvolume, basevolume, aveprice, numtrades]\n\
pricearray(base, rel, starttime=0, endtime=0, timescale=60) -> [timestamp, avebid, aveask, highbid, lowask]\n\
@ -269,12 +268,6 @@ zeroconf_claim(address, expiration=0)\n\
{
return(LP_portfolio());
}
else if ( strcmp(method,"parselog") == 0 )
{
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
return(jprint(LP_statslog_disp(2000000000,2000000000,"",zero,0,0),1));
}
else if ( strcmp(method,"statsdisp") == 0 )
{
return(jprint(LP_statslog_disp(juint(argjson,"starttime"),juint(argjson,"endtime"),jstr(argjson,"gui"),jbits256(argjson,"pubkey"),jstr(argjson,"base"),jstr(argjson,"rel")),1));
@ -299,11 +292,12 @@ zeroconf_claim(address, expiration=0)\n\
return(basilisk_swapentries(base,rel,jint(argjson,"limit")));
else return(basilisk_swaplist(0,0));
}
else if ( strcmp(method,"dynamictrust") == 0 )
/*else if ( strcmp(method,"dynamictrust") == 0 )
{
struct LP_address *ap; char *coinaddr;
if ( (ptr= LP_coinsearch("KMD")) != 0 && (coinaddr= jstr(argjson,"address")) != 0 )
{
LP_zeroconf_deposits(ptr);
if ( (ap= LP_addressfind(ptr,coinaddr)) != 0 )
{
retjson = cJSON_CreateObject();
@ -314,7 +308,7 @@ zeroconf_claim(address, expiration=0)\n\
}
}
return(clonestr("{\"error\":\"cant find address\"}"));
}
}*/
else if ( (retstr= LP_istradebots_command(ctx,pubsock,method,argjson)) != 0 )
return(retstr);
if ( base[0] != 0 && rel[0] != 0 )
@ -630,15 +624,12 @@ zeroconf_claim(address, expiration=0)\n\
else if ( strcmp(method,"tradestatus") == 0 )
{
bits256 zero; cJSON *tmpjson;
bits256 zero; cJSON *tmpjson; struct LP_quoteinfo Q;
LP_tradecommand_log(argjson);
//printf("GOT TRADESTATUS! %s\n",jprint(argjson,0));
if ( LP_statslog_parse() > 0 )
{
memset(zero.bytes,0,sizeof(zero));
if ( (tmpjson= LP_statslog_disp(2000000000,2000000000,"",zero,0,0))) // pending swaps
free_json(tmpjson);
}
LP_quoteparse(&Q,argjson);
LP_requestinit(&Q.R,Q.srchash,Q.desthash,Q.srccoin,Q.satoshis-Q.txfee,Q.destcoin,Q.destsatoshis-Q.desttxfee,Q.timestamp,Q.quotetime,0);
LP_tradecommand_log(argjson);
printf("%-4d (%-10u %10u) %12s id.%22llu %5s/%-5s %12.8f -> %11.8f price %11.8f | RT.%d %d\n",(uint32_t)time(NULL) % 3600,Q.R.requestid,Q.R.quoteid,method,(long long)Q.aliceid,Q.srccoin,Q.destcoin,dstr(Q.satoshis),dstr(Q.destsatoshis),(double)Q.destsatoshis/Q.satoshis,LP_RTcount,LP_swapscount);
retstr = clonestr("{\"result\":\"success\"}");
}
else if ( strcmp(method,"wantnotify") == 0 )

13
iguana/exchanges/LP_nativeDEX.c

@ -17,22 +17,24 @@
// LP_nativeDEX.c
// marketmaker
//
// feature requests:
// alice waiting for bestprice
// USD paxprice based USDvalue in portfolio
// cancel bid/ask
// delay swap credit back until notarization
// electrum dynamic trust over 1000
// https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for signing BCH/BTG
//
// bugs, validations:
// portfolio value based on ask?
// verify encrypted destpubkey, broadcast:0 setprice
// USD paxprice based USDvalue in portfolio
// improve critical section detection when parallel trades
// 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
// dont change error messages:
// if (enable_electrum_coin_output_data.error == 'couldnt find coin locally installed') { //{error: "couldnt find coin locally installed", coin: "BTC"}
//if (enable_native_coin_output_data.error == 'couldnt find coin locally installed') { //{error: "couldnt find coin locally installed", coin: "BTC"}
// if (!data.error === true && data.error !== 'coin is disabled') {
// if (bot_output_data.error == 'not enough funds') {
#include <stdio.h>
@ -89,7 +91,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,LP_cJSONmutex,LP_logmutex;
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,LP_logmutex,LP_statslogmutex;
int32_t LP_canbind;
char *Broadcaststr,*Reserved_msgs[2][1000];
int32_t num_Reserved_msgs[2],max_Reserved_msgs[2];
@ -1127,6 +1129,7 @@ void LPinit(uint16_t myport,uint16_t mypullport,uint16_t mypubport,uint16_t mybu
portable_mutex_init(&LP_tradebotsmutex);
portable_mutex_init(&LP_cJSONmutex);
portable_mutex_init(&LP_logmutex);
portable_mutex_init(&LP_statslogmutex);
myipaddr = clonestr("127.0.0.1");
#ifndef _WIN32
#ifndef FROM_JS

2
iguana/exchanges/LP_ordermatch.c

@ -496,7 +496,7 @@ int32_t LP_connectstartbob(void *ctx,int32_t pubsock,cJSON *argjson,char *base,c
bits256 zero;
memset(zero.bytes,0,sizeof(zero));
LP_reserved_msg(1,base,rel,zero,jprint(retjson,0));
//LP_reserved_msg(0,base,rel,zero,jprint(retjson,0));
LP_reserved_msg(0,base,rel,zero,jprint(retjson,0));
free_json(retjson);
retval = 0;
} else printf("error launching swaploop\n");

2
iguana/exchanges/LP_stats.c

@ -30,7 +30,6 @@ static uint32_t LP_requests,LP_reserveds,LP_connects,LP_connecteds,LP_tradestatu
void LP_tradecommand_log(cJSON *argjson)
{
static FILE *logfp; char *jsonstr;
portable_mutex_lock(&LP_logmutex);
if ( logfp == 0 )
{
if ( (logfp= fopen(LP_STATSLOG_FNAME,"rb+")) != 0 )
@ -44,7 +43,6 @@ void LP_tradecommand_log(cJSON *argjson)
free(jsonstr);
fflush(logfp);
}
portable_mutex_unlock(&LP_logmutex);
}
void LP_statslog_parseline(cJSON *lineobj)

2
iguana/exchanges/LP_transaction.c

@ -1126,7 +1126,7 @@ int32_t LP_vins_select(void *ctx,struct iguana_info *coin,int64_t *totalp,int64_
if ( LP_validSPV(coin->symbol,coin->smartaddr,up->U.txid,up->U.vout) < 0 )
continue;
}
if ( LP_allocated(up->U.txid,up->U.vout) != 0 )
if ( bits256_cmp(utxotxid,up->U.txid) != 0 && LP_allocated(up->U.txid,up->U.vout) != 0 )
continue;
up->spendheight = 1;
total += up->U.value;

5
iguana/exchanges/LP_utxo.c

@ -419,7 +419,7 @@ int32_t LP_address_utxoadd(uint32_t timestamp,char *debug,struct iguana_info *co
struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
{
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,vout,height; cJSON *array,*item; int64_t value; bits256 txid; uint32_t now;
struct LP_address *ap; struct LP_address_utxo *up,*tmp; int32_t i,n,vout,height; cJSON *array,*item,*txobj; int64_t value; bits256 txid; uint32_t now;
LP_address(coin,coin->smartaddr);
LP_listunspent_issue(coin->symbol,coin->smartaddr,2);
if ( (ap= LP_addressfind(coin,coin->smartaddr)) == 0 )
@ -448,6 +448,9 @@ struct LP_address *LP_address_utxo_reset(struct iguana_info *coin)
//{"tx_hash":"38d1b7c73015e1b1d6cb7fc314cae402a635b7d7ea294970ab857df8777a66f4","tx_pos":0,"height":577975,"value":238700}
item = jitem(array,i);
value = LP_listunspent_parseitem(coin,&txid,&vout,&height,item);
if ( (txobj= LP_gettxout(coin->symbol,coin->symbol,txid,vout)) == 0 )
continue;
else free_json(txobj);
LP_address_utxoadd(now,"withdraw",coin,coin->smartaddr,txid,vout,value,height,-1);
if ( (up= LP_address_utxofind(coin,coin->smartaddr,txid,vout)) == 0 )
printf("couldnt find just added %s/%d ht.%d %.8f\n",bits256_str(str,txid),vout,height,dstr(value));

Loading…
Cancel
Save