diff --git a/crates/l2/sequencer/l1_committer.rs b/crates/l2/sequencer/l1_committer.rs index 6adb69105b1..b11b2fd85c4 100644 --- a/crates/l2/sequencer/l1_committer.rs +++ b/crates/l2/sequencer/l1_committer.rs @@ -4,7 +4,8 @@ use crate::{ sequencer::{ errors::CommitterError, utils::{ - self, fetch_blocks_with_respective_fee_configs, get_git_commit_hash, system_now_ms, + self, batch_checkpoint_name, fetch_blocks_with_respective_fee_configs, + get_git_commit_hash, system_now_ms, }, }, }; @@ -1313,7 +1314,3 @@ pub async fn regenerate_head_state( Ok(()) } - -fn batch_checkpoint_name(batch_number: u64) -> String { - format!("checkpoint_batch_{batch_number}") -} diff --git a/crates/l2/sequencer/l1_proof_sender.rs b/crates/l2/sequencer/l1_proof_sender.rs index 7cc89978b20..d68a220b932 100644 --- a/crates/l2/sequencer/l1_proof_sender.rs +++ b/crates/l2/sequencer/l1_proof_sender.rs @@ -1,4 +1,8 @@ -use std::collections::{BTreeMap, HashMap}; +use std::{ + collections::{BTreeMap, HashMap}, + fs::remove_dir_all, + path::PathBuf, +}; use ethrex_common::{Address, U256}; use ethrex_l2_common::{ @@ -30,7 +34,7 @@ use super::{ use crate::{ CommitterConfig, EthConfig, ProofCoordinatorConfig, SequencerConfig, based::sequencer_state::{SequencerState, SequencerStatus}, - sequencer::errors::ProofSenderError, + sequencer::{errors::ProofSenderError, utils::batch_checkpoint_name}, }; use aligned_sdk::{ common::{ @@ -71,6 +75,8 @@ pub struct L1ProofSender { l1_chain_id: u64, network: Network, fee_estimate: FeeEstimationType, + /// Directory where checkpoints are stored. + checkpoints_dir: PathBuf, aligned_mode: bool, } @@ -89,6 +95,7 @@ pub struct L1ProofSenderHealth { } impl L1ProofSender { + #[expect(clippy::too_many_arguments)] async fn new( cfg: &ProofCoordinatorConfig, committer_cfg: &CommitterConfig, @@ -97,6 +104,7 @@ impl L1ProofSender { aligned_cfg: &AlignedConfig, rollup_store: StoreRollup, needed_proof_types: Vec, + checkpoints_dir: PathBuf, ) -> Result { let eth_client = EthClient::new_with_config( eth_cfg.rpc_url.clone(), @@ -123,6 +131,7 @@ impl L1ProofSender { l1_chain_id, network: aligned_cfg.network.clone(), fee_estimate, + checkpoints_dir, aligned_mode: aligned_cfg.aligned_mode, }) } @@ -132,6 +141,7 @@ impl L1ProofSender { sequencer_state: SequencerState, rollup_store: StoreRollup, needed_proof_types: Vec, + checkpoints_dir: PathBuf, ) -> Result, ProofSenderError> { let state = Self::new( &cfg.proof_coordinator, @@ -141,6 +151,7 @@ impl L1ProofSender { &cfg.aligned, rollup_store, needed_proof_types, + checkpoints_dir, ) .await?; let mut l1_proof_sender = L1ProofSender::start(state); @@ -200,6 +211,20 @@ impl L1ProofSender { self.rollup_store .set_latest_sent_batch_proof(batch_to_send) .await?; + + // Remove checkpoint from batch sent - 1. + // That checkpoint was needed to generate the proof for the batch we just sent. + // The checkpoint for the batch we have just sent is needed for the next batch. + let checkpoint_path = self + .checkpoints_dir + .join(batch_checkpoint_name(batch_to_send - 1)); + if checkpoint_path.exists() { + let _ = remove_dir_all(&checkpoint_path).inspect_err(|e| { + error!( + "Failed to remove checkpoint directory at path {checkpoint_path:?}. Should be removed manually. Error: {e}" + ) + }); + } } else { let missing_proof_types: Vec = missing_proof_types .iter() diff --git a/crates/l2/sequencer/mod.rs b/crates/l2/sequencer/mod.rs index 9044fdcccaf..1e696cea262 100644 --- a/crates/l2/sequencer/mod.rs +++ b/crates/l2/sequencer/mod.rs @@ -105,7 +105,7 @@ pub async fn start_l2( cfg.clone(), shared_state.clone(), genesis, - checkpoints_dir, + checkpoints_dir.clone(), ) .await .inspect_err(|err| { @@ -126,6 +126,7 @@ pub async fn start_l2( shared_state.clone(), rollup_store.clone(), needed_proof_types.clone(), + checkpoints_dir, ) .await .inspect_err(|err| { diff --git a/crates/l2/sequencer/utils.rs b/crates/l2/sequencer/utils.rs index fa2fff1df34..0b19e610d56 100644 --- a/crates/l2/sequencer/utils.rs +++ b/crates/l2/sequencer/utils.rs @@ -194,3 +194,7 @@ where pub fn get_git_commit_hash() -> String { env!("VERGEN_GIT_SHA").to_string() } + +pub fn batch_checkpoint_name(batch_number: u64) -> String { + format!("checkpoint_batch_{batch_number}") +}