Skip to content

Commit 24cef5b

Browse files
committed
handle finalized head in reconciliation
1 parent 1ff7ec3 commit 24cef5b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

crates/chain-orchestrator/src/consolidation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ pub(crate) async fn reconcile_batch<L2P: Provider<Scroll>>(
3939
// The block matches the derived attributes and the block is below or equal to the
4040
// safe current safe head.
4141
if attributes.block_number <= fcs.finalized_block_info().number ||
42-
attributes.block_number <= fcs.safe_block_info().number
42+
((attributes.block_number <= fcs.safe_block_info().number) &&
43+
batch.target_status.is_consolidated())
4344
{
4445
Ok::<_, ChainOrchestratorError>(BlockConsolidationAction::Skip(block_info))
4546
} else {

crates/engine/src/fcs.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,16 @@ impl ForkchoiceState {
4848
pub async fn from_provider<P: Provider<Scroll>>(provider: &P) -> Option<Self> {
4949
let latest_block =
5050
provider.get_block(BlockId::Number(BlockNumberOrTag::Latest)).await.ok()??;
51-
let safe_block =
51+
let mut safe_block =
5252
provider.get_block(BlockId::Number(BlockNumberOrTag::Safe)).await.ok()??;
5353
let finalized_block =
5454
provider.get_block(BlockId::Number(BlockNumberOrTag::Finalized)).await.ok()??;
55+
56+
// Ensure safe is at least finalized.
57+
if safe_block.header.number < finalized_block.header.number {
58+
safe_block = finalized_block.clone();
59+
}
60+
5561
Some(Self {
5662
head: BlockInfo { number: latest_block.header.number, hash: latest_block.header.hash },
5763
safe: BlockInfo { number: safe_block.header.number, hash: safe_block.header.hash },

crates/primitives/src/batch.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ pub enum BatchStatus {
7979
}
8080

8181
impl BatchStatus {
82+
/// Returns true if the batch status is consolidated.
83+
pub const fn is_consolidated(&self) -> bool {
84+
matches!(self, Self::Consolidated)
85+
}
86+
8287
/// Returns true if the batch status is finalized.
8388
pub const fn is_finalized(&self) -> bool {
8489
matches!(self, Self::Finalized)

0 commit comments

Comments
 (0)