Skip to content

Commit

Permalink
fix: default featuers
Browse files Browse the repository at this point in the history
  • Loading branch information
nhtyy committed Dec 12, 2024
1 parent 2025ef5 commit 3ff6af7
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 74 deletions.
3 changes: 1 addition & 2 deletions crates/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion crates/sdk/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::path::PathBuf;

use anyhow::{Context, Result};

#[cfg(feature = "network-v2")]
use {
futures::StreamExt,
indicatif::{ProgressBar, ProgressStyle},
Expand Down
5 changes: 4 additions & 1 deletion crates/sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/src/local/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
139 changes: 70 additions & 69 deletions crates/sdk/src/network-v2/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ pub struct NetworkProver {
cycles_limit: u64,
}

pub struct NetworkProverBuilder {
rpc_url: Option<String>,
private_key: Option<String>,
timeout: Option<u64>,
cycle_limit: Option<u64>,
}

impl NetworkProver {
/// Creates a new [`NetworkProver`] with the given private private_key.
/// This function uses default timeout and cycle limit.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -434,8 +373,8 @@ impl Prover for NetworkProver {
) -> Result<SP1ProofWithPublicValues> {
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
}

Expand All @@ -448,8 +387,8 @@ impl Prover for NetworkProver {
) -> Result<SP1ProofWithPublicValues> {
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()
}

Expand Down Expand Up @@ -483,6 +422,68 @@ impl<'a> IntoFuture for NetworkProofRequest<'a> {
}
}

pub struct NetworkProverBuilder {
rpc_url: Option<String>,
private_key: Option<String>,
timeout: Option<u64>,
cycle_limit: Option<u64>,
}


#[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::*;
Expand Down

0 comments on commit 3ff6af7

Please sign in to comment.