Skip to content

Commit

Permalink
Move functions from Runner trait to the implementation and fix PR r…
Browse files Browse the repository at this point in the history
…emarks
  • Loading branch information
sfauvel committed Sep 6, 2024
1 parent 9380dc4 commit d60e407
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
1 change: 1 addition & 0 deletions mithril-common/src/messages/epoch_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct EpochSettingsMessage {
/// Next Protocol parameters
#[serde(rename = "next_protocol")]
pub next_protocol_parameters: ProtocolParameters,

/// Current Signers
pub current_signers: Vec<SignerMessagePart>,

Expand Down
81 changes: 34 additions & 47 deletions mithril-signer/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ pub trait Runner: Send + Sync {
/// Fetch the current time point from the Cardano node.
async fn get_current_time_point(&self) -> StdResult<TimePoint>;

/// Get the current signers.
/// // TODO return a &Vec
async fn get_current_signers(&self) -> StdResult<Vec<Signer>>;

/// Get the next signers.
async fn get_next_signers(&self) -> StdResult<Vec<Signer>>;

/// Get the next signers with their stake.
async fn get_current_signers_with_stake(&self) -> StdResult<Vec<SignerWithStake>>;

/// Get the next signers with their stake.
async fn get_next_signers_with_stake(&self) -> StdResult<Vec<SignerWithStake>>;

/// Register the signer verification key to the aggregator.
async fn register_signer_to_aggregator(&self) -> StdResult<()>;

Expand Down Expand Up @@ -110,40 +97,6 @@ impl SignerRunner {
pub fn new(config: Configuration, services: SignerDependencyContainer) -> Self {
Self { services, config }
}
}

#[cfg_attr(test, automock)]
#[async_trait]
impl Runner for SignerRunner {
async fn get_epoch_settings(&self) -> StdResult<Option<EpochSettings>> {
debug!("RUNNER: get_epoch_settings");

self.services
.certificate_handler
.retrieve_epoch_settings()
.await
.map_err(|e| e.into())
}

async fn get_pending_certificate(&self) -> StdResult<Option<CertificatePending>> {
debug!("RUNNER: get_pending_certificate");

self.services
.certificate_handler
.retrieve_pending_certificate()
.await
.map_err(|e| e.into())
}

async fn get_current_time_point(&self) -> StdResult<TimePoint> {
debug!("RUNNER: get_current_time_point");

self.services
.ticker_service
.get_current_time_point()
.await
.with_context(|| "Runner can not get current time point")
}

async fn get_current_signers(&self) -> StdResult<Vec<Signer>> {

Check warning

Code scanning / clippy

methods get_current_signers and get_next_signers are never used Warning

methods get\_current\_signers and get\_next\_signers are never used

Check warning

Code scanning / clippy

methods get_current_signers and get_next_signers are never used Warning

methods get\_current\_signers and get\_next\_signers are never used
debug!("RUNNER: get_current_signers");
Expand Down Expand Up @@ -186,6 +139,40 @@ impl Runner for SignerRunner {
.next_signers_with_stake()
.await
}
}

#[cfg_attr(test, automock)]
#[async_trait]
impl Runner for SignerRunner {
async fn get_epoch_settings(&self) -> StdResult<Option<EpochSettings>> {
debug!("RUNNER: get_epoch_settings");

self.services
.certificate_handler
.retrieve_epoch_settings()
.await
.map_err(|e| e.into())
}

async fn get_pending_certificate(&self) -> StdResult<Option<CertificatePending>> {
debug!("RUNNER: get_pending_certificate");

self.services
.certificate_handler
.retrieve_pending_certificate()
.await
.map_err(|e| e.into())
}

async fn get_current_time_point(&self) -> StdResult<TimePoint> {
debug!("RUNNER: get_current_time_point");

self.services
.ticker_service
.get_current_time_point()
.await
.with_context(|| "Runner can not get current time point")
}

async fn register_signer_to_aggregator(&self) -> StdResult<()> {
debug!("RUNNER: register_signer_to_aggregator");
Expand Down
3 changes: 2 additions & 1 deletion mithril-signer/src/services/epoch_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::RunnerError;
#[derive(Debug, Error)]
pub enum EpochServiceError {
/// Raised when service has not collected data at least once.
#[error("Epoch service was not initialized, the function `inform_epoch` must be called first")]
#[error("Epoch service was not initialized, the function `inform_epoch_settings` must be called first")]
NotYetInitialized,
}

Expand Down Expand Up @@ -108,6 +108,7 @@ impl MithrilEpochService {

Ok(signers_with_stake)
}

fn unwrap_data(&self) -> Result<&EpochData, EpochServiceError> {
self.epoch_data
.as_ref()
Expand Down

0 comments on commit d60e407

Please sign in to comment.