Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jtguibas committed Aug 11, 2024
1 parent 85c0069 commit 5337558
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions core/src/utils/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub fn setup_logger() {
let default_filter = "off";
let env_filter = EnvFilter::try_from_default_env()
.unwrap_or_else(|_| EnvFilter::new(default_filter))
.add_directive("hyper=off".parse().unwrap())
.add_directive("p3_keccak_air=off".parse().unwrap())
.add_directive("p3_fri=off".parse().unwrap())
.add_directive("p3_dft=off".parse().unwrap())
Expand Down
45 changes: 34 additions & 11 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::Arc;

use crate::proto::api::ProverServiceClient;

use proto::api::ReadyRequest;
use serde::{Deserialize, Serialize};
use sp1_core::io::SP1Stdin;
use sp1_core::stark::ShardProof;
Expand Down Expand Up @@ -91,18 +92,21 @@ impl SP1ProverServer {
let cleanup_name = container_name;
let cleanup_flag = cleaned_up.clone();

// TODO: pull container if not present
// TODO: inherit RUST_LOG from the environment
// TODO: hit ready endpoint to check if container is ready
// Pull the docker image if it's not present.
Command::new("sudo")
.args(["docker", "pull", image_name])
.status()
.expect("failed to pull docker image");

// Spawn a new thread to start the Docker container.
// Start the docker container.
let rust_log_level = std::env::var("RUST_LOG").unwrap_or("none".to_string());
std::thread::spawn(move || {
Command::new("sudo")
.args([
"docker",
"run",
"-e",
"RUST_LOG=debug",
format!("RUST_LOG={}", rust_log_level).as_str(),
"-p",
"3000:3000",
"--rm",
Expand All @@ -113,13 +117,11 @@ impl SP1ProverServer {
container_name,
image_name,
])
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.expect("failed to start Docker container");
});

// Kill the container on control-c.
ctrlc::set_handler(move || {
tracing::debug!("received Ctrl+C, cleaning up...");
if !cleanup_flag.load(Ordering::SeqCst) {
Expand All @@ -130,8 +132,30 @@ impl SP1ProverServer {
})
.unwrap();

tracing::debug!("sleeping for 20 seconds to allow server to start");
std::thread::sleep(Duration::from_secs(20));
// Wait a few seconds for the container to start.
std::thread::sleep(Duration::from_secs(2));

// Check if the container is ready.
let client = Client::from_base_url(
Url::parse("http://localhost:3000/twirp/").expect("failed to parse url"),
)
.expect("failed to create client");
let rt = Runtime::new().unwrap();
rt.block_on(async {
tracing::info!("waiting for proving server to be ready");
loop {
let request = ReadyRequest {};
let response = client.ready(request).await;
if let Ok(response) = response {
if response.ready {
tracing::info!("proving server is ready");
break;
}
}
tracing::info!("proving server is not ready, retrying...");
std::thread::sleep(Duration::from_secs(2));
}
});

SP1ProverServer {
client: Client::from_base_url(
Expand Down Expand Up @@ -263,7 +287,6 @@ impl Drop for SP1ProverServer {

/// Cleans up the a docker container with the given name.
fn cleanup_container(container_name: &str) {
tracing::debug!("cleaning up container: {}", container_name);
if let Err(e) = Command::new("sudo")
.args(["docker", "rm", "-f", container_name])
.status()
Expand Down

0 comments on commit 5337558

Please sign in to comment.