pub fn new(moongate_server: MoongateServer) -> Result<Self, Box<dyn StdError>> {
        let reqwest_middlewares = vec![Box::new(LoggingMiddleware) as Box<dyn Middleware>];

        let prover = match moongate_server {
            MoongateServer::External { endpoint } => {
                let client = Client::new(
                    Url::parse(&endpoint).expect("failed to parse url"),
                    reqwest::Client::new(),
                    reqwest_middlewares,
                )
                .expect("failed to create client");

                SP1CudaProver { client, managed_container: None }
            }
            MoongateServer::Local { visible_device_index, port } => {
                Self::start_moongate_server(reqwest_middlewares, visible_device_index, port)?
            }
        };

        let timeout = Duration::from_secs(300);
        let start_time = Instant::now();

        block_on(async {
            tracing::info!("waiting for proving server to be ready");
            loop {
                if start_time.elapsed() > timeout {
                    return Err("Timeout: proving server did not become ready within 60 seconds. Please check your Docker container and network settings.".to_string());
                }

                let request = ReadyRequest {};
                match prover.client.ready(request).await {
                    Ok(response) if response.ready => {
                        tracing::info!("proving server is ready");
                        break;
                    }
                    Ok(_) => {
                        tracing::info!("proving server is not ready, retrying...");
                    }
                    Err(e) => {
                        tracing::warn!("Error checking server readiness: {}", e);
                    }
                }
                tokio::time::sleep(Duration::from_secs(2)).await;
            }
            Ok(())
        })?;

        Ok(prover)
    }
Creates a new [SP1CudaProver] that can be used to communicate with the Moongate server at
`moongate_endpoint`, or if not provided, create one that runs inside a Docker container.
crates/cuda/src/lib.rs