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

feat: propagate witness generation errors #132

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 8 additions & 2 deletions scripts/witnessgen/bin/native_host_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ async fn main() -> Result<()> {
init_tracing_subscriber(cfg.v)?;

if cfg.server {
start_server(cfg).await?;
let res = start_server(cfg).await;
if res.is_err() {
std::process::exit(1);
}
} else {
start_server_and_native_client(cfg).await?;
let res = start_server_and_native_client(cfg).await;
if res.is_err() {
std::process::exit(1);
}
}

println!("Exiting host program.");
Expand Down
39 changes: 22 additions & 17 deletions utils/host/src/witnessgen.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Result;
use std::time::Duration;
use tokio::time::timeout;

use kona_host::HostCli;

Expand Down Expand Up @@ -102,12 +101,13 @@ impl WitnessGenExecutor {
// after your custom behavior, otherwise you won't be able to terminate "normally".

// Wait for all processes to complete.
let result = self.wait_for_processes().await;
let any_failed = result.is_err();

if any_failed {
if let Some(err) = self.wait_for_processes().await.err() {
self.kill_all(binary_name).await?;
Err(anyhow::anyhow!("One or more child processes failed or timed out"))
Err(anyhow::anyhow!(
"Killed all witness generation processes because one failed. Error: {}",
err
))
} else {
Ok(())
}
Expand All @@ -117,19 +117,22 @@ impl WitnessGenExecutor {
/// an error.
async fn wait_for_processes(&mut self) -> Result<()> {
for child in &mut self.ongoing_processes {
match timeout(self.timeout, child.child.wait()).await {
Ok(Ok(status)) if !status.success() => {
return Err(anyhow::anyhow!("Child process exited with non-zero status"));
println!("Waiting for process to finish");
tokio::select! {
result = child.child.wait() => {
match result {
Ok(status) if !status.success() => {
return Err(anyhow::anyhow!("Witness generation process exited because it failed."));
}
Err(e) => {
return Err(anyhow::anyhow!("Failed to get witness generation process status: {}", e));
}
_ => {}
}
}
Ok(Err(e)) => {
eprintln!("Child process error: {}", e);
return Err(anyhow::anyhow!("Child process error"));
_ = tokio::time::sleep(self.timeout) => {
return Err(anyhow::anyhow!("Witness generation process timed out."));
}
Err(_) => {
eprintln!("Child process timed out");
return Err(anyhow::anyhow!("Child process timed out"));
}
_ => {}
}
}
Ok(())
Expand All @@ -143,7 +146,9 @@ impl WitnessGenExecutor {
async fn kill_all(&mut self, binary_name: String) -> Result<()> {
// Kill the "native client" processes.
for mut child in self.ongoing_processes.drain(..) {
child.child.kill().await?;
if let Ok(None) = child.child.try_wait() {
child.child.kill().await?;
}
}

// Kill the spawned witness gen program.
Expand Down
Loading