Skip to content

Commit d560c36

Browse files
authored
Merge branch 'main' into morty-add-anvil-to-test-fixture
2 parents 0b8dd48 + 987000d commit d560c36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1172
-799
lines changed

Cargo.lock

Lines changed: 40 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[workspace.package]
2-
version = "0.0.1"
2+
version = "1.0.0"
33
edition = "2021"
4-
rust-version = "1.82"
4+
rust-version = "1.83"
55
license = "MIT OR Apache-2.0"
66
exclude = [".github/"]
77

@@ -221,8 +221,10 @@ clap = { version = "4", features = ["derive", "env"] }
221221
derive_more = { version = "2.0", default-features = false }
222222
eyre = "0.6"
223223
futures = { version = "0.3", default-features = false }
224+
lru = "0.13.0"
224225
metrics = "0.24.0"
225226
metrics-derive = "0.1"
227+
moka = "0.12.11"
226228
parking_lot = "0.12"
227229
rand = { version = "0.9" }
228230
rayon = "1.7"

crates/chain-orchestrator/src/consolidation.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ pub(crate) async fn reconcile_batch<L2P: Provider<Scroll>>(
3636
// Extract the block info with L1 messages.
3737
let block_info: L2BlockInfoWithL1Messages = (&current_block).into();
3838

39-
// The block matches the derived attributes and the block is below or equal to the
40-
// safe current safe head.
41-
if attributes.block_number <= fcs.finalized_block_info().number ||
42-
((attributes.block_number <= fcs.safe_block_info().number) &&
43-
batch.target_status.is_consolidated())
44-
{
39+
// The derived attributes match the L2 chain but are associated with a block
40+
// number less than or equal to the finalized block, so skip.
41+
if attributes.block_number <= fcs.finalized_block_info().number {
4542
Ok::<_, ChainOrchestratorError>(BlockConsolidationAction::Skip(block_info))
4643
} else {
47-
// The block matches the derived attributes, no action is needed.
44+
// The block matches the derived attributes but is above the finalized block,
45+
// so we need to update the fcs.
4846
Ok::<_, ChainOrchestratorError>(BlockConsolidationAction::UpdateFcs(block_info))
4947
}
5048
} else {

crates/chain-orchestrator/src/sync.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ impl SyncState {
2626
}
2727

2828
/// Returns a mutable reference to the sync mode of L1.
29-
pub fn l1_mut(&mut self) -> &mut SyncMode {
29+
pub const fn l1_mut(&mut self) -> &mut SyncMode {
3030
&mut self.l1
3131
}
3232

3333
/// Returns a mutable reference to the sync mode of L2.
34-
pub fn l2_mut(&mut self) -> &mut SyncMode {
34+
pub const fn l2_mut(&mut self) -> &mut SyncMode {
3535
&mut self.l2
3636
}
3737

@@ -64,12 +64,12 @@ impl SyncMode {
6464
}
6565

6666
/// Sets the sync mode to [`SyncMode::Synced`].
67-
pub fn set_synced(&mut self) {
67+
pub const fn set_synced(&mut self) {
6868
*self = Self::Synced;
6969
}
7070

7171
/// Sets the sync mode to [`SyncMode::Syncing`].
72-
pub fn set_syncing(&mut self) {
72+
pub const fn set_syncing(&mut self) {
7373
*self = Self::Syncing;
7474
}
7575
}

crates/database/db/src/db.rs

Lines changed: 14 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,14 @@ impl DatabaseReadOperations for Database {
643643
)
644644
}
645645

646+
async fn get_max_block_data_hint_block_number(&self) -> Result<u64, DatabaseError> {
647+
metered!(
648+
DatabaseOperation::GetMaxBlockDataHintBlockNumber,
649+
self,
650+
tx(|tx| async move { tx.get_max_block_data_hint_block_number().await })
651+
)
652+
}
653+
646654
async fn get_l2_block_and_batch_info_by_hash(
647655
&self,
648656
block_hash: B256,
@@ -862,7 +870,7 @@ mod test {
862870
BatchCommitData, BatchInfo, BlockInfo, L1MessageEnvelope, L2BlockInfoWithL1Messages,
863871
};
864872
use scroll_alloy_consensus::TxL1Message;
865-
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter};
873+
use sea_orm::EntityTrait;
866874

867875
#[tokio::test]
868876
async fn test_database_round_trip_batch_commit() {
@@ -1227,11 +1235,13 @@ mod test {
12271235

12281236
#[tokio::test]
12291237
async fn test_delete_l1_messages_gt() {
1238+
reth_tracing::init_test_tracing();
1239+
12301240
// Set up the test database.
12311241
let db = setup_test_db().await;
12321242

12331243
// Generate unstructured bytes.
1234-
let mut bytes = [0u8; 1024];
1244+
let mut bytes = [0u8; 10240];
12351245
rand::rng().fill(bytes.as_mut_slice());
12361246
let mut u = Unstructured::new(&bytes);
12371247

@@ -1276,6 +1286,8 @@ mod test {
12761286

12771287
#[tokio::test]
12781288
async fn test_get_l2_block_info_by_number() {
1289+
reth_tracing::init_test_tracing();
1290+
12791291
// Set up the test database.
12801292
let db = setup_test_db().await;
12811293

@@ -1475,67 +1487,6 @@ mod test {
14751487
}
14761488
}
14771489

1478-
#[tokio::test]
1479-
async fn test_insert_block_upsert_behavior() {
1480-
reth_tracing::init_test_tracing();
1481-
1482-
// Set up the test database.
1483-
let db = setup_test_db().await;
1484-
1485-
// Generate unstructured bytes.
1486-
let mut bytes = [0u8; 1024];
1487-
rand::rng().fill(bytes.as_mut_slice());
1488-
let mut u = Unstructured::new(&bytes);
1489-
1490-
// Generate batches
1491-
let batch_data_1 = BatchCommitData { index: 100, ..Arbitrary::arbitrary(&mut u).unwrap() };
1492-
let batch_info_1: BatchInfo = batch_data_1.clone().into();
1493-
let batch_data_2 = BatchCommitData { index: 200, ..Arbitrary::arbitrary(&mut u).unwrap() };
1494-
let batch_info_2: BatchInfo = batch_data_2.clone().into();
1495-
1496-
db.insert_batch(batch_data_1).await.unwrap();
1497-
db.insert_batch(batch_data_2).await.unwrap();
1498-
1499-
// Insert initial block
1500-
let block_info = BlockInfo { number: 600, hash: B256::arbitrary(&mut u).unwrap() };
1501-
db.insert_blocks(vec![block_info], batch_info_1).await.unwrap();
1502-
1503-
// Verify initial insertion
1504-
let retrieved_block = db.get_l2_block_info_by_number(600).await.unwrap();
1505-
assert_eq!(retrieved_block, Some(block_info));
1506-
1507-
// Verify initial batch association using model conversion
1508-
let initial_l2_block_model = models::l2_block::Entity::find()
1509-
.filter(models::l2_block::Column::BlockNumber.eq(600))
1510-
.one(db.inner().get_connection())
1511-
.await
1512-
.unwrap()
1513-
.unwrap();
1514-
let (initial_block_info, initial_batch_info): (BlockInfo, BatchInfo) =
1515-
initial_l2_block_model.into();
1516-
assert_eq!(initial_block_info, block_info);
1517-
assert_eq!(initial_batch_info, batch_info_1);
1518-
1519-
// Update the same block with different batch info (upsert)
1520-
db.insert_blocks(vec![block_info], batch_info_2).await.unwrap();
1521-
1522-
// Verify the block still exists and was updated
1523-
let retrieved_block = db.get_l2_block_info_by_number(600).await.unwrap().unwrap();
1524-
assert_eq!(retrieved_block, block_info);
1525-
1526-
// Verify batch association was updated using model conversion
1527-
let updated_l2_block_model = models::l2_block::Entity::find()
1528-
.filter(models::l2_block::Column::BlockNumber.eq(600))
1529-
.one(db.inner().get_connection())
1530-
.await
1531-
.unwrap()
1532-
.unwrap();
1533-
let (updated_block_info, updated_batch_info): (BlockInfo, BatchInfo) =
1534-
updated_l2_block_model.into();
1535-
assert_eq!(updated_block_info, block_info);
1536-
assert_eq!(updated_batch_info, batch_info_2);
1537-
}
1538-
15391490
#[tokio::test]
15401491
async fn test_prepare_on_startup() {
15411492
let db = setup_test_db().await;

crates/database/db/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub use db::Database;
99
mod error;
1010
pub use error::DatabaseError;
1111

12+
mod maintenance;
13+
pub use maintenance::DatabaseMaintenance;
14+
1215
mod metrics;
1316

1417
mod models;

0 commit comments

Comments
 (0)