Skip to content

Commit

Permalink
feat: multiple conn mng has been simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
rozhkovdmitrii committed Sep 25, 2023
1 parent d5fa172 commit e7a10f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
20 changes: 6 additions & 14 deletions mm2src/coins/utxo/rpc_clients/conn_mng_multiple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,17 @@ impl ConnMngMultiple {
if guarded.conn_ctxs.is_empty() {
return ERR!("Not settings to connect to found");
}
let mut notified = vec![];
// let event_handlers = guarded.event_handlers.clone();

let event_handlers = guarded.event_handlers.clone();
for mut conn_ctx in &mut guarded.conn_ctxs {
let conn_settings = conn_ctx.conn_settings.clone();
let weak_spawner = conn_ctx.abortable_system.weak_spawner();
let (connection, ready_notify) =
try_s!(spawn_electrum(&conn_settings, event_handlers.clone(), weak_spawner));
let self_clone = self.clone();
let event_handlers = event_handlers.clone();
notified.push(Box::new(
async move {
ready_notify.notified().await;
}
.boxed(),
));
conn_ctx.connection.replace(Arc::new(AsyncMutex::new(connection)));
self.0.abortable_system.weak_spawner().spawn(async move {
let _ = self_clone.connect_to(conn_settings, event_handlers, weak_spawner).await;
});
}
drop(guarded);
select_all(notified).await;
Ok(())
}

Expand Down Expand Up @@ -142,7 +134,7 @@ impl ConnMngMultiple {
}

async fn resume_server(self, address: String) -> Result<(), String> {
debug!("Resume holding address: {}", address);
debug!("Resume address: {}", address);
let guard = self.0.guarded.lock().await;

let conn_ctx = Self::get_conn_ctx(&guard, &address)?;
Expand Down
3 changes: 1 addition & 2 deletions mm2src/coins/utxo/rpc_clients/conn_mng_selective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl ConnMngTrait for ConnMngSelective {
if let Err(err) = self_copy.clone().suspend_server(address.clone()).await {
error!("Failed to suspend server: {}, error: {}", address, err);
}
// !!!!!!! TODO: no need to connect
if let Err(err) = self_copy.connect().await {
error!(
"Failed to reconnect after addr was disconnected: {}, error: {}",
Expand Down Expand Up @@ -305,7 +304,7 @@ impl ConnMngSelective {
}

async fn resume_server(self, address: String) -> Result<(), String> {
debug!("Resume holding address: {}", address);
debug!("Resume address: {}", address);
let mut guard = self.0.guarded.lock().await;
let priority = guard
.conn_ctxs
Expand Down
3 changes: 1 addition & 2 deletions mm2src/coins/utxo/utxo_builder/utxo_coin_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,10 @@ pub trait UtxoCoinBuilderCommonOps {
error!("Error connecting to the electrum server address: {}", err);
};

// TODO: use connected and verified notify!!! At least try to make it better. Current uproach is not good )
let mut attempts = 0i32;
while !client.is_connected().await {
debug!("check if client is connected and version is negotiated");
if attempts >= 30 {
if attempts >= 10 {
return MmError::err(UtxoCoinBuildError::FailedToConnectToElectrums {
electrum_servers: servers.clone(),
seconds: 5,
Expand Down

0 comments on commit e7a10f0

Please sign in to comment.