mithril_aggregator/services/certificate_chain_synchronizer/
interface.rs

1use async_trait::async_trait;
2
3use mithril_common::StdResult;
4use mithril_common::entities::Certificate;
5
6use crate::entities::OpenMessage;
7
8/// Define how to synchronize the certificate chain with a remote source
9#[cfg_attr(test, mockall::automock)]
10#[async_trait::async_trait]
11pub trait CertificateChainSynchronizer: Send + Sync {
12    /// Synchronize the certificate chain with a remote source
13    ///
14    /// If `force` is true, the chain will always be synchronized, else it will only synchronize
15    /// if the remote source has started a new chain with a new Genesis.
16    async fn synchronize_certificate_chain(&self, force: bool) -> StdResult<()>;
17}
18
19/// Define how to retrieve remote certificate details
20#[cfg_attr(test, mockall::automock)]
21#[async_trait]
22pub trait RemoteCertificateRetriever: Sync + Send {
23    /// Get latest certificate
24    async fn get_latest_certificate_details(&self) -> StdResult<Option<Certificate>>;
25
26    /// Get genesis certificate
27    async fn get_genesis_certificate_details(&self) -> StdResult<Option<Certificate>>;
28}
29
30/// Define how to store the synchronized certificate and retrieve details about the actual local chain
31#[cfg_attr(test, mockall::automock)]
32#[async_trait]
33pub trait SynchronizedCertificateStorer: Send + Sync {
34    /// Insert a list of Certificates in the database, if some already exists, they will be deleted before inserting
35    async fn insert_or_replace_many(&self, certificates: Vec<Certificate>) -> StdResult<()>;
36
37    /// Get the latest genesis Certificate
38    async fn get_latest_genesis(&self) -> StdResult<Option<Certificate>>;
39}
40
41/// Define how to store the open message created at the end of the synchronization process
42#[cfg_attr(test, mockall::automock)]
43#[async_trait]
44pub trait OpenMessageStorer: Send + Sync {
45    /// Store an open_message in the database
46    async fn insert_or_replace_open_message(&self, open_message: OpenMessage) -> StdResult<()>;
47}