@@ -298,6 +298,14 @@ impl<
298
298
) ) ;
299
299
}
300
300
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
+
301
309
// If the received header tail has a block number that is less than the current header
302
310
// tail then we should fetch more headers for the current chain to aid
303
311
// reconciliation.
@@ -361,14 +369,6 @@ impl<
361
369
break pos;
362
370
}
363
371
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
-
372
372
tracing:: trace!( target: "scroll::chain_orchestrator" , number = ?( received_chain_headers. last( ) . expect( "chain can not be empty" ) . number - 1 ) , "fetching block" ) ;
373
373
if let Some ( header) = network_client
374
374
. get_header ( BlockHashOrNumber :: Hash (
@@ -722,15 +722,15 @@ impl<
722
722
}
723
723
724
724
/// 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 .
726
726
async fn fetch_highest_finalized_block (
727
727
database : Arc < Database > ,
728
728
batch_hash : B256 ,
729
729
l2_block_number : Arc < AtomicU64 > ,
730
730
) -> Result < Option < BlockInfo > , ChainOrchestratorError > {
731
731
let finalized_block = database. get_highest_block_for_batch_hash ( batch_hash) . await ?;
732
732
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.
734
734
// in which case also update the `l2_finalized_block_number` value.
735
735
Ok ( finalized_block. filter ( |info| {
736
736
let current_l2_block_number = l2_block_number. load ( Ordering :: Relaxed ) ;
@@ -1167,18 +1167,19 @@ mod test {
1167
1167
1168
1168
#[ tokio:: test]
1169
1169
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 ;
1172
1172
1173
1173
// Generate unstructured bytes.
1174
1174
let mut bytes = [ 0u8 ; 1024 ] ;
1175
1175
rand:: rng ( ) . fill ( bytes. as_mut_slice ( ) ) ;
1176
1176
let mut u = Unstructured :: new ( & bytes) ;
1177
1177
1178
1178
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 ( ) ) ) ;
1180
1181
1181
- let event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1182
+ let event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1182
1183
1183
1184
// Verify the event structure
1184
1185
match event {
@@ -1196,7 +1197,7 @@ mod test {
1196
1197
1197
1198
#[ tokio:: test]
1198
1199
async fn test_handle_batch_commit_with_revert ( ) {
1199
- // Instantiate indexer and db
1200
+ // Instantiate chain orchestrator and db
1200
1201
let ( mut chain_orchestrator, db) = setup_test_chain_orchestrator ( ) . await ;
1201
1202
1202
1203
// Generate unstructured bytes.
@@ -1317,8 +1318,8 @@ mod test {
1317
1318
1318
1319
#[ tokio:: test]
1319
1320
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 ;
1322
1323
1323
1324
// Generate unstructured bytes.
1324
1325
let mut bytes = [ 0u8 ; 1024 ] ;
@@ -1330,13 +1331,13 @@ mod test {
1330
1331
..Arbitrary :: arbitrary ( & mut u) . unwrap ( )
1331
1332
} ;
1332
1333
let block_number = u64:: arbitrary ( & mut u) . unwrap ( ) ;
1333
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1334
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1334
1335
message : message. clone ( ) ,
1335
1336
block_number,
1336
1337
block_timestamp : 0 ,
1337
1338
} ) ;
1338
1339
1339
- let _ = indexer . next ( ) . await ;
1340
+ let _ = chain_orchestrator . next ( ) . await ;
1340
1341
1341
1342
let l1_message_result =
1342
1343
db. get_l1_message_by_index ( message. queue_index ) . await . unwrap ( ) . unwrap ( ) ;
@@ -1347,16 +1348,16 @@ mod test {
1347
1348
1348
1349
#[ tokio:: test]
1349
1350
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 ;
1352
1353
1353
1354
// insert the previous L1 message in database.
1354
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1355
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1355
1356
message : TxL1Message { queue_index : 1062109 , ..Default :: default ( ) } ,
1356
1357
block_number : 1475588 ,
1357
1358
block_timestamp : 1745305199 ,
1358
1359
} ) ;
1359
- let _ = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1360
+ let _ = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1360
1361
1361
1362
// <https://sepolia.scrollscan.com/tx/0xd80cd61ac5d8665919da19128cc8c16d3647e1e2e278b931769e986d01c6b910>
1362
1363
let message = TxL1Message {
@@ -1367,13 +1368,13 @@ mod test {
1367
1368
sender : address ! ( "61d8d3E7F7c656493d1d76aAA1a836CEdfCBc27b" ) ,
1368
1369
input : bytes ! ( "8ef1332e000000000000000000000000323522a8de3cddeddbb67094eecaebc2436d6996000000000000000000000000323522a8de3cddeddbb67094eecaebc2436d699600000000000000000000000000000000000000000000000000038d7ea4c6800000000000000000000000000000000000000000000000000000000000001034de00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000" ) ,
1369
1370
} ;
1370
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1371
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1371
1372
message : message. clone ( ) ,
1372
1373
block_number : 14755883 ,
1373
1374
block_timestamp : 1745305200 ,
1374
1375
} ) ;
1375
1376
1376
- let _ = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1377
+ let _ = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1377
1378
1378
1379
let l1_message_result =
1379
1380
db. get_l1_message_by_index ( message. queue_index ) . await . unwrap ( ) . unwrap ( ) ;
@@ -1386,8 +1387,8 @@ mod test {
1386
1387
1387
1388
#[ tokio:: test]
1388
1389
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 ;
1391
1392
1392
1393
// Generate unstructured bytes.
1393
1394
let mut bytes = [ 0u8 ; 1024 ] ;
@@ -1411,9 +1412,12 @@ mod test {
1411
1412
let batch_commit_block_30 = batch_commit_block_30;
1412
1413
1413
1414
// 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 ( ) ) ) ;
1417
1421
1418
1422
// Generate 3 random L1 messages and set their block numbers
1419
1423
let l1_message_block_1 = L1MessageEnvelope {
@@ -1436,27 +1440,27 @@ mod test {
1436
1440
} ;
1437
1441
1438
1442
// Index L1 messages
1439
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1443
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1440
1444
message : l1_message_block_1. clone ( ) . transaction ,
1441
1445
block_number : l1_message_block_1. clone ( ) . l1_block_number ,
1442
1446
block_timestamp : 0 ,
1443
1447
} ) ;
1444
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1448
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1445
1449
message : l1_message_block_20. clone ( ) . transaction ,
1446
1450
block_number : l1_message_block_20. clone ( ) . l1_block_number ,
1447
1451
block_timestamp : 0 ,
1448
1452
} ) ;
1449
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1453
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1450
1454
message : l1_message_block_30. clone ( ) . transaction ,
1451
1455
block_number : l1_message_block_30. clone ( ) . l1_block_number ,
1452
1456
block_timestamp : 0 ,
1453
1457
} ) ;
1454
1458
1455
1459
// Reorg at block 20
1456
- indexer . handle_l1_notification ( L1Notification :: Reorg ( 20 ) ) ;
1460
+ chain_orchestrator . handle_l1_notification ( L1Notification :: Reorg ( 20 ) ) ;
1457
1461
1458
1462
for _ in 0 ..7 {
1459
- indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1463
+ chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1460
1464
}
1461
1465
1462
1466
// Check that the batch input at block 30 is deleted
@@ -1485,8 +1489,8 @@ mod test {
1485
1489
#[ ignore]
1486
1490
#[ tokio:: test]
1487
1491
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 ;
1490
1494
1491
1495
// Generate unstructured bytes.
1492
1496
let mut bytes = [ 0u8 ; 8192 ] ;
@@ -1503,10 +1507,12 @@ mod test {
1503
1507
} ;
1504
1508
1505
1509
// 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 ( ) ) ) ;
1508
1514
for _ in 0 ..2 {
1509
- let _event = indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1515
+ let _event = chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1510
1516
}
1511
1517
1512
1518
let batch_1 = BatchInfo :: new ( batch_commit_block_1. index , batch_commit_block_1. hash ) ;
@@ -1527,12 +1533,12 @@ mod test {
1527
1533
..Arbitrary :: arbitrary ( & mut u) . unwrap ( )
1528
1534
} ,
1529
1535
} ;
1530
- indexer . handle_l1_notification ( L1Notification :: L1Message {
1536
+ chain_orchestrator . handle_l1_notification ( L1Notification :: L1Message {
1531
1537
message : l1_message. transaction . clone ( ) ,
1532
1538
block_number : l1_message. l1_block_number ,
1533
1539
block_timestamp : 0 ,
1534
1540
} ) ;
1535
- indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1541
+ chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1536
1542
l1_messages. push ( l1_message) ;
1537
1543
}
1538
1544
@@ -1555,19 +1561,20 @@ mod test {
1555
1561
None
1556
1562
} ;
1557
1563
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) ;
1559
1566
} else {
1560
- indexer . consolidate_validated_l2_blocks ( vec ! [ l2_block. clone( ) ] ) ;
1567
+ chain_orchestrator . consolidate_validated_l2_blocks ( vec ! [ l2_block. clone( ) ] ) ;
1561
1568
}
1562
1569
1563
- indexer . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1570
+ chain_orchestrator . next ( ) . await . unwrap ( ) . unwrap ( ) ;
1564
1571
blocks. push ( l2_block) ;
1565
1572
}
1566
1573
1567
1574
// First we assert that we dont reorg the L2 or message queue hash for a higher block
1568
1575
// 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 ( ) ;
1571
1578
assert_eq ! (
1572
1579
event,
1573
1580
ChainOrchestratorEvent :: ChainUnwound {
@@ -1580,8 +1587,8 @@ mod test {
1580
1587
1581
1588
// Reorg at block 7 which is one of the messages that has not been executed yet. No reorg
1582
1589
// 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 ( ) ;
1585
1592
1586
1593
assert_eq ! (
1587
1594
event,
@@ -1594,16 +1601,19 @@ mod test {
1594
1601
) ;
1595
1602
1596
1603
// 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 ( ) ;
1599
1606
1600
1607
assert_eq ! (
1601
1608
event,
1602
1609
ChainOrchestratorEvent :: ChainUnwound {
1603
1610
l1_block_number: 3 ,
1604
1611
queue_index: Some ( 4 ) ,
1605
1612
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
+ ) ) ,
1607
1617
}
1608
1618
) ;
1609
1619
}
0 commit comments