Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mithril-aggregator/config/dev.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"network": "testnet",
"url_snapshot_manifest": "https://storage.googleapis.com/cardano-testnet/snapshots.json"
"url_snapshot_manifest": "https://storage.googleapis.com/cardano-testnet/snapshots.json",
"snapshot_store_type": "gcp",
"snapshot_uploader_type": "gcp"
}
4 changes: 3 additions & 1 deletion mithril-aggregator/config/testnet.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"network": "testnet",
"url_snapshot_manifest": "https://storage.googleapis.com/cardano-testnet/snapshots.json"
"url_snapshot_manifest": "https://storage.googleapis.com/cardano-testnet/snapshots.json",
"snapshot_store_type": "gcp",
"snapshot_uploader_type": "gcp"
}
16 changes: 8 additions & 8 deletions mithril-aggregator/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ use tokio::sync::RwLock;

use super::entities::*;
use super::multi_signer::MultiSigner;
use super::snapshot_store::SnapshotStorer;
use super::snapshot_stores::SnapshotStore;

/// BeaconStoreWrapper wraps a BeaconStore
pub type BeaconStoreWrapper = Arc<RwLock<dyn BeaconStore>>;

/// SnapshotStorerWrapper wraps a SnapshotStorer
pub type SnapshotStorerWrapper = Arc<RwLock<dyn SnapshotStorer>>;
/// SnapshotStoreWrapper wraps a SnapshotStore
pub type SnapshotStoreWrapper = Arc<RwLock<dyn SnapshotStore>>;

/// MultiSignerWrapper wraps a MultiSigner
pub type MultiSignerWrapper = Arc<RwLock<dyn MultiSigner>>;

/// DependencyManager handles the dependencies
pub struct DependencyManager {
pub config: Config,
pub snapshot_storer: Option<SnapshotStorerWrapper>,
pub snapshot_store: Option<SnapshotStoreWrapper>,
pub multi_signer: Option<MultiSignerWrapper>,
pub beacon_store: Option<BeaconStoreWrapper>,
}
Expand All @@ -28,15 +28,15 @@ impl DependencyManager {
pub fn new(config: Config) -> Self {
Self {
config,
snapshot_storer: None,
snapshot_store: None,
multi_signer: None,
beacon_store: None,
}
}

/// With SnapshotStorer
pub fn with_snapshot_storer(&mut self, snapshot_storer: SnapshotStorerWrapper) -> &mut Self {
self.snapshot_storer = Some(snapshot_storer);
/// With SnapshotStore
pub fn with_snapshot_store(&mut self, snapshot_store: SnapshotStoreWrapper) -> &mut Self {
self.snapshot_store = Some(snapshot_store);
self
}

Expand Down
60 changes: 60 additions & 0 deletions mithril-aggregator/src/entities.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
use crate::dependency::SnapshotStoreWrapper;
use crate::snapshot_stores::LocalSnapshotStore;
use crate::snapshot_uploaders::SnapshotUploader;
use crate::tools::GcpFileUploader;
use crate::{LocalSnapshotUploader, RemoteSnapshotStore, RemoteSnapshotUploader};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use std::sync::Arc;
use tokio::sync::RwLock;

/// Aggregator configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -8,4 +16,56 @@ pub struct Config {

/// Snapshots manifest location
pub url_snapshot_manifest: String,

/// Type of snapshot store to use
pub snapshot_store_type: SnapshotStoreType,

/// Type of snapshot uploader to use
pub snapshot_uploader_type: SnapshotUploaderType,

/// Server listening IP
pub server_url: String,

/// Directory to snapshot
pub db_directory: PathBuf,

/// Directory to store snapshot
pub snapshot_directory: PathBuf,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SnapshotStoreType {
Gcp,
Local,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SnapshotUploaderType {
Gcp,
Local,
}

impl Config {
pub fn build_snapshot_store(&self) -> SnapshotStoreWrapper {
match self.snapshot_store_type {
SnapshotStoreType::Gcp => Arc::new(RwLock::new(RemoteSnapshotStore::new(
Box::new(GcpFileUploader::default()),
self.url_snapshot_manifest.clone(),
))),
SnapshotStoreType::Local => Arc::new(RwLock::new(LocalSnapshotStore::new())),
}
}

pub fn build_snapshot_uploader(&self) -> Box<dyn SnapshotUploader> {
match self.snapshot_store_type {
SnapshotStoreType::Gcp => Box::new(RemoteSnapshotUploader::new(Box::new(
GcpFileUploader::default(),
))),
SnapshotStoreType::Local => {
Box::new(LocalSnapshotUploader::new(self.server_url.clone()))
}
}
}
}
Loading