Skip to content

Commit

Permalink
fix: timing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
fborello-lambda committed Dec 11, 2024
1 parent d840b58 commit dcf737d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
24 changes: 18 additions & 6 deletions crates/l2/proposer/prover_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use secp256k1::SecretKey;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
fmt::Debug,
io::{BufReader, BufWriter, Write},
net::{IpAddr, Shutdown, TcpListener, TcpStream},
sync::mpsc::{self, Receiver},
Expand Down Expand Up @@ -58,7 +59,7 @@ pub enum ProverType {
SP1,
}

#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Risc0Proof {
pub receipt: Box<risc0_zkvm::Receipt>,
pub prover_id: Vec<u32>,
Expand Down Expand Up @@ -129,6 +130,15 @@ pub struct Sp1Proof {
pub vk: sp1_sdk::SP1VerifyingKey,
}

impl Debug for Sp1Proof {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Sp1Proof")
.field("proof", &self.proof)
.field("vk", &self.vk.bytes32())
.finish()
}
}

pub struct Sp1ContractData {
pub public_values: Vec<u8>,
pub vk: Vec<u8>,
Expand Down Expand Up @@ -166,7 +176,7 @@ impl Sp1Proof {
}
}

#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum ProvingOutput {
RISC0(Risc0Proof),
SP1(Sp1Proof),
Expand Down Expand Up @@ -395,21 +405,23 @@ impl ProverServer {

// Check if we have the proof for that ProverType
// If we don't have it, insert it.
inner_hmap
.entry(proving_type)
.or_insert(proving_output.clone());
inner_hmap.entry(proving_type).or_insert(proving_output);

if block_number != (last_verified_block + 1) {
return Err(ProverServerError::Custom(format!("Prover Client submitted an invalid block_number: {block_number}. The last_proved_block is: {}", last_verified_block)));
}

let inner_hmap = self
.proving_output_per_block
.get(&block_number)
.ok_or(ProverServerError::Custom("Custom".to_owned()))?;
// Wait for all the ProverTypes
if inner_hmap.contains_key(&ProverType::RISC0)
&& inner_hmap.contains_key(&ProverType::SP1)
{
self.handle_proof_submission(block_number).await?;
// Remove the Proofs for the block_number
self.proving_output_per_block.remove_entry(&block_number);
self.proving_output_per_block.remove(&block_number);
}
}
Err(e) => {
Expand Down
1 change: 1 addition & 0 deletions crates/l2/prover/src/prover_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl ProverClient {
warn!("Failed to request new data: {e}");
}
}
sleep(Duration::from_millis(self.interval_ms)).await;
}
}

Expand Down

0 comments on commit dcf737d

Please sign in to comment.