mithril_aggregator/services/signer_registration/
api.rs1use 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#[derive(Debug, Clone, PartialEq, Eq)]
14pub struct SignerRegistrationRound {
15 pub epoch: Epoch,
17
18 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#[cfg_attr(test, mockall::automock)]
34#[async_trait]
35pub trait SignerRegisterer: Sync + Send {
36 async fn register_signer(
38 &self,
39 epoch: Epoch,
40 signer: &Signer,
41 ) -> Result<SignerWithStake, SignerRegistrationError>;
42
43 async fn get_current_round(&self) -> Option<SignerRegistrationRound>;
45}
46
47#[cfg_attr(test, mockall::automock)]
49#[async_trait]
50pub trait SignerSynchronizer: Sync + Send {
51 async fn can_synchronize_signers(&self, epoch: Epoch) -> Result<bool, SignerRegistrationError>;
53
54 async fn synchronize_all_signers(&self) -> Result<(), SignerRegistrationError>;
56}
57
58#[cfg_attr(test, mockall::automock)]
60#[async_trait]
61pub trait SignerRegistrationRoundOpener: Sync + Send {
62 async fn open_registration_round(
64 &self,
65 registration_epoch: Epoch,
66 stake_distribution: StakeDistribution,
67 ) -> StdResult<()>;
68
69 async fn close_registration_round(&self) -> StdResult<()>;
71}
72
73#[cfg_attr(test, mockall::automock)]
75#[async_trait]
76pub trait SignerRecorder: Sync + Send {
77 async fn record_signer_registration(&self, signer_id: String) -> StdResult<()>;
79}
80
81#[cfg_attr(test, mockall::automock)]
83#[async_trait]
84pub trait SignerRegistrationVerifier: Send + Sync {
85 async fn verify(
87 &self,
88 signer: &Signer,
89 stake_distribution: &StakeDistribution,
90 ) -> StdResult<SignerWithStake>;
91}
92
93#[cfg_attr(test, mockall::automock)]
95#[async_trait]
96pub trait LeaderAggregatorClient: Sync + Send {
97 async fn retrieve_epoch_settings(&self) -> StdResult<Option<LeaderAggregatorEpochSettings>>;
99}