Skip to content

[Provider] Improve the L1MessageProvider interface and implementations #162

Open
@greged93

Description

@greged93

The L1MessageProvider uses a cursor pattern which is a impractical and can lead to misses in cases where we forgot to update the cursor. Instead of a cursor, we could just return an iterator over the messages, which we could easily get from the database by adding a method similar to get_l1_messages which would take an index or a queue hash.

/// Gets an iterator over all [`L1MessageEnvelope`]s in the database.
async fn get_l1_messages<'a>(
&'a self,
) -> Result<impl Stream<Item = Result<L1MessageEnvelope, DatabaseError>> + 'a, DatabaseError>
{
Ok(models::l1_message::Entity::find()
.stream(self.get_connection())
.await?
.map(|res| Ok(res.map(Into::into)?)))
}

This solution should fit for both the sequencer and the derivation pipeline, both consumers of the trait.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions