Skip to content

Commit

Permalink
Merge pull request #768 from input-output-hk/greg/add_signer_era_warning
Browse files Browse the repository at this point in the history
make signer warn when coming era is unsupported
  • Loading branch information
ghubertpalo authored Feb 23, 2023
2 parents 24ea177 + 943bf59 commit 0b425aa
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.2.22"
version = "0.2.23"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
20 changes: 15 additions & 5 deletions mithril-aggregator/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,23 @@ impl AggregatorRunnerTrait for AggregatorRunner {
.map_err(|e| {
RuntimeError::General(format!("Could not get Era information ('{e}')").into())
})?;
self.dependencies.era_checker.change_era(
token.get_current_supported_era().map_err(|e| {
RuntimeError::General(format!("Could not update EraChecker service ('{e}')").into())
})?,
token.get_current_epoch(),
let current_era = token.get_current_supported_era().map_err(|e| {
RuntimeError::General(format!("Could not update EraChecker service ('{e}')").into())
})?;
self.dependencies
.era_checker
.change_era(current_era, token.get_current_epoch());
debug!(
"Current Era is {} (Epoch {}).",
current_era,
token.get_current_epoch()
);

if token.get_next_supported_era().is_err() {
let era_name = &token.get_next_era_marker().unwrap().name;
warn!("Upcoming Era '{era_name}' is not supported by this version of the software. Please update!");
}

Ok(())
}
}
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/src/runtime/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl AggregatorRuntime {

loop {
if let Err(e) = self.cycle().await {
error!("STATE MACHINE: an error occurred: "; "error" => ?e);
error!("STATE MACHINE: an error occurred: {e}");
}

info!(
Expand Down
6 changes: 5 additions & 1 deletion mithril-common/src/era/era_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl EraEpochToken {
/// software.
pub fn get_current_supported_era(&self) -> Result<SupportedEra, UnsupportedEraError> {
SupportedEra::from_str(&self.current_era.name)
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))
}

/// Return the [EraMarker] of the current Era.
Expand All @@ -75,7 +76,10 @@ impl EraEpochToken {
/// for upgrade.
pub fn get_next_supported_era(&self) -> Result<Option<SupportedEra>, UnsupportedEraError> {
match self.next_era.as_ref() {
Some(marker) => Ok(Some(SupportedEra::from_str(&marker.name)?)),
Some(marker) => Ok(Some(
SupportedEra::from_str(&marker.name)
.map_err(|_| UnsupportedEraError::new(&self.current_era.name))?,
)),
None => Ok(None),
}
}
Expand Down
15 changes: 14 additions & 1 deletion mithril-common/src/era/supported_era.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
use serde::{Deserialize, Serialize};
use strum::IntoEnumIterator;
use strum_macros::{Display, EnumIter, EnumString};
use thiserror::Error;

/// Error related to [SupportedEra] String parsing implementation.
pub type UnsupportedEraError = strum::ParseError;
#[derive(Debug, Error)]
#[error("Unsupported Era '{era}'.")]
pub struct UnsupportedEraError {
era: String,
}

impl UnsupportedEraError {
pub fn new(era: &str) -> Self {
Self {
era: era.to_owned(),
}
}
}

/// The era that the software is running or will run
#[derive(
Expand Down
2 changes: 1 addition & 1 deletion mithril-signer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-signer"
version = "0.2.14"
version = "0.2.15"
description = "A Mithril Signer"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
17 changes: 13 additions & 4 deletions mithril-signer/src/runtime/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,21 @@ impl Runner for SignerRunner {
.read_era_epoch_token(epoch)
.await
.map_err(Box::new)?;

self.services.era_checker.change_era(
era_token.get_current_supported_era()?,
era_token.get_current_epoch(),
let current_era = era_token.get_current_supported_era()?;
self.services
.era_checker
.change_era(current_era, era_token.get_current_epoch());
debug!(
"Current Era is {} (Epoch {}).",
current_era,
era_token.get_current_epoch()
);

if era_token.get_next_supported_era().is_err() {
let era_name = &era_token.get_next_era_marker().unwrap().name;
warn!("Upcoming Era '{era_name}' is not supported by this version of the software. Please update!");
}

Ok(())
}
}
Expand Down
3 changes: 2 additions & 1 deletion mithril-signer/src/runtime/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl StateMachine {

loop {
if let Err(e) = self.cycle().await {
error!("STATE MACHINE: an error occured: "; "error" => ?e);
error!("STATE MACHINE: an error occured: {e}");
}

info!(
Expand Down Expand Up @@ -126,6 +126,7 @@ impl StateMachine {
} else if let Some(epoch_settings) = self.runner.get_epoch_settings().await? {
info!("→ Epoch settings found");
if epoch_settings.epoch >= *epoch {
info!("new Epoch found");
info!(" ⋅ transiting to REGISTERED");
self.state = self
.transition_from_unregistered_to_registered(&epoch_settings)
Expand Down

0 comments on commit 0b425aa

Please sign in to comment.