diff --git a/iguana/exchanges/LP_include.h b/iguana/exchanges/LP_include.h index 870628dc9..efce3fe4b 100644 --- a/iguana/exchanges/LP_include.h +++ b/iguana/exchanges/LP_include.h @@ -40,6 +40,7 @@ void emscripten_usleep(int32_t x); // returns immediate, no sense for sleeping #define LP_HTTP_TIMEOUT 3 // 1 is too small due to edge cases of time(NULL) #define LP_AUTOTRADE_TIMEOUT 15 #define ELECTRUM_TIMEOUT 10 +#define LP_ELECTRUM_KEEPALIVE 60 #define LP_ELECTRUM_MAXERRORS 777 #define LP_MEMPOOL_TIMEINCR 10 diff --git a/iguana/exchanges/LP_nativeDEX.c b/iguana/exchanges/LP_nativeDEX.c index 6ae7a566a..d8ff7961c 100644 --- a/iguana/exchanges/LP_nativeDEX.c +++ b/iguana/exchanges/LP_nativeDEX.c @@ -19,7 +19,6 @@ // marketmaker // // electrum keepalive -// merge bots + portfoliot // verify portfolio, interest to KMD withdraw // dPoW security -> 4: KMD notarized, 5: BTC notarized, after next notary elections // bigendian architectures need to use little endian for sighash calcs @@ -494,7 +493,7 @@ int32_t LP_utxos_sync(struct LP_peerinfo *peer) void LP_coinsloop(void *_coins) { - struct LP_address *ap=0,*atmp; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t oldht,j,nonz; char *coins = _coins; + struct LP_address *ap=0,*atmp; cJSON *retjson; struct LP_address_utxo *up,*tmp; struct iguana_info *coin,*ctmp; char str[65]; struct electrum_info *ep,*backupep=0; bits256 zero; int32_t oldht,j,nonz; char *coins = _coins; while ( 1 ) { nonz = 0; @@ -548,6 +547,16 @@ void LP_coinsloop(void *_coins) } } } + while ( ep != 0 ) + { + if ( time(NULL) > ep->keepalive+LP_ELECTRUM_KEEPALIVE ) + { + printf("%s electrum.%p needs a keepalive: lag.%d\n",ep->symbol,ep,(int32_t)(time(NULL) - ep->keepalive)); + if ( (retjson= electrum_donation(ep->symbol,ep,&retjson)) != 0 ) + free_json(retjson); + } + ep = ep->prev; + } continue; } if ( coin->firstrefht == 0 ) diff --git a/iguana/exchanges/LP_socket.c b/iguana/exchanges/LP_socket.c index 55e30ade7..16da1a0c3 100644 --- a/iguana/exchanges/LP_socket.c +++ b/iguana/exchanges/LP_socket.c @@ -245,7 +245,7 @@ struct electrum_info struct electrum_info *prev; int32_t bufsize,sock,*heightp,numerrors; struct iguana_info *coin; - uint32_t stratumid,lasttime,pending,*heighttimep; + uint32_t stratumid,lasttime,keepalive,pending,*heighttimep; char ipaddr[64],symbol[16]; uint16_t port; uint8_t buf[]; @@ -931,6 +931,7 @@ void LP_dedicatedloop(void *arg) ep->sock = -1; break; } + ep->keepalive = (uint32_t)time(NULL); if ( sitem->expiration != 0 ) sitem->expiration += (uint32_t)time(NULL); else sitem->expiration = (uint32_t)time(NULL) + ELECTRUM_TIMEOUT;