From 128b1c86e3586fccd7102c557d6ebc497886b621 Mon Sep 17 00:00:00 2001 From: jl777 Date: Wed, 18 Apr 2018 15:21:38 +0300 Subject: [PATCH] Fix swap negotiation wait times for slow coins, also have in-between times for btcsforks --- iguana/exchanges/LP_coins.c | 13 ++++++++++++ iguana/exchanges/LP_include.h | 1 + iguana/exchanges/LP_swap.c | 39 +++++++++++++++++++++++------------ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/iguana/exchanges/LP_coins.c b/iguana/exchanges/LP_coins.c index 0f3a564ba..23ebc15b8 100644 --- a/iguana/exchanges/LP_coins.c +++ b/iguana/exchanges/LP_coins.c @@ -20,6 +20,19 @@ char *portstrs[][3] = { { "BTC", "8332" }, { "KMD", "7771" } }; +int32_t LP_is_slowcoin(char *symbol) +{ + if ( strcmp(symbol,"BTC") == 0 ) + return(2); + else if ( strcmp(symbol,"BCH") == 0 ) + return(1); + else if ( strcmp(symbol,"BTG") == 0 ) + return(1); + else if ( strcmp(symbol,"SBTC") == 0 ) + return(1); + else return(0); +} + uint16_t LP_rpcport(char *symbol) { int32_t i; diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 5d159e337..c5f752471 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -577,6 +577,7 @@ int64_t LP_outpoint_amount(char *symbol,bits256 txid,int32_t vout); void LP_initpeers(int32_t pubsock,struct LP_peerinfo *mypeer,char *myipaddr,uint16_t myport,uint16_t netid,char *seednode); int _decreasing_uint64(const void *a,const void *b); int32_t LP_alice_eligible(uint32_t quotetime); +int32_t LP_is_slowcoin(char *symbol); void LP_listunspent_query(char *symbol,char *coinaddr); int32_t bitcoin_priv2wif(char *symbol,uint8_t wiftaddr,char *wifstr,bits256 privkey,uint8_t addrtype); diff --git a/iguana/exchanges/LP_swap.c b/iguana/exchanges/LP_swap.c index dbf2011b3..181acdd72 100644 --- a/iguana/exchanges/LP_swap.c +++ b/iguana/exchanges/LP_swap.c @@ -18,9 +18,6 @@ // marketmaker // -/* - make sure to broadcast deposit before claiming refund, or to just skip it if neither is done - */ // included from basilisk.c @@ -107,13 +104,15 @@ depositspent.(f34e04ad74e290f63f3d0bccb7d0d50abfa54eea58de38816fdc596a19767add) alice.1 bob.0 */ -#define TX_WAIT_TIMEOUT 1800 +#define TX_WAIT_TIMEOUT 1800 // hard to increase this without hitting protocol limits (2/4 hrs) uint32_t LP_atomic_locktime(char *base,char *rel) { - if ( strcmp(base,"BTC") != 0 && strcmp(rel,"BTC") != 0 ) - return(INSTANTDEX_LOCKTIME); - else return(INSTANTDEX_LOCKTIME * 10); + if ( strcmp(base,"BTC") == 0 && strcmp(rel,"BTC") == 0 ) + return(INSTANTDEX_LOCKTIME * 10); + else if ( LP_is_slowcoin(base) > 0 || LP_is_slowcoin(rel) > 0 ) + return(INSTANTDEX_LOCKTIME * 4); + else return(INSTANTDEX_LOCKTIME); } void basilisk_rawtx_purge(struct basilisk_rawtx *rawtx) @@ -832,9 +831,19 @@ uint32_t LP_swapwait(uint32_t expiration,uint32_t requestid,uint32_t quoteid,int } } +int32_t LP_calc_waittimeout(char *symbol) +{ + int32_t waittimeout = TX_WAIT_TIMEOUT; + if ( strcmp(symbol,"BTC") == 0 ) + waittimeout *= 8; + else if ( LP_is_slowcoin(symbol) != 0 ) + waittimeout *= 4; + return(waittimeout); +} + void LP_bobloop(void *_swap) { - uint8_t *data; char bobstr[65],alicestr[65]; int32_t maxlen,m,n,err=0; uint32_t expiration; struct basilisk_swap *swap = _swap; + uint8_t *data; char bobstr[65],alicestr[65]; int32_t bobwaittimeout,alicewaittimeout,maxlen,m,n,err=0; uint32_t expiration; struct basilisk_swap *swap = _swap; G.LP_pendingswaps++; //printf("start swap iambob\n"); LP_etomicsymbol(bobstr,swap->I.bobtomic,swap->I.bobstr); @@ -842,6 +851,8 @@ void LP_bobloop(void *_swap) maxlen = 1024*1024 + sizeof(*swap); data = malloc(maxlen); expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT; + bobwaittimeout = LP_calc_waittimeout(bobstr); + alicewaittimeout = LP_calc_waittimeout(alicestr); if ( swap != 0 ) { if ( LP_waitsend("pubkeys",120,swap->N.pair,swap,data,maxlen,LP_pubkeys_verify,LP_pubkeys_data) < 0 ) @@ -862,7 +873,7 @@ void LP_bobloop(void *_swap) //LP_swapsfp_update(&swap->I.req); LP_swap_critical = (uint32_t)time(NULL); LP_unavailableset(swap->bobdeposit.utxotxid,swap->bobdeposit.utxovout,(uint32_t)time(NULL)+60,swap->I.otherhash); - if ( LP_waitfor(swap->N.pair,swap,TX_WAIT_TIMEOUT,LP_verify_otherfee) < 0 ) + if ( LP_waitfor(swap->N.pair,swap,bobwaittimeout,LP_verify_otherfee) < 0 ) { error = 1; err = -2004, printf("error waiting for alicefee\n"); @@ -876,7 +887,7 @@ void LP_bobloop(void *_swap) } } LP_unavailableset(swap->bobpayment.utxotxid,swap->bobpayment.utxovout,(uint32_t)time(NULL)+60,swap->I.otherhash); - if ( error == 0 && LP_waitfor(swap->N.pair,swap,TX_WAIT_TIMEOUT,LP_verify_alicepayment) < 0 ) + if ( error == 0 && LP_waitfor(swap->N.pair,swap,alicewaittimeout,LP_verify_alicepayment) < 0 ) { error = 1; err = -2006, printf("error waiting for alicepayment\n"); @@ -926,13 +937,15 @@ void LP_bobloop(void *_swap) void LP_aliceloop(void *_swap) { - uint8_t *data; char bobstr[65],alicestr[65]; int32_t maxlen,n,m,err=0; uint32_t expiration; struct basilisk_swap *swap = _swap; + uint8_t *data; char bobstr[65],alicestr[65]; int32_t bobwaittimeout,alicewaittimeout,maxlen,n,m,err=0; uint32_t expiration; struct basilisk_swap *swap = _swap; G.LP_pendingswaps++; LP_etomicsymbol(bobstr,swap->I.bobtomic,swap->I.bobstr); LP_etomicsymbol(alicestr,swap->I.alicetomic,swap->I.alicestr); maxlen = 1024*1024 + sizeof(*swap); data = malloc(maxlen); expiration = (uint32_t)time(NULL) + LP_SWAPSTEP_TIMEOUT; + bobwaittimeout = LP_calc_waittimeout(bobstr); + alicewaittimeout = LP_calc_waittimeout(alicestr); if ( swap != 0 ) { printf("start swap iamalice pair.%d\n",swap->N.pair); @@ -950,7 +963,7 @@ void LP_aliceloop(void *_swap) LP_swap_critical = (uint32_t)time(NULL); if ( LP_swapdata_rawtxsend(swap->N.pair,swap,0x80,data,maxlen,&swap->myfee,0x40,0) == 0 ) err = -1004, printf("error sending alicefee\n"); - else if ( LP_waitfor(swap->N.pair,swap,TX_WAIT_TIMEOUT,LP_verify_bobdeposit) < 0 ) + else if ( LP_waitfor(swap->N.pair,swap,bobwaittimeout,LP_verify_bobdeposit) < 0 ) err = -1005, printf("error waiting for bobdeposit\n"); else { @@ -975,7 +988,7 @@ void LP_aliceloop(void *_swap) } //swap->sentflag = 1; LP_swap_critical = (uint32_t)time(NULL); - if ( LP_waitfor(swap->N.pair,swap,TX_WAIT_TIMEOUT,LP_verify_bobpayment) < 0 ) + if ( LP_waitfor(swap->N.pair,swap,bobwaittimeout,LP_verify_bobpayment) < 0 ) err = -1007, printf("error waiting for bobpayment\n"); else {