diff --git a/coordinator/src/fetch.rs b/coordinator/src/fetch.rs index e7452389..d0db6729 100644 --- a/coordinator/src/fetch.rs +++ b/coordinator/src/fetch.rs @@ -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, + checkpoint_method: &Option, source: &BlockSource, ) -> Result { match source { @@ -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 { diff --git a/coordinator/src/input.rs b/coordinator/src/input.rs index 7d809c54..c53f2547 100644 --- a/coordinator/src/input.rs +++ b/coordinator/src/input.rs @@ -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)] @@ -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, + /// the block before the current block number, or + /// [Checkpoint::BlockNumberNegativeOffset] set to 1. + pub checkpoint: Option, /// The termination condition. If not provided, will not terminate until /// exhausted or an error occurs. pub terminate_on: Option, @@ -135,12 +136,4 @@ impl ProveBlocksInput { pub fn estimate_expected_number_proofs(&self) -> Option { 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, - } - } } diff --git a/coordinator/src/manyprover.rs b/coordinator/src/manyprover.rs index 614ca05a..220ae341 100644 --- a/coordinator/src/manyprover.rs +++ b/coordinator/src/manyprover.rs @@ -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 => (), } @@ -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); @@ -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