Skip to content

Commit

Permalink
Cleanup Snapshot Stores in aggregator
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraynaud committed May 15, 2023
1 parent 9771f12 commit 5608aff
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 213 deletions.
3 changes: 0 additions & 3 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ use mithril_common::CardanoNetwork;
use crate::tools::GcpFileUploader;
use crate::{LocalSnapshotUploader, RemoteSnapshotUploader, SnapshotUploader};

// TODO: 'LIST_SNAPSHOTS_MAX_ITEMS' keep as const or in config, or add a parameter to `list_snapshots`?
pub const LIST_SNAPSHOTS_MAX_ITEMS: usize = 20;

/// Different kinds of execution environments
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum ExecutionEnvironment {
Expand Down
5 changes: 1 addition & 4 deletions mithril-aggregator/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use sqlite::Connection;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::{Mutex, RwLock};

use crate::event_store::EventMessage;
use crate::{
artifact_builder::ArtifactBuilderService,
certifier_service::CertifierService,
Expand All @@ -27,7 +28,6 @@ use crate::{
SignerRegisterer, SignerRegistrationRoundOpener, Snapshotter, VerificationKeyStore,
VerificationKeyStorer,
};
use crate::{event_store::EventMessage, snapshot_stores::SnapshotStore};
use crate::{event_store::TransmitterService, multi_signer::MultiSigner};
use crate::{
snapshot_uploaders::SnapshotUploader, stake_distribution_service::StakeDistributionService,
Expand All @@ -50,9 +50,6 @@ pub struct DependencyManager {
/// It shall be a private dependency.
pub stake_store: Arc<StakePoolStore>,

/// Snapshot store.
pub snapshot_store: Arc<dyn SnapshotStore>,

/// Snapshot uploader service.
pub snapshot_uploader: Arc<dyn SnapshotUploader>,

Expand Down
32 changes: 4 additions & 28 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::{
MithrilArtifactBuilderService, MithrilStakeDistributionArtifactBuilder,
},
certifier_service::{CertifierService, MithrilCertifierService},
configuration::{ExecutionEnvironment, LIST_SNAPSHOTS_MAX_ITEMS},
configuration::ExecutionEnvironment,
database::provider::{
CertificateRepository, CertificateStoreAdapter, EpochSettingStore, OpenMessageRepository,
SignedEntityStoreAdapter, SignedEntityStorer, SignerRegistrationStoreAdapter, SignerStore,
Expand All @@ -55,10 +55,9 @@ use crate::{
tools::{GcpFileUploader, GenesisToolsDependency},
AggregatorConfig, AggregatorRunner, AggregatorRuntime, CertificatePendingStore,
CertificateStore, Configuration, DependencyManager, DumbSnapshotUploader, DumbSnapshotter,
GzipSnapshotter, LocalSnapshotStore, LocalSnapshotUploader, MithrilSignerRegisterer,
MultiSigner, MultiSignerImpl, ProtocolParametersStore, ProtocolParametersStorer,
RemoteSnapshotUploader, SnapshotStore, SnapshotUploader, SnapshotUploaderType, Snapshotter,
VerificationKeyStore,
GzipSnapshotter, LocalSnapshotUploader, MithrilSignerRegisterer, MultiSigner, MultiSignerImpl,
ProtocolParametersStore, ProtocolParametersStorer, RemoteSnapshotUploader, SnapshotUploader,
SnapshotUploaderType, Snapshotter, VerificationKeyStore,
};

use super::{DependenciesBuilderError, Result};
Expand Down Expand Up @@ -87,9 +86,6 @@ pub struct DependenciesBuilder {
/// It shall be a private dependency.
pub stake_store: Option<Arc<StakePoolStore>>,

/// Snapshot store.
pub snapshot_store: Option<Arc<dyn SnapshotStore>>,

/// Snapshot uploader service.
pub snapshot_uploader: Option<Arc<dyn SnapshotUploader>>,

Expand Down Expand Up @@ -191,7 +187,6 @@ impl DependenciesBuilder {
configuration,
sqlite_connection: None,
stake_store: None,
snapshot_store: None,
snapshot_uploader: None,
multi_signer: None,
certificate_pending_store: None,
Expand Down Expand Up @@ -291,24 +286,6 @@ impl DependenciesBuilder {
Ok(self.stake_store.as_ref().cloned().unwrap())
}

async fn build_snapshot_store(&mut self) -> Result<Arc<dyn SnapshotStore>> {
Ok(Arc::new(LocalSnapshotStore::new(
Box::new(SignedEntityStoreAdapter::new(
self.get_sqlite_connection().await?,
)),
LIST_SNAPSHOTS_MAX_ITEMS,
)))
}

/// Return a configured [SnapshotStore]
pub async fn get_snapshot_store(&mut self) -> Result<Arc<dyn SnapshotStore>> {
if self.snapshot_store.is_none() {
self.snapshot_store = Some(self.build_snapshot_store().await?);
}

Ok(self.snapshot_store.as_ref().cloned().unwrap())
}

async fn build_snapshot_uploader(&mut self) -> Result<Arc<dyn SnapshotUploader>> {
if self.configuration.environment == ExecutionEnvironment::Production {
match self.configuration.snapshot_uploader_type {
Expand Down Expand Up @@ -960,7 +937,6 @@ impl DependenciesBuilder {
config: self.configuration.clone(),
sqlite_connection: self.get_sqlite_connection().await?,
stake_store: self.get_stake_store().await?,
snapshot_store: self.get_snapshot_store().await?,
snapshot_uploader: self.get_snapshot_uploader().await?,
multi_signer: self.get_multi_signer().await?,
certificate_pending_store: self.get_certificate_pending_store().await?,
Expand Down
2 changes: 0 additions & 2 deletions mithril-aggregator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ mod message_adapters;
mod multi_signer;
mod runtime;
mod signer_registerer;
mod snapshot_stores;
mod snapshot_uploaders;
mod snapshotter;
pub mod stake_distribution_service;
Expand All @@ -38,7 +37,6 @@ pub use crate::configuration::{
Configuration, DefaultConfiguration, ExecutionEnvironment, SnapshotUploaderType,
};
pub use crate::multi_signer::{MultiSigner, MultiSignerImpl, ProtocolError};
pub use crate::snapshot_stores::{LocalSnapshotStore, SnapshotStore};
pub use command_args::MainOpts;
pub use dependency::DependencyManager;
pub use message_adapters::{
Expand Down
126 changes: 0 additions & 126 deletions mithril-aggregator/src/snapshot_stores/local_snapshot_store.rs

This file was deleted.

9 changes: 0 additions & 9 deletions mithril-aggregator/src/snapshot_stores/mod.rs

This file was deleted.

36 changes: 0 additions & 36 deletions mithril-aggregator/src/snapshot_stores/snapshot_store.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod tests {
let digest = "41e27b9ed5a32531b95b2b7ff3c0757591a06a337efaf19a524a998e348028e7";
let archive = create_fake_archive(source_dir.path(), digest);
let expected_location = format!(
"{}{}/snapshot/{}/download",
"{}{}/artifact/snapshot/{}/download",
url,
http_server::SERVER_BASE_PATH,
&digest
Expand Down
15 changes: 11 additions & 4 deletions mithril-aggregator/tests/test_extensions/runtime_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use mithril_aggregator::{
use mithril_common::crypto_helper::{ProtocolClerk, ProtocolGenesisSigner};
use mithril_common::digesters::DumbImmutableFileObserver;
use mithril_common::entities::{
Certificate, Epoch, ImmutableFileNumber, SignedEntityType, SignerWithStake, Snapshot,
Beacon, Certificate, Epoch, ImmutableFileNumber, SignedEntityType, SignerWithStake, Snapshot,
StakeDistribution,
};
use mithril_common::{chain_observer::FakeObserver, digesters::DumbImmutableDigester};
Expand Down Expand Up @@ -318,14 +318,21 @@ impl RuntimeTester {
.get_list(1000) // Arbitrary high number to get all of them in store
.await
.map_err(|e| format!("Querying certificate store should not fail {e:?}"))?;
let snapshots = self
let signed_entity_records = self
.deps_builder
.get_snapshot_store()
.get_signed_entity_storer()
.await
.unwrap()
.list_snapshots()
.get_last_signed_entities_by_type(
&SignedEntityType::CardanoImmutableFilesFull(Beacon::default()),
20,
)
.await
.map_err(|e| format!("Querying snapshot store should not fail {e:?}"))?;
let snapshots = signed_entity_records
.into_iter()
.map(|record| serde_json::from_str(&record.artifact).unwrap())
.collect::<Vec<Snapshot>>();

Ok((certificates, snapshots))
}
Expand Down

0 comments on commit 5608aff

Please sign in to comment.