use PROVER_CYCLE_WAIT
@@ -64,15 +64,21 @@ impl<C: ApiClient> Worker<C> {
}
fn run_rounds(&self, start_heartbeats_tx: mpsc::Sender<i32>) {
- // TODO: add PROVER_CYCLE_WAIT usage
let mut rng = rand::OsRng::new().unwrap();
+ let pause_duration = time::Duration::from_secs(models::node::config::PROVER_CYCLE_WAIT);
while !self.stop_signal.load(Ordering::SeqCst) {
+ self.next_round(&mut rng, &start_heartbeats_tx);
+ thread::sleep(pause_duration);
+ }
+ }
+
+ fn next_round(&self, rng: &mut rand::OsRng, start_heartbeats_tx: &mpsc::Sender<i32>) {
let block_to_prove = self.api_client.block_to_prove();
let block_to_prove = match block_to_prove {
Ok(b) => b,
// TODO: log error
- _ => continue,
+ _ => return,
};
let (block, job_id) = match block_to_prove {
@@ -82,7 +88,7 @@ impl<C: ApiClient> Worker<C> {
// Notify heartbeat routine on new proving block or None.
start_heartbeats_tx.send(job_id);
if job_id == 0 {
- continue;
+ return;
}
// TODO: timeout
let prover_data = match self
@@ -92,7 +98,7 @@ impl<C: ApiClient> Worker<C> {
Ok(v) => v,
Err(err) => {
error!("could not get prover data for block {}: {}", block, err);
- continue;
+ return;
}
};
@@ -110,8 +116,7 @@ impl<C: ApiClient> Worker<C> {
validator_account: prover_data.validator_account,
};
- let proof =
- bellman::groth16::create_random_proof(instance, &self.circuit_params, &mut rng);
+ let proof = bellman::groth16::create_random_proof(instance, &self.circuit_params, rng);
if proof.is_err() {
// TODO: panic?
@@ -123,11 +128,8 @@ impl<C: ApiClient> Worker<C> {
let pvk = bellman::groth16::prepare_verifying_key(&self.circuit_params.vk);
- let res = bellman::groth16::verify_proof(
- &pvk,
- &p.clone(),
- &[prover_data.public_data_commitment],
- );
+ let res =
+ bellman::groth16::verify_proof(&pvk, &p.clone(), &[prover_data.public_data_commitment]);
if res.is_err() {
panic!("err")
// return Err("Proof verification has failed".to_owned());
@@ -140,7 +142,6 @@ impl<C: ApiClient> Worker<C> {
self.api_client
.publish(block, p, prover_data.public_data_commitment);
}
- }
fn keep_sending_work_heartbeats(&self, start_heartbeats_rx: mpsc::Receiver<i32>) {
let mut job_id = 0;
