Skip to content

Added more control over checkpoints #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions coordinator/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,34 @@ impl std::error::Error for FetchError {}
// Fetching
//=============================================================================

#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub enum Checkpoint {
Constant(u64),
BlockNumberNegativeOffset(u64),
}

impl Default for Checkpoint {
fn default() -> Self {
Self::BlockNumberNegativeOffset(1)
}
}

impl Checkpoint {
pub fn get_checkpoint(&self, block_number: u64) -> u64 {
match self {
Self::BlockNumberNegativeOffset(offset) if block_number > *offset => {
block_number - offset
}
Self::BlockNumberNegativeOffset(_) => 0,
Self::Constant(constant_value) => *constant_value,
}
}
}

/// Fetches the prover input given the [BlockSource]
pub async fn fetch(
block_number: u64,
checkpoint_block_number: Option<u64>,
checkpoint_method: &Option<Checkpoint>,
source: &BlockSource,
) -> Result<ProverInput, FetchError> {
match source {
Expand All @@ -42,11 +66,9 @@ pub async fn fetch(
let fetch_prover_input_request = FetchProverInputRequest {
rpc_url: rpc_url.as_str(),
block_number,
checkpoint_block_number: match checkpoint_block_number {
Some(checkpoint) => checkpoint,
None if block_number == 0 => 0,
None => block_number - 1,
},
checkpoint_block_number: checkpoint_method
.unwrap_or_default()
.get_checkpoint(block_number),
};

match fetch_prover_input(fetch_prover_input_request).await {
Expand Down
15 changes: 4 additions & 11 deletions coordinator/src/input.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module contains a lot of the important input structs
use serde::{Deserialize, Serialize};

use crate::benchmarking::BenchmarkOutputConfig;
use crate::{benchmarking::BenchmarkOutputConfig, fetch::Checkpoint};

/// The means for terminating.
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
Expand Down Expand Up @@ -95,8 +95,9 @@ pub struct ProveBlocksInput {
/// The starting block number
pub start_block_number: u64,
/// The checkpoint block number. If not provided, will be the
/// `start_block_number` - 1.
pub checkpoint_block_number: Option<u64>,
/// the block before the current block number, or
/// [Checkpoint::BlockNumberNegativeOffset] set to 1.
pub checkpoint: Option<Checkpoint>,
/// The termination condition. If not provided, will not terminate until
/// exhausted or an error occurs.
pub terminate_on: Option<TerminateOn>,
Expand Down Expand Up @@ -135,12 +136,4 @@ impl ProveBlocksInput {
pub fn estimate_expected_number_proofs(&self) -> Option<u64> {
self.get_expected_number_proofs()
}

/// Returns either the checkpoint value or the start block number - 1
pub fn get_checkpoint_block_number(&self) -> u64 {
match self.checkpoint_block_number {
Some(checkpoint) => checkpoint,
None => self.start_block_number - 1,
}
}
}
8 changes: 3 additions & 5 deletions coordinator/src/manyprover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ impl ManyProver {
"Forwarding proofs with parallel not supported",
)));
}
warn!(
"There are some issues with forward_prev = true, would recommend leaving it false"
)
}
Some(false) | None => (),
}
Expand Down Expand Up @@ -263,7 +260,8 @@ impl ManyProver {
// FETCHING
debug!("Attempting to fetch block {}", block_num);
let fetch_start_instance = Instant::now();
let prover_input = match fetch(block_num, None, &input.block_source).await {
let prover_input = match fetch(block_num, &input.checkpoint, &input.block_source).await
{
Ok(prover_input) => prover_input,
Err(err) => {
error!("Failed to fetch block number: {}", block_num);
Expand Down Expand Up @@ -705,7 +703,7 @@ impl ManyProver {
let fetch_start_instance = Instant::now();
let prover_input = match fetch(
cur_block_num,
None, // input.checkpoint_block_number,
&self.input_request.checkpoint,
&self.input_request.block_source,
)
.await
Expand Down
Loading