mithril_aggregator/services/signer_registration/
api.rs

1use async_trait::async_trait;
2
3use mithril_common::{
4    StdResult,
5    entities::{Epoch, Signer, SignerWithStake, StakeDistribution},
6};
7
8use crate::entities::LeaderAggregatorEpochSettings;
9
10use super::SignerRegistrationError;
11
12/// Represents the information needed to handle a signer registration round
13#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct SignerRegistrationRound {
15    /// Registration round epoch
16    pub epoch: Epoch,
17
18    /// Stake distribution
19    pub(super) stake_distribution: StakeDistribution,
20}
21
22#[cfg(test)]
23impl SignerRegistrationRound {
24    pub(crate) fn dummy(epoch: Epoch, stake_distribution: StakeDistribution) -> Self {
25        Self {
26            epoch,
27            stake_distribution,
28        }
29    }
30}
31
32/// Trait to register a signer
33#[cfg_attr(test, mockall::automock)]
34#[async_trait]
35pub trait SignerRegisterer: Sync + Send {
36    /// Register a signer
37    async fn register_signer(
38        &self,
39        epoch: Epoch,
40        signer: &Signer,
41    ) -> Result<SignerWithStake, SignerRegistrationError>;
42
43    /// Get current open round if exists
44    async fn get_current_round(&self) -> Option<SignerRegistrationRound>;
45}
46
47/// Trait to synchronize signers
48#[cfg_attr(test, mockall::automock)]
49#[async_trait]
50pub trait SignerSynchronizer: Sync + Send {
51    /// Check if the signers can be synchronized
52    async fn can_synchronize_signers(&self, epoch: Epoch) -> Result<bool, SignerRegistrationError>;
53
54    /// Synchronize all signers
55    async fn synchronize_all_signers(&self) -> Result<(), SignerRegistrationError>;
56}
57
58/// Trait to open a signer registration round
59#[cfg_attr(test, mockall::automock)]
60#[async_trait]
61pub trait SignerRegistrationRoundOpener: Sync + Send {
62    /// Open a signer registration round
63    async fn open_registration_round(
64        &self,
65        registration_epoch: Epoch,
66        stake_distribution: StakeDistribution,
67    ) -> StdResult<()>;
68
69    /// Close a signer registration round
70    async fn close_registration_round(&self) -> StdResult<()>;
71}
72
73/// Signer recorder trait
74#[cfg_attr(test, mockall::automock)]
75#[async_trait]
76pub trait SignerRecorder: Sync + Send {
77    /// Record a signer registration
78    async fn record_signer_registration(&self, signer_id: String) -> StdResult<()>;
79}
80
81/// A trait for verifying a [Signer] registration.
82#[cfg_attr(test, mockall::automock)]
83#[async_trait]
84pub trait SignerRegistrationVerifier: Send + Sync {
85    /// Verifies a [Signer] registration.
86    async fn verify(
87        &self,
88        signer: &Signer,
89        stake_distribution: &StakeDistribution,
90    ) -> StdResult<SignerWithStake>;
91}
92
93/// Define how data are retrieved from a leader aggregator
94#[cfg_attr(test, mockall::automock)]
95#[async_trait]
96pub trait LeaderAggregatorClient: Sync + Send {
97    /// Retrieves epoch settings from the aggregator
98    async fn retrieve_epoch_settings(&self) -> StdResult<Option<LeaderAggregatorEpochSettings>>;
99}