Revert "Reestablish connection when mixclient fails (#445)" (#472)

This reverts commit aa69eeca00.
This commit is contained in:
Giacomo Pasini 2023-10-23 16:53:20 +02:00 committed by GitHub
parent d528ebd2ea
commit 3ce8cacb30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 29 deletions

View File

@ -1,6 +1,6 @@
use std::{ops::Range, time::Duration};
use mixnet_client::{MessageStream, MixnetClient};
use mixnet_client::MixnetClient;
use nomos_core::wire;
use rand::{rngs::OsRng, thread_rng, Rng};
use serde::{Deserialize, Serialize};
@ -47,26 +47,11 @@ impl MixnetHandler {
}
pub async fn run(&mut self) {
const BASE_DELAY: Duration = Duration::from_secs(5);
// we need this loop to help us reestablish the connection in case
// the mixnet client fails for whatever reason
let mut backoff = 0;
loop {
match self.client.run().await {
Ok(stream) => {
backoff = 0;
Self::handle_stream(self.commands_tx.clone(), stream).await;
}
Err(e) => {
tracing::error!("mixnet client error: {e}");
backoff += 1;
tokio::time::sleep(BASE_DELAY * backoff).await;
}
}
}
}
let Ok(mut stream) = self.client.run().await else {
tracing::error!("Could not quickstart mixnet stream");
return;
};
async fn handle_stream(tx: mpsc::Sender<Command>, mut stream: MessageStream) {
while let Some(result) = stream.next().await {
match result {
Ok(msg) => {
@ -77,7 +62,8 @@ impl MixnetHandler {
continue;
};
tx.send(Command::DirectBroadcastAndRetry {
self.commands_tx
.send(Command::DirectBroadcastAndRetry {
topic,
message,
retry_count: 0,
@ -86,8 +72,7 @@ impl MixnetHandler {
.unwrap_or_else(|_| tracing::error!("could not schedule broadcast"));
}
Err(e) => {
tracing::error!("mixnet client stream error: {e}");
// TODO: handle mixnet client stream error
todo!("Handle mixclient error: {e}");
}
}
}

View File

@ -45,6 +45,7 @@ impl NetworkBackend for Libp2p {
fn new(config: Self::Settings, overwatch_handle: OverwatchHandle) -> Self {
let (commands_tx, commands_rx) = tokio::sync::mpsc::channel(BUFFER_SIZE);
let (events_tx, _) = tokio::sync::broadcast::channel(BUFFER_SIZE);
let mut mixnet_handler = MixnetHandler::new(&config, commands_tx.clone());
overwatch_handle.runtime().spawn(async move {
mixnet_handler.run().await;