Skip to content

Commit d6a78f9

Browse files
authored
feat: update log process ordering (#432)
* update log process ordering * update batch revent logic
1 parent 648b929 commit d6a78f9

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

crates/chain-orchestrator/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,10 @@ impl<
841841
.await?;
842842

843843
// Update the forkchoice state to the new safe block.
844-
self.engine.update_fcs(None, Some(safe_block_info), None).await?;
844+
if self.sync_state.is_synced() {
845+
tracing::info!(target: "scroll::chain_orchestrator", ?safe_block_info, "Updating safe head to block after batch revert");
846+
self.engine.update_fcs(None, Some(safe_block_info), None).await?;
847+
}
845848

846849
Ok(Some(ChainOrchestratorEvent::BatchReverted { batch_info, safe_head: safe_block_info }))
847850
}

crates/watcher/src/lib.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,28 @@ where
325325
if latest.header.number != self.current_block_number {
326326
// index the next range of blocks.
327327
let logs = self.next_filtered_logs(latest.header.number).await?;
328+
let num_logs = logs.len();
328329

329330
// prepare notifications.
330331
let mut notifications = Vec::with_capacity(logs.len());
331332

332-
// handle all events.
333-
notifications.extend(self.handle_l1_messages(&logs).await?);
334-
notifications.extend(self.handle_batch_reverts(&logs).await?);
335-
notifications.extend(self.handle_batch_revert_ranges(&logs).await?);
336-
notifications.extend(self.handle_batch_commits(&logs).await?);
337-
notifications.extend(self.handle_batch_finalization(&logs).await?);
333+
for log in logs {
334+
let sig = log.topics()[0];
335+
336+
let notification = match sig {
337+
QueueTransaction::SIGNATURE_HASH => self.handle_l1_messages(&[log]).await?,
338+
CommitBatch::SIGNATURE_HASH => self.handle_batch_commits(&[log]).await?,
339+
FinalizeBatch::SIGNATURE_HASH => self.handle_batch_finalization(&[log]).await?,
340+
RevertBatch_0::SIGNATURE_HASH => self.handle_batch_reverts(&[log]).await?,
341+
RevertBatch_1::SIGNATURE_HASH => {
342+
self.handle_batch_revert_ranges(&[log]).await?
343+
}
344+
_ => unreachable!("log signature already filtered"),
345+
};
346+
347+
notifications.extend(notification);
348+
}
349+
338350
if let Some(system_contract_update) =
339351
self.handle_system_contract_update(&latest).await?
340352
{
@@ -344,9 +356,9 @@ where
344356
// Check that we haven't generated more notifications than logs
345357
// Note: notifications.len() may be less than logs.len() because genesis batch
346358
// (batch_index=0) is intentionally skipped
347-
if notifications.len() > logs.len() {
359+
if notifications.len() > num_logs {
348360
return Err(L1WatcherError::Logs(FilterLogError::InvalidNotificationCount(
349-
logs.len(),
361+
num_logs,
350362
notifications.len(),
351363
)))
352364
}

0 commit comments

Comments
 (0)