Skip to content

Commit

Permalink
feat: increase CLI speed and speed analytics (#1448)
Browse files Browse the repository at this point in the history
  • Loading branch information
collinjackson authored Feb 22, 2025
1 parent 8c19ccf commit c5a2d74
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
1 change: 1 addition & 0 deletions clients/cli/src/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub fn track(
"timezone": timezone,
"local_hour": local_now.hour(),
"day_of_week": local_now.weekday().number_from_monday(),
"event_id": system_time,
});

// Add event properties to the properties JSON
Expand Down
8 changes: 6 additions & 2 deletions clients/cli/src/orchestrator_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::nexus_orchestrator::{
GetProofTaskRequest, GetProofTaskResponse, NodeType, SubmitProofRequest,
};
use prost::Message;
use reqwest::Client;
use reqwest::{Client, ClientBuilder};
use std::time::Duration;

pub struct OrchestratorClient {
client: Client,
Expand All @@ -16,7 +17,10 @@ pub struct OrchestratorClient {
impl OrchestratorClient {
pub fn new(environment: config::Environment) -> Self {
Self {
client: Client::new(),
client: ClientBuilder::new()
.timeout(Duration::from_millis(1000))
.build()
.expect("Failed to create HTTP client"),
base_url: environment.orchestrator_url(),
// environment,
}
Expand Down
29 changes: 18 additions & 11 deletions clients/cli/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,29 @@ async fn authenticated_proving(
) -> Result<(), Box<dyn std::error::Error>> {
let client = OrchestratorClient::new(environment.clone());

println!("1. Fetching a task to prove from Nexus Orchestrator...");
let proof_task = client.get_proof_task(node_id).await?;
println!("2. Received a task to prove from Nexus Orchestrator...");
println!("Fetching a task to prove from Nexus Orchestrator...");
let proof_task = match client.get_proof_task(node_id).await {
Ok(task) => {
println!("Success.");
task
},
Err(_) => {
println!("Using local inputs.");
return anonymous_proving();
},
};
println!("Received a task to prove from Nexus Orchestrator...");

let public_input: u32 = proof_task.public_inputs[0] as u32;

println!("3. Compiling guest program...");
println!("Compiling guest program...");
let elf_file_path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join("assets")
.join("fib_input");
let prover =
Stwo::<Local>::new_from_file(&elf_file_path).expect("failed to load guest program");

println!("4. Creating ZK proof with inputs");
println!("Creating ZK proof with inputs");
let (view, proof) = prover
.prove_with_input::<(), u32>(&(), &public_input)
.expect("Failed to run prover");
Expand All @@ -41,11 +50,11 @@ async fn authenticated_proving(
let proof_hash = format!("{:x}", Keccak256::digest(&proof_bytes));

println!("\tProof size: {} bytes", proof_bytes.len());
println!("5. Submitting ZK proof to Nexus Orchestrator...");
println!("Submitting ZK proof to Nexus Orchestrator...");
client
.submit_proof(node_id, &proof_hash, proof_bytes)
.await?;
println!("{}", "6. ZK proof successfully submitted".green());
println!("{}", "ZK proof successfully submitted".green());

Ok(())
}
Expand Down Expand Up @@ -127,7 +136,7 @@ pub async fn start_prover(
proof_count += 1;

analytics::track(
"cli_proof_anon".to_string(),
"cli_proof_anon_v2".to_string(),
format!("Completed anon proof iteration #{}", proof_count),
serde_json::json!({
"node_id": "anonymous",
Expand All @@ -137,7 +146,6 @@ pub async fn start_prover(
environment,
client_id.clone(),
);
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
}
}
setup::SetupResult::Connected(node_id) => {
Expand Down Expand Up @@ -188,7 +196,7 @@ pub async fn start_prover(
proof_count += 1;

analytics::track(
"cli_proof_node".to_string(),
"cli_proof_node_v2".to_string(),
format!("Completed proof iteration #{}", proof_count),
serde_json::json!({
"node_id": node_id,
Expand All @@ -198,7 +206,6 @@ pub async fn start_prover(
environment,
client_id.clone(),
);
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
}
}
setup::SetupResult::Invalid => Err("Invalid setup option selected".into()),
Expand Down
2 changes: 1 addition & 1 deletion clients/cli/src/utils/cli_branding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn print_banner() {
"{} {} {}\n",
"Welcome to the".bright_white(),
"Nexus Network CLI".bright_cyan().bold(),
"v0.5.5".bright_white()
"v0.5.7".bright_white()
);
println!(
"{}",
Expand Down

0 comments on commit c5a2d74

Please sign in to comment.