Skip to content

Commit 120452b

Browse files
committed
feature(aggregator): implement local network configuration provider
1 parent bc2e5d5 commit 120452b

File tree

5 files changed

+299
-84
lines changed

5 files changed

+299
-84
lines changed

mithril-aggregator/src/dependency_injection/builder/enablers/epoch.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
1+
use mithril_protocol_config::http_client::http_impl::HttpMithrilNetworkConfigurationProvider;
12
use std::sync::Arc;
23
use tokio::sync::RwLock;
34

5+
use mithril_protocol_config::interface::MithrilNetworkConfigurationProvider;
6+
47
use crate::dependency_injection::{DependenciesBuilder, EpochServiceWrapper, Result};
58
use crate::get_dependency;
6-
use crate::services::{EpochServiceDependencies, MithrilEpochService};
9+
use crate::services::{
10+
EpochServiceDependencies, LocalMithrilNetworkConfigurationProvider, MithrilEpochService,
11+
};
12+
713
impl DependenciesBuilder {
814
async fn build_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
915
let verification_key_store = self.get_verification_key_store().await?;
1016
let epoch_settings_storer = self.get_epoch_settings_store().await?;
1117
let chain_observer = self.get_chain_observer().await?;
1218
let era_checker = self.get_era_checker().await?;
1319
let stake_store = self.get_stake_store().await?;
14-
//remove conf usage for epoch_settings and allowed_discriminants and send mithril_network_configuration instread
15-
let epoch_settings = self.configuration.get_epoch_settings_configuration();
1620
let allowed_discriminants = self
1721
.configuration
1822
.compute_allowed_signed_entity_types_discriminants()?;
1923

20-
let network_configuration_provider = self.get_mithril_network_configuration_provider();
2124
let epoch_service = Arc::new(RwLock::new(MithrilEpochService::new(
22-
network_configuration_provider,
25+
self.get_mithril_network_configuration_provider().await?,
2326
EpochServiceDependencies::new(
2427
epoch_settings_storer,
2528
verification_key_store,
@@ -38,4 +41,45 @@ impl DependenciesBuilder {
3841
pub async fn get_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
3942
get_dependency!(self.epoch_service)
4043
}
44+
45+
async fn build_mithril_network_configuration_provider(
46+
&mut self,
47+
) -> Result<Arc<dyn MithrilNetworkConfigurationProvider>> {
48+
let network_configuration_provider: Arc<dyn MithrilNetworkConfigurationProvider> =
49+
if self.configuration.is_follower_aggregator() {
50+
Arc::new(HttpMithrilNetworkConfigurationProvider::new(
51+
self.get_leader_aggregator_client().await?,
52+
))
53+
} else {
54+
Arc::new(LocalMithrilNetworkConfigurationProvider::new(
55+
self.configuration.get_epoch_settings_configuration(),
56+
self.configuration
57+
.compute_allowed_signed_entity_types_discriminants()?,
58+
self.get_epoch_settings_store().await?,
59+
))
60+
};
61+
62+
Ok(network_configuration_provider)
63+
}
64+
65+
/// [MithrilNetworkConfigurationProvider][mithril_protocol_config::interface::MithrilNetworkConfigurationProvider] service
66+
pub async fn get_mithril_network_configuration_provider(
67+
&mut self,
68+
) -> Result<Arc<dyn MithrilNetworkConfigurationProvider>> {
69+
get_dependency!(self.mithril_network_configuration_provider)
70+
}
71+
}
72+
73+
// Todo remove after rebase with shared aggregator client:
74+
#[async_trait::async_trait]
75+
impl mithril_protocol_config::http_client::http_impl::ProtocolConfigurationRetrieverFromAggregator
76+
for crate::services::AggregatorHTTPClient
77+
{
78+
/// Retrieves protocol configuration for a given epoch from the aggregator
79+
async fn retrieve_protocol_configuration(
80+
&self,
81+
_epoch: mithril_common::entities::Epoch,
82+
) -> mithril_common::StdResult<mithril_common::messages::ProtocolConfigurationMessage> {
83+
unimplemented!()
84+
}
4185
}

mithril-aggregator/src/dependency_injection/builder/enablers/mithril_network_configuration.rs

Lines changed: 0 additions & 78 deletions
This file was deleted.

mithril-aggregator/src/dependency_injection/builder/enablers/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
mod cardano_node;
44
mod epoch;
55
mod misc;
6-
mod mithril_network_configuration;
76
mod ticker;

mithril-aggregator/src/services/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod certificate_chain_synchronizer;
1515
mod certifier;
1616
mod epoch_service;
1717
mod message;
18+
mod network_configuration_provider;
1819
mod prover;
1920
mod signable_builder;
2021
mod signature_consumer;
@@ -32,6 +33,7 @@ pub use certificate_chain_synchronizer::*;
3233
pub use certifier::*;
3334
pub use epoch_service::*;
3435
pub use message::*;
36+
pub use network_configuration_provider::*;
3537
pub use prover::*;
3638
pub use signable_builder::*;
3739
pub use signature_consumer::*;

0 commit comments

Comments
 (0)