Skip to content

Commit 49d38e5

Browse files
committed
Revert "add possibility to filter by processed to get_batch_by_index"
This reverts commit f15ffb9.
1 parent 02fb909 commit 49d38e5

File tree

4 files changed

+20
-34
lines changed

4 files changed

+20
-34
lines changed

crates/chain-orchestrator/src/lib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -722,14 +722,12 @@ impl<
722722

723723
// Perform a consistency check to ensure the previous commit batch exists in the
724724
// database.
725-
if tx.get_batch_by_index(prev_batch_index, None).await?.is_none() {
725+
if tx.get_batch_by_index(prev_batch_index).await?.is_none() {
726726
return Err(ChainOrchestratorError::BatchCommitGap(batch_clone.index));
727727
}
728728

729729
// Check if batch already exists in DB.
730-
if let Some(existing_batch) =
731-
tx.get_batch_by_index(batch_clone.index, Some(true)).await?
732-
{
730+
if let Some(existing_batch) = tx.get_batch_by_index(batch_clone.index).await? {
733731
if existing_batch.hash == batch_clone.hash {
734732
// This means we have already processed this batch commit, we will skip
735733
// it.

crates/database/db/src/db.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,11 @@ impl DatabaseReadOperations for Database {
413413
async fn get_batch_by_index(
414414
&self,
415415
batch_index: u64,
416-
processed: Option<bool>,
417416
) -> Result<Option<BatchCommitData>, DatabaseError> {
418417
metered!(
419418
DatabaseOperation::GetBatchByIndex,
420419
self,
421-
tx(move |tx| async move { tx.get_batch_by_index(batch_index, processed).await })
420+
tx(move |tx| async move { tx.get_batch_by_index(batch_index).await })
422421
)
423422
}
424423

@@ -736,7 +735,7 @@ mod test {
736735
// Round trip the BatchCommitData through the database.
737736
db.insert_batch(batch_commit.clone()).await.unwrap();
738737
let batch_commit_from_db =
739-
db.get_batch_by_index(batch_commit.index, None).await.unwrap().unwrap();
738+
db.get_batch_by_index(batch_commit.index).await.unwrap().unwrap();
740739

741740
assert_eq!(batch_commit, batch_commit_from_db);
742741
}
@@ -1250,7 +1249,7 @@ mod test {
12501249

12511250
// Insert L2 blocks with different batch indices
12521251
for i in 100..110 {
1253-
let batch_data = db.get_batch_by_index(i, None).await.unwrap().unwrap();
1252+
let batch_data = db.get_batch_by_index(i).await.unwrap().unwrap();
12541253
let batch_info: BatchInfo = batch_data.into();
12551254
let block_info = BlockInfo { number: 500 + i, hash: B256::arbitrary(&mut u).unwrap() };
12561255

@@ -1419,9 +1418,9 @@ mod test {
14191418
db.set_finalized_l1_block_number(21).await.unwrap();
14201419

14211420
// Verify the batches and blocks were inserted correctly
1422-
let retrieved_batch_1 = db.get_batch_by_index(1, None).await.unwrap().unwrap();
1423-
let retrieved_batch_2 = db.get_batch_by_index(2, None).await.unwrap().unwrap();
1424-
let retrieved_batch_3 = db.get_batch_by_index(3, None).await.unwrap().unwrap();
1421+
let retrieved_batch_1 = db.get_batch_by_index(1).await.unwrap().unwrap();
1422+
let retrieved_batch_2 = db.get_batch_by_index(2).await.unwrap().unwrap();
1423+
let retrieved_batch_3 = db.get_batch_by_index(3).await.unwrap().unwrap();
14251424
let retried_block_1 = db.get_l2_block_info_by_number(1).await.unwrap().unwrap();
14261425
let retried_block_2 = db.get_l2_block_info_by_number(2).await.unwrap().unwrap();
14271426
let retried_block_3 = db.get_l2_block_info_by_number(3).await.unwrap().unwrap();
@@ -1442,9 +1441,9 @@ mod test {
14421441
assert_eq!(result, (Some(block_2), Some(11)));
14431442

14441443
// Verify that batches 2 and 3 are deleted
1445-
let batch_1 = db.get_batch_by_index(1, None).await.unwrap();
1446-
let batch_2 = db.get_batch_by_index(2, None).await.unwrap();
1447-
let batch_3 = db.get_batch_by_index(3, None).await.unwrap();
1444+
let batch_1 = db.get_batch_by_index(1).await.unwrap();
1445+
let batch_2 = db.get_batch_by_index(2).await.unwrap();
1446+
let batch_3 = db.get_batch_by_index(3).await.unwrap();
14481447
assert!(batch_1.is_some());
14491448
assert!(batch_2.is_none());
14501449
assert!(batch_3.is_none());

crates/database/db/src/operations.rs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,7 @@ impl<T: WriteConnectionProvider + ?Sized + Sync> DatabaseWriteOperations for T {
374374
.map(|(_, batch_info)| batch_info)
375375
.filter(|b| b.index > 1)
376376
{
377-
let batch =
378-
self.get_batch_by_index(batch_info.index, None).await?.expect("batch must exist");
377+
let batch = self.get_batch_by_index(batch_info.index).await?.expect("batch must exist");
379378
self.delete_batches_gt_block_number(batch.block_number.saturating_sub(1)).await?;
380379
};
381380

@@ -384,8 +383,7 @@ impl<T: WriteConnectionProvider + ?Sized + Sync> DatabaseWriteOperations for T {
384383
else {
385384
return Ok((None, None));
386385
};
387-
let batch =
388-
self.get_batch_by_index(batch_info.index, None).await?.expect("batch must exist");
386+
let batch = self.get_batch_by_index(batch_info.index).await?.expect("batch must exist");
389387
Ok((Some(block_info), Some(batch.block_number.saturating_add(1))))
390388
}
391389

@@ -651,7 +649,6 @@ pub trait DatabaseReadOperations {
651649
async fn get_batch_by_index(
652650
&self,
653651
batch_index: u64,
654-
processed: Option<bool>,
655652
) -> Result<Option<BatchCommitData>, DatabaseError>;
656653

657654
/// Get the latest L1 block number from the database.
@@ -730,21 +727,13 @@ impl<T: ReadConnectionProvider + Sync + ?Sized> DatabaseReadOperations for T {
730727
async fn get_batch_by_index(
731728
&self,
732729
batch_index: u64,
733-
processed: Option<bool>,
734730
) -> Result<Option<BatchCommitData>, DatabaseError> {
735-
let query = if let Some(p) = processed {
736-
models::batch_commit::Entity::find().filter(
737-
models::batch_commit::Column::Index
738-
.eq(TryInto::<i64>::try_into(batch_index).expect("index should fit in i64"))
739-
.and(models::batch_commit::Column::Processed.eq(p)),
740-
)
741-
} else {
742-
models::batch_commit::Entity::find_by_id(
743-
TryInto::<i64>::try_into(batch_index).expect("index should fit in i64"),
744-
)
745-
};
746-
747-
Ok(query.one(self.get_connection()).await.map(|x| x.map(Into::into))?)
731+
Ok(models::batch_commit::Entity::find_by_id(
732+
TryInto::<i64>::try_into(batch_index).expect("index should fit in i64"),
733+
)
734+
.one(self.get_connection())
735+
.await
736+
.map(|x| x.map(Into::into))?)
748737
}
749738

750739
async fn get_latest_l1_block_number(&self) -> Result<u64, DatabaseError> {

crates/derivation-pipeline/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ where
215215

216216
// get the batch commit data.
217217
let batch = db
218-
.get_batch_by_index(batch_info.index, None)
218+
.get_batch_by_index(batch_info.index)
219219
.await
220220
.map_err(|err| (batch_info.clone(), err.into()))?
221221
.ok_or((

0 commit comments

Comments
 (0)