Skip to content

Commit a028165

Browse files
authored
Merge pull request #3372 from input-output-hk/djo/3333/aggregator-state-machine-blocked-state
feat(aggregator): add state machine `blocked` state
2 parents 87f436d + 88dc4d0 commit a028165

27 files changed

Lines changed: 1220 additions & 508 deletions

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/website/root/mithril/advanced/mithril-network/aggregator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The Mithril aggregator's **REST API** documentation can be found here :
9898

9999
- A runtime powered by a state machine:
100100
- The runtime operates synchronously and is scheduled to execute at regular intervals
101-
- It encompasses three potential states: **IDLE**, **READY**, and **SIGNING**
101+
- It encompasses four potential states: **IDLE**, **BLOCKED**, **READY**, and **SIGNING**
102102
- The runtime effectively manages state transitions
103103
- The runtime structure is illustrated in the diagram below:
104104

606 KB
Loading

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.9.16"
3+
version = "0.9.17"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! Aggregator specific certificate chain validation errors
2+
3+
use thiserror::Error;
4+
5+
use mithril_common::entities::Epoch;
6+
7+
/// Error raised when the local certificate chain has an epoch gap.
8+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
9+
#[error(
10+
"There is an epoch gap between the last certificate epoch ({certificate_epoch:?}) and current epoch ({current_epoch:?}). A leader aggregator must be re-genesis by the owner of the genesis keys, a follower aggregator will automatically catchup with the leader's certificate chain."
11+
)]
12+
pub struct CertificateEpochGap {
13+
/// Epoch of the last issued certificate.
14+
pub certificate_epoch: Epoch,
15+
16+
/// Given current epoch.
17+
pub current_epoch: Epoch,
18+
}

mithril-aggregator/src/entities/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
//! This module provide domain entities for the services & state machine.
44
//!
55
mod aggregator_epoch_settings;
6+
mod certificate_chain_error;
67
mod leader_aggregator_epoch_settings;
78
mod open_message;
89
mod signer_registration_message;
910
mod signer_ticker_message;
1011

1112
pub use aggregator_epoch_settings::AggregatorEpochSettings;
13+
pub use certificate_chain_error::*;
1214
pub use leader_aggregator_epoch_settings::LeaderAggregatorEpochSettings;
1315
pub use open_message::OpenMessage;
1416
pub use signer_registration_message::{

mithril-aggregator/src/runtime/runner.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ pub trait AggregatorRunnerTrait: Sync + Send {
5151
current_time_point: &TimePoint,
5252
) -> StdResult<Option<OpenMessage>>;
5353

54+
/// Returns the epoch of the last genesis certificate, if any.
55+
async fn last_genesis_certificate_epoch(&self) -> StdResult<Option<Epoch>>;
56+
5457
/// Check if a certificate chain is valid.
5558
async fn is_certificate_chain_valid(&self, time_point: &TimePoint) -> StdResult<()>;
5659

@@ -75,6 +78,7 @@ pub trait AggregatorRunnerTrait: Sync + Send {
7578
/// Synchronize the follower aggregator certificate chain
7679
async fn synchronize_follower_aggregator_certificate_chain(
7780
&self,
81+
time_point: &TimePoint,
7882
force_sync: bool,
7983
) -> StdResult<()>;
8084

@@ -232,6 +236,17 @@ impl AggregatorRunnerTrait for AggregatorRunner {
232236
Ok(None)
233237
}
234238

239+
async fn last_genesis_certificate_epoch(&self) -> StdResult<Option<Epoch>> {
240+
debug!(self.logger, ">> last_genesis_certificate_epoch");
241+
let epoch = self
242+
.dependencies
243+
.certificate_repository
244+
.get_latest_genesis_certificate::<Certificate>()
245+
.await?
246+
.map(|c| c.epoch);
247+
Ok(epoch)
248+
}
249+
235250
async fn is_certificate_chain_valid(&self, time_point: &TimePoint) -> StdResult<()> {
236251
debug!(self.logger, ">> is_certificate_chain_valid");
237252
self.dependencies
@@ -502,6 +517,7 @@ impl AggregatorRunnerTrait for AggregatorRunner {
502517

503518
async fn synchronize_follower_aggregator_certificate_chain(
504519
&self,
520+
time_point: &TimePoint,
505521
force_sync: bool,
506522
) -> StdResult<()> {
507523
debug!(
@@ -510,7 +526,7 @@ impl AggregatorRunnerTrait for AggregatorRunner {
510526
);
511527
self.dependencies
512528
.certificate_chain_synchronizer
513-
.synchronize_certificate_chain(force_sync)
529+
.synchronize_certificate_chain(time_point.epoch, force_sync)
514530
.await
515531
}
516532
}

0 commit comments

Comments
 (0)