Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Commit

Permalink
Use Arc<AtomicI32>>for prover_id
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzandrock committed Feb 17, 2020
1 parent c62577f commit 40992ce
Showing 1 changed file with 35 additions and 17 deletions.
52 changes: 35 additions & 17 deletions core/prover/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Built-in deps
use std::sync::atomic::{AtomicBool, AtomicI32, Ordering};
use std::sync::mpsc;
use std::sync::{atomic::AtomicBool, Arc};
use std::sync::Arc;
use std::{env, thread, time};
// External deps
use crypto_exports::franklin_crypto::alt_babyjubjub::AltJubjubBn256;
@@ -16,6 +17,7 @@ use prover::{start, BabyProver};

fn main() {
env_logger::init();
const ABSENT_PROVER_ID: i32 = -1;

// handle ctrl+c
let stop_signal = Arc::new(AtomicBool::new(false));
@@ -44,19 +46,12 @@ fn main() {
heartbeat_interval,
stop_signal,
);
// Register prover
let prover_id = api_client
.register_prover()
.expect("failed to register prover");
// Start prover
let (exit_err_tx, exit_err_rx) = mpsc::channel();
thread::spawn(move || {
start(worker, exit_err_tx);
});

let prover_id_arc = Arc::new(AtomicI32::new(ABSENT_PROVER_ID));

// Handle termination requests.
{
let prover_id = prover_id;
let prover_id_arc = prover_id_arc.clone();
let api_client = api_client.clone();
thread::spawn(move || {
let signals = Signals::new(&[
@@ -67,22 +62,45 @@ fn main() {
.expect("Signals::new() failed");
for _ in signals.forever() {
info!("Termination signal received.");
match api_client.prover_stopped(prover_id) {
Ok(_) => {}
Err(e) => error!("failed to send prover stop request: {}", e),
let prover_id = prover_id_arc.load(Ordering::SeqCst);
if prover_id != ABSENT_PROVER_ID {
match api_client.prover_stopped(prover_id) {
Ok(_) => {}
Err(e) => error!("failed to send prover stop request: {}", e),
}
}

std::process::exit(0);
}
});
}

// Register prover
prover_id_arc.store(
api_client
.register_prover()
.expect("failed to register prover"),
Ordering::SeqCst,
);

// Start prover
let (exit_err_tx, exit_err_rx) = mpsc::channel();
thread::spawn(move || {
start(worker, exit_err_tx);
});

// Handle prover exit errors.
let err = exit_err_rx.recv();
error!("prover exited with error: {:?}", err);
api_client
.prover_stopped(prover_id)
.expect("failed to send prover stop request");
{
let prover_id = prover_id_arc.load(Ordering::SeqCst);
if prover_id != ABSENT_PROVER_ID {
match api_client.prover_stopped(prover_id) {
Ok(_) => {}
Err(e) => error!("failed to send prover stop request: {}", e),
}
}
}
}

fn read_from_key_dir(key_dir: String) -> groth16::Parameters<Engine> {

0 comments on commit 40992ce

Please sign in to comment.