Skip to content

Commit 54bb0c3

Browse files
committed
fix test shutdown_consolidates_most_recent_batch_on_startup
1 parent 875f745 commit 54bb0c3

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

crates/derivation-pipeline/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,7 @@ mod tests {
522522

523523
// as long as we don't call `push_batch`, pipeline should not return attributes.
524524
pipeline
525-
.push_batch(
526-
BatchInfo { index: 12, hash: batch_data.hash },
527-
BatchStatus::Consolidated,
528-
)
525+
.push_batch(BatchInfo { index: 12, hash: batch_data.hash }, BatchStatus::Consolidated)
529526
.await;
530527

531528
// wait for 5 seconds to ensure the pipeline is in a retry loop.

crates/node/tests/e2e.rs

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ async fn shutdown_consolidates_most_recent_batch_on_startup() -> eyre::Result<()
656656
// Lets iterate over all blocks expected to be derived from the first batch commit.
657657
let consolidation_outcome = loop {
658658
let event = rnm_events.next().await;
659-
println!("Received event: {:?}", event);
659+
tracing::info!(target: "scroll::test", event = ?event, "Received event");
660660
if let Some(ChainOrchestratorEvent::BatchConsolidated(consolidation_outcome)) = event {
661661
break consolidation_outcome;
662662
}
@@ -756,37 +756,55 @@ async fn shutdown_consolidates_most_recent_batch_on_startup() -> eyre::Result<()
756756
// Request an event stream from the rollup node manager.
757757
let mut rnm_events = handle.get_event_listener().await?;
758758

759-
println!("im here");
759+
// Send the second batch again to test skipping of already known batch.
760+
l1_notification_tx
761+
.send(Arc::new(L1Notification::BatchCommit {
762+
block_info: block_1_info,
763+
data: batch_1_data.clone(),
764+
}))
765+
.await?;
766+
loop {
767+
select! {
768+
_ = tokio::time::sleep(Duration::from_secs(5)) => {
769+
bail!("Timed out waiting for first consolidated block after RNM restart");
770+
}
771+
772+
evt = rnm_events.next() => {
773+
tracing::info!(target: "scroll::test", event = ?evt, "Received event");
774+
775+
if evt == Some(ChainOrchestratorEvent::BatchCommitDuplicate(batch_1_data.index)) {
776+
break;
777+
}
778+
}
779+
}
780+
}
760781

761-
// Send the second batch again to mimic the watcher behaviour.
782+
// Send L1 finalized block event again to trigger consolidation from the last known safe block.
762783
let block_1_info = BlockInfo { number: 18318215, hash: B256::random() };
763784
l1_notification_tx.send(Arc::new(L1Notification::Finalized(block_1_info.number))).await?;
764785

765-
let mut l2_block = None;
786+
let l2_block;
766787
// Lets fetch the first consolidated block event - this should be the first block of the batch.
767-
select! {
768-
_ = tokio::time::sleep(Duration::from_secs(5)) => {
769-
bail!("Timed out waiting for first consolidated block after RNM restart");
770-
}
788+
loop {
789+
select! {
790+
_ = tokio::time::sleep(Duration::from_secs(5)) => {
791+
bail!("Timed out waiting for first consolidated block after RNM restart");
792+
}
771793

772-
evt = rnm_events.next() => {
773-
if let Some(ChainOrchestratorEvent::BlockConsolidated(consolidation_outcome)) = evt {
774-
l2_block = Some(consolidation_outcome.block_info().clone());
775-
} else {
776-
println!("Received unexpected event: {:?}", evt);
794+
evt = rnm_events.next() => {
795+
if let Some(ChainOrchestratorEvent::BlockConsolidated(consolidation_outcome)) = evt {
796+
l2_block = Some(consolidation_outcome.block_info().clone());
797+
break;
798+
}
799+
800+
tracing::info!(target: "scroll::test", event = ?evt, "Received event");
777801
}
778802
}
779803
}
780804

781-
println!("First consolidated block after RNM restart: {:?}", l2_block);
782-
// TODO: this test needs to be adjusted since currently a partial batch is applied and assumed
783-
// that it will be re-applied on restart. However, with the gap detection and skipping of
784-
// duplicate batches this doesn't work. We need the changes from https://github.com/scroll-tech/rollup-node/pull/409
785-
return Ok(());
786-
787-
// One issue #273 is completed, we will again have safe blocks != finalized blocks, and this
788-
// should be changed to 1. Assert that the consolidated block is the first block that was not
789-
// previously processed of the batch.
805+
// Assert that the consolidated block is the first block that was not previously processed of
806+
// the batch. The last consolidated block before shutdown was block 40, so the next should
807+
// be block 41. Since we apply blocks from a partially processed batch this is expected as described in https://github.com/scroll-tech/rollup-node/issues/411. Once we implement full batch atomicity (for setting safe blocks from a batch) this should change to block 5.
790808
assert_eq!(
791809
l2_block.unwrap().block_info.number,
792810
41,
@@ -800,7 +818,7 @@ async fn shutdown_consolidates_most_recent_batch_on_startup() -> eyre::Result<()
800818
if let Some(ChainOrchestratorEvent::BlockConsolidated(consolidation_outcome)) =
801819
rnm_events.next().await
802820
{
803-
assert!(consolidation_outcome.block_info().block_info.number == i);
821+
assert_eq!(consolidation_outcome.block_info().block_info.number, i);
804822
break;
805823
}
806824
}

0 commit comments

Comments
 (0)