From 55c188c05e53ab8626371f130208b1fbf72655f6 Mon Sep 17 00:00:00 2001 From: frisitano Date: Mon, 8 Sep 2025 20:37:51 +0800 Subject: [PATCH] update batch finalization logic --- crates/chain-orchestrator/src/event.rs | 9 +++------ crates/chain-orchestrator/src/lib.rs | 11 +++++++++++ crates/manager/src/manager/mod.rs | 7 +++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/chain-orchestrator/src/event.rs b/crates/chain-orchestrator/src/event.rs index caf94579..154f2da1 100644 --- a/crates/chain-orchestrator/src/event.rs +++ b/crates/chain-orchestrator/src/event.rs @@ -2,9 +2,7 @@ use alloy_consensus::Header; use alloy_primitives::{Signature, B256}; use reth_network_peers::PeerId; use reth_scroll_primitives::ScrollBlock; -use rollup_node_primitives::{ - BatchInfo, BlockInfo, ChainImport, L2BlockInfoWithL1Messages, WithFinalizedBlockNumber, -}; +use rollup_node_primitives::{BatchInfo, BlockInfo, ChainImport, L2BlockInfoWithL1Messages}; /// An event emitted by the `ChainOrchestrator`. #[derive(Debug, Clone, PartialEq, Eq)] @@ -40,9 +38,8 @@ pub enum ChainOrchestratorEvent { /// The safe L2 block info. safe_head: Option, }, - /// A batch has been finalized returning an optional finalized L2 block. Also returns a - /// [`BatchInfo`] if the finalized event occurred in a finalized L1 block. - BatchFinalized(Option>, Option), + /// A batch has been finalized returning a list of finalized batches. + BatchFinalized(u64, Vec), /// An L1 block has been finalized returning the L1 block number and the list of finalized /// batches. L1BlockFinalized(u64, Vec), diff --git a/crates/chain-orchestrator/src/lib.rs b/crates/chain-orchestrator/src/lib.rs index cadc2cb1..93f32cf0 100644 --- a/crates/chain-orchestrator/src/lib.rs +++ b/crates/chain-orchestrator/src/lib.rs @@ -556,6 +556,7 @@ impl< self.database.clone(), index, block_number, + self.l1_finalized_block_number.clone(), )), )) } @@ -695,10 +696,20 @@ impl< database: Arc, batch_index: u64, block_number: u64, + finalized_block_number: Arc, ) -> Result, ChainOrchestratorError> { // finalize all batches up to `batch_index`. database.finalize_batches_up_to_index(batch_index, block_number).await?; + // Get all unprocessed batches that have been finalized by this L1 block finalization. + let finalized_block_number = finalized_block_number.load(Ordering::Relaxed); + if finalized_block_number >= block_number { + let finalized_batches = database + .fetch_and_update_unprocessed_finalized_batches(finalized_block_number) + .await?; + return Ok(Some(ChainOrchestratorEvent::BatchFinalized(block_number, finalized_batches))) + } + Ok(None) } } diff --git a/crates/manager/src/manager/mod.rs b/crates/manager/src/manager/mod.rs index 72c23708..6f16d5aa 100644 --- a/crates/manager/src/manager/mod.rs +++ b/crates/manager/src/manager/mod.rs @@ -274,7 +274,7 @@ where // // push the batch info into the derivation pipeline. // self.derivation_pipeline.push_batch(batch_info, l1_block_number); } - ChainOrchestratorEvent::BatchFinalized(batch_info, ..) => { + ChainOrchestratorEvent::BatchFinalized(block_number, finalized_batches) => { // Uncomment once we implement issue #273. // // update the fcs on new finalized block. // if let Some(finalized_block) = finalized_block { @@ -282,9 +282,8 @@ where // } // Remove once we implement issue #273. // Update the derivation pipeline on new finalized batch. - #[allow(clippy::collapsible_match)] - if let Some(batch_info) = batch_info { - self.derivation_pipeline.push_batch(batch_info.inner, batch_info.number); + for batch_info in finalized_batches { + self.derivation_pipeline.push_batch(batch_info, block_number); } } ChainOrchestratorEvent::L1BlockFinalized(l1_block_number, finalized_batches, ..) => {