1- use std:: collections:: { BTreeMap , HashMap } ;
1+ use std:: {
2+ collections:: { BTreeMap , HashMap } ,
3+ fs:: remove_dir_all,
4+ path:: PathBuf ,
5+ } ;
26
37use ethrex_common:: { Address , U256 } ;
48use ethrex_l2_common:: {
@@ -30,7 +34,7 @@ use super::{
3034use crate :: {
3135 CommitterConfig , EthConfig , ProofCoordinatorConfig , SequencerConfig ,
3236 based:: sequencer_state:: { SequencerState , SequencerStatus } ,
33- sequencer:: errors:: ProofSenderError ,
37+ sequencer:: { errors:: ProofSenderError , utils :: batch_checkpoint_name } ,
3438} ;
3539use aligned_sdk:: {
3640 common:: {
@@ -71,6 +75,8 @@ pub struct L1ProofSender {
7175 l1_chain_id : u64 ,
7276 network : Network ,
7377 fee_estimate : FeeEstimationType ,
78+ /// Directory where checkpoints are stored.
79+ checkpoints_dir : PathBuf ,
7480 aligned_mode : bool ,
7581}
7682
@@ -89,6 +95,7 @@ pub struct L1ProofSenderHealth {
8995}
9096
9197impl L1ProofSender {
98+ #[ expect( clippy:: too_many_arguments) ]
9299 async fn new (
93100 cfg : & ProofCoordinatorConfig ,
94101 committer_cfg : & CommitterConfig ,
@@ -97,6 +104,7 @@ impl L1ProofSender {
97104 aligned_cfg : & AlignedConfig ,
98105 rollup_store : StoreRollup ,
99106 needed_proof_types : Vec < ProverType > ,
107+ checkpoints_dir : PathBuf ,
100108 ) -> Result < Self , ProofSenderError > {
101109 let eth_client = EthClient :: new_with_config (
102110 eth_cfg. rpc_url . clone ( ) ,
@@ -123,6 +131,7 @@ impl L1ProofSender {
123131 l1_chain_id,
124132 network : aligned_cfg. network . clone ( ) ,
125133 fee_estimate,
134+ checkpoints_dir,
126135 aligned_mode : aligned_cfg. aligned_mode ,
127136 } )
128137 }
@@ -132,6 +141,7 @@ impl L1ProofSender {
132141 sequencer_state : SequencerState ,
133142 rollup_store : StoreRollup ,
134143 needed_proof_types : Vec < ProverType > ,
144+ checkpoints_dir : PathBuf ,
135145 ) -> Result < GenServerHandle < L1ProofSender > , ProofSenderError > {
136146 let state = Self :: new (
137147 & cfg. proof_coordinator ,
@@ -141,6 +151,7 @@ impl L1ProofSender {
141151 & cfg. aligned ,
142152 rollup_store,
143153 needed_proof_types,
154+ checkpoints_dir,
144155 )
145156 . await ?;
146157 let mut l1_proof_sender = L1ProofSender :: start ( state) ;
@@ -200,6 +211,20 @@ impl L1ProofSender {
200211 self . rollup_store
201212 . set_latest_sent_batch_proof ( batch_to_send)
202213 . await ?;
214+
215+ // Remove checkpoint from batch sent - 1.
216+ // That checkpoint was needed to generate the proof for the batch we just sent.
217+ // The checkpoint for the batch we have just sent is needed for the next batch.
218+ let checkpoint_path = self
219+ . checkpoints_dir
220+ . join ( batch_checkpoint_name ( batch_to_send - 1 ) ) ;
221+ if checkpoint_path. exists ( ) {
222+ let _ = remove_dir_all ( & checkpoint_path) . inspect_err ( |e| {
223+ error ! (
224+ "Failed to remove checkpoint directory at path {checkpoint_path:?}. Should be removed manually. Error: {e}"
225+ )
226+ } ) ;
227+ }
203228 } else {
204229 let missing_proof_types: Vec < String > = missing_proof_types
205230 . iter ( )
0 commit comments