-
Notifications
You must be signed in to change notification settings - Fork 393
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
chore: compile time errors for conflicting flags, clean up flags in sdk #1805
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
use cfg_if::cfg_if; | ||
use std::path::PathBuf; | ||
|
||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
|
@@ -42,18 +41,18 @@ pub fn try_install_circuit_artifacts(artifacts_type: &str) -> PathBuf { | |
build_dir.display() | ||
); | ||
} else { | ||
cfg_if! { | ||
if #[cfg(any(feature = "network", feature = "network-v2"))] { | ||
println!( | ||
"[sp1] {} circuit artifacts for version {} do not exist at {}. downloading...", | ||
artifacts_type, | ||
SP1_CIRCUIT_VERSION, | ||
build_dir.display() | ||
); | ||
install_circuit_artifacts(build_dir.clone(), artifacts_type); | ||
} | ||
} | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: no action needed, but I think it's kind of weird how the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh youre saying that the artifacts actually shouldn't be gated because all modes mauy need them? Not actually sure just kept the original functionality here |
||
println!( | ||
"[sp1] {} circuit artifacts for version {} do not exist at {}. downloading...", | ||
artifacts_type, | ||
SP1_CIRCUIT_VERSION, | ||
build_dir.display() | ||
); | ||
install_circuit_artifacts(build_dir.clone(), artifacts_type); | ||
}; | ||
} | ||
|
||
build_dir | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ | |
SP1VerifyingKey, | ||
}; | ||
|
||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
use conflicting::conflicting; | ||
|
||
/// A client for interacting with SP1. | ||
pub struct ProverClient { | ||
/// The underlying prover implementation. | ||
|
@@ -71,6 +74,7 @@ | |
/// std::env::set_var("SP1_PROVER", "local"); | ||
/// let client = ProverClient::new(); | ||
/// ``` | ||
#[deprecated = "Use `ProverClient::builder` instead"] | ||
pub fn new() -> Self { | ||
#[allow(unreachable_code)] | ||
match env::var("SP1_PROVER").unwrap_or("local".to_string()).to_lowercase().as_str() { | ||
|
@@ -185,18 +189,18 @@ | |
/// | ||
/// let client = ProverClient::network(private_key, rpc_url, skip_simulation); | ||
/// ``` | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to fix these CI failures before merging. Maybe we need to check sp1-sdk using both the network and network-v2 features ... Honestly, if we deprecate network v1 in the next couple months maybe we should just deal with these sins until then. |
||
pub fn network(private_key: String, rpc_url: Option<String>, skip_simulation: bool) -> Self { | ||
cfg_if! { | ||
if #[cfg(feature = "network-v2")] { | ||
conflicting! { | ||
Check failure on line 194 in crates/sdk/src/lib.rs GitHub Actions / Test (ARM)
Check failure on line 194 in crates/sdk/src/lib.rs GitHub Actions / Test (ARM)
Check failure on line 194 in crates/sdk/src/lib.rs GitHub Actions / Formatting & Clippy
Check failure on line 194 in crates/sdk/src/lib.rs GitHub Actions / Formatting & Clippy
Check failure on line 194 in crates/sdk/src/lib.rs GitHub Actions / Test (x86-64)
|
||
"network" => { | ||
Self { | ||
Check failure on line 196 in crates/sdk/src/lib.rs GitHub Actions / Test (ARM)
Check failure on line 196 in crates/sdk/src/lib.rs GitHub Actions / Formatting & Clippy
|
||
prover: Box::new(NetworkProverV2::new(&private_key, rpc_url, skip_simulation)), | ||
prover: Box::new(NetworkProverV1::new(&private_key, rpc_url, skip_simulation)), | ||
} | ||
} else if #[cfg(feature = "network")] { | ||
}, | ||
"network-v2" => { | ||
Self { | ||
prover: Box::new(NetworkProverV1::new(&private_key, rpc_url, skip_simulation)), | ||
prover: Box::new(NetworkProverV2::new(&private_key, rpc_url, skip_simulation)), | ||
} | ||
} else { | ||
panic!("network feature is not enabled") | ||
} | ||
} | ||
} | ||
|
@@ -315,16 +319,19 @@ | |
|
||
impl Default for ProverClient { | ||
fn default() -> Self { | ||
Self::new() | ||
Self::cpu() | ||
} | ||
} | ||
|
||
/// Builder type for [`ProverClient`]. | ||
#[derive(Debug, Default)] | ||
pub struct ProverClientBuilder { | ||
mode: Option<ProverMode>, | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
private_key: Option<String>, | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
rpc_url: Option<String>, | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
skip_simulation: bool, | ||
} | ||
|
||
|
@@ -336,18 +343,21 @@ | |
} | ||
|
||
/// Sets the private key. | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
pub fn private_key(mut self, private_key: String) -> Self { | ||
self.private_key = Some(private_key); | ||
self | ||
} | ||
|
||
/// Sets the RPC URL. | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
pub fn rpc_url(mut self, rpc_url: String) -> Self { | ||
self.rpc_url = Some(rpc_url); | ||
self | ||
} | ||
|
||
/// Skips simulation. | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
pub fn skip_simulation(mut self) -> Self { | ||
self.skip_simulation = true; | ||
self | ||
|
@@ -357,29 +367,22 @@ | |
pub fn build(self) -> ProverClient { | ||
match self.mode.expect("The prover mode is required") { | ||
ProverMode::Cpu => ProverClient::cpu(), | ||
ProverMode::Cuda => { | ||
cfg_if! { | ||
if #[cfg(feature = "cuda")] { | ||
ProverClient::cuda() | ||
} else { | ||
panic!("cuda feature is not enabled") | ||
} | ||
} | ||
} | ||
#[cfg(feature = "cuda")] | ||
ProverMode::Cuda => ProverClient::cuda(), | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
ProverMode::Network => { | ||
let private_key = self.private_key.expect("The private key is required"); | ||
|
||
cfg_if! { | ||
if #[cfg(feature = "network-v2")] { | ||
conflicting! { | ||
Check failure on line 376 in crates/sdk/src/lib.rs GitHub Actions / Test (ARM)
Check failure on line 376 in crates/sdk/src/lib.rs GitHub Actions / Test (ARM)
Check failure on line 376 in crates/sdk/src/lib.rs GitHub Actions / Formatting & Clippy
Check failure on line 376 in crates/sdk/src/lib.rs GitHub Actions / Formatting & Clippy
Check failure on line 376 in crates/sdk/src/lib.rs GitHub Actions / Test (x86-64)
|
||
"network" => { | ||
ProverClient { | ||
Check failure on line 378 in crates/sdk/src/lib.rs GitHub Actions / Test (ARM)
Check failure on line 378 in crates/sdk/src/lib.rs GitHub Actions / Formatting & Clippy
|
||
prover: Box::new(NetworkProverV2::new(&private_key, self.rpc_url, self.skip_simulation)), | ||
prover: Box::new(NetworkProverV1::new(&private_key, self.rpc_url, self.skip_simulation)), | ||
} | ||
} else if #[cfg(feature = "network")] { | ||
}, | ||
"network-v2" => { | ||
ProverClient { | ||
prover: Box::new(NetworkProverV1::new(&private_key, self.rpc_url, self.skip_simulation)), | ||
prover: Box::new(NetworkProverV2::new(&private_key, self.rpc_url, self.skip_simulation)), | ||
} | ||
} else { | ||
panic!("network feature is not enabled") | ||
} | ||
} | ||
} | ||
|
@@ -388,51 +391,6 @@ | |
} | ||
} | ||
|
||
/// Builder type for network prover. | ||
#[cfg(any(feature = "network", feature = "network-v2"))] | ||
#[derive(Debug, Default)] | ||
pub struct NetworkProverBuilder { | ||
private_key: Option<String>, | ||
rpc_url: Option<String>, | ||
skip_simulation: bool, | ||
} | ||
|
||
impl NetworkProverBuilder { | ||
/// Sets the private key. | ||
pub fn private_key(mut self, private_key: String) -> Self { | ||
self.private_key = Some(private_key); | ||
self | ||
} | ||
|
||
/// Sets the RPC URL. | ||
pub fn rpc_url(mut self, rpc_url: String) -> Self { | ||
self.rpc_url = Some(rpc_url); | ||
self | ||
} | ||
|
||
/// Skips simulation. | ||
pub fn skip_simulation(mut self) -> Self { | ||
self.skip_simulation = true; | ||
self | ||
} | ||
|
||
/// Creates a new [NetworkProverV1]. | ||
#[cfg(feature = "network")] | ||
pub fn build(self) -> NetworkProverV1 { | ||
let private_key = self.private_key.expect("The private key is required"); | ||
|
||
NetworkProverV1::new(&private_key, self.rpc_url, self.skip_simulation) | ||
} | ||
|
||
/// Creates a new [NetworkProverV2]. | ||
#[cfg(feature = "network-v2")] | ||
pub fn build_v2(self) -> NetworkProverV2 { | ||
let private_key = self.private_key.expect("The private key is required"); | ||
|
||
NetworkProverV2::new(&private_key, self.rpc_url, self.skip_simulation) | ||
} | ||
} | ||
|
||
/// Utility method for blocking on an async function. | ||
/// | ||
/// If we're already in a tokio runtime, we'll block in place. Otherwise, we'll create a new | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ use crate::{ | |
client::NetworkClient, | ||
proto::network::{ProofMode, ProofStatus}, | ||
}, | ||
NetworkProverBuilder, Prover, SP1Context, SP1ProofKind, SP1ProofWithPublicValues, | ||
SP1ProvingKey, SP1VerifyingKey, | ||
Prover, SP1Context, SP1ProofKind, SP1ProofWithPublicValues, SP1ProvingKey, SP1VerifyingKey, | ||
}; | ||
use anyhow::Result; | ||
use sp1_core_machine::io::SP1Stdin; | ||
|
@@ -39,11 +38,6 @@ impl NetworkProver { | |
Self { client: NetworkClient::new(private_key, rpc_url), local_prover, skip_simulation } | ||
} | ||
|
||
/// Creates a new network prover builder. See [`NetworkProverBuilder`] for more details. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think either @ctian1 or @ratankaliani needs this I don't remember who |
||
pub fn builder() -> NetworkProverBuilder { | ||
NetworkProverBuilder::default() | ||
} | ||
|
||
/// Requests a proof from the prover network, returning the proof ID. | ||
pub async fn request_proof( | ||
&self, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how the prover crate now has a "cuda" and "network feature that don't do anything at all. On second thought, it's even kind of weird that the ProverMode lives in the prover crate in the first place. I feel like the prover crate should pretty much solely be concerned with generating different kinds of proofs on-device, and not really think about anything else.
cc @ctian1 @ratankaliani for second opinions
@leruaa why did you need to move the provermode here in the first place?