fuel_core_relayer/
ports.rs

1//! Ports used by the relayer to access the outside world
2
3use async_trait::async_trait;
4use fuel_core_storage::Result as StorageResult;
5use fuel_core_types::{
6    blockchain::primitives::DaBlockHeight,
7    services::relayer::Event,
8};
9
10#[cfg(test)]
11mod tests;
12
13/// Manages state related to supported external chains.
14#[async_trait]
15pub trait RelayerDb: Send + Sync {
16    /// Add bridge events to database. Events are not revertible.
17    /// Must only set a new da height if it is greater than the current.
18    fn insert_events(
19        &mut self,
20        da_height: &DaBlockHeight,
21        events: &[Event],
22    ) -> StorageResult<()>;
23
24    /// Get finalized da height that represent last block from da layer that got finalized.
25    /// Panics if height is not set as of initialization of database.
26    fn get_finalized_da_height(&self) -> Option<DaBlockHeight>;
27}
28
29/// The trait that should be implemented by the database transaction returned by the database.
30#[cfg_attr(test, mockall::automock)]
31pub trait DatabaseTransaction {
32    /// Commits the changes to the underlying storage.
33    fn commit(self) -> StorageResult<()>;
34}
35
36/// The trait indicates that the type supports storage transactions.
37pub trait Transactional {
38    /// The type of the storage transaction;
39    type Transaction<'a>: DatabaseTransaction
40    where
41        Self: 'a;
42
43    /// Returns the storage transaction.
44    fn transaction(&mut self) -> Self::Transaction<'_>;
45
46    /// Returns the latest da block height.
47    fn latest_da_height(&self) -> Option<DaBlockHeight>;
48}