Skip to content

Commit

Permalink
Fix commitment_threshold test
Browse files Browse the repository at this point in the history
  • Loading branch information
rakanalh committed Jul 17, 2024
1 parent dbd1f25 commit fe72228
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,15 @@ where
async fn submit_commitment(
&mut self,
commitment_info: commitment_controller::CommitmentInfo,
resubmit: bool,
wait_for_da_response: bool,
) -> anyhow::Result<()> {
let l2_start = *commitment_info.l2_height_range.start();
let l2_end = *commitment_info.l2_height_range.end();

// Clear state diff early
self.ledger_db.set_state_diff(vec![])?;
self.last_state_diff = vec![];

// calculate exclusive range end
let range_end = BatchNumber(l2_end.0 + 1); // cannnot add u64 to BatchNumber directly

Expand Down Expand Up @@ -711,22 +715,17 @@ where
}
};

if !resubmit {
if wait_for_da_response {
// Handle DA response blocking
handle_da_response.await;
} else {
// Add commitment to pending commitments
self.ledger_db
.put_pending_commitment_l2_range(&(l2_start, l2_end))?;

// Clear state diff
self.ledger_db.set_state_diff(vec![])?;
self.last_state_diff = vec![];

// Handle DA response non-blocking
tokio::spawn(handle_da_response);
} else {
// Handle DA response blocking
handle_da_response.await;
}

Ok(())
}

Expand Down Expand Up @@ -845,8 +844,8 @@ where
}
}
},
force = da_commitment_rx.select_next_some() => {
if let Err(e) = self.try_submit_commitment(force).await {
commitment_threshold_reached = da_commitment_rx.select_next_some() => {
if let Err(e) = self.try_submit_commitment(commitment_threshold_reached).await {
error!("Failed to submit commitment: {}", e);
}
},
Expand Down

0 comments on commit fe72228

Please sign in to comment.