Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions crates/batcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,11 @@ impl Batcher {
// TODO: In the future, we should re-add the failed batch back to the queue
// For now, we flush everything as a safety measure
self.flush_queue_and_clear_nonce_cache().await;

return Err(BatcherError::StateCorruptedAndFlushed(format!(
"Queue and user states flushed due to insufficient balance for user {:?}",
address
)));
}
_ => {
// Add more cases here if we want in the future
Expand Down Expand Up @@ -1952,12 +1957,19 @@ impl Batcher {

// If batch finalization failed, restore the proofs to the queue
if let Err(e) = batch_finalization_result {
error!(
"Batch finalization failed, restoring proofs to queue: {:?}",
e
);
self.restore_proofs_after_batch_failure(&finalized_batch)
.await;
error!("Batch finalization failed: {:?}", e);

// If the queue was flushed, don't recover
match &e {
BatcherError::StateCorruptedAndFlushed(_) => {
info!("State was corrupted and flushed - not restoring proofs");
}
_ => {
info!("Restoring proofs to queue after batch failure");
self.restore_proofs_after_batch_failure(&finalized_batch)
.await;
}
}
return Err(e);
}
}
Expand Down
4 changes: 4 additions & 0 deletions crates/batcher/src/types/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub enum BatcherError {
WsSinkEmpty,
AddressNotFoundInUserStates(Address),
QueueRemoveError(String),
StateCorruptedAndFlushed(String),
}

impl From<tungstenite::Error> for BatcherError {
Expand Down Expand Up @@ -147,6 +148,9 @@ impl fmt::Debug for BatcherError {
BatcherError::QueueRemoveError(e) => {
write!(f, "Error while removing entry from queue: {}", e)
}
BatcherError::StateCorruptedAndFlushed(reason) => {
write!(f, "Batcher state was corrupted and flushed: {}", reason)
}
}
}
}
Expand Down
Loading