Skip to content

Commit 02c4468

Browse files
gianbelincheManuelBilbaoilitteri
authored
fix(l2): remove used checkpoints (#5120)
**Motivation** Checkpoints are never deleted <!-- Why does this pull request exist? What are its goals? --> **Description** Delete checkpoints once we verify the corresponding batch <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> --------- Co-authored-by: Manuel Iñaki Bilbao <[email protected]> Co-authored-by: Ivan Litteri <[email protected]>
1 parent 1748ddc commit 02c4468

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

crates/l2/sequencer/l1_committer.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use crate::{
44
sequencer::{
55
errors::CommitterError,
66
utils::{
7-
self, fetch_blocks_with_respective_fee_configs, get_git_commit_hash, system_now_ms,
7+
self, batch_checkpoint_name, fetch_blocks_with_respective_fee_configs,
8+
get_git_commit_hash, system_now_ms,
89
},
910
},
1011
};
@@ -1313,7 +1314,3 @@ pub async fn regenerate_head_state(
13131314

13141315
Ok(())
13151316
}
1316-
1317-
fn batch_checkpoint_name(batch_number: u64) -> String {
1318-
format!("checkpoint_batch_{batch_number}")
1319-
}

crates/l2/sequencer/l1_proof_sender.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use std::collections::{BTreeMap, HashMap};
1+
use std::{
2+
collections::{BTreeMap, HashMap},
3+
fs::remove_dir_all,
4+
path::PathBuf,
5+
};
26

37
use ethrex_common::{Address, U256};
48
use ethrex_l2_common::{
@@ -30,7 +34,7 @@ use super::{
3034
use 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
};
3539
use 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

9197
impl 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()

crates/l2/sequencer/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub async fn start_l2(
105105
cfg.clone(),
106106
shared_state.clone(),
107107
genesis,
108-
checkpoints_dir,
108+
checkpoints_dir.clone(),
109109
)
110110
.await
111111
.inspect_err(|err| {
@@ -126,6 +126,7 @@ pub async fn start_l2(
126126
shared_state.clone(),
127127
rollup_store.clone(),
128128
needed_proof_types.clone(),
129+
checkpoints_dir,
129130
)
130131
.await
131132
.inspect_err(|err| {

crates/l2/sequencer/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,7 @@ where
194194
pub fn get_git_commit_hash() -> String {
195195
env!("VERGEN_GIT_SHA").to_string()
196196
}
197+
198+
pub fn batch_checkpoint_name(batch_number: u64) -> String {
199+
format!("checkpoint_batch_{batch_number}")
200+
}

0 commit comments

Comments
 (0)