From 3ff6af744365e8b051ed561a03bcafe8987c103c Mon Sep 17 00:00:00 2001 From: nhtyy Date: Wed, 11 Dec 2024 18:51:05 -0800 Subject: [PATCH] fix: default featuers --- crates/sdk/Cargo.toml | 3 +- crates/sdk/src/artifacts.rs | 1 - crates/sdk/src/client.rs | 5 +- crates/sdk/src/local/prover.rs | 2 +- crates/sdk/src/network-v2/prover.rs | 139 ++++++++++++++-------------- 5 files changed, 76 insertions(+), 74 deletions(-) diff --git a/crates/sdk/Cargo.toml b/crates/sdk/Cargo.toml index 4a276341e..38da4cf96 100644 --- a/crates/sdk/Cargo.toml +++ b/crates/sdk/Cargo.toml @@ -20,7 +20,7 @@ reqwest = { version = "0.12.4", default-features = false, features = [ "rustls-tls", "trust-dns", "stream", -], optional = true } +] } anyhow = "1.0.83" sp1-prover = { workspace = true } sp1-core-machine = { workspace = true } @@ -67,7 +67,6 @@ network-v2 = [ "dep:alloy-signer-local", "dep:alloy-primitives", "dep:alloy-signer", - "dep:reqwest", "dep:twirp", "dep:reqwest-middleware", "dep:tonic", diff --git a/crates/sdk/src/artifacts.rs b/crates/sdk/src/artifacts.rs index ea614d679..7f1d871f5 100644 --- a/crates/sdk/src/artifacts.rs +++ b/crates/sdk/src/artifacts.rs @@ -2,7 +2,6 @@ use std::path::PathBuf; use anyhow::{Context, Result}; -#[cfg(feature = "network-v2")] use { futures::StreamExt, indicatif::{ProgressBar, ProgressStyle}, diff --git a/crates/sdk/src/client.rs b/crates/sdk/src/client.rs index c9bb81db7..27b9fe673 100644 --- a/crates/sdk/src/client.rs +++ b/crates/sdk/src/client.rs @@ -11,7 +11,10 @@ use sp1_core_executor::{ExecutionError, ExecutionReport}; use sp1_core_machine::io::SP1Stdin; use sp1_primitives::io::SP1PublicValues; use sp1_prover::{SP1ProvingKey, SP1VerifyingKey}; -use std::{env, sync::Arc}; +use std::sync::Arc; + +#[cfg(feature = "network-v2")] +use std::env; mod request; pub use request::DynProofRequest; diff --git a/crates/sdk/src/local/prover.rs b/crates/sdk/src/local/prover.rs index af6d6350f..d91d20e8d 100644 --- a/crates/sdk/src/local/prover.rs +++ b/crates/sdk/src/local/prover.rs @@ -381,7 +381,7 @@ impl LocalProverBuilder { Self { timeout: None, cycle_limit: None } } - pub fn timeout(mut self, timeout: u64) -> Self { + pub fn with_timeout(mut self, timeout: u64) -> Self { self.timeout = Some(timeout); self } diff --git a/crates/sdk/src/network-v2/prover.rs b/crates/sdk/src/network-v2/prover.rs index d92776c9d..f610c5edd 100644 --- a/crates/sdk/src/network-v2/prover.rs +++ b/crates/sdk/src/network-v2/prover.rs @@ -48,13 +48,6 @@ pub struct NetworkProver { cycles_limit: u64, } -pub struct NetworkProverBuilder { - rpc_url: Option, - private_key: Option, - timeout: Option, - cycle_limit: Option, -} - impl NetworkProver { /// Creates a new [`NetworkProver`] with the given private private_key. /// This function uses default timeout and cycle limit. @@ -217,60 +210,6 @@ impl NetworkProver { } } -#[allow(clippy::new_without_default)] -impl NetworkProverBuilder { - /// Creates a new network prover builder. - pub fn new() -> Self { - Self { rpc_url: None, private_key: None, timeout: None, cycle_limit: None } - } - - /// Sets the RPC URL for the prover network. - /// - /// This configures the endpoint that will be used for all network operations. - /// If not set, the default RPC URL will be used. - pub fn rpc_url(mut self, url: String) -> Self { - self.rpc_url = Some(url); - self - } - - /// Sets the private key to use for the prover network. - /// - /// This is required and must be set before building the prover. - pub fn private_key(mut self, key: String) -> Self { - self.private_key = Some(key); - self - } - - /// Sets the timeout for proof requests. - /// - /// This is the maximum amount of time to wait for the request to be fulfilled. - pub fn with_timeout(mut self, timeout: u64) -> Self { - self.timeout = Some(timeout); - self - } - - /// Sets the cycle limit for proof requests. - /// - /// This is the maximum number of cycles to allow for the execution of the request. - pub fn with_cycle_limit(mut self, cycle_limit: u64) -> Self { - self.cycle_limit = Some(cycle_limit); - self - } - - /// Builds the prover with the given configuration. - pub fn build(self) -> NetworkProver { - NetworkProver { - prover: Arc::new(SP1Prover::new()), - network_client: NetworkClient::new( - &self.private_key.expect("A private key set on the builder"), - ) - .rpc_url(self.rpc_url.unwrap_or(DEFAULT_PROVER_NETWORK_RPC.to_string())), - timeout: self.timeout.unwrap_or(DEFAULT_TIMEOUT), - cycles_limit: self.cycle_limit.unwrap_or(DEFAULT_CYCLE_LIMIT), - } - } -} - pub struct NetworkProofRequest<'a> { prover: &'a NetworkProver, pk: &'a SP1ProvingKey, @@ -323,17 +262,17 @@ impl<'a> NetworkProofRequest<'a> { self } - pub fn with_version(mut self, version: String) -> Self { + pub fn version(mut self, version: String) -> Self { self.version = version; self } - pub fn with_timeout(mut self, timeout: u64) -> Self { + pub fn timeout(mut self, timeout: u64) -> Self { self.timeout = timeout; self } - pub fn with_cycle_limit(mut self, cycle_limit: u64) -> Self { + pub fn cycle_limit(mut self, cycle_limit: u64) -> Self { self.cycle_limit = Some(cycle_limit); self } @@ -343,7 +282,7 @@ impl<'a> NetworkProofRequest<'a> { self } - pub fn with_strategy(mut self, strategy: FulfillmentStrategy) -> Self { + pub fn strategy(mut self, strategy: FulfillmentStrategy) -> Self { self.strategy = strategy; self } @@ -434,8 +373,8 @@ impl Prover for NetworkProver { ) -> Result { self.prove(pk, stdin) .with_mode(opts.mode) - .with_timeout(opts.timeout) - .with_cycle_limit(opts.cycle_limit) + .timeout(opts.timeout) + .cycle_limit(opts.cycle_limit) .await } @@ -448,8 +387,8 @@ impl Prover for NetworkProver { ) -> Result { self.prove(pk, stdin) .with_mode(opts.mode) - .with_timeout(opts.timeout) - .with_cycle_limit(opts.cycle_limit) + .timeout(opts.timeout) + .cycle_limit(opts.cycle_limit) .run() } @@ -483,6 +422,68 @@ impl<'a> IntoFuture for NetworkProofRequest<'a> { } } +pub struct NetworkProverBuilder { + rpc_url: Option, + private_key: Option, + timeout: Option, + cycle_limit: Option, +} + + +#[allow(clippy::new_without_default)] +impl NetworkProverBuilder { + /// Creates a new network prover builder. + pub fn new() -> Self { + Self { rpc_url: None, private_key: None, timeout: None, cycle_limit: None } + } + + /// Sets the RPC URL for the prover network. + /// + /// This configures the endpoint that will be used for all network operations. + /// If not set, the default RPC URL will be used. + pub fn rpc_url(mut self, url: String) -> Self { + self.rpc_url = Some(url); + self + } + + /// Sets the private key to use for the prover network. + /// + /// This is required and must be set before building the prover. + pub fn private_key(mut self, key: String) -> Self { + self.private_key = Some(key); + self + } + + /// Sets the timeout for proof requests. + /// + /// This is the maximum amount of time to wait for the request to be fulfilled. + pub fn with_timeout(mut self, timeout: u64) -> Self { + self.timeout = Some(timeout); + self + } + + /// Sets the cycle limit for proof requests. + /// + /// This is the maximum number of cycles to allow for the execution of the request. + pub fn with_cycle_limit(mut self, cycle_limit: u64) -> Self { + self.cycle_limit = Some(cycle_limit); + self + } + + /// Builds the prover with the given configuration. + pub fn build(self) -> NetworkProver { + NetworkProver { + prover: Arc::new(SP1Prover::new()), + network_client: NetworkClient::new( + &self.private_key.expect("A private key set on the builder"), + ) + .rpc_url(self.rpc_url.unwrap_or(DEFAULT_PROVER_NETWORK_RPC.to_string())), + timeout: self.timeout.unwrap_or(DEFAULT_TIMEOUT), + cycles_limit: self.cycle_limit.unwrap_or(DEFAULT_CYCLE_LIMIT), + } + } +} + // #[cfg(test)] // mod tests { // use super::*;