Skip to content

Commit

Permalink
Merge pull request #901 from input-output-hk/ensemble/853-use-signabl…
Browse files Browse the repository at this point in the history
…e-builder-service-aggregator

Use Signable Builder Service in aggregator
  • Loading branch information
jpraynaud authored May 4, 2023
2 parents 0c2476b + 2849055 commit 0ab4ef1
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 265 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.3.12"
version = "0.3.13"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl ArtifactBuilderService for MithrilArtifactBuilderService {
.compute_artifact(beacon, certificate)
.await?,
)),
_ => todo!(),
SignedEntityType::CardanoStakeDistribution(_) => todo!(),
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions mithril-aggregator/src/artifact_builder/dummy_artifact.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use async_trait::async_trait;
use mithril_common::{
entities::Certificate,
signable_builder::{Artifact, DummyBeacon},
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 {
Expand Down
19 changes: 4 additions & 15 deletions mithril-aggregator/src/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub struct DependencyManager {
pub signer_recorder: Arc<dyn SignerRecorder>,

/// Signable Builder Service
pub signable_builder_service: Arc<SignableBuilderService>,
pub signable_builder_service: Arc<dyn SignableBuilderService>,

/// Artifact Builder Service
pub artifact_builder_service: Arc<dyn ArtifactBuilderService>,
Expand Down Expand Up @@ -311,23 +311,12 @@ impl DependencyManager {

#[cfg(test)]
pub mod tests {
use crate::{
dependency_injection::DependenciesBuilder, AggregatorConfig, Configuration,
DependencyManager,
};
use mithril_common::CardanoNetwork;
use crate::{dependency_injection::DependenciesBuilder, Configuration, DependencyManager};

pub async fn initialize_dependencies() -> (DependencyManager, AggregatorConfig) {
pub async fn initialize_dependencies() -> DependencyManager {
let config = Configuration::new_sample();
let mut builder = DependenciesBuilder::new(config);
let dependency_manager = builder.build_dependency_container().await.unwrap();

let config = AggregatorConfig::new(
dependency_manager.config.run_interval,
CardanoNetwork::TestNet(42),
dependency_manager.config.db_directory.as_path(),
);

(dependency_manager, config)
builder.build_dependency_container().await.unwrap()
}
}
21 changes: 12 additions & 9 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{
},
event_store::{EventMessage, EventStore, TransmitterService},
http_server::routes::router,
signable_builder::SignableBuilderService,
signable_builder::{MithrilSignableBuilderService, SignableBuilderService},
signer_registerer::SignerRecorder,
stake_distribution_service::{MithrilStakeDistributionService, StakeDistributionService},
ticker_service::{MithrilTickerService, TickerService},
Expand Down Expand Up @@ -172,7 +172,7 @@ pub struct DependenciesBuilder {
pub signer_recorder: Option<Arc<dyn SignerRecorder>>,

/// Signable Builder Service
pub signable_builder_service: Option<Arc<SignableBuilderService>>,
pub signable_builder_service: Option<Arc<dyn SignableBuilderService>>,

/// Artifact Builder Service
pub artifact_builder_service: Option<Arc<dyn ArtifactBuilderService>>,
Expand Down Expand Up @@ -877,13 +877,14 @@ impl DependenciesBuilder {
Ok(self.signer_recorder.as_ref().cloned().unwrap())
}

async fn build_signable_builder_service(&mut self) -> Result<Arc<SignableBuilderService>> {
let mithril_stake_distribution_builder = MithrilStakeDistributionSignableBuilder::default();
let immutable_signable_builder = CardanoImmutableFilesFullSignableBuilder::new(
async fn build_signable_builder_service(&mut self) -> Result<Arc<dyn SignableBuilderService>> {
let mithril_stake_distribution_builder =
Arc::new(MithrilStakeDistributionSignableBuilder::default());
let immutable_signable_builder = Arc::new(CardanoImmutableFilesFullSignableBuilder::new(
self.get_immutable_digester().await?,
self.get_logger().await?,
);
let signable_builder_service = Arc::new(SignableBuilderService::new(
));
let signable_builder_service = Arc::new(MithrilSignableBuilderService::new(
mithril_stake_distribution_builder,
immutable_signable_builder,
));
Expand All @@ -892,7 +893,9 @@ impl DependenciesBuilder {
}

/// [SignableBuilderService] service
pub async fn get_signable_builder_service(&mut self) -> Result<Arc<SignableBuilderService>> {
pub async fn get_signable_builder_service(
&mut self,
) -> Result<Arc<dyn SignableBuilderService>> {
if self.signable_builder_service.is_none() {
self.signable_builder_service = Some(self.build_signable_builder_service().await?);
}
Expand Down Expand Up @@ -1035,7 +1038,7 @@ impl DependenciesBuilder {
let runtime = AggregatorRuntime::new(
Duration::from_millis(config.interval),
None,
Arc::new(AggregatorRunner::new(config, dependency_container)),
Arc::new(AggregatorRunner::new(dependency_container)),
)
.await
.map_err(|e| DependenciesBuilderError::Initialization {
Expand Down
12 changes: 6 additions & 6 deletions mithril-aggregator/src/http_server/routes/certificate_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod tests {
async fn test_certificate_pending_get_ok() {
let method = Method::GET.as_str();
let path = "/certificate-pending";
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;

let response = request()
.method(method)
Expand All @@ -135,7 +135,7 @@ mod tests {

#[tokio::test]
async fn test_certificate_pending_get_ok_204() {
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;

let method = Method::GET.as_str();
let path = "/certificate-pending";
Expand All @@ -160,7 +160,7 @@ mod tests {
async fn test_certificate_pending_get_ko_500() {
let method = Method::GET.as_str();
let path = "/certificate-pending";
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;

let response = request()
.method(method)
Expand All @@ -180,7 +180,7 @@ mod tests {

#[tokio::test]
async fn test_certificate_certificate_hash_get_ok() {
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;
dependency_manager
.certificate_store
.save(fake_data::genesis_certificate(
Expand Down Expand Up @@ -210,7 +210,7 @@ mod tests {

#[tokio::test]
async fn test_certificate_certificate_hash_get_ok_404() {
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;

let method = Method::GET.as_str();
let path = "/certificate/{certificate_hash}";
Expand All @@ -233,7 +233,7 @@ mod tests {

#[tokio::test]
async fn test_certificate_certificate_hash_get_ko() {
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
let certificate_store = CertificateStore::new(Box::new(FailStoreAdapter::<
String,
entities::Certificate,
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/http_server/routes/epoch_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod tests {
async fn test_epoch_settings_get_ok() {
let method = Method::GET.as_str();
let path = "/epoch-settings";
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;

let response = request()
.method(method)
Expand All @@ -131,7 +131,7 @@ mod tests {
async fn test_epoch_settings_get_ko_500() {
let method = Method::GET.as_str();
let path = "/epoch-settings";
let (dependency_manager, _) = initialize_dependencies().await;
let dependency_manager = initialize_dependencies().await;

let response = request()
.method(method)
Expand Down
10 changes: 5 additions & 5 deletions mithril-aggregator/src/http_server/routes/signatures_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod tests {
mock_certifier_service
.expect_register_single_signature()
.return_once(move |_, _| Ok(()));
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.certifier_service = Arc::new(mock_certifier_service);

let message = RegisterSignatureMessage::dummy();
Expand Down Expand Up @@ -147,7 +147,7 @@ mod tests {
mock_certifier_service
.expect_register_single_signature()
.return_once(move |_, _| Ok(()));
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.certifier_service = Arc::new(mock_certifier_service);

let mut message = RegisterSignatureMessage::dummy();
Expand Down Expand Up @@ -185,7 +185,7 @@ mod tests {
signed_entity_type,
)))
});
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.certifier_service = Arc::new(mock_certifier_service);

let method = Method::POST.as_str();
Expand Down Expand Up @@ -220,7 +220,7 @@ mod tests {
signed_entity_type,
)))
});
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.certifier_service = Arc::new(mock_certifier_service);

let method = Method::POST.as_str();
Expand Down Expand Up @@ -253,7 +253,7 @@ mod tests {
"an error occurred".to_string(),
)))
});
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.certifier_service = Arc::new(mock_certifier_service);

let message = RegisterSignatureMessage::dummy();
Expand Down
8 changes: 4 additions & 4 deletions mithril-aggregator/src/http_server/routes/signer_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mod tests {
mock_signer_registerer
.expect_get_current_round()
.return_once(|| None);
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.signer_registerer = Arc::new(mock_signer_registerer);

let signer: RegisterSignerMessage = RegisterSignerMessage::dummy();
Expand Down Expand Up @@ -203,7 +203,7 @@ mod tests {
mock_signer_registerer
.expect_get_current_round()
.return_once(|| None);
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.signer_registerer = Arc::new(mock_signer_registerer);

let signer: RegisterSignerMessage = RegisterSignerMessage::dummy();
Expand Down Expand Up @@ -241,7 +241,7 @@ mod tests {
mock_signer_registerer
.expect_get_current_round()
.return_once(|| None);
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.signer_registerer = Arc::new(mock_signer_registerer);

let signer: RegisterSignerMessage = RegisterSignerMessage::dummy();
Expand Down Expand Up @@ -279,7 +279,7 @@ mod tests {
mock_signer_registerer
.expect_get_current_round()
.return_once(|| None);
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.signer_registerer = Arc::new(mock_signer_registerer);

let signer: RegisterSignerMessage = RegisterSignerMessage::dummy();
Expand Down
16 changes: 8 additions & 8 deletions mithril-aggregator/src/http_server/routes/snapshot_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ mod tests {
.expect_list_snapshots()
.return_const(Ok(fake_snapshots))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -237,7 +237,7 @@ mod tests {
"an error occurred".to_string(),
)))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -267,7 +267,7 @@ mod tests {
.expect_get_snapshot_details()
.return_const(Ok(Some(fake_snapshot)))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -296,7 +296,7 @@ mod tests {
.expect_get_snapshot_details()
.return_const(Ok(None))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -327,7 +327,7 @@ mod tests {
"an error occurred".to_string(),
)))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -357,7 +357,7 @@ mod tests {
.expect_get_snapshot_details()
.return_const(Ok(Some(fake_snapshot)))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -386,7 +386,7 @@ mod tests {
.expect_get_snapshot_details()
.return_const(Ok(None))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down Expand Up @@ -417,7 +417,7 @@ mod tests {
"an error occurred".to_string(),
)))
.once();
let (mut dependency_manager, _) = initialize_dependencies().await;
let mut dependency_manager = initialize_dependencies().await;
dependency_manager.snapshot_store = Arc::new(mock_snapshot_store);

let method = Method::GET.as_str();
Expand Down
Loading

0 comments on commit 0ab4ef1

Please sign in to comment.