Skip to content

Commit

Permalink
refactor(aggregator): streamline some configuration usages
Browse files Browse the repository at this point in the history
- move `get_epoch_settings_configuration` to the Configuration struct as
  it have no other dependencies
- use directly `Configuration::compute_allowed_signed_entity_types_discriminants`
  instead of `get_allowed_signed_entity_types_discriminants` as the only
  thing that the latter do is calling the former.
  • Loading branch information
Alenar committed Feb 7, 2025
1 parent 6d4dd91 commit f6f0e06
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
17 changes: 13 additions & 4 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use anyhow::{anyhow, Context};
use config::{ConfigError, Map, Source, Value, ValueKind};
use mithril_common::chain_observer::ChainObserverType;
use mithril_common::crypto_helper::ProtocolGenesisSigner;
use mithril_common::era::adapters::EraReaderAdapterType;
use mithril_doc::{Documenter, DocumenterDefault, StructDoc};
use serde::{Deserialize, Serialize};
use std::collections::{BTreeSet, HashMap};
use std::path::PathBuf;
use std::str::FromStr;

use mithril_common::chain_observer::ChainObserverType;
use mithril_common::crypto_helper::ProtocolGenesisSigner;
use mithril_common::entities::{
BlockNumber, CardanoTransactionsSigningConfig, CompressionAlgorithm,
HexEncodedGenesisVerificationKey, ProtocolParameters, SignedEntityConfig,
SignedEntityTypeDiscriminants,
};
use mithril_common::era::adapters::EraReaderAdapterType;
use mithril_common::{CardanoNetwork, StdResult};
use mithril_doc::{Documenter, DocumenterDefault, StructDoc};

use crate::entities::AggregatorEpochSettings;
use crate::http_server::SERVER_BASE_PATH;
use crate::tools::url_sanitizer::SanitizedUrlWithTrailingSlash;

Expand Down Expand Up @@ -366,6 +367,14 @@ impl Configuration {
SnapshotUploaderType::Gcp => false,
}
}

/// Infer the [AggregatorEpochSettings] from the configuration.
pub fn get_epoch_settings_configuration(&mut self) -> AggregatorEpochSettings {
AggregatorEpochSettings {
protocol_parameters: self.protocol_parameters.clone(),
cardano_transactions_signing_config: self.cardano_transactions_signing_config.clone(),
}
}
}

/// Default configuration with all the default values for configurations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ impl DependenciesBuilder {
&mut self,
) -> Result<Arc<CardanoTransactionsPreloader>> {
let activation = self
.get_allowed_signed_entity_types_discriminants()?
.configuration
.compute_allowed_signed_entity_types_discriminants()?
.contains(&SignedEntityTypeDiscriminants::CardanoTransactions);
let cardano_transactions_preloader = CardanoTransactionsPreloader::new(
self.get_signed_entity_lock().await?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ impl DependenciesBuilder {
let chain_observer = self.get_chain_observer().await?;
let era_checker = self.get_era_checker().await?;
let stake_distribution_service = self.get_stake_distribution_service().await?;
let epoch_settings = self.get_epoch_settings_configuration()?;
let allowed_discriminants = self.get_allowed_signed_entity_types_discriminants()?;
let epoch_settings = self.configuration.get_epoch_settings_configuration();
let allowed_discriminants = self
.configuration
.compute_allowed_signed_entity_types_discriminants()?;

let epoch_service = Arc::new(RwLock::new(MithrilEpochService::new(
epoch_settings,
Expand Down
30 changes: 4 additions & 26 deletions mithril-aggregator/src/dependency_injection/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod support;

use anyhow::Context;
use slog::Logger;
use std::{collections::BTreeSet, path::PathBuf, sync::Arc};
use std::{path::PathBuf, sync::Arc};
use tokio::{
sync::{
mpsc::{UnboundedReceiver, UnboundedSender},
Expand All @@ -24,7 +24,6 @@ use mithril_common::{
digesters::{
cache::ImmutableFileDigestCacheProvider, ImmutableDigester, ImmutableFileObserver,
},
entities::SignedEntityTypeDiscriminants,
era::{EraChecker, EraReader, EraReaderAdapter},
signable_builder::{SignableBuilderService, SignableSeedBuilder, TransactionsImporter},
signed_entity_type_lock::SignedEntityTypeLock,
Expand All @@ -41,7 +40,6 @@ use crate::{
CertificateRepository, EpochSettingsStore, OpenMessageRepository, SignedEntityStorer,
SignerStore, StakePoolStore,
},
entities::AggregatorEpochSettings,
event_store::{EventMessage, TransmitterService},
file_uploaders::FileUploader,
http_server::routes::router::{self, RouterConfig, RouterState},
Expand Down Expand Up @@ -282,17 +280,6 @@ impl DependenciesBuilder {
}
}

/// Get the allowed signed entity types discriminants
fn get_allowed_signed_entity_types_discriminants(
&self,
) -> Result<BTreeSet<SignedEntityTypeDiscriminants>> {
let allowed_discriminants = self
.configuration
.compute_allowed_signed_entity_types_discriminants()?;

Ok(allowed_discriminants)
}

fn get_cardano_db_artifacts_dir(&self) -> Result<PathBuf> {
let cardano_db_artifacts_dir = self
.configuration
Expand All @@ -311,17 +298,6 @@ impl DependenciesBuilder {
Ok(cardano_db_artifacts_dir)
}

fn get_epoch_settings_configuration(&mut self) -> Result<AggregatorEpochSettings> {
let epoch_settings = AggregatorEpochSettings {
protocol_parameters: self.configuration.protocol_parameters.clone(),
cardano_transactions_signing_config: self
.configuration
.cardano_transactions_signing_config
.clone(),
};
Ok(epoch_settings)
}

/// Return an unconfigured [DependencyContainer]
pub async fn build_dependency_container(&mut self) -> Result<DependencyContainer> {
#[allow(deprecated)]
Expand Down Expand Up @@ -405,7 +381,9 @@ impl DependenciesBuilder {
RouterConfig {
network: self.configuration.get_network()?,
server_url: self.configuration.get_server_url()?,
allowed_discriminants: self.get_allowed_signed_entity_types_discriminants()?,
allowed_discriminants: self
.configuration
.compute_allowed_signed_entity_types_discriminants()?,
cardano_transactions_prover_max_hashes_allowed_by_request: self
.configuration
.cardano_transactions_prover_max_hashes_allowed_by_request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl DependenciesBuilder {
.replace_cardano_signing_config_empty_values(cardano_signing_config)?;
}

let epoch_settings_configuration = self.get_epoch_settings_configuration()?;
let epoch_settings_configuration = self.configuration.get_epoch_settings_configuration();
debug!(
logger,
"Handle discrepancies at startup of epoch settings store, will record epoch settings from the configuration for epoch {current_epoch}";
Expand Down

0 comments on commit f6f0e06

Please sign in to comment.