Skip to content

Commit

Permalink
feat: CLI can self-update when there is a new version and properly co…
Browse files Browse the repository at this point in the history
…ntinue proving (#62)
  • Loading branch information
dprats authored Nov 27, 2024
1 parent 7365590 commit f2adb21
Show file tree
Hide file tree
Showing 8 changed files with 762 additions and 4 deletions.
Binary file added .DS_Store
Binary file not shown.
172 changes: 171 additions & 1 deletion clients/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions clients/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ ark-vesta = "0.4.0"
ark-test-curves = { version = "0.4.2", features = ["bls12_381_curve"] }
iana-time-zone = "0.1.60"
chrono = "0.4.38"
self_update = "0.41.0"
dirs = "5.0.1"
semver = "1.0.23"
parking_lot = "0.12.3"

[patch.crates-io]
ark-crypto-primitives = { git = "https://github.com/arkworks-rs/crypto-primitives", rev = "d27a5c8" }
Expand Down
24 changes: 21 additions & 3 deletions clients/cli/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod config;
mod connection;
mod generated;
mod prover_id_manager;
mod updater;
pub mod utils;
mod websocket;

use crate::analytics::track;
Expand Down Expand Up @@ -48,8 +50,10 @@ use std::fs::File;
use std::io::Read;
use zstd::stream::Encoder;

use crate::utils::updater::{AutoUpdaterMode, UpdaterConfig};

// The interval at which to send updates to the orchestrator
const UPDATE_INTERVAL_IN_SECONDS: u64 = 180; // 3 minutes
const PROOF_PROGRESS_UPDATE_INTERVAL_IN_SECONDS: u64 = 180; // 3 minutes

#[derive(Parser, Debug)]
struct Args {
Expand All @@ -63,6 +67,10 @@ struct Args {
/// Whether to hang up after the first proof
#[arg(short, long, default_value_t = false)]
just_once: bool,

/// Mode for the auto updater (production/test)
#[arg(short, long, value_enum, default_value_t = AutoUpdaterMode::Production)]
updater_mode: AutoUpdaterMode,
}

fn get_file_as_byte_vec(filename: &str) -> Vec<u8> {
Expand All @@ -76,6 +84,8 @@ fn get_file_as_byte_vec(filename: &str) -> Vec<u8> {

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Check for CLI updates periodically

// Configure the tracing subscriber
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
Expand All @@ -91,6 +101,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
args.port
);

// Initialize the CLI auto-updater that checks for and applies updates to the CLI:
// a. Create the updater config
let updater_config = UpdaterConfig::new(args.updater_mode, args.hostname);

// b. runs the CLI's auto updater in a separate thread continuously in intervals
updater::spawn_auto_update_thread(&updater_config).expect("Failed to spawn auto-update thread");

let k = 4;
// TODO(collinjackson): Get parameters from a file or URL.
let pp = gen_vm_pp::<C1, seq::SetupParams<(G1, G2, C1, C2, RO, SC)>>(k as usize, &())
Expand Down Expand Up @@ -213,7 +230,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
progress_time = Instant::now();

//If it has been three minutes since the last orchestrator update, send the orchestator the update
if timer_since_last_orchestrator_update.elapsed().as_secs() > UPDATE_INTERVAL_IN_SECONDS
if timer_since_last_orchestrator_update.elapsed().as_secs()
> PROOF_PROGRESS_UPDATE_INTERVAL_IN_SECONDS
{
println!(
"\tWill try sending update to orchestrator with interval queued_steps_proven: {}",
Expand Down Expand Up @@ -319,7 +337,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if args.just_once {
break;
} else {
println!("Waiting for another program to prove...");
println!("\n\nWaiting for a new program to prove...");
}
}

Expand Down
Loading

0 comments on commit f2adb21

Please sign in to comment.