Skip to content

Commit

Permalink
Fix commitment threshold test (#896)
Browse files Browse the repository at this point in the history
* Enable logs on tests

* Fix commitment_threshold test

* Fix get_soft_batch returning None

* Turn off logging
  • Loading branch information
rakanalh authored Jul 17, 2024
1 parent b9eccab commit 411bf9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
8 changes: 7 additions & 1 deletion bin/citrea/tests/e2e/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,8 @@ async fn test_system_tx_effect_on_block_gas_limit() -> Result<(), anyhow::Error>
let last_in_receipt = last_in_tx.unwrap().get_receipt().await.unwrap();

wait_for_l2_block(&seq_test_client, 1, None).await;
// Wait for storage
sleep(Duration::from_secs(1)).await;

let initial_soft_batch = seq_test_client
.ledger_get_soft_batch_by_number::<MockDaSpec>(1)
Expand Down Expand Up @@ -1923,7 +1925,7 @@ fn find_subarray(haystack: &[u8], needle: &[u8]) -> Option<usize> {

#[tokio::test(flavor = "multi_thread")]
async fn sequencer_crash_and_replace_full_node() -> Result<(), anyhow::Error> {
citrea::initialize_logging(tracing::Level::DEBUG);
// citrea::initialize_logging(tracing::Level::DEBUG);

let storage_dir = tempdir_with_children(&["DA", "sequencer", "full-node"]);
let da_db_dir = storage_dir.path().join("DA").to_path_buf();
Expand Down Expand Up @@ -3452,6 +3454,10 @@ async fn test_sequencer_fill_missing_da_blocks() -> Result<(), anyhow::Error> {
// publish an extra l2 block
seq_test_client.send_publish_batch_request().await;
wait_for_l2_block(&seq_test_client, last_filler_l2_block + 1, None).await;

// Wait for storage
sleep(Duration::from_secs(1)).await;

// ensure that the latest l2 block points to latest da block and has correct height
let head_soft_batch = seq_test_client
.ledger_get_head_soft_batch()
Expand Down
2 changes: 1 addition & 1 deletion bin/citrea/tests/evm/archival_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{

#[tokio::test(flavor = "multi_thread")]
async fn test_archival_state() -> Result<(), anyhow::Error> {
// citrea::initialize_logging(tracing::Level::INFO);
// citrea::initialize_logging(tracing::Level::DEBUG);

let storage_dir = tempdir_with_children(&["DA", "sequencer", "full-node"]);
let da_db_dir = storage_dir.path().join("DA").to_path_buf();
Expand Down
23 changes: 11 additions & 12 deletions crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,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 @@ -712,22 +716,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 @@ -846,8 +845,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 411bf9a

Please sign in to comment.