Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: panic app when cannot send prove #15

Merged
merged 7 commits into from
Oct 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions clients/cli/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use nexus_core::{
init_circuit_trace, key::CanonicalSerialize, pp::gen_vm_pp, prove_seq_step, types::*,
},
};
use std::env;
// use std::env;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// use std::env;

use zstd::stream::Encoder;
use rand::{ RngCore };

Expand Down Expand Up @@ -125,10 +125,25 @@ async fn main() {
)),
};

client
.send(Message::Binary(registration.encode_to_vec()))
.await
.unwrap();
let mut retries = 0;
let max_retries = 5;

loop {
if let Err(e) = client.send(Message::Binary(registration.encode_to_vec())).await {
eprintln!("Failed to send message: {:?}, attempt {}/{}", e, retries + 1, max_retries);

retries += 1;
if retries >= max_retries {
eprintln!("Max retries reached, exiting...");
break;
}

// Optionally, add a delay before retrying
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do exponential backoff here? (Multiply sleep delay by 2 each time.)

} else {
break;
}
}

track(
"register".into(),
Expand Down Expand Up @@ -261,10 +276,26 @@ async fn main() {
}),
);
progress_time = SystemTime::now();
client
.send(Message::Binary(progress.encode_to_vec()))
.await
.unwrap();

let mut retries = 0;
let max_retries = 5;
loop {
if let Err(e) = client.send(Message::Binary(progress.encode_to_vec())).await {
eprintln!("Failed to send message: {:?}, attempt {}/{}", e, retries + 1, max_retries);

retries += 1;
if retries >= max_retries {
eprintln!("Max retries reached, exiting...");
break;
}

// Optionally, add a delay before retrying
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do exponential backoff here? (Multiply sleep delay by 2 each time.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, let me update

Copy link
Collaborator

@collinjackson collinjackson Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this, and remove the comment

-                    // Optionally, add a delay before retrying
-                    tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
+                    tokio::time::sleep(tokio::time::Duration::from_secs(u64::pow(2, retries))).await;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated, please help me check and merge.

Thank you

} else {
break;
}
}

if step == end - 1 {
let mut buf = Vec::new();
let mut writer = Box::new(&mut buf);
Expand Down Expand Up @@ -323,4 +354,4 @@ async fn main() {
&ws_addr_string,
json!({ "prover_id": prover_id }),
);
}
}