@@ -298,6 +298,14 @@ impl<
298298 ) ) ;
299299 }
300300
301+ // If the current header block number is less than the latest safe block number then
302+ // we should error.
303+ if received_chain_headers. last ( ) . expect ( "chain can not be empty" ) . number <=
304+ latest_safe_block. number
305+ {
306+ return Err ( ChainOrchestratorError :: L2SafeBlockReorgDetected ) ;
307+ }
308+
301309 // If the received header tail has a block number that is less than the current header
302310 // tail then we should fetch more headers for the current chain to aid
303311 // reconciliation.
@@ -361,14 +369,6 @@ impl<
361369 break pos;
362370 }
363371
364- // If the current header block number is less than the latest safe block number then
365- // we should error.
366- if received_chain_headers. last ( ) . expect ( "chain can not be empty" ) . number <=
367- latest_safe_block. number
368- {
369- return Err ( ChainOrchestratorError :: L2SafeBlockReorgDetected ) ;
370- }
371-
372372 tracing:: trace!( target: "scroll::chain_orchestrator" , number = ?( received_chain_headers. last( ) . expect( "chain can not be empty" ) . number - 1 ) , "fetching block" ) ;
373373 if let Some ( header) = network_client
374374 . get_header ( BlockHashOrNumber :: Hash (
@@ -722,15 +722,15 @@ impl<
722722 }
723723
724724 /// Returns the highest finalized block for the provided batch hash. Will return [`None`] if the
725- /// block number has already been seen by the indexer .
725+ /// block number has already been seen by the chain orchestrator .
726726 async fn fetch_highest_finalized_block (
727727 database : Arc < Database > ,
728728 batch_hash : B256 ,
729729 l2_block_number : Arc < AtomicU64 > ,
730730 ) -> Result < Option < BlockInfo > , ChainOrchestratorError > {
731731 let finalized_block = database. get_highest_block_for_batch_hash ( batch_hash) . await ?;
732732
733- // only return the block if the indexer hasn't seen it.
733+ // only return the block if the chain orchestrator hasn't seen it.
734734 // in which case also update the `l2_finalized_block_number` value.
735735 Ok ( finalized_block. filter ( |info| {
736736 let current_l2_block_number = l2_block_number. load ( Ordering :: Relaxed ) ;
@@ -1167,18 +1167,19 @@ mod test {
11671167
11681168 #[ tokio:: test]
11691169 async fn test_handle_commit_batch ( ) {
1170- // Instantiate indexer and db
1171- let ( mut indexer , db) = setup_test_chain_orchestrator ( ) . await ;
1170+ // Instantiate chain orchestrator and db
1171+ let ( mut chain_orchestrator , db) = setup_test_chain_orchestrator ( ) . await ;
11721172
11731173 // Generate unstructured bytes.
11741174 let mut bytes = [ 0u8 ; 1024 ] ;
11751175 rand:: rng ( ) . fill ( bytes. as_mut_slice ( ) ) ;
11761176 let mut u = Unstructured :: new ( & bytes) ;
11771177
11781178 let batch_commit = BatchCommitData :: arbitrary ( & mut u) . unwrap ( ) ;
1179- indexer. handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit. clone ( ) ) ) ;
1179+ chain_orchestrator
1180+ . handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit. clone ( ) ) ) ;
11801181
1181- let event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1182+ let event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
11821183
11831184 // Verify the event structure
11841185 match event {
@@ -1196,7 +1197,7 @@ mod test {
11961197
11971198 #[ tokio:: test]
11981199 async fn test_handle_batch_commit_with_revert ( ) {
1199- // Instantiate indexer and db
1200+ // Instantiate chain orchestrator and db
12001201 let ( mut chain_orchestrator, db) = setup_test_chain_orchestrator ( ) . await ;
12011202
12021203 // Generate unstructured bytes.
@@ -1317,8 +1318,8 @@ mod test {
13171318
13181319 #[ tokio:: test]
13191320 async fn test_handle_l1_message ( ) {
1320- // Instantiate indexer and db
1321- let ( mut indexer , db) = setup_test_chain_orchestrator ( ) . await ;
1321+ // Instantiate chain orchestrator and db
1322+ let ( mut chain_orchestrator , db) = setup_test_chain_orchestrator ( ) . await ;
13221323
13231324 // Generate unstructured bytes.
13241325 let mut bytes = [ 0u8 ; 1024 ] ;
@@ -1330,13 +1331,13 @@ mod test {
13301331 ..Arbitrary :: arbitrary ( & mut u) . unwrap ( )
13311332 } ;
13321333 let block_number = u64:: arbitrary ( & mut u) . unwrap ( ) ;
1333- indexer . handle_l1_notification ( L1Notification :: L1Message {
1334+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
13341335 message : message. clone ( ) ,
13351336 block_number,
13361337 block_timestamp : 0 ,
13371338 } ) ;
13381339
1339- let _ = indexer . next ( ) . await ;
1340+ let _ = chain_orchestrator . next ( ) . await ;
13401341
13411342 let l1_message_result =
13421343 db. get_l1_message_by_index ( message. queue_index ) . await . unwrap ( ) . unwrap ( ) ;
@@ -1347,16 +1348,16 @@ mod test {
13471348
13481349 #[ tokio:: test]
13491350 async fn test_l1_message_hash_queue ( ) {
1350- // Instantiate indexer and db
1351- let ( mut indexer , db) = setup_test_chain_orchestrator ( ) . await ;
1351+ // Instantiate chain orchestrator and db
1352+ let ( mut chain_orchestrator , db) = setup_test_chain_orchestrator ( ) . await ;
13521353
13531354 // insert the previous L1 message in database.
1354- indexer . handle_l1_notification ( L1Notification :: L1Message {
1355+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
13551356 message : TxL1Message { queue_index : 1062109 , ..Default :: default ( ) } ,
13561357 block_number : 1475588 ,
13571358 block_timestamp : 1745305199 ,
13581359 } ) ;
1359- let _ = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1360+ let _ = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
13601361
13611362 // <https://sepolia.scrollscan.com/tx/0xd80cd61ac5d8665919da19128cc8c16d3647e1e2e278b931769e986d01c6b910>
13621363 let message = TxL1Message {
@@ -1367,13 +1368,13 @@ mod test {
13671368 sender : address ! ( "61d8d3E7F7c656493d1d76aAA1a836CEdfCBc27b" ) ,
13681369 input : bytes ! ( "8ef1332e000000000000000000000000323522a8de3cddeddbb67094eecaebc2436d6996000000000000000000000000323522a8de3cddeddbb67094eecaebc2436d699600000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000000000001034de00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000" ) ,
13691370 } ;
1370- indexer . handle_l1_notification ( L1Notification :: L1Message {
1371+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
13711372 message : message. clone ( ) ,
13721373 block_number : 14755883 ,
13731374 block_timestamp : 1745305200 ,
13741375 } ) ;
13751376
1376- let _ = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1377+ let _ = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
13771378
13781379 let l1_message_result =
13791380 db. get_l1_message_by_index ( message. queue_index ) . await . unwrap ( ) . unwrap ( ) ;
@@ -1386,8 +1387,8 @@ mod test {
13861387
13871388 #[ tokio:: test]
13881389 async fn test_handle_reorg ( ) {
1389- // Instantiate indexer and db
1390- let ( mut indexer , db) = setup_test_chain_orchestrator ( ) . await ;
1390+ // Instantiate chain orchestrator and db
1391+ let ( mut chain_orchestrator , db) = setup_test_chain_orchestrator ( ) . await ;
13911392
13921393 // Generate unstructured bytes.
13931394 let mut bytes = [ 0u8 ; 1024 ] ;
@@ -1411,9 +1412,12 @@ mod test {
14111412 let batch_commit_block_30 = batch_commit_block_30;
14121413
14131414 // Index batch inputs
1414- indexer. handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_1. clone ( ) ) ) ;
1415- indexer. handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_20. clone ( ) ) ) ;
1416- indexer. handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_30. clone ( ) ) ) ;
1415+ chain_orchestrator
1416+ . handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_1. clone ( ) ) ) ;
1417+ chain_orchestrator
1418+ . handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_20. clone ( ) ) ) ;
1419+ chain_orchestrator
1420+ . handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_30. clone ( ) ) ) ;
14171421
14181422 // Generate 3 random L1 messages and set their block numbers
14191423 let l1_message_block_1 = L1MessageEnvelope {
@@ -1436,27 +1440,27 @@ mod test {
14361440 } ;
14371441
14381442 // Index L1 messages
1439- indexer . handle_l1_notification ( L1Notification :: L1Message {
1443+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
14401444 message : l1_message_block_1. clone ( ) . transaction ,
14411445 block_number : l1_message_block_1. clone ( ) . l1_block_number ,
14421446 block_timestamp : 0 ,
14431447 } ) ;
1444- indexer . handle_l1_notification ( L1Notification :: L1Message {
1448+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
14451449 message : l1_message_block_20. clone ( ) . transaction ,
14461450 block_number : l1_message_block_20. clone ( ) . l1_block_number ,
14471451 block_timestamp : 0 ,
14481452 } ) ;
1449- indexer . handle_l1_notification ( L1Notification :: L1Message {
1453+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
14501454 message : l1_message_block_30. clone ( ) . transaction ,
14511455 block_number : l1_message_block_30. clone ( ) . l1_block_number ,
14521456 block_timestamp : 0 ,
14531457 } ) ;
14541458
14551459 // Reorg at block 20
1456- indexer . handle_l1_notification ( L1Notification :: Reorg ( 20 ) ) ;
1460+ chain_orchestrator . handle_l1_notification ( L1Notification :: Reorg ( 20 ) ) ;
14571461
14581462 for _ in 0 ..7 {
1459- indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1463+ chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
14601464 }
14611465
14621466 // Check that the batch input at block 30 is deleted
@@ -1485,8 +1489,8 @@ mod test {
14851489 #[ ignore]
14861490 #[ tokio:: test]
14871491 async fn test_handle_reorg_executed_l1_messages ( ) {
1488- // Instantiate indexer and db
1489- let ( mut indexer , _database) = setup_test_chain_orchestrator ( ) . await ;
1492+ // Instantiate chain orchestrator and db
1493+ let ( mut chain_orchestrator , _database) = setup_test_chain_orchestrator ( ) . await ;
14901494
14911495 // Generate unstructured bytes.
14921496 let mut bytes = [ 0u8 ; 8192 ] ;
@@ -1503,10 +1507,12 @@ mod test {
15031507 } ;
15041508
15051509 // Index batch inputs
1506- indexer. handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_1. clone ( ) ) ) ;
1507- indexer. handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_10. clone ( ) ) ) ;
1510+ chain_orchestrator
1511+ . handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_1. clone ( ) ) ) ;
1512+ chain_orchestrator
1513+ . handle_l1_notification ( L1Notification :: BatchCommit ( batch_commit_block_10. clone ( ) ) ) ;
15081514 for _ in 0 ..2 {
1509- let _event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1515+ let _event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
15101516 }
15111517
15121518 let batch_1 = BatchInfo :: new ( batch_commit_block_1. index , batch_commit_block_1. hash ) ;
@@ -1527,12 +1533,12 @@ mod test {
15271533 ..Arbitrary :: arbitrary ( & mut u) . unwrap ( )
15281534 } ,
15291535 } ;
1530- indexer . handle_l1_notification ( L1Notification :: L1Message {
1536+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
15311537 message : l1_message. transaction . clone ( ) ,
15321538 block_number : l1_message. l1_block_number ,
15331539 block_timestamp : 0 ,
15341540 } ) ;
1535- indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1541+ chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
15361542 l1_messages. push ( l1_message) ;
15371543 }
15381544
@@ -1555,19 +1561,20 @@ mod test {
15551561 None
15561562 } ;
15571563 if let Some ( batch_info) = batch_info {
1558- indexer. persist_l1_consolidated_blocks ( vec ! [ l2_block. clone( ) ] , batch_info) ;
1564+ chain_orchestrator
1565+ . persist_l1_consolidated_blocks ( vec ! [ l2_block. clone( ) ] , batch_info) ;
15591566 } else {
1560- indexer . consolidate_validated_l2_blocks ( vec ! [ l2_block. clone( ) ] ) ;
1567+ chain_orchestrator . consolidate_validated_l2_blocks ( vec ! [ l2_block. clone( ) ] ) ;
15611568 }
15621569
1563- indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1570+ chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
15641571 blocks. push ( l2_block) ;
15651572 }
15661573
15671574 // First we assert that we dont reorg the L2 or message queue hash for a higher block
15681575 // than any of the L1 messages.
1569- indexer . handle_l1_notification ( L1Notification :: Reorg ( 17 ) ) ;
1570- let event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1576+ chain_orchestrator . handle_l1_notification ( L1Notification :: Reorg ( 17 ) ) ;
1577+ let event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
15711578 assert_eq ! (
15721579 event,
15731580 ChainOrchestratorEvent :: ChainUnwound {
@@ -1580,8 +1587,8 @@ mod test {
15801587
15811588 // Reorg at block 7 which is one of the messages that has not been executed yet. No reorg
15821589 // but we should ensure the L1 messages have been deleted.
1583- indexer . handle_l1_notification ( L1Notification :: Reorg ( 7 ) ) ;
1584- let event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1590+ chain_orchestrator . handle_l1_notification ( L1Notification :: Reorg ( 7 ) ) ;
1591+ let event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
15851592
15861593 assert_eq ! (
15871594 event,
@@ -1594,16 +1601,19 @@ mod test {
15941601 ) ;
15951602
15961603 // Now reorg at block 5 which contains L1 messages that have been executed .
1597- indexer . handle_l1_notification ( L1Notification :: Reorg ( 3 ) ) ;
1598- let event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1604+ chain_orchestrator . handle_l1_notification ( L1Notification :: Reorg ( 3 ) ) ;
1605+ let event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
15991606
16001607 assert_eq ! (
16011608 event,
16021609 ChainOrchestratorEvent :: ChainUnwound {
16031610 l1_block_number: 3 ,
16041611 queue_index: Some ( 4 ) ,
16051612 l2_head_block_info: Some ( blocks[ 3 ] . block_info) ,
1606- l2_safe_block_info: Some ( BlockInfo :: new( 0 , indexer. chain_spec. genesis_hash( ) ) ) ,
1613+ l2_safe_block_info: Some ( BlockInfo :: new(
1614+ 0 ,
1615+ chain_orchestrator. chain_spec. genesis_hash( )
1616+ ) ) ,
16071617 }
16081618 ) ;
16091619 }
0 commit comments