-
Notifications
You must be signed in to change notification settings - Fork 130
fix(l2): remove one-time checkpoint if already exists #5083
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR addresses a bug where batch preparation retries would fail due to an existing one-time checkpoint directory. The fix ensures that if a one-time checkpoint already exists (from a previous failed attempt), it is removed before attempting to create a new one.
Key Changes:
- Added a check to detect if a one-time checkpoint directory already exists
- Implemented removal of existing one-time checkpoint directories before creating new ones
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
crates/l2/sequencer/l1_committer.rs
Outdated
|
|
||
| if one_time_checkpoint_path.exists() { | ||
| remove_dir_all(&one_time_checkpoint_path).map_err(|e| { | ||
| CommitterError::FailedToCreateCheckpoint(format!( |
Copilot
AI
Oct 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error type FailedToCreateCheckpoint is misleading when removing an existing checkpoint. Consider creating a more specific error variant like FailedToRemoveCheckpoint or using a more generic error message that reflects the cleanup operation.
| CommitterError::FailedToCreateCheckpoint(format!( | |
| CommitterError::FailedToRemoveCheckpoint(format!( |
Lines of code reportTotal lines added: Detailed view |
|
The PR was changed to use a random |
crates/l2/sequencer/l1_committer.rs
Outdated
| .inspect_err(|_| { | ||
| if one_time_checkpoint_path.exists() { | ||
| // Remove one-time checkpoint directory | ||
| let _ = remove_dir_all(&one_time_checkpoint_path); | ||
| } | ||
| })?; | ||
|
|
||
| if one_time_checkpoint_path.exists() { | ||
| remove_dir_all(&one_time_checkpoint_path).map_err(|e| { | ||
| CommitterError::FailedToCreateCheckpoint(format!( | ||
| "Failed to remove one-time checkpoint directory {one_time_checkpoint_path:?}: {e}" | ||
| )) | ||
| })?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the one_time_checkpoint_path whether or not it returns an error, we can do it in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done bd44892!
**Motivation** In a previous PR, DB checkpoints were introduced to ensure old state availability in the current path-based fashion. Every time a batch is sealed, a checkpoint whose state is the state of the latest block of the sealed batch is created to be used in the next batch. The checkpoint is needed in two different steps of the batch commitment: for batch preparation (this is essentially building the batch) and for witness generation. Both steps need a non-modified checkpoint, but they both need to modify the checkpoint to be able to re-execute the batch. As batch preparation occurs before witness generation, we opted to create a one-time checkpoint out of the main checkpoint that can be modified during batch preparation if needed (sometimes the batch was already available in the DB, and there's no need to re-execute anything); then, witness generation modifies the original checkpoint as needed because it is no longer needed. Once the one-time checkpoint fulfills its purpose, it is removed. Currently, if batch preparation fails, the one-time checkpoint is not removed, and after retrying batch preparation, there's another attempt at creating the one-time checkpoint, which ends in an error because the directory already exists. We need to either avoid creating the one-time checkpoint again or to remove the existing one. **Description** Remove the existing one-time checkpoint if it already exists. --------- Co-authored-by: avilagaston9 <[email protected]> Co-authored-by: Gianbelinche <[email protected]>
Motivation
In a previous PR, DB checkpoints were introduced to ensure old state availability in the current path-based fashion. Every time a batch is sealed, a checkpoint whose state is the state of the latest block of the sealed batch is created to be used in the next batch.
The checkpoint is needed in two different steps of the batch commitment: for batch preparation (this is essentially building the batch) and for witness generation. Both steps need a non-modified checkpoint, but they both need to modify the checkpoint to be able to re-execute the batch.
As batch preparation occurs before witness generation, we opted to create a one-time checkpoint out of the main checkpoint that can be modified during batch preparation if needed (sometimes the batch was already available in the DB, and there's no need to re-execute anything); then, witness generation modifies the original checkpoint as needed because it is no longer needed.
Once the one-time checkpoint fulfills its purpose, it is removed. Currently, if batch preparation fails, the one-time checkpoint is not removed, and after retrying batch preparation, there's another attempt at creating the one-time checkpoint, which ends in an error because the directory already exists. We need to either avoid creating the one-time checkpoint again or to remove the existing one.
Description
Remove the existing one-time checkpoint if it already exists.