Skip to content

Commit b69115a

Browse files
committed
feat(aggregator): implement local configuration for mithril network configuration and adapt epoch service
1 parent 567b1df commit b69115a

File tree

9 files changed

+447
-118
lines changed

9 files changed

+447
-118
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
11
use std::sync::Arc;
22
use tokio::sync::RwLock;
33

4+
use mithril_protocol_config::{
5+
http::HttpMithrilNetworkConfigurationProvider, interface::MithrilNetworkConfigurationProvider,
6+
};
7+
48
use crate::dependency_injection::{DependenciesBuilder, EpochServiceWrapper, Result};
59
use crate::get_dependency;
6-
use crate::services::{EpochServiceDependencies, MithrilEpochService};
10+
use crate::services::{
11+
EpochServiceDependencies, LocalMithrilNetworkConfigurationProvider, MithrilEpochService,
12+
};
13+
714
impl DependenciesBuilder {
815
async fn build_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
916
let verification_key_store = self.get_verification_key_store().await?;
1017
let epoch_settings_storer = self.get_epoch_settings_store().await?;
1118
let chain_observer = self.get_chain_observer().await?;
1219
let era_checker = self.get_era_checker().await?;
1320
let stake_store = self.get_stake_store().await?;
14-
let epoch_settings = self.configuration.get_epoch_settings_configuration();
1521
let allowed_discriminants = self
1622
.configuration
1723
.compute_allowed_signed_entity_types_discriminants()?;
1824

1925
let epoch_service = Arc::new(RwLock::new(MithrilEpochService::new(
20-
epoch_settings,
2126
EpochServiceDependencies::new(
27+
self.get_mithril_network_configuration_provider().await?,
2228
epoch_settings_storer,
2329
verification_key_store,
2430
chain_observer,
@@ -36,4 +42,33 @@ impl DependenciesBuilder {
3642
pub async fn get_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
3743
get_dependency!(self.epoch_service)
3844
}
45+
46+
async fn build_mithril_network_configuration_provider(
47+
&mut self,
48+
) -> Result<Arc<dyn MithrilNetworkConfigurationProvider>> {
49+
let network_configuration_provider: Arc<dyn MithrilNetworkConfigurationProvider> =
50+
if self.configuration.is_follower_aggregator() {
51+
Arc::new(HttpMithrilNetworkConfigurationProvider::new(
52+
self.get_leader_aggregator_client().await?,
53+
))
54+
} else {
55+
Arc::new(LocalMithrilNetworkConfigurationProvider::new(
56+
self.configuration.get_epoch_settings_configuration(),
57+
self.configuration
58+
.compute_allowed_signed_entity_types_discriminants()?,
59+
self.get_epoch_settings_store().await?,
60+
))
61+
};
62+
63+
//TODO handle discrepency here
64+
65+
Ok(network_configuration_provider)
66+
}
67+
68+
/// [MithrilNetworkConfigurationProvider][mithril_protocol_config::interface::MithrilNetworkConfigurationProvider] service
69+
pub async fn get_mithril_network_configuration_provider(
70+
&mut self,
71+
) -> Result<Arc<dyn MithrilNetworkConfigurationProvider>> {
72+
get_dependency!(self.mithril_network_configuration_provider)
73+
}
3974
}

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

Lines changed: 0 additions & 32 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/dependency_injection/builder/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use mithril_persistence::{
3636
database::repository::CardanoTransactionRepository,
3737
sqlite::{SqliteConnection, SqliteConnectionPool},
3838
};
39+
use mithril_protocol_config::interface::MithrilNetworkConfigurationProvider;
3940
use mithril_signed_entity_lock::SignedEntityTypeLock;
4041
use mithril_ticker::TickerService;
4142

@@ -254,6 +255,10 @@ pub struct DependenciesBuilder {
254255
/// Epoch service.
255256
pub epoch_service: Option<EpochServiceWrapper>,
256257

258+
/// Mithril network configuration provider
259+
pub mithril_network_configuration_provider:
260+
Option<Arc<dyn MithrilNetworkConfigurationProvider>>,
261+
257262
/// Signed Entity storer
258263
pub signed_entity_storer: Option<Arc<dyn SignedEntityStorer>>,
259264

@@ -339,6 +344,7 @@ impl DependenciesBuilder {
339344
signed_entity_service: None,
340345
certifier_service: None,
341346
epoch_service: None,
347+
mithril_network_configuration_provider: None,
342348
signed_entity_storer: None,
343349
message_service: None,
344350
prover_service: None,
@@ -395,6 +401,9 @@ impl DependenciesBuilder {
395401
signed_entity_service: self.get_signed_entity_service().await?,
396402
certifier_service: self.get_certifier_service().await?,
397403
epoch_service: self.get_epoch_service().await?,
404+
mithril_network_configuration_provider: self
405+
.get_mithril_network_configuration_provider()
406+
.await?,
398407
ticker_service: self.get_ticker_service().await?,
399408
signed_entity_storer: self.get_signed_entity_storer().await?,
400409
signer_getter: self.get_signer_store().await?,

mithril-aggregator/src/dependency_injection/containers/serve.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use mithril_protocol_config::interface::MithrilNetworkConfigurationProvider;
12
use slog::Logger;
23
use std::sync::Arc;
34
use tokio::sync::RwLock;
@@ -100,6 +101,9 @@ pub struct ServeCommandDependenciesContainer {
100101
/// Epoch service
101102
pub(crate) epoch_service: EpochServiceWrapper,
102103

104+
/// Mithril network configuration provider
105+
pub(crate) mithril_network_configuration_provider: Arc<dyn MithrilNetworkConfigurationProvider>,
106+
103107
/// Ticker Service
104108
pub(crate) ticker_service: Arc<dyn TickerService>,
105109

mithril-aggregator/src/entities/aggregator_epoch_settings.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,31 @@ pub struct AggregatorEpochSettings {
99
/// Cardano transactions signing configuration
1010
pub cardano_transactions_signing_config: CardanoTransactionsSigningConfig,
1111
}
12+
13+
#[cfg(test)]
14+
mod test_utils {
15+
use std::collections::BTreeSet;
16+
17+
use mithril_common::entities::SignedEntityTypeDiscriminants;
18+
use mithril_protocol_config::model::{
19+
MithrilNetworkConfigurationForEpoch, SignedEntityTypeConfiguration,
20+
};
21+
22+
use super::*;
23+
24+
impl AggregatorEpochSettings {
25+
/// Convert this epoch setting into a [MithrilNetworkConfigurationForEpoch]
26+
pub fn into_network_configuration_for_epoch(
27+
self,
28+
enabled_signed_entity_types: BTreeSet<SignedEntityTypeDiscriminants>,
29+
) -> MithrilNetworkConfigurationForEpoch {
30+
MithrilNetworkConfigurationForEpoch {
31+
protocol_parameters: self.protocol_parameters,
32+
enabled_signed_entity_types,
33+
signed_entity_types_config: SignedEntityTypeConfiguration {
34+
cardano_transactions: Some(self.cardano_transactions_signing_config),
35+
},
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)