Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fix: rebase on top of discard-intermediary-proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Jun 14, 2024
1 parent 729a6f0 commit 630e2f6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 4 additions & 1 deletion leader/src/jerigon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ pub(crate) async fn jerigon_main(
.into_iter()
.rev()
.skip(1)
.map(|b| generate_block_proof_file_name(&proof_output_dir.to_str(), b))
.filter_map(|(_, block_proof)| {
block_proof
.map(|b| generate_block_proof_file_name(&proof_output_dir.to_str(), b.b_height))
})
.for_each(|path| {
if let Err(e) = std::fs::remove_file(path) {
error!("Failed to remove intermediate proof file: {e}");
Expand Down
11 changes: 7 additions & 4 deletions leader/src/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ pub(crate) async fn stdio_main(
blocks: serde_path_to_error::deserialize(des)?,
};

let block_proofs = prover_input
.prove(&runtime, previous, save_inputs_on_error)
.await;
let proved_blocks = prover_input
.prove(&runtime, previous, save_inputs_on_error, None)
.await?;
runtime.close().await?;
let proofs = block_proofs?;

let proofs: Vec<GeneratedBlockProof> = proved_blocks
.into_iter()
.filter_map(|(_, proof)| proof)
.collect();
std::io::stdout().write_all(&serde_json::to_vec(&proofs)?)?;

Ok(())
Expand Down
17 changes: 13 additions & 4 deletions prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,16 @@ pub struct ProverInput {
}

impl ProverInput {
/// Prove all the blocks in the input.
/// Return the list of block numbers that are proved and if the proof data
/// is not saved to disk, return the generated block proofs as well.
pub async fn prove(
self,
runtime: &Runtime,
previous_proof: Option<GeneratedBlockProof>,
save_inputs_on_error: bool,
proof_output_dir: Option<PathBuf>,
) -> Result<Vec<BlockNumber>> {
) -> Result<Vec<(BlockNumber, Option<GeneratedBlockProof>)>> {
let mut prev: Option<BoxFuture<Result<GeneratedBlockProof>>> =
previous_proof.map(|proof| Box::pin(futures::future::ok(proof)) as BoxFuture<_>);

Expand All @@ -157,14 +160,20 @@ impl ProverInput {
let proof = proof?;
let block_number = proof.b_height;

// Write latest generated proof to disk or stdout
ProverInput::write_proof(proof_output_dir, &proof).await?;
// Write latest generated proof to disk if proof_output_dir is provided
let return_proof: Option<GeneratedBlockProof> =
if proof_output_dir.is_some() {
ProverInput::write_proof(proof_output_dir, &proof).await?;
None
} else {
Some(proof.clone())
};

if tx.send(proof).is_err() {
anyhow::bail!("Failed to send proof");
}

Ok(block_number)
Ok((block_number, return_proof))
})
.boxed();

Expand Down

0 comments on commit 630e2f6

Please sign in to comment.