Skip to content

Commit ed24b6f

Browse files
committed
Simplify new cycle log for state machines
1 parent c95d4c1 commit ed24b6f

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

mithril-aggregator/src/runtime/state_machine.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{AggregatorRunnerTrait, RuntimeError};
22

33
use mithril_common::entities::{Beacon, CertificatePending};
4-
use slog_scope::{debug, error, info, trace, warn};
4+
use slog_scope::{error, info, trace, warn};
55
use std::fmt::Display;
66
use std::sync::Arc;
77
use tokio::time::{sleep, Duration};
@@ -32,9 +32,16 @@ pub enum AggregatorState {
3232
impl Display for AggregatorState {
3333
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3434
match self {
35-
AggregatorState::Idle(state) => write!(f, "Idle - {:?}", state.current_beacon),
36-
AggregatorState::Ready(state) => write!(f, "Ready - {:?}", state.current_beacon),
37-
AggregatorState::Signing(state) => write!(f, "Signing - {:?}", state.current_beacon),
35+
AggregatorState::Idle(state) => write!(
36+
f,
37+
"Idle - {}",
38+
match &state.current_beacon {
39+
None => "No Beacon".to_string(),
40+
Some(b) => b.to_string(),
41+
}
42+
),
43+
AggregatorState::Ready(state) => write!(f, "Ready - {}", state.current_beacon),
44+
AggregatorState::Signing(state) => write!(f, "Signing - {}", state.current_beacon),
3845
}
3946
}
4047
}
@@ -90,11 +97,11 @@ impl AggregatorRuntime {
9097

9198
/// Launches an infinite loop ticking the state machine.
9299
pub async fn run(&mut self) {
93-
info!("state machine: launching");
100+
info!("STATE MACHINE: launching");
94101

95102
loop {
96103
if let Err(e) = self.cycle().await {
97-
error!("state machine: an error occurred: "; "error" => ?e);
104+
error!("STATE MACHINE: an error occurred: "; "error" => ?e);
98105
}
99106

100107
info!("Sleeping for {} ms", self.state_sleep.as_millis());
@@ -105,7 +112,7 @@ impl AggregatorRuntime {
105112
/// Perform one tick of the state machine.
106113
pub async fn cycle(&mut self) -> Result<(), RuntimeError> {
107114
info!("================================================================================");
108-
info!("STATE MACHINE: new cycle"; "current_state" => self.state.to_string());
115+
info!("STATE MACHINE: new cycle: {}", self.state);
109116

110117
match self.state.clone() {
111118
AggregatorState::Idle(state) => {

mithril-common/src/entities/beacon.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::entities::{Epoch, ImmutableFileNumber};
22
use serde::{Deserialize, Serialize};
33
use sha2::{Digest, Sha256};
44
use std::cmp::Ordering;
5+
use std::fmt::{Display, Formatter};
56
use thiserror::Error;
67

78
/// Beacon represents a point in the Cardano chain at which a Mithril certificate should be produced
@@ -83,6 +84,16 @@ impl PartialOrd for Beacon {
8384
}
8485
}
8586

87+
impl Display for Beacon {
88+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
89+
write!(
90+
f,
91+
"Beacon (network: {}, epoch: {}, immutable_file_number: {})",
92+
self.network, self.epoch, self.immutable_file_number
93+
)
94+
}
95+
}
96+
8697
impl Beacon {
8798
/// Beacon factory
8899
pub fn new(network: String, epoch: u64, immutable_file_number: ImmutableFileNumber) -> Beacon {

mithril-signer/src/runtime/state_machine.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,17 @@ impl SignerState {
5050

5151
impl Display for SignerState {
5252
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53-
match *self {
54-
Self::Unregistered(_) => write!(f, "unregistered"),
55-
Self::Registered(_) => write!(f, "registered"),
56-
Self::Signed(_) => write!(f, "signed"),
53+
match self {
54+
Self::Unregistered(state) => write!(
55+
f,
56+
"Unregistered - {}",
57+
match state {
58+
None => "No Epoch".to_string(),
59+
Some(e) => format!("Epoch({})", e),
60+
}
61+
),
62+
Self::Registered(state) => write!(f, "Registered - {}", state.beacon),
63+
Self::Signed(state) => write!(f, "Signed - {}", state.beacon),
5764
}
5865
}
5966
}
@@ -86,11 +93,11 @@ impl StateMachine {
8693

8794
/// Launch the state machine until an error occurs or it is interrupted.
8895
pub async fn run(&mut self) -> Result<(), Box<dyn Error>> {
89-
info!("state machine: launching");
96+
info!("STATE MACHINE: launching");
9097

9198
loop {
9299
if let Err(e) = self.cycle().await {
93-
error!("state machine: an error occured: "; "error" => ?e);
100+
error!("STATE MACHINE: an error occured: "; "error" => ?e);
94101
}
95102

96103
info!("Sleeping for {} ms", self.state_sleep.as_millis());
@@ -101,7 +108,7 @@ impl StateMachine {
101108
/// Perform a cycle of the state machine.
102109
pub async fn cycle(&mut self) -> Result<(), Box<dyn Error + Sync + Send>> {
103110
info!("================================================================================");
104-
info!("STATE MACHINE: new cycle"; "current_state" => ?self.state);
111+
info!("STATE MACHINE: new cycle: {}", self.state);
105112

106113
match &self.state {
107114
SignerState::Unregistered(maybe_epoch) => {

0 commit comments

Comments
 (0)