Skip to content

Commit 5060dab

Browse files
committed
fixes
1 parent ab3acb7 commit 5060dab

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

crates/chain-orchestrator/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ impl<
415415
self.engine.update_fcs(None, Some(block_info), None).await?;
416416
}
417417
}
418+
419+
// Revert the L1 watcher to the specified block.
420+
self.l1_watcher.revert_to_l1_block(block_number);
421+
418422
self.notify(ChainOrchestratorEvent::UnwoundToL1Block(block_number));
419423
let _ = tx.send(true);
420424
}

crates/node/tests/e2e.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,16 @@ async fn can_revert_to_l1_block() -> eyre::Result<()> {
10251025
// Wait for the chain to be unwound
10261026
fixture.expect_event().revert_to_l1_block().await?;
10271027

1028+
// Now have the L1 watcher mock handle the command to rewind the L1 head.
1029+
fixture
1030+
.follower(0)
1031+
.rollup_manager_handle
1032+
.l1_watcher_mock
1033+
.as_mut()
1034+
.unwrap()
1035+
.handle_command()
1036+
.await;
1037+
10281038
// Get the node status
10291039
let status = fixture.get_status(0).await?;
10301040

crates/watcher/src/handle/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@ impl L1WatcherHandle {
3434
}
3535

3636
/// Reset the L1 Watcher to a specific block number with a fresh notification channel.
37-
pub fn revert_to_l1_block(&self, block: u64) -> mpsc::Receiver<Arc<L1Notification>> {
37+
pub fn revert_to_l1_block(&mut self, block: u64) {
3838
// Create a fresh notification channel with the same capacity as the original channel
3939
let capacity = self.l1_notification_rx.max_capacity();
4040
let (tx, rx) = mpsc::channel(capacity);
4141

42+
// Send the reset command to the watcher
4243
self.send_command(L1WatcherCommand::ResetToBlock { block, tx });
4344

44-
rx
45+
// Replace the old receiver with the new one
46+
self.l1_notification_rx = rx;
4547
}
4648
}

crates/watcher/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ where
338338

339339
// reset the state.
340340
self.current_block_number = block;
341-
self.unfinalized_blocks.clear();
342341
self.is_synced = false;
343342

344343
// replace the notification sender.

crates/watcher/src/test_utils/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ pub struct L1WatcherMock {
2121
pub notification_tx: mpsc::Sender<Arc<L1Notification>>,
2222
}
2323

24+
impl L1WatcherMock {
25+
/// Handle commands sent to the L1 watcher mock.
26+
pub async fn handle_command(&mut self) {
27+
let mut commands = self.command_rx.lock().await;
28+
if let Some(command) = commands.recv().await {
29+
match command {
30+
L1WatcherCommand::ResetToBlock { block, tx } => {
31+
// For testing purposes, we can just log the reset action.
32+
tracing::info!(target: "scroll::watcher::test_utils", "L1 Watcher Mock resetting to block {}", block);
33+
self.notification_tx = tx;
34+
}
35+
}
36+
}
37+
}
38+
}
39+
2440
/// Returns a chain of random headers of size `len`.
2541
pub fn chain(len: usize) -> (Header, Header, Vec<Header>) {
2642
assert!(len >= 2, "chain should have a minimal length of two");

0 commit comments

Comments
 (0)