diff --git a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs index d1da44c783d..bdc50d4dc76 100644 --- a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs +++ b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs @@ -121,8 +121,11 @@ mod tests { async fn build_mithril_stake_distribution_artifact_when_given_mithril_stake_distribution_entity_type( ) { let signers_with_stake = fake_data::signers_with_stakes(5); - let mithril_stake_distribution_expected = - MithrilStakeDistribution::new(Epoch(1), signers_with_stake); + let mithril_stake_distribution_expected = MithrilStakeDistribution::new( + Epoch(1), + signers_with_stake, + "certificate-123".to_string(), + ); let mithril_stake_distribution_clone = mithril_stake_distribution_expected.clone(); let mock_signed_entity_storer = MockSignedEntityStorer::new(); diff --git a/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs b/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs index 598bc4f5564..eda275e0768 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_immutable_files_full.rs @@ -157,7 +157,7 @@ mod tests { #[tokio::test] async fn should_compute_valid_artifact() { let beacon = fake_data::beacon(); - let certificate = fake_data::certificate("cert-123".to_string()); + let certificate = fake_data::certificate("certificate-123".to_string()); let snapshot_digest = certificate .protocol_message .get_message_part(&ProtocolMessagePartKey::SnapshotDigest) diff --git a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs index 5ab546d6348..bcf3530d471 100644 --- a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs +++ b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs @@ -26,12 +26,13 @@ impl ArtifactBuilder for MithrilStakeDistributi async fn compute_artifact( &self, beacon: Epoch, - _certificate: &Certificate, + certificate: &Certificate, ) -> StdResult { let multi_signer = self.multi_signer.read().await; Ok(MithrilStakeDistribution::new( beacon, multi_signer.get_next_signers_with_stake().await?, + certificate.hash.to_owned(), )) } } @@ -48,7 +49,7 @@ mod tests { async fn should_compute_valid_artifact() { let signers_with_stake = fake_data::signers_with_stakes(5); let signers_with_stake_clone = signers_with_stake.clone(); - let certificate = fake_data::certificate("cert-123".to_string()); + let certificate = fake_data::certificate("certificate-123".to_string()); let mut mock_multi_signer = MockMultiSigner::new(); mock_multi_signer .expect_get_next_signers_with_stake() @@ -59,7 +60,11 @@ mod tests { .compute_artifact(Epoch(1), &certificate) .await .unwrap(); - let artifact_expected = MithrilStakeDistribution::new(Epoch(1), signers_with_stake); + let artifact_expected = MithrilStakeDistribution::new( + Epoch(1), + signers_with_stake, + "certificate-123".to_string(), + ); assert_eq!(artifact_expected, artifact); } @@ -68,8 +73,16 @@ mod tests { let signers_with_stake = fake_data::signers_with_stakes(5); assert_eq!( - MithrilStakeDistribution::new(Epoch(1), signers_with_stake.clone()), - MithrilStakeDistribution::new(Epoch(1), signers_with_stake.into_iter().rev().collect()) + MithrilStakeDistribution::new( + Epoch(1), + signers_with_stake.clone(), + "certificate-123".to_string() + ), + MithrilStakeDistribution::new( + Epoch(1), + signers_with_stake.into_iter().rev().collect(), + "certificate-123".to_string() + ) ); } @@ -77,9 +90,16 @@ mod tests { fn hash_value_doesnt_change_if_signers_order_change() { let signers_with_stake = fake_data::signers_with_stakes(5); - let sd = MithrilStakeDistribution::new(Epoch(1), signers_with_stake.clone()); - let sd2 = - MithrilStakeDistribution::new(Epoch(1), signers_with_stake.into_iter().rev().collect()); + let sd = MithrilStakeDistribution::new( + Epoch(1), + signers_with_stake.clone(), + "certificate-123".to_string(), + ); + let sd2 = MithrilStakeDistribution::new( + Epoch(1), + signers_with_stake.into_iter().rev().collect(), + "certificate-123".to_string(), + ); assert_eq!(sd.hash, sd2.hash); } diff --git a/mithril-aggregator/src/database/provider/certificate.rs b/mithril-aggregator/src/database/provider/certificate.rs index cc1efa15753..9245209f86c 100644 --- a/mithril-aggregator/src/database/provider/certificate.rs +++ b/mithril-aggregator/src/database/provider/certificate.rs @@ -743,11 +743,13 @@ mod tests { fn get_certificate_record_by_certificate_id() { let connection = Connection::open(":memory:").unwrap(); let provider = CertificateRecordProvider::new(&connection); - let condition = provider.condition_by_certificate_id("cert-123").unwrap(); + let condition = provider + .condition_by_certificate_id("certificate-123") + .unwrap(); let (filter, values) = condition.expand(); assert_eq!("certificate_id = ?1".to_string(), filter); - assert_eq!(vec![Value::String("cert-123".to_string())], values); + assert_eq!(vec![Value::String("certificate-123".to_string())], values); } #[test] diff --git a/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_list_message.rs b/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_list_message.rs index 7aba1641d79..78a28671603 100644 --- a/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_list_message.rs +++ b/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_list_message.rs @@ -35,6 +35,7 @@ mod tests { epoch: Epoch(1), signers_with_stake: signers_with_stakes(1), hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), }; let mithril_stake_distribution_list_message = ToMithrilStakeDistributionListMessageAdapter::adapt(vec![mithril_stake_distribution]); diff --git a/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_message.rs b/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_message.rs index 34770826fa4..f9616d08622 100644 --- a/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_message.rs +++ b/mithril-aggregator/src/message_adapters/to_mithril_stake_distribution_message.rs @@ -13,6 +13,7 @@ impl MessageAdapter epoch: from.epoch, signers_with_stake: from.signers_with_stake, hash: from.hash, + certificate_hash: from.certificate_hash, } } } @@ -29,11 +30,13 @@ mod tests { epoch: Epoch(1), signers_with_stake: fake_data::signers_with_stakes(2), hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), }; let mithril_stake_distribution_message_expected = MithrilStakeDistributionMessage { epoch: Epoch(1), signers_with_stake: fake_data::signers_with_stakes(2), hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), }; let mithril_stake_distribution_message = ToMithrilStakeDistributionMessageAdapter::adapt(mithril_stake_distribution); diff --git a/mithril-common/src/entities/mithril_stake_distribution.rs b/mithril-common/src/entities/mithril_stake_distribution.rs index 5fdd13a052c..3186112253a 100644 --- a/mithril-common/src/entities/mithril_stake_distribution.rs +++ b/mithril-common/src/entities/mithril_stake_distribution.rs @@ -17,17 +17,25 @@ pub struct MithrilStakeDistribution { /// Hash of the Mithril Stake Distribution (different from the AVK). pub hash: String, + + /// Hash of the associated certificate + pub certificate_hash: String, } impl MithrilStakeDistribution { /// MithrilStakeDistribution artifact factory - pub fn new(epoch: Epoch, signers_with_stake: Vec) -> Self { + pub fn new( + epoch: Epoch, + signers_with_stake: Vec, + certificate_hash: String, + ) -> Self { let mut signers_with_stake_sorted = signers_with_stake; signers_with_stake_sorted.sort(); let mut mithril_stake_distribution = Self { epoch, signers_with_stake: signers_with_stake_sorted, hash: "".to_string(), + certificate_hash, }; mithril_stake_distribution.hash = mithril_stake_distribution.compute_hash(); mithril_stake_distribution @@ -39,6 +47,7 @@ impl MithrilStakeDistribution { for signer_with_stake in &self.signers_with_stake { hasher.update(signer_with_stake.compute_hash().as_bytes()); } + hasher.update(self.certificate_hash.as_bytes()); hex::encode(hasher.finalize()) } } diff --git a/mithril-common/src/messages/mithril_stake_distribution.rs b/mithril-common/src/messages/mithril_stake_distribution.rs index dfd80d3990c..070b78ab03c 100644 --- a/mithril-common/src/messages/mithril_stake_distribution.rs +++ b/mithril-common/src/messages/mithril_stake_distribution.rs @@ -15,6 +15,9 @@ pub struct MithrilStakeDistributionMessage { /// Hash of the Mithril Stake Distribution (different from the AVK). pub hash: String, + + /// Hash of the associated certificate + pub certificate_hash: String, } impl MithrilStakeDistributionMessage { @@ -27,6 +30,7 @@ impl MithrilStakeDistributionMessage { .unwrap() .to_owned()], hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), } } } @@ -40,6 +44,7 @@ mod tests { epoch: Epoch(1), signers_with_stake: fake_data::signers_with_stakes(1), hash: "hash-123".to_string(), + certificate_hash: "cert-hash-123".to_string(), } } @@ -55,7 +60,8 @@ mod tests { "stake": 826 } ], - "hash": "hash-123" + "hash": "hash-123", + "certificate_hash": "cert-hash-123" }"#; let message: MithrilStakeDistributionMessage = serde_json::from_str(json).expect( "This JSON is expected to be succesfully parsed into a MithrilStakeDistributionMessage instance.", diff --git a/mithril-common/src/test_utils/fake_data.rs b/mithril-common/src/test_utils/fake_data.rs index e49dbeb1288..d9de3ef0a01 100644 --- a/mithril-common/src/test_utils/fake_data.rs +++ b/mithril-common/src/test_utils/fake_data.rs @@ -192,6 +192,7 @@ pub fn mithril_stake_distributions(total: u64) -> Vec>() } diff --git a/openapi.yaml b/openapi.yaml index b496d13d10a..e334b15f589 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -767,10 +767,15 @@ components: description: Hash of the Mithril stake distribution type: string format: bytes + certificate_hash: + description: Hash of the associated certificate + type: string + format: bytes example: { "epoch": 123, - "hash":"24qQwKgWw4mr5kRZLIUA9XAsB0vSvijo8FIfrGFwBtdCNQVhBc9PXu7RiCHSRem3MmHoKbo" + "hash":"24qQwKgWw4mr5kRZLIUA9XAsB0vSvijo8FIfrGFwBtdCNQVhBc9PXu7RiCHSRem3MmHoKbo", + "certificate_hash": "AsB0vSvijo8FIfrG/FwBtdCNQVhBc9P24qQwKgWw4mr5kRZL+IUA9XXu7RiCHSRem3MmHoKbo" } MithrilStakeDistributionMessage: @@ -790,6 +795,10 @@ components: description: Hash of the Mithril stake distribution type: string format: bytes + certificate_hash: + description: Hash of the associated certificate + type: string + format: bytes signers: description: The list of the signers with their stakes and verification keys type: array @@ -799,6 +808,7 @@ components: { "epoch": 123, "hash":"24qQwKgWw4mr5kRZLIUA9XAsB0vSvijo8FIfrGFwBtdCNQVhBc9PXu7RiCHSRem3MmHoKbo", + "certificate_hash": "AsB0vSvijo8FIfrG/FwBtdCNQVhBc9P24qQwKgWw4mr5kRZL+IUA9XXu7RiCHSRem3MmHoKbo", "signers": [ {