Skip to content

Commit 1ae0110

Browse files
authored
Merge pull request #908 from input-output-hk/ensemble/907-handle-multiple-signed-entity-types-runtime-aggregator
Handle multiple Signed Entity Types in aggregator runtime
2 parents cbf035d + cf551ca commit 1ae0110

24 files changed

+887
-264
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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.3.15"
3+
version = "0.3.16"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/artifact_builder/artifact_builder_service.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use async_trait::async_trait;
22
use chrono::Utc;
3-
3+
use slog_scope::info;
44
use std::sync::Arc;
55

66
use mithril_common::{
@@ -84,6 +84,12 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService {
8484
signed_entity_type: SignedEntityType,
8585
certificate: &Certificate,
8686
) -> StdResult<()> {
87+
info!(
88+
"MithrilArtifactBuilderService::create_artifact";
89+
"signed_entity_type" => ?signed_entity_type,
90+
"certificate_hash" => &certificate.hash
91+
);
92+
8793
let artifact = self
8894
.compute_artifact(signed_entity_type.clone(), certificate)
8995
.await?;
@@ -117,7 +123,8 @@ mod tests {
117123
async fn build_mithril_stake_distribution_artifact_when_given_mithril_stake_distribution_entity_type(
118124
) {
119125
let signers_with_stake = fake_data::signers_with_stakes(5);
120-
let mithril_stake_distribution_expected = MithrilStakeDistribution::new(signers_with_stake);
126+
let mithril_stake_distribution_expected =
127+
MithrilStakeDistribution::new(Epoch(1), signers_with_stake);
121128
let mithril_stake_distribution_clone = mithril_stake_distribution_expected.clone();
122129

123130
let mock_signed_entity_storer = MockSignedEntityStorer::new();

mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ use mithril_common::{
1515
/// Mithril Stake Distribution
1616
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
1717
pub struct MithrilStakeDistribution {
18+
epoch: Epoch,
1819
signers_with_stake: Vec<SignerWithStake>,
1920
hash: String,
2021
}
2122

2223
impl MithrilStakeDistribution {
2324
/// MithrilStakeDistribution artifact factory
24-
pub fn new(signers_with_stake: Vec<SignerWithStake>) -> Self {
25+
pub fn new(epoch: Epoch, signers_with_stake: Vec<SignerWithStake>) -> Self {
2526
let mut signers_with_stake_sorted = signers_with_stake;
2627
signers_with_stake_sorted.sort();
2728
let mut mithril_stake_distribution = Self {
29+
epoch,
2830
signers_with_stake: signers_with_stake_sorted,
2931
hash: "".to_string(),
3032
};
@@ -34,6 +36,7 @@ impl MithrilStakeDistribution {
3436

3537
fn compute_hash(&self) -> String {
3638
let mut hasher = Sha256::new();
39+
hasher.update(self.epoch.0.to_be_bytes());
3740
for signer_with_stake in &self.signers_with_stake {
3841
hasher.update(signer_with_stake.compute_hash().as_bytes());
3942
}
@@ -64,11 +67,12 @@ impl MithrilStakeDistributionArtifactBuilder {
6467
impl ArtifactBuilder<Epoch, MithrilStakeDistribution> for MithrilStakeDistributionArtifactBuilder {
6568
async fn compute_artifact(
6669
&self,
67-
_beacon: Epoch,
70+
beacon: Epoch,
6871
_certificate: &Certificate,
6972
) -> StdResult<MithrilStakeDistribution> {
7073
let multi_signer = self.multi_signer.read().await;
7174
Ok(MithrilStakeDistribution::new(
75+
beacon,
7276
multi_signer.get_next_signers_with_stake().await?,
7377
))
7478
}
@@ -97,7 +101,7 @@ mod tests {
97101
.compute_artifact(Epoch(1), &certificate)
98102
.await
99103
.unwrap();
100-
let artifact_expected = MithrilStakeDistribution::new(signers_with_stake);
104+
let artifact_expected = MithrilStakeDistribution::new(Epoch(1), signers_with_stake);
101105
assert_eq!(artifact_expected, artifact);
102106
}
103107

@@ -106,17 +110,18 @@ mod tests {
106110
let signers_with_stake = fake_data::signers_with_stakes(5);
107111

108112
assert_eq!(
109-
MithrilStakeDistribution::new(signers_with_stake.clone()),
110-
MithrilStakeDistribution::new(signers_with_stake.into_iter().rev().collect())
113+
MithrilStakeDistribution::new(Epoch(1), signers_with_stake.clone()),
114+
MithrilStakeDistribution::new(Epoch(1), signers_with_stake.into_iter().rev().collect())
111115
);
112116
}
113117

114118
#[test]
115119
fn hash_value_doesnt_change_if_signers_order_change() {
116120
let signers_with_stake = fake_data::signers_with_stakes(5);
117121

118-
let sd = MithrilStakeDistribution::new(signers_with_stake.clone());
119-
let sd2 = MithrilStakeDistribution::new(signers_with_stake.into_iter().rev().collect());
122+
let sd = MithrilStakeDistribution::new(Epoch(1), signers_with_stake.clone());
123+
let sd2 =
124+
MithrilStakeDistribution::new(Epoch(1), signers_with_stake.into_iter().rev().collect());
120125

121126
assert_eq!(sd.hash, sd2.hash);
122127
}

mithril-aggregator/src/certifier_service.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,6 @@ impl CertifierService for MithrilCertifierService {
226226
) -> StdResult<OpenMessage> {
227227
debug!("CertifierService::create_open_message(signed_entity_type: {signed_entity_type:?}, protocol_message: {protocol_message:?})");
228228
let current_epoch = self.current_epoch.read().await;
229-
230229
let open_message = self
231230
.open_message_repository
232231
.create_open_message(*current_epoch, signed_entity_type, protocol_message)

mithril-aggregator/src/database/migration.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,35 @@ alter table open_message add column is_certified bool not null default false;
297297
SqlMigration::new(
298298
11,
299299
r#"
300-
alter table signed_entity add column artifact json not null;
301-
update signed_entity set artifact = entity;
302-
alter table signed_entity drop column entity;
300+
alter table signed_entity rename to signed_entity_old;
301+
create table signed_entity (
302+
signed_entity_id text not null,
303+
signed_entity_type_id integer not null,
304+
certificate_id text not null,
305+
beacon json not null,
306+
artifact json not null,
307+
created_at text not null default current_timestamp,
308+
primary key (signed_entity_id)
309+
foreign key (signed_entity_type_id) references signed_entity_type(signed_entity_type_id)
310+
foreign key (certificate_id) references certificate(certificate_id)
311+
);
312+
insert into signed_entity (signed_entity_id,
313+
signed_entity_type_id,
314+
certificate_id,
315+
beacon,
316+
artifact, created_at)
317+
select signed_entity_id, signed_entity_type_id, certificate_id, beacon, entity, created_at
318+
from signed_entity_old
319+
order by rowid asc;
320+
drop table signed_entity_old;
321+
"#,
322+
),
323+
// Migration 12
324+
// Alter `open_message` table
325+
SqlMigration::new(
326+
12,
327+
r#"
328+
create unique index open_message_unique_index on open_message(signed_entity_type_id, beacon);
303329
"#,
304330
),
305331
]

0 commit comments

Comments
 (0)