diff --git a/mm2src/coins/utxo/rpc_clients/electrum_rpc/client.rs b/mm2src/coins/utxo/rpc_clients/electrum_rpc/client.rs index 08f9a7f30c..d2efd76aa9 100644 --- a/mm2src/coins/utxo/rpc_clients/electrum_rpc/client.rs +++ b/mm2src/coins/utxo/rpc_clients/electrum_rpc/client.rs @@ -310,12 +310,12 @@ impl ElectrumClient { { Ok(response) => Ok(response), // If we failed the request using only the active connections, try again using all connections. - Err(_) => { + Err(_) if !send_to_all => { warn!("Failed to send the request using active connections, trying all connections."); let connections = self.connection_manager.get_all_connections(); // The concurrency here must be `1`, because we are trying out connections that aren't maintained // which means we might break the max connections rule. - // We will at most we will break this rule by `1` (have `max_connected + 1` open connections). + // We will at most break this rule by `1` (have `max_connected + 1` open connections). let concurrency = 1; match self .send_request_using(&request, connections, send_to_all, concurrency) @@ -325,6 +325,7 @@ impl ElectrumClient { Err(err_vec) => Err(JsonRpcErrorType::Internal(format!("All servers errored: {err_vec:?}"))), } }, + Err(e) => Err(JsonRpcErrorType::Internal(format!("All servers errored: {e:?}"))), } } diff --git a/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection_manager/manager.rs b/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection_manager/manager.rs index 21232a50ec..05fd78dd20 100644 --- a/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection_manager/manager.rs +++ b/mm2src/coins/utxo/rpc_clients/electrum_rpc/connection_manager/manager.rs @@ -9,6 +9,7 @@ use super::connection_context::ConnectionContext; use crate::utxo::rpc_clients::UtxoRpcClientOps; use common::executor::abortable_queue::AbortableQueue; use common::executor::{AbortableSystem, SpawnFuture, Timer}; +use common::log::debug; use common::notifier::{Notifiee, Notifier}; use common::now_ms; use keys::Address; @@ -267,6 +268,7 @@ impl ConnectionManager { /// Handles the disconnection event from an Electrum server. pub fn on_disconnected(&self, server_address: &str) { + debug!("Electrum server disconnected: {}", server_address); let all_connections = self.read_connections(); let connection_ctx = unwrap_or_return!(all_connections.get(server_address)); @@ -387,9 +389,8 @@ impl ConnectionManager { let client = unwrap_or_return!(self.get_client()); // Sort the candidate connections by their priority/ID. candidate_connections.sort_by_key(|(_, priority)| *priority); - for (connection, _) in candidate_connections { + for (connection, connection_id) in candidate_connections { let address = connection.address().to_string(); - let connection_id = unwrap_or_continue!(self.read_connections().get(&address)).id; let (maintained_connections_size, lowest_priority_connection_id) = { let maintained_connections = self.read_maintained_connections(); let maintained_connections_size = maintained_connections.len() as u32; diff --git a/mm2src/coins/utxo/rpc_clients/electrum_rpc/constants.rs b/mm2src/coins/utxo/rpc_clients/electrum_rpc/constants.rs index 13c661e2d8..6b9a2fbcdc 100644 --- a/mm2src/coins/utxo/rpc_clients/electrum_rpc/constants.rs +++ b/mm2src/coins/utxo/rpc_clients/electrum_rpc/constants.rs @@ -20,6 +20,8 @@ pub const NO_FORCE_CONNECT_METHODS: &[&str] = &[ "server.version", ]; /// Electrum methods that should be sent to all connections even after receiving a response from a subset of them. +/// Note that this is only applicable to active/maintained connections. If an electrum request fails by all maintained +/// connections, a fallback using all connections will *NOT* be attempted. pub const SEND_TO_ALL_METHODS: &[&str] = &[ // A ping should be sent to all connections even if we got a response from one of them early. "server.ping",