Skip to content

Commit e9cff2d

Browse files
authored
fix: L1 message L1MessageKey::BlockNumber lookup edge case (#402)
* fix: L1 message L1MessageKey::BlockNumber lookup edge case * update comment * update comment * address comment * address comment
1 parent 8d487db commit e9cff2d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

crates/database/db/src/operations.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -854,12 +854,15 @@ impl<T: ReadConnectionProvider + Sync + ?Sized> DatabaseReadOperations for T {
854854
.one(self.get_connection())
855855
.await?
856856
{
857-
// Yield n messages starting from the found queue index + 1.
857+
// Yield n messages starting from the found queue index + 1. Only return
858+
// messages that have not been skipped (skipped = false) to handle the edge
859+
// case where the last message in a batch is skipped.
860+
let condition = Condition::all()
861+
// We add 1 to the queue index to constrain across block boundaries
862+
.add(models::l1_message::Column::QueueIndex.gte(record.queue_index + 1))
863+
.add(models::l1_message::Column::Skipped.eq(false));
858864
Ok(models::l1_message::Entity::find()
859-
.filter(
860-
// We add 1 to the queue index to constrain across block boundaries
861-
models::l1_message::Column::QueueIndex.gte(record.queue_index + 1),
862-
)
865+
.filter(condition)
863866
.order_by_asc(models::l1_message::Column::QueueIndex)
864867
.limit(Some(n as u64))
865868
.all(self.get_connection())
@@ -871,6 +874,7 @@ impl<T: ReadConnectionProvider + Sync + ?Sized> DatabaseReadOperations for T {
871874
// index starting from the beginning.
872875
else {
873876
Ok(models::l1_message::Entity::find()
877+
.filter(models::l1_message::Column::Skipped.eq(false))
874878
.order_by_asc(models::l1_message::Column::QueueIndex)
875879
.limit(Some(n as u64))
876880
.all(self.get_connection())

0 commit comments

Comments
 (0)