From de4ce27a2c5adcd35dfcb971238c91e28accb05b Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:39:20 +0200 Subject: [PATCH 01/11] Cleanup allow dead code macro --- mithril-aggregator/src/database/provider/open_message.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/mithril-aggregator/src/database/provider/open_message.rs b/mithril-aggregator/src/database/provider/open_message.rs index ea85ae8eb67..0f8aaa36567 100644 --- a/mithril-aggregator/src/database/provider/open_message.rs +++ b/mithril-aggregator/src/database/provider/open_message.rs @@ -23,7 +23,6 @@ type StdResult = Result; /// An open message is a message open for signatures. Every signer may send a /// single signature for this message from which a multi signature will be /// generated if possible. -#[allow(dead_code)] #[derive(Debug, Clone, PartialEq, Eq)] pub struct OpenMessageRecord { /// OpenMessage unique identifier From 6bcbeadab779cf767b7e07788a1a3e96fcc14d45 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:43:47 +0200 Subject: [PATCH 02/11] Cleanup DummyArtifact --- .../src/artifact_builder/dummy_artifact.rs | 58 ------------------- .../src/artifact_builder/mod.rs | 2 - 2 files changed, 60 deletions(-) delete mode 100644 mithril-aggregator/src/artifact_builder/dummy_artifact.rs diff --git a/mithril-aggregator/src/artifact_builder/dummy_artifact.rs b/mithril-aggregator/src/artifact_builder/dummy_artifact.rs deleted file mode 100644 index 41462c503b0..00000000000 --- a/mithril-aggregator/src/artifact_builder/dummy_artifact.rs +++ /dev/null @@ -1,58 +0,0 @@ -use async_trait::async_trait; -use mithril_common::{ - entities::{Beacon, Certificate}, - signable_builder::Artifact, - StdResult, -}; -use serde::{Deserialize, Serialize}; - -use crate::artifact_builder::ArtifactBuilder; - -type DummyBeacon = Beacon; - -/// Dummy artifact -#[derive(Serialize, Deserialize, PartialEq, Debug)] -pub struct DummyArtifact { - message: String, - beacon: DummyBeacon, -} - -impl DummyArtifact { - /// Dummy artifact factory - pub fn new(message: String, beacon: DummyBeacon) -> Self { - Self { message, beacon } - } -} - -#[typetag::serde] -impl Artifact for DummyArtifact {} - -/// A [DummyArtifact] builder -pub struct DummyArtifactBuilder {} - -impl DummyArtifactBuilder { - /// Dummy artifact builder factory - pub fn new() -> Self { - Self {} - } -} - -impl Default for DummyArtifactBuilder { - fn default() -> Self { - Self::new() - } -} - -#[async_trait] -impl ArtifactBuilder for DummyArtifactBuilder { - async fn compute_artifact( - &self, - beacon: DummyBeacon, - certificate: &Certificate, - ) -> StdResult { - Ok(DummyArtifact::new( - format!("certificate id is {}", certificate.hash), - beacon, - )) - } -} diff --git a/mithril-aggregator/src/artifact_builder/mod.rs b/mithril-aggregator/src/artifact_builder/mod.rs index 54c3d07e6c5..6ddf8ca98cf 100644 --- a/mithril-aggregator/src/artifact_builder/mod.rs +++ b/mithril-aggregator/src/artifact_builder/mod.rs @@ -2,12 +2,10 @@ mod artifact_builder_service; mod cardano_immutable_files_full; -mod dummy_artifact; mod interface; mod mithril_stake_distribution; pub use artifact_builder_service::*; pub use cardano_immutable_files_full::*; -pub use dummy_artifact::*; pub use interface::*; pub use mithril_stake_distribution::*; From b563520febc68986ff51450de5130509ad9b5949 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:39:57 +0200 Subject: [PATCH 03/11] Add SignedEntityStorer trait --- .../src/database/provider/signed_entity.rs | 51 +++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/mithril-aggregator/src/database/provider/signed_entity.rs b/mithril-aggregator/src/database/provider/signed_entity.rs index 8cc84d7c474..646d9ad99f5 100644 --- a/mithril-aggregator/src/database/provider/signed_entity.rs +++ b/mithril-aggregator/src/database/provider/signed_entity.rs @@ -11,28 +11,32 @@ use mithril_common::{ WhereCondition, }, store::adapter::{AdapterError, StoreAdapter}, + StdResult, }; use mithril_common::StdError; use tokio::sync::Mutex; +#[cfg(test)] +use mockall::automock; + /// SignedEntity record is the representation of a stored signed_entity. #[derive(Debug, PartialEq, Clone)] pub struct SignedEntityRecord { /// Signed entity id. - signed_entity_id: String, + pub signed_entity_id: String, /// Signed entity type. - signed_entity_type: SignedEntityType, + pub signed_entity_type: SignedEntityType, /// Certificate id for this signed entity. - certificate_id: String, + pub certificate_id: String, /// Raw signed entity (in JSON format). pub entity: String, /// Date and time when the signed_entity was created - created_at: String, + pub created_at: String, } impl From for SignedEntityRecord { @@ -242,6 +246,20 @@ impl<'conn> Provider<'conn> for InsertSignedEntityRecordProvider<'conn> { } } +/// Signed entity storer trait +#[cfg_attr(test, automock)] +#[async_trait] +pub trait SignedEntityStorer: Sync + Send { + /// Store a signed entity + async fn store_signed_entity(&self, signed_entity: &SignedEntityRecord) -> StdResult<()>; + + /// Get signed entity type + async fn get_signed_entity( + &self, + signed_entity_id: String, + ) -> StdResult>; +} + /// Service to deal with signed_entity (read & write). pub struct SignedEntityStoreAdapter { connection: Arc>, @@ -254,6 +272,31 @@ impl SignedEntityStoreAdapter { } } +#[async_trait] +impl SignedEntityStorer for SignedEntityStoreAdapter { + async fn store_signed_entity(&self, signed_entity: &SignedEntityRecord) -> StdResult<()> { + let connection = &*self.connection.lock().await; + let provider = InsertSignedEntityRecordProvider::new(connection); + let _signed_entity_record = provider.persist(signed_entity.to_owned())?; + + Ok(()) + } + + async fn get_signed_entity( + &self, + signed_entity_id: String, + ) -> StdResult> { + let connection = &*self.connection.lock().await; + let provider = SignedEntityRecordProvider::new(connection); + let mut cursor = provider + .get_by_signed_entity_id(signed_entity_id) + .map_err(|e| AdapterError::GeneralError(format!("{e}")))?; + let signed_entity = cursor.next(); + + Ok(signed_entity) + } +} + #[async_trait] impl StoreAdapter for SignedEntityStoreAdapter { type Key = String; From 6f3b65a5ea215d5943ea619fd593c3db97cd7c65 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:40:45 +0200 Subject: [PATCH 04/11] Update ArtifactBuilderService to persist signed entities --- .../artifact_builder_service.rs | 53 +++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs index d5512e0ed23..f455985d062 100644 --- a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs +++ b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs @@ -1,4 +1,6 @@ use async_trait::async_trait; +use chrono::Utc; +use uuid::Uuid; use std::sync::Arc; @@ -8,7 +10,10 @@ use mithril_common::{ StdResult, }; -use crate::artifact_builder::ArtifactBuilder; +use crate::{ + artifact_builder::ArtifactBuilder, + database::provider::{SignedEntityRecord, SignedEntityStorer}, +}; use super::MithrilStakeDistribution; @@ -25,10 +30,19 @@ pub trait ArtifactBuilderService: Send + Sync { signed_entity_type: SignedEntityType, certificate: &Certificate, ) -> StdResult>; + + /// Create an save signed entity + async fn create_and_save_signed_entity( + &self, + signed_entity_type: SignedEntityType, + certificate: &Certificate, + artifact: Arc, + ) -> StdResult<()>; } /// Mithril ArtifactBuilder Service pub struct MithrilArtifactBuilderService { + signed_entity_storer: Arc, mithril_stake_distribution_artifact_builder: Arc>, cardano_immutable_files_full_artifact_builder: Arc>, @@ -36,14 +50,15 @@ pub struct MithrilArtifactBuilderService { impl MithrilArtifactBuilderService { /// MithrilArtifactBuilderService factory - #[allow(dead_code)] pub fn new( + signed_entity_storer: Arc, mithril_stake_distribution_artifact_builder: Arc< dyn ArtifactBuilder, >, cardano_immutable_files_full_artifact_builder: Arc>, ) -> Self { Self { + signed_entity_storer, mithril_stake_distribution_artifact_builder, cardano_immutable_files_full_artifact_builder, } @@ -52,7 +67,6 @@ impl MithrilArtifactBuilderService { #[async_trait] impl ArtifactBuilderService for MithrilArtifactBuilderService { - #[allow(dead_code)] async fn compute_artifact( &self, signed_entity_type: SignedEntityType, @@ -72,6 +86,27 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService { SignedEntityType::CardanoStakeDistribution(_) => todo!(), } } + + async fn create_and_save_signed_entity( + &self, + signed_entity_type: SignedEntityType, + certificate: &Certificate, + artifact: Arc, + ) -> StdResult<()> { + let signed_entity = SignedEntityRecord { + signed_entity_id: Uuid::new_v4().to_string(), + signed_entity_type, + certificate_id: certificate.hash.clone(), + entity: serde_json::to_string(&artifact)?, + created_at: format!("{:?}", Utc::now()), + }; + + self.signed_entity_storer + .store_signed_entity(&signed_entity) + .await?; + + Ok(()) + } } #[cfg(test)] @@ -80,7 +115,9 @@ mod tests { use super::*; - use crate::artifact_builder::MockArtifactBuilder; + use crate::{ + artifact_builder::MockArtifactBuilder, database::provider::MockSignedEntityStorer, + }; #[tokio::test] async fn build_mithril_stake_distribution_artifact_when_given_mithril_stake_distribution_entity_type( @@ -88,6 +125,9 @@ mod tests { let signers_with_stake = fake_data::signers_with_stakes(5); let mithril_stake_distribution_expected = MithrilStakeDistribution::new(signers_with_stake); let mithril_stake_distribution_clone = mithril_stake_distribution_expected.clone(); + + let mock_signed_entity_storer = MockSignedEntityStorer::new(); + let mut mock_mithril_stake_distribution_artifact_builder = MockArtifactBuilder::::new(); mock_mithril_stake_distribution_artifact_builder @@ -99,6 +139,7 @@ mod tests { MockArtifactBuilder::::new(); let artifact_builder_service = MithrilArtifactBuilderService::new( + Arc::new(mock_signed_entity_storer), Arc::new(mock_mithril_stake_distribution_artifact_builder), Arc::new(mock_cardano_immutable_files_full_artifact_builder), ); @@ -121,6 +162,9 @@ mod tests { async fn build_snapshot_artifact_when_given_cardano_immutable_files_full_entity_type() { let snapshot_expected = fake_data::snapshots(1).first().unwrap().to_owned(); let snapshot_expected_clone = snapshot_expected.clone(); + + let mock_signed_entity_storer = MockSignedEntityStorer::new(); + let mock_mithril_stake_distribution_artifact_builder = MockArtifactBuilder::::new(); @@ -132,6 +176,7 @@ mod tests { .return_once(move |_, _| Ok(snapshot_expected_clone)); let artifact_builder_service = MithrilArtifactBuilderService::new( + Arc::new(mock_signed_entity_storer), Arc::new(mock_mithril_stake_distribution_artifact_builder), Arc::new(mock_cardano_immutable_files_full_artifact_builder), ); From f68e0e8ddb893a49ec420142e7504548e96d9f3c Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:41:41 +0200 Subject: [PATCH 05/11] Wire SignedEntityStorer in dependencies --- mithril-aggregator/src/dependency.rs | 17 ++++++++---- .../src/dependency_injection/builder.rs | 26 ++++++++++++++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/mithril-aggregator/src/dependency.rs b/mithril-aggregator/src/dependency.rs index a06be4111d1..4b0d98c1bd1 100644 --- a/mithril-aggregator/src/dependency.rs +++ b/mithril-aggregator/src/dependency.rs @@ -17,11 +17,15 @@ use std::{collections::HashMap, sync::Arc}; use tokio::sync::{Mutex, RwLock}; use crate::{ - artifact_builder::ArtifactBuilderService, certifier_service::CertifierService, - configuration::*, database::provider::StakePoolStore, signer_registerer::SignerRecorder, - ticker_service::TickerService, CertificatePendingStore, CertificateStore, - ProtocolParametersStore, ProtocolParametersStorer, SignerRegisterer, - SignerRegistrationRoundOpener, Snapshotter, VerificationKeyStore, VerificationKeyStorer, + artifact_builder::ArtifactBuilderService, + certifier_service::CertifierService, + configuration::*, + database::provider::{SignedEntityStorer, StakePoolStore}, + signer_registerer::SignerRecorder, + ticker_service::TickerService, + CertificatePendingStore, CertificateStore, ProtocolParametersStore, ProtocolParametersStorer, + SignerRegisterer, SignerRegistrationRoundOpener, Snapshotter, VerificationKeyStore, + VerificationKeyStorer, }; use crate::{event_store::EventMessage, snapshot_stores::SnapshotStore}; use crate::{event_store::TransmitterService, multi_signer::MultiSigner}; @@ -123,6 +127,9 @@ pub struct DependencyManager { /// Ticker Service pub ticker_service: Arc, + + /// Signed Entity storer + pub signed_entity_storer: Arc, } #[doc(hidden)] diff --git a/mithril-aggregator/src/dependency_injection/builder.rs b/mithril-aggregator/src/dependency_injection/builder.rs index afc25538355..d79b4002129 100644 --- a/mithril-aggregator/src/dependency_injection/builder.rs +++ b/mithril-aggregator/src/dependency_injection/builder.rs @@ -44,7 +44,7 @@ use crate::{ configuration::{ExecutionEnvironment, LIST_SNAPSHOTS_MAX_ITEMS}, database::provider::{ CertificateRepository, CertificateStoreAdapter, EpochSettingStore, OpenMessageRepository, - SignedEntityStoreAdapter, SignerRegistrationStoreAdapter, SignerStore, + SignedEntityStoreAdapter, SignedEntityStorer, SignerRegistrationStoreAdapter, SignerStore, SingleSignatureRepository, StakePoolStore, }, event_store::{EventMessage, EventStore, TransmitterService}, @@ -179,6 +179,9 @@ pub struct DependenciesBuilder { /// Certifier service pub certifier_service: Option>, + + /// Signed Entity storer + pub signed_entity_storer: Option>, } impl DependenciesBuilder { @@ -218,6 +221,7 @@ impl DependenciesBuilder { signable_builder_service: None, artifact_builder_service: None, certifier_service: None, + signed_entity_storer: None, } } @@ -904,6 +908,7 @@ impl DependenciesBuilder { } async fn build_artifact_builder_service(&mut self) -> Result> { + let signed_entity_storer = self.build_signed_entity_storer().await?; let multi_signer = self.get_multi_signer().await?; let mithril_stake_distribution_artifact_builder = Arc::new(MithrilStakeDistributionArtifactBuilder::new(multi_signer)); @@ -913,6 +918,7 @@ impl DependenciesBuilder { CardanoImmutableFilesFullArtifactBuilder::new(snapshotter, snapshot_uploader), ); let artifact_builder_service = Arc::new(MithrilArtifactBuilderService::new( + signed_entity_storer, mithril_stake_distribution_artifact_builder, cardano_immutable_files_full_artifact_builder, )); @@ -931,6 +937,23 @@ impl DependenciesBuilder { Ok(self.artifact_builder_service.as_ref().cloned().unwrap()) } + async fn build_signed_entity_storer(&mut self) -> Result> { + let signed_entity_storer = Arc::new(SignedEntityStoreAdapter::new( + self.get_sqlite_connection().await?, + )); + + Ok(signed_entity_storer) + } + + /// [SignedEntityStorer] service + pub async fn get_signed_entity_storer(&mut self) -> Result> { + if self.signed_entity_storer.is_none() { + self.signed_entity_storer = Some(self.build_signed_entity_storer().await?); + } + + Ok(self.signed_entity_storer.as_ref().cloned().unwrap()) + } + /// Return an unconfigured [DependencyManager] pub async fn build_dependency_container(&mut self) -> Result { let dependency_manager = DependencyManager { @@ -963,6 +986,7 @@ impl DependenciesBuilder { artifact_builder_service: self.get_artifact_builder_service().await?, certifier_service: self.get_certifier_service().await?, ticker_service: self.get_ticker_service().await?, + signed_entity_storer: self.get_signed_entity_storer().await?, }; Ok(dependency_manager) From 179bc2301353e263577c36a2a942ebe5d57c51d2 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:42:37 +0200 Subject: [PATCH 06/11] Use ArtifactBuilderService in aggregator runtime --- mithril-aggregator/src/runtime/runner.rs | 26 ++++++++++++++ .../src/runtime/state_machine.rs | 34 +++---------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index 71b43a850dc..436e49e9a33 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -149,6 +149,13 @@ pub trait AggregatorRunnerTrait: Sync + Send { remote_locations: Vec, ) -> Result>; + /// Create an artifact and persist it. + async fn create_and_save_artifact( + &self, + signed_entity_type: &SignedEntityType, + certificate: &Certificate, + ) -> Result<(), Box>; + /// Update the EraChecker with EraReader information. async fn update_era_checker( &self, @@ -548,6 +555,25 @@ impl AggregatorRunnerTrait for AggregatorRunner { Ok(snapshot) } + async fn create_and_save_artifact( + &self, + signed_entity_type: &SignedEntityType, + certificate: &Certificate, + ) -> Result<(), Box> { + debug!("RUNNER: create and save artifact"); + let artifact = self + .dependencies + .artifact_builder_service + .compute_artifact(signed_entity_type.to_owned(), certificate) + .await?; + self.dependencies + .artifact_builder_service + .create_and_save_signed_entity(signed_entity_type.to_owned(), certificate, artifact) + .await?; + + Ok(()) + } + async fn update_era_checker( &self, beacon: &Beacon, diff --git a/mithril-aggregator/src/runtime/state_machine.rs b/mithril-aggregator/src/runtime/state_machine.rs index 916e011de25..e988b702a22 100644 --- a/mithril-aggregator/src/runtime/state_machine.rs +++ b/mithril-aggregator/src/runtime/state_machine.rs @@ -282,18 +282,8 @@ impl AggregatorRuntime { })?; self.runner.drop_pending_certificate().await?; - let ongoing_snapshot = self - .runner - .create_snapshot_archive(&state.current_beacon, &state.protocol_message) - .await?; - let locations = self - .runner - .upload_snapshot_archive(&ongoing_snapshot) - .await?; - - let _ = self - .runner - .create_and_save_snapshot(certificate, &ongoing_snapshot, locations) + self.runner + .create_and_save_artifact(&state.signed_entity_type, &certificate) .await?; Ok(IdleState { @@ -356,10 +346,7 @@ impl AggregatorRuntime { #[cfg(test)] mod tests { - use std::path::Path; - use crate::entities::OpenMessage; - use crate::snapshotter::OngoingSnapshot; use super::super::runner::MockAggregatorRunner; use super::*; @@ -684,22 +671,9 @@ mod tests { .once() .returning(|| Ok(Some(fake_data::certificate_pending()))); runner - .expect_create_snapshot_archive() - .once() - .returning(|_, _| { - Ok(OngoingSnapshot::new( - Path::new("/tmp/archive.zip").to_path_buf(), - 1234, - )) - }); - runner - .expect_upload_snapshot_archive() - .once() - .returning(|_path| Ok(vec!["locA".to_string(), "locB".to_string()])); - runner - .expect_create_and_save_snapshot() + .expect_create_and_save_artifact() .once() - .returning(|_, _, _| Ok(fake_data::snapshots(1)[0].clone())); + .returning(|_, _| Ok(())); let state = SigningState { current_beacon: fake_data::beacon(), From 2c495f77e72ddc852bee6db7003d0d3286bd47dd Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 16:57:35 +0200 Subject: [PATCH 07/11] Fix backward compatibility for Snapshot as Signed Entity --- Cargo.lock | 1 + .../src/artifact_builder/artifact_builder_service.rs | 3 +-- mithril-common/Cargo.toml | 1 + mithril-common/src/entities/snapshot.rs | 6 +++++- mithril-common/src/signable_builder/interface.rs | 8 +++++++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18a3203b46b..215ed2d3d62 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2207,6 +2207,7 @@ dependencies = [ "thiserror", "tokio", "typetag", + "uuid", "walkdir", "warp", ] diff --git a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs index f455985d062..45c34729f5a 100644 --- a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs +++ b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use chrono::Utc; -use uuid::Uuid; use std::sync::Arc; @@ -94,7 +93,7 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService { artifact: Arc, ) -> StdResult<()> { let signed_entity = SignedEntityRecord { - signed_entity_id: Uuid::new_v4().to_string(), + signed_entity_id: artifact.get_id(), signed_entity_type, certificate_id: certificate.hash.clone(), entity: serde_json::to_string(&artifact)?, diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 83c3fcad52f..96744855acb 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -50,6 +50,7 @@ strum_macros = "0.24.1" thiserror = "1.0.31" tokio = { version = "1.17.0", features = ["full"] } typetag = "0.2.8" +uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics"] } walkdir = "2" warp = "0.3" diff --git a/mithril-common/src/entities/snapshot.rs b/mithril-common/src/entities/snapshot.rs index 2216617c864..e927fe13585 100644 --- a/mithril-common/src/entities/snapshot.rs +++ b/mithril-common/src/entities/snapshot.rs @@ -45,4 +45,8 @@ impl Snapshot { } #[typetag::serde] -impl Artifact for Snapshot {} +impl Artifact for Snapshot { + fn get_id(&self) -> String { + self.digest.clone() + } +} diff --git a/mithril-common/src/signable_builder/interface.rs b/mithril-common/src/signable_builder/interface.rs index 2f2282ad6a3..e6a23e7eff7 100644 --- a/mithril-common/src/signable_builder/interface.rs +++ b/mithril-common/src/signable_builder/interface.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; use std::fmt::Debug; +use uuid::Uuid; use crate::{entities::ProtocolMessage, StdResult}; @@ -11,7 +12,12 @@ pub trait Beacon: Send + Sync {} /// Artifact is a trait for types that represent signed artifacts #[typetag::serde(tag = "type")] -pub trait Artifact: Debug + Send + Sync {} +pub trait Artifact: Debug + Send + Sync { + /// Get artifact identifier + fn get_id(&self) -> String { + Uuid::new_v4().to_string() + } +} /// SignableBuilder is trait for building a protocol message for a beacon #[cfg_attr(test, automock)] From 4cc1342eef0c425fdc75fbb6f0c1d8b5f0b6fd8d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Fri, 5 May 2023 17:02:37 +0200 Subject: [PATCH 08/11] Cleanup runtime runner in aggregator And remove create & upload snapshot archive and create snapshot functions. --- mithril-aggregator/src/runtime/error.rs | 4 - mithril-aggregator/src/runtime/runner.rs | 176 +---------------------- 2 files changed, 4 insertions(+), 176 deletions(-) diff --git a/mithril-aggregator/src/runtime/error.rs b/mithril-aggregator/src/runtime/error.rs index 75cff727a58..edf6e306429 100644 --- a/mithril-aggregator/src/runtime/error.rs +++ b/mithril-aggregator/src/runtime/error.rs @@ -60,10 +60,6 @@ impl From> for RuntimeError { // TODO: Are these errors still relevant, do we need to remove them? #[allow(clippy::enum_variant_names)] pub enum RunnerError { - /// Protocol message part is missing - #[error("Missing protocol message: '{0}'.")] - MissingProtocolMessage(String), - /// No stack distribution found #[error("Missing stack distribution: '{0}'.")] MissingStakeDistribution(String), diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index 436e49e9a33..ac3f9e6c91d 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -1,5 +1,4 @@ use async_trait::async_trait; -use chrono::Utc; use mithril_common::entities::Epoch; use mithril_common::entities::SignedEntityType; use mithril_common::store::StakeStorer; @@ -7,7 +6,7 @@ use slog_scope::{debug, warn}; use mithril_common::crypto_helper::ProtocolStakeDistribution; use mithril_common::entities::{ - Beacon, Certificate, CertificatePending, ProtocolMessage, ProtocolMessagePartKey, Snapshot, + Beacon, Certificate, CertificatePending, ProtocolMessage, ProtocolMessagePartKey, }; use mithril_common::CardanoNetwork; @@ -17,10 +16,8 @@ use std::path::PathBuf; use std::sync::Arc; use crate::entities::OpenMessage; -use crate::snapshot_uploaders::SnapshotLocation; -use crate::snapshotter::OngoingSnapshot; use crate::RuntimeError; -use crate::{DependencyManager, ProtocolError, SnapshotError}; +use crate::{DependencyManager, ProtocolError}; #[cfg(test)] use mockall::automock; @@ -124,31 +121,6 @@ pub trait AggregatorRunnerTrait: Sync + Send { signed_entity_type: &SignedEntityType, ) -> Result, Box>; - /// Create an archive of the cardano node db directory naming it after the given beacon. - /// - /// Returns the path of the created archive and the archive size as byte. - async fn create_snapshot_archive( - &self, - beacon: &Beacon, - protocol_message: &ProtocolMessage, - ) -> Result>; - - /// Upload the snapshot at the given location using the configured uploader(s). - /// - /// **Important**: the snapshot is removed after the upload succeeded. - async fn upload_snapshot_archive( - &self, - ongoing_snapshot: &OngoingSnapshot, - ) -> Result, Box>; - - /// Create a snapshot and save it to the given locations. - async fn create_and_save_snapshot( - &self, - certificate: Certificate, - ongoing_snapshot: &OngoingSnapshot, - remote_locations: Vec, - ) -> Result>; - /// Create an artifact and persist it. async fn create_and_save_artifact( &self, @@ -469,92 +441,6 @@ impl AggregatorRunnerTrait for AggregatorRunner { .await } - async fn create_snapshot_archive( - &self, - beacon: &Beacon, - protocol_message: &ProtocolMessage, - ) -> Result> { - debug!("RUNNER: create snapshot archive"); - - let snapshotter = self.dependencies.snapshotter.clone(); - let snapshot_digest = protocol_message - .get_message_part(&ProtocolMessagePartKey::SnapshotDigest) - .ok_or_else(|| { - RunnerError::MissingProtocolMessage(format!( - "no digest message part found for beacon '{beacon:?}'." - )) - })?; - let snapshot_name = format!( - "{}-e{}-i{}.{}.tar.gz", - beacon.network, beacon.epoch.0, beacon.immutable_file_number, snapshot_digest - ); - // spawn a separate thread to prevent blocking - let ongoing_snapshot = - tokio::task::spawn_blocking(move || -> Result { - snapshotter.snapshot(&snapshot_name) - }) - .await??; - - debug!(" > snapshot created: '{:?}'", ongoing_snapshot); - - Ok(ongoing_snapshot) - } - - async fn upload_snapshot_archive( - &self, - ongoing_snapshot: &OngoingSnapshot, - ) -> Result, Box> { - debug!("RUNNER: upload snapshot archive"); - let location = self - .dependencies - .snapshot_uploader - .upload_snapshot(ongoing_snapshot.get_file_path()) - .await?; - - if let Err(error) = tokio::fs::remove_file(ongoing_snapshot.get_file_path()).await { - warn!( - " > Post upload ongoing snapshot file removal failure: {}", - error - ); - } - - Ok(vec![location]) - } - - async fn create_and_save_snapshot( - &self, - certificate: Certificate, - ongoing_snapshot: &OngoingSnapshot, - remote_locations: Vec, - ) -> Result> { - debug!("RUNNER: create and save snapshot"); - let snapshot_digest = certificate - .protocol_message - .get_message_part(&ProtocolMessagePartKey::SnapshotDigest) - .ok_or_else(|| { - RunnerError::MissingProtocolMessage(format!( - "message part 'digest' not found for snapshot '{}'.", - ongoing_snapshot.get_file_path().display() - )) - })? - .to_owned(); - let snapshot = Snapshot::new( - snapshot_digest, - certificate.beacon, - certificate.hash, - *ongoing_snapshot.get_file_size(), - format!("{:?}", Utc::now()), - remote_locations, - ); - - self.dependencies - .snapshot_store - .add_snapshot(snapshot.clone()) - .await?; - - Ok(snapshot) - } - async fn create_and_save_artifact( &self, signed_entity_type: &SignedEntityType, @@ -629,8 +515,6 @@ impl AggregatorRunnerTrait for AggregatorRunner { #[cfg(test)] pub mod tests { use crate::certifier_service::MockCertifierService; - use crate::multi_signer::MockMultiSigner; - use crate::snapshotter::OngoingSnapshot; use crate::{ initialize_dependencies, runtime::{AggregatorRunner, AggregatorRunnerTrait}, @@ -639,16 +523,13 @@ pub mod tests { use mithril_common::chain_observer::FakeObserver; use mithril_common::digesters::DumbImmutableFileObserver; use mithril_common::entities::{ - Beacon, CertificatePending, Epoch, ProtocolMessage, SignedEntityType, StakeDistribution, + Beacon, CertificatePending, Epoch, SignedEntityType, StakeDistribution, }; use mithril_common::store::StakeStorer; + use mithril_common::test_utils::fake_data; use mithril_common::test_utils::MithrilFixtureBuilder; - use mithril_common::{entities::ProtocolMessagePartKey, test_utils::fake_data}; use mithril_common::{BeaconProviderImpl, CardanoNetwork}; - use std::path::Path; use std::sync::Arc; - use tempfile::NamedTempFile; - use tokio::sync::RwLock; #[tokio::test] async fn test_get_beacon_from_chain() { @@ -939,55 +820,6 @@ pub mod tests { assert_eq!(None, maybe_saved_cert); } - #[tokio::test] - async fn test_remove_snapshot_archive_after_upload() { - let deps = initialize_dependencies().await; - let runner = AggregatorRunner::new(Arc::new(deps)); - let file = NamedTempFile::new().unwrap(); - let file_path = file.path(); - let snapshot = OngoingSnapshot::new(file_path.to_path_buf(), 7331); - - runner - .upload_snapshot_archive(&snapshot) - .await - .expect("Snapshot upload should not fail"); - - assert!( - !file_path.exists(), - "Ongoing snapshot file should have been removed after upload" - ); - } - - #[tokio::test] - async fn test_create_snapshot_archive_name_archive_after_beacon() { - let beacon = Beacon::new("network".to_string(), 20, 145); - let mut message = ProtocolMessage::new(); - message.set_message_part( - ProtocolMessagePartKey::SnapshotDigest, - "test+digest".to_string(), - ); - let mock_multi_signer = MockMultiSigner::new(); - let mut deps = initialize_dependencies().await; - deps.multi_signer = Arc::new(RwLock::new(mock_multi_signer)); - let runner = AggregatorRunner::new(Arc::new(deps)); - - let ongoing_snapshot = runner - .create_snapshot_archive(&beacon, &message) - .await - .expect("create_snapshot_archive should not fail"); - - assert_eq!( - Path::new( - format!( - "{}-e{}-i{}.{}.tar.gz", - beacon.network, beacon.epoch.0, beacon.immutable_file_number, "test+digest" - ) - .as_str() - ), - ongoing_snapshot.get_file_path() - ); - } - #[tokio::test] async fn test_update_era_checker() { let deps = initialize_dependencies().await; From 8b5944a83603801bc62b7eb04f73313358937049 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 9 May 2023 11:30:43 +0200 Subject: [PATCH 09/11] Apply review comments --- Cargo.lock | 2 +- mithril-aggregator/Cargo.toml | 1 + .../artifact_builder_service.rs | 25 +++++------ .../mithril_stake_distribution.rs | 45 ++++++++++++++++++- mithril-aggregator/src/runtime/runner.rs | 13 ++---- .../src/runtime/state_machine.rs | 4 +- mithril-common/Cargo.toml | 1 - mithril-common/src/entities/signer.rs | 2 +- .../src/signable_builder/interface.rs | 5 +-- 9 files changed, 63 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 215ed2d3d62..8564d18a5b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2120,6 +2120,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", + "sha2 0.10.6", "slog", "slog-async", "slog-bunyan", @@ -2207,7 +2208,6 @@ dependencies = [ "thiserror", "tokio", "typetag", - "uuid", "walkdir", "warp", ] diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index 06a63f72d00..bc2098e38c9 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -23,6 +23,7 @@ semver = "1.0.16" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" serde_yaml = "0.9.10" +sha2 = "0.10.2" slog = { version = "2.7.0", features = ["max_level_trace", "release_max_level_debug"] } slog-async = "2.7.0" slog-bunyan = "2.4.0" diff --git a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs index 45c34729f5a..4d4bf8fd172 100644 --- a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs +++ b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs @@ -23,19 +23,11 @@ use mockall::automock; #[cfg_attr(test, automock)] #[async_trait] pub trait ArtifactBuilderService: Send + Sync { - /// Compute artifact from signed entity type - async fn compute_artifact( + /// Create artifact for a signed entity type and a certificate + async fn create_artifact( &self, signed_entity_type: SignedEntityType, certificate: &Certificate, - ) -> StdResult>; - - /// Create an save signed entity - async fn create_and_save_signed_entity( - &self, - signed_entity_type: SignedEntityType, - certificate: &Certificate, - artifact: Arc, ) -> StdResult<()>; } @@ -62,10 +54,8 @@ impl MithrilArtifactBuilderService { cardano_immutable_files_full_artifact_builder, } } -} -#[async_trait] -impl ArtifactBuilderService for MithrilArtifactBuilderService { + /// Compute artifact from signed entity type async fn compute_artifact( &self, signed_entity_type: SignedEntityType, @@ -85,13 +75,18 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService { SignedEntityType::CardanoStakeDistribution(_) => todo!(), } } +} - async fn create_and_save_signed_entity( +#[async_trait] +impl ArtifactBuilderService for MithrilArtifactBuilderService { + async fn create_artifact( &self, signed_entity_type: SignedEntityType, certificate: &Certificate, - artifact: Arc, ) -> StdResult<()> { + let artifact = self + .compute_artifact(signed_entity_type.clone(), certificate) + .await?; let signed_entity = SignedEntityRecord { signed_entity_id: artifact.get_id(), signed_entity_type, diff --git a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs index 68647d4155e..d516d6946ac 100644 --- a/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs +++ b/mithril-aggregator/src/artifact_builder/mithril_stake_distribution.rs @@ -1,5 +1,6 @@ use async_trait::async_trait; use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; use std::sync::Arc; use tokio::sync::RwLock; @@ -15,17 +16,37 @@ use mithril_common::{ #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] pub struct MithrilStakeDistribution { signers_with_stake: Vec, + hash: String, } impl MithrilStakeDistribution { /// MithrilStakeDistribution artifact factory pub fn new(signers_with_stake: Vec) -> Self { - Self { signers_with_stake } + let mut signers_with_stake_sorted = signers_with_stake; + signers_with_stake_sorted.sort(); + let mut mithril_stake_distribution = Self { + signers_with_stake: signers_with_stake_sorted, + hash: "".to_string(), + }; + mithril_stake_distribution.hash = mithril_stake_distribution.compute_hash(); + mithril_stake_distribution + } + + fn compute_hash(&self) -> String { + let mut hasher = Sha256::new(); + for signer_with_stake in &self.signers_with_stake { + hasher.update(signer_with_stake.compute_hash().as_bytes()); + } + hex::encode(hasher.finalize()) } } #[typetag::serde] -impl Artifact for MithrilStakeDistribution {} +impl Artifact for MithrilStakeDistribution { + fn get_id(&self) -> String { + self.hash.clone() + } +} /// A [MithrilStakeDistributionArtifact] builder pub struct MithrilStakeDistributionArtifactBuilder { @@ -79,4 +100,24 @@ mod tests { let artifact_expected = MithrilStakeDistribution::new(signers_with_stake); assert_eq!(artifact_expected, artifact); } + + #[test] + fn sort_given_signers_when_created() { + let signers_with_stake = fake_data::signers_with_stakes(5); + + assert_eq!( + MithrilStakeDistribution::new(signers_with_stake.clone()), + MithrilStakeDistribution::new(signers_with_stake.into_iter().rev().collect()) + ); + } + + #[test] + fn hash_value_doesnt_change_if_signers_order_change() { + let signers_with_stake = fake_data::signers_with_stakes(5); + + let sd = MithrilStakeDistribution::new(signers_with_stake.clone()); + let sd2 = MithrilStakeDistribution::new(signers_with_stake.into_iter().rev().collect()); + + assert_eq!(sd.hash, sd2.hash); + } } diff --git a/mithril-aggregator/src/runtime/runner.rs b/mithril-aggregator/src/runtime/runner.rs index ac3f9e6c91d..eb58fc029cf 100644 --- a/mithril-aggregator/src/runtime/runner.rs +++ b/mithril-aggregator/src/runtime/runner.rs @@ -122,7 +122,7 @@ pub trait AggregatorRunnerTrait: Sync + Send { ) -> Result, Box>; /// Create an artifact and persist it. - async fn create_and_save_artifact( + async fn create_artifact( &self, signed_entity_type: &SignedEntityType, certificate: &Certificate, @@ -441,20 +441,15 @@ impl AggregatorRunnerTrait for AggregatorRunner { .await } - async fn create_and_save_artifact( + async fn create_artifact( &self, signed_entity_type: &SignedEntityType, certificate: &Certificate, ) -> Result<(), Box> { - debug!("RUNNER: create and save artifact"); - let artifact = self - .dependencies - .artifact_builder_service - .compute_artifact(signed_entity_type.to_owned(), certificate) - .await?; + debug!("RUNNER: create artifact"); self.dependencies .artifact_builder_service - .create_and_save_signed_entity(signed_entity_type.to_owned(), certificate, artifact) + .create_artifact(signed_entity_type.to_owned(), certificate) .await?; Ok(()) diff --git a/mithril-aggregator/src/runtime/state_machine.rs b/mithril-aggregator/src/runtime/state_machine.rs index e988b702a22..646a459203a 100644 --- a/mithril-aggregator/src/runtime/state_machine.rs +++ b/mithril-aggregator/src/runtime/state_machine.rs @@ -283,7 +283,7 @@ impl AggregatorRuntime { self.runner.drop_pending_certificate().await?; self.runner - .create_and_save_artifact(&state.signed_entity_type, &certificate) + .create_artifact(&state.signed_entity_type, &certificate) .await?; Ok(IdleState { @@ -671,7 +671,7 @@ mod tests { .once() .returning(|| Ok(Some(fake_data::certificate_pending()))); runner - .expect_create_and_save_artifact() + .expect_create_artifact() .once() .returning(|_, _| Ok(())); diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 96744855acb..83c3fcad52f 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -50,7 +50,6 @@ strum_macros = "0.24.1" thiserror = "1.0.31" tokio = { version = "1.17.0", features = ["full"] } typetag = "0.2.8" -uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics"] } walkdir = "2" warp = "0.3" diff --git a/mithril-common/src/entities/signer.rs b/mithril-common/src/entities/signer.rs index 5d8beb5f3be..1c4a792841e 100644 --- a/mithril-common/src/entities/signer.rs +++ b/mithril-common/src/entities/signer.rs @@ -81,7 +81,7 @@ impl From for Signer { } /// Signer represents a signing party in the network (including its stakes) -#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Serialize, Deserialize)] pub struct SignerWithStake { /// The unique identifier of the signer // TODO: Should be removed once the signer certification is fully deployed diff --git a/mithril-common/src/signable_builder/interface.rs b/mithril-common/src/signable_builder/interface.rs index e6a23e7eff7..95f2d522571 100644 --- a/mithril-common/src/signable_builder/interface.rs +++ b/mithril-common/src/signable_builder/interface.rs @@ -1,6 +1,5 @@ use async_trait::async_trait; use std::fmt::Debug; -use uuid::Uuid; use crate::{entities::ProtocolMessage, StdResult}; @@ -14,9 +13,7 @@ pub trait Beacon: Send + Sync {} #[typetag::serde(tag = "type")] pub trait Artifact: Debug + Send + Sync { /// Get artifact identifier - fn get_id(&self) -> String { - Uuid::new_v4().to_string() - } + fn get_id(&self) -> String; } /// SignableBuilder is trait for building a protocol message for a beacon From 80158cb58548013a62c5f7a38014b2b21c9f8696 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 9 May 2023 11:38:11 +0200 Subject: [PATCH 10/11] Rename 'entity' field to 'artifact' in SignedEntityRecord --- .../artifact_builder_service.rs | 2 +- mithril-aggregator/src/database/migration.rs | 10 +++++++ .../src/database/provider/signed_entity.rs | 28 +++++++++---------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs index 4d4bf8fd172..5faceef520c 100644 --- a/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs +++ b/mithril-aggregator/src/artifact_builder/artifact_builder_service.rs @@ -91,7 +91,7 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService { signed_entity_id: artifact.get_id(), signed_entity_type, certificate_id: certificate.hash.clone(), - entity: serde_json::to_string(&artifact)?, + artifact: serde_json::to_string(&artifact)?, created_at: format!("{:?}", Utc::now()), }; diff --git a/mithril-aggregator/src/database/migration.rs b/mithril-aggregator/src/database/migration.rs index f35b18b4b95..a654e2c06f5 100644 --- a/mithril-aggregator/src/database/migration.rs +++ b/mithril-aggregator/src/database/migration.rs @@ -290,6 +290,16 @@ drop table single_signature_legacy; alter table open_message drop column message; alter table open_message add column protocol_message json not null; alter table open_message add column is_certified bool not null default false; +"#, + ), + // Migration 11 + // Alter `signed_entity` table + SqlMigration::new( + 11, + r#" +alter table signed_entity add column artifact json not null; +update signed_entity set artifact = entity; +alter table signed_entity drop column entity; "#, ), ] diff --git a/mithril-aggregator/src/database/provider/signed_entity.rs b/mithril-aggregator/src/database/provider/signed_entity.rs index 646d9ad99f5..73df3311729 100644 --- a/mithril-aggregator/src/database/provider/signed_entity.rs +++ b/mithril-aggregator/src/database/provider/signed_entity.rs @@ -32,8 +32,8 @@ pub struct SignedEntityRecord { /// Certificate id for this signed entity. pub certificate_id: String, - /// Raw signed entity (in JSON format). - pub entity: String, + /// Raw artifact (in JSON format). + pub artifact: String, /// Date and time when the signed_entity was created pub created_at: String, @@ -46,7 +46,7 @@ impl From for SignedEntityRecord { signed_entity_id: other.digest, signed_entity_type: SignedEntityType::CardanoImmutableFilesFull(other.beacon), certificate_id: other.certificate_hash, - entity, + artifact: entity, created_at: other.created_at, } } @@ -54,7 +54,7 @@ impl From for SignedEntityRecord { impl From for Snapshot { fn from(other: SignedEntityRecord) -> Snapshot { - serde_json::from_str(&other.entity).unwrap() + serde_json::from_str(&other.artifact).unwrap() } } @@ -67,7 +67,7 @@ impl SqLiteEntity for SignedEntityRecord { let signed_entity_type_id_int = row.get::(1); let certificate_id = row.get::(2); let beacon_str = row.get::(3); - let entity_str = row.get::(4); + let artifact_str = row.get::(4); let created_at = row.get::(5); let signed_entity_record = Self { @@ -81,7 +81,7 @@ impl SqLiteEntity for SignedEntityRecord { &beacon_str, )?, certificate_id, - entity: entity_str, + artifact: artifact_str, created_at, }; @@ -102,7 +102,7 @@ impl SqLiteEntity for SignedEntityRecord { ), ("certificate_id", "{:signed_entity:}.certificate_id", "text"), ("beacon", "{:signed_entity:}.beacon", "text"), - ("entity", "{:signed_entity:}.entity", "text"), + ("artifact", "{:signed_entity:}.artifact", "text"), ("created_at", "{:signed_entity:}.created_at", "text"), ]) } @@ -201,13 +201,13 @@ impl<'conn> InsertSignedEntityRecordProvider<'conn> { fn get_insert_condition(&self, signed_entity_record: SignedEntityRecord) -> WhereCondition { WhereCondition::new( - "(signed_entity_id, signed_entity_type_id, certificate_id, beacon, entity, created_at) values (?*, ?*, ?*, ?*, ?*, ?*)", + "(signed_entity_id, signed_entity_type_id, certificate_id, beacon, artifact, created_at) values (?*, ?*, ?*, ?*, ?*, ?*)", vec![ Value::String(signed_entity_record.signed_entity_id), Value::Integer(signed_entity_record.signed_entity_type.index() as i64), Value::String(signed_entity_record.certificate_id), Value::String(signed_entity_record.signed_entity_type.get_json_beacon().unwrap()), - Value::String(signed_entity_record.entity), + Value::String(signed_entity_record.artifact), Value::String(signed_entity_record.created_at), ], ) @@ -380,7 +380,7 @@ mod tests { snapshot.beacon, ), certificate_id: snapshot.certificate_hash, - entity, + artifact: entity, created_at: snapshot.created_at, } }) @@ -432,7 +432,7 @@ mod tests { ) .unwrap(); statement - .bind(5, signed_entity_record.entity.as_str()) + .bind(5, signed_entity_record.artifact.as_str()) .unwrap(); statement .bind(6, signed_entity_record.created_at.as_str()) @@ -461,7 +461,7 @@ mod tests { let aliases = SourceAlias::new(&[("{:signed_entity:}", "se")]); assert_eq!( - "se.signed_entity_id as signed_entity_id, se.signed_entity_type_id as signed_entity_type_id, se.certificate_id as certificate_id, se.beacon as beacon, se.entity as entity, se.created_at as created_at" + "se.signed_entity_id as signed_entity_id, se.signed_entity_type_id as signed_entity_type_id, se.certificate_id as certificate_id, se.beacon as beacon, se.artifact as artifact, se.created_at as created_at" .to_string(), projection.expand(aliases) ); @@ -507,7 +507,7 @@ mod tests { let (values, params) = condition.expand(); assert_eq!( - "(signed_entity_id, signed_entity_type_id, certificate_id, beacon, entity, created_at) values (?1, ?2, ?3, ?4, ?5, ?6)".to_string(), + "(signed_entity_id, signed_entity_type_id, certificate_id, beacon, artifact, created_at) values (?1, ?2, ?3, ?4, ?5, ?6)".to_string(), values ); assert_eq!( @@ -521,7 +521,7 @@ mod tests { .get_json_beacon() .unwrap() ), - Value::String(signed_entity_record.entity), + Value::String(signed_entity_record.artifact), Value::String(signed_entity_record.created_at), ], params From ff2d6616614f06b2bb1e3b723f3895e97b1933c0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Tue, 9 May 2023 11:45:46 +0200 Subject: [PATCH 11/11] Bump crates versions --- Cargo.lock | 4 ++-- mithril-aggregator/Cargo.toml | 2 +- mithril-common/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8564d18a5b5..2d87131d6ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2103,7 +2103,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.3.14" +version = "0.3.15" dependencies = [ "async-trait", "chrono", @@ -2168,7 +2168,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.2.50" +version = "0.2.51" dependencies = [ "async-trait", "bech32", diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index bc2098e38c9..f9fbcd2535c 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.3.14" +version = "0.3.15" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 83c3fcad52f..874d3840791 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.2.50" +version = "0.2.51" authors = { workspace = true } edition = { workspace = true } documentation = { workspace = true }