From 250d25ada6223e90a8abef1e5c05556ca28dbba0 Mon Sep 17 00:00:00 2001 From: devbordecraft Date: Sat, 11 Dec 2021 16:56:33 +0100 Subject: [PATCH] Fix electrum query failing (CloseNotify bug) and use a more stable mainnet electrum server. --- CHANGELOG.md | 4 ++++ swap/src/asb/config.rs | 2 +- swap/src/bitcoin/wallet.rs | 23 ++++++++++++++--------- swap/src/cli/command.rs | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26745ad6..94fe4037 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The ASB to no longer work as a rendezvous server. The ASB can still register with rendezvous server as usual. +### Fixed + +- Mitigate CloseNotify bug #797 by retrying getting ScriptStatus if it fail and using a more stable public mainnet electrum server. + ## [0.9.0] - 2021-10-07 ### Changed diff --git a/swap/src/asb/config.rs b/swap/src/asb/config.rs index a8c7f37f..17c94691 100644 --- a/swap/src/asb/config.rs +++ b/swap/src/asb/config.rs @@ -58,7 +58,7 @@ impl GetDefaults for Mainnet { data_dir: default_asb_data_dir()?.join("mainnet"), listen_address_tcp: Multiaddr::from_str("/ip4/0.0.0.0/tcp/9939")?, listen_address_ws: Multiaddr::from_str("/ip4/0.0.0.0/tcp/9940/ws")?, - electrum_rpc_url: Url::parse("ssl://electrum.blockstream.info:50002")?, + electrum_rpc_url: Url::parse("ssl://blockstream.info:700")?, monero_wallet_rpc_url: Url::parse("http://127.0.0.1:18083/json_rpc")?, price_ticker_ws_url: Url::parse("wss://ws.kraken.com")?, bitcoin_confirmation_target: 3, diff --git a/swap/src/bitcoin/wallet.rs b/swap/src/bitcoin/wallet.rs index d08d56c3..d9631bf9 100644 --- a/swap/src/bitcoin/wallet.rs +++ b/swap/src/bitcoin/wallet.rs @@ -149,18 +149,21 @@ impl Wallet { Ok(new_status) => new_status, Err(error) => { tracing::warn!(%txid, "Failed to get status of script: {:#}", error); - return; + ScriptStatus::Retrying } }; + + if new_status != ScriptStatus::Retrying + { + last_status = Some(print_status_change(txid, last_status, new_status)); - last_status = Some(print_status_change(txid, last_status, new_status)); - - let all_receivers_gone = sender.send(new_status).is_err(); - - if all_receivers_gone { - tracing::debug!(%txid, "All receivers gone, removing subscription"); - client.lock().await.subscriptions.remove(&(txid, script)); - return; + let all_receivers_gone = sender.send(new_status).is_err(); + + if all_receivers_gone { + tracing::debug!(%txid, "All receivers gone, removing subscription"); + client.lock().await.subscriptions.remove(&(txid, script)); + return; + } } } }); @@ -823,6 +826,7 @@ pub enum ScriptStatus { Unseen, InMempool, Confirmed(Confirmed), + Retrying, } impl ScriptStatus { @@ -898,6 +902,7 @@ impl fmt::Display for ScriptStatus { match self { ScriptStatus::Unseen => write!(f, "unseen"), ScriptStatus::InMempool => write!(f, "in mempool"), + ScriptStatus::Retrying => write!(f, "retrying"), ScriptStatus::Confirmed(inner) => { write!(f, "confirmed with {} blocks", inner.confirmations()) } diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 491f3dea..ccb46fa2 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -19,7 +19,7 @@ pub const DEFAULT_MONERO_DAEMON_ADDRESS: &str = "node.melo.tools:18081"; pub const DEFAULT_MONERO_DAEMON_ADDRESS_STAGENET: &str = "stagenet.melo.tools:38081"; // See: https://1209k.com/bitcoin-eye/ele.php?chain=btc -const DEFAULT_ELECTRUM_RPC_URL: &str = "ssl://electrum.blockstream.info:50002"; +const DEFAULT_ELECTRUM_RPC_URL: &str = "ssl://blockstream.info:700"; // See: https://1209k.com/bitcoin-eye/ele.php?chain=tbtc pub const DEFAULT_ELECTRUM_RPC_URL_TESTNET: &str = "ssl://electrum.blockstream.info:60002";