Browse Source

Merge pull request #771 from jl777/jl777

Fix swap negotiation wait times for slow coins, also have in-between times for btcsforks
patch-3
jl777 7 years ago
committed by GitHub
parent
commit
66ccbd8ab5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      iguana/exchanges/LP_coins.c
  2. 1
      iguana/exchanges/LP_include.h
  3. 39
      iguana/exchanges/LP_swap.c

13
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;

1
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);

39
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
{

Loading…
Cancel
Save