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: 2 additions & 2 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.5.77"
version = "0.5.78"
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 @@ -44,7 +44,7 @@ mod tests {

use super::*;

use crate::{entities::AggregatorEpochSettings, services::FakeEpochService};
use crate::{entities::AggregatorEpochSettings, services::FakeEpochServiceBuilder};

#[tokio::test]
async fn should_compute_valid_artifact() {
Expand All @@ -54,14 +54,13 @@ mod tests {
protocol_parameters: fake_data::protocol_parameters(),
..AggregatorEpochSettings::dummy()
};
let epoch_service = FakeEpochService::with_data(
Epoch(1),
&epoch_settings,
&epoch_settings,
&epoch_settings,
&signers_with_stake,
&signers_with_stake,
);
let epoch_service = FakeEpochServiceBuilder {
epoch_settings: epoch_settings.clone(),
current_signers_with_stake: signers_with_stake.clone(),
next_signers_with_stake: signers_with_stake.clone(),
..FakeEpochServiceBuilder::dummy(Epoch(1))
}
.build();
let mithril_stake_distribution_artifact_builder =
MithrilStakeDistributionArtifactBuilder::new(Arc::new(RwLock::new(epoch_service)));
let artifact = mithril_stake_distribution_artifact_builder
Expand Down
34 changes: 25 additions & 9 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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::HashMap;
use std::collections::{BTreeSet, HashMap};
use std::path::PathBuf;
use std::str::FromStr;

Expand Down Expand Up @@ -289,22 +289,23 @@ impl Configuration {
.map(|limit| if limit > 3 { limit as u64 } else { 3 })
}

/// Compute a [SignedEntityConfig] based on this configuration.
pub fn compute_signed_entity_config(&self) -> StdResult<SignedEntityConfig> {
let network = self.get_network()?;
/// Compute the list of signed entity discriminants that are allowed to be processed based on this configuration.
pub fn compute_allowed_signed_entity_types_discriminants(
&self,
) -> StdResult<BTreeSet<SignedEntityTypeDiscriminants>> {
let allowed_discriminants = self
.signed_entity_types
.as_ref()
.map(SignedEntityTypeDiscriminants::parse_list)
.transpose()
.with_context(|| "Invalid 'signed_entity_types' configuration")?
.unwrap_or_default();
let allowed_discriminants =
SignedEntityConfig::append_allowed_signed_entity_types_discriminants(
allowed_discriminants,
);

Ok(SignedEntityConfig {
allowed_discriminants,
network,
cardano_transactions_signing_config: self.cardano_transactions_signing_config.clone(),
})
Ok(allowed_discriminants)
}
}

Expand Down Expand Up @@ -540,4 +541,19 @@ mod test {
DefaultConfiguration::default().cardano_transactions_signing_config
);
}

#[test]
fn compute_allowed_signed_entity_types_discriminants_append_default_discriminants() {
let config = Configuration {
signed_entity_types: None,
..Configuration::new_sample()
};

assert_eq!(
config
.compute_allowed_signed_entity_types_discriminants()
.unwrap(),
BTreeSet::from(SignedEntityConfig::DEFAULT_ALLOWED_DISCRIMINANTS)
);
}
}
50 changes: 23 additions & 27 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Context;
use semver::Version;
use slog::Logger;
use std::sync::Arc;
use std::{collections::BTreeSet, sync::Arc};
use tokio::{
sync::{
mpsc::{UnboundedReceiver, UnboundedSender},
Expand Down Expand Up @@ -29,10 +29,7 @@ use mithril_common::{
CardanoImmutableDigester, DumbImmutableFileObserver, ImmutableDigester,
ImmutableFileObserver, ImmutableFileSystemObserver,
},
entities::{
CertificatePending, CompressionAlgorithm, Epoch, SignedEntityConfig,
SignedEntityTypeDiscriminants,
},
entities::{CertificatePending, CompressionAlgorithm, Epoch, SignedEntityTypeDiscriminants},
era::{
adapters::{EraReaderAdapterBuilder, EraReaderDummyAdapter},
EraChecker, EraMarker, EraReader, EraReaderAdapter, SupportedEra,
Expand Down Expand Up @@ -101,9 +98,6 @@ pub struct DependenciesBuilder {
/// Configuration parameters
pub configuration: Configuration,

/// Signed entity configuration
pub signed_entity_config: Option<SignedEntityConfig>,

/// SQLite database connection
pub sqlite_connection: Option<Arc<SqliteConnection>>,

Expand Down Expand Up @@ -246,7 +240,6 @@ impl DependenciesBuilder {
pub fn new(configuration: Configuration) -> Self {
Self {
configuration,
signed_entity_config: None,
sqlite_connection: None,
sqlite_connection_cardano_transaction_pool: None,
stake_store: None,
Expand Down Expand Up @@ -294,13 +287,15 @@ impl DependenciesBuilder {
}
}

/// Get the signed entity configuration
pub fn get_signed_entity_config(&mut self) -> Result<SignedEntityConfig> {
if self.signed_entity_config.is_none() {
self.signed_entity_config = Some(self.configuration.compute_signed_entity_config()?);
}
/// 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(self.signed_entity_config.clone().unwrap())
Ok(allowed_discriminants)
}

fn build_sqlite_connection(
Expand Down Expand Up @@ -584,8 +579,9 @@ impl DependenciesBuilder {
// Temporary fix, should be removed
// Replace empty JSON values '{}' injected with Migration #28
let cardano_signing_config = self
.get_signed_entity_config()?
.cardano_transactions_signing_config;
.configuration
.cardano_transactions_signing_config
.clone();
#[allow(deprecated)]
epoch_settings_store
.replace_cardano_signing_config_empty_values(cardano_signing_config)?;
Expand Down Expand Up @@ -1220,13 +1216,16 @@ impl DependenciesBuilder {
async fn build_epoch_service(&mut self) -> Result<EpochServiceWrapper> {
let verification_key_store = self.get_verification_key_store().await?;
let epoch_settings_storer = self.get_epoch_settings_storer().await?;

let epoch_settings = self.get_epoch_settings_configuration()?;
let network = self.configuration.get_network()?;
let allowed_discriminants = self.get_allowed_signed_entity_types_discriminants()?;

let epoch_service = Arc::new(RwLock::new(MithrilEpochService::new(
epoch_settings,
epoch_settings_storer,
verification_key_store,
network,
allowed_discriminants,
)));

Ok(epoch_service)
Expand Down Expand Up @@ -1333,8 +1332,9 @@ impl DependenciesBuilder {
let epoch_settings = AggregatorEpochSettings {
protocol_parameters: self.configuration.protocol_parameters.clone(),
cardano_transactions_signing_config: self
.get_signed_entity_config()?
.cardano_transactions_signing_config,
.configuration
.cardano_transactions_signing_config
.clone(),
};
Ok(epoch_settings)
}
Expand All @@ -1343,7 +1343,7 @@ impl DependenciesBuilder {
pub async fn build_dependency_container(&mut self) -> Result<DependencyContainer> {
let dependency_manager = DependencyContainer {
config: self.configuration.clone(),
signed_entity_config: self.get_signed_entity_config()?,
allowed_discriminants: self.get_allowed_signed_entity_types_discriminants()?,
sqlite_connection: self.get_sqlite_connection().await?,
sqlite_connection_cardano_transaction_pool: self
.get_sqlite_connection_cardano_transaction_pool()
Expand Down Expand Up @@ -1400,10 +1400,7 @@ impl DependenciesBuilder {
pub async fn create_aggregator_runner(&mut self) -> Result<AggregatorRuntime> {
let dependency_container = Arc::new(self.build_dependency_container().await?);

let config = AggregatorConfig::new(
Duration::from_millis(self.configuration.run_interval),
self.get_signed_entity_config()?,
);
let config = AggregatorConfig::new(Duration::from_millis(self.configuration.run_interval));
let runtime = AggregatorRuntime::new(
config,
None,
Expand Down Expand Up @@ -1432,8 +1429,7 @@ impl DependenciesBuilder {
&mut self,
) -> Result<Arc<CardanoTransactionsPreloader>> {
let activation = self
.get_signed_entity_config()?
.list_allowed_signed_entity_types_discriminants()
.get_allowed_signed_entity_types_discriminants()?
.contains(&SignedEntityTypeDiscriminants::CardanoTransactions);
let cardano_transactions_preloader = CardanoTransactionsPreloader::new(
self.get_signed_entity_lock().await?,
Expand Down
25 changes: 12 additions & 13 deletions mithril-aggregator/src/dependency_injection/containers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use mithril_persistence::sqlite::SqliteConnectionPool;
use std::sync::Arc;
use std::{collections::BTreeSet, sync::Arc};
use tokio::sync::RwLock;

use mithril_common::{
Expand All @@ -10,7 +9,7 @@ use mithril_common::{
crypto_helper::ProtocolGenesisVerifier,
digesters::{ImmutableDigester, ImmutableFileObserver},
entities::{
CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, SignedEntityConfig,
CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, SignedEntityTypeDiscriminants,
SignerWithStake, StakeDistribution,
},
era::{EraChecker, EraReader},
Expand All @@ -19,7 +18,10 @@ use mithril_common::{
test_utils::MithrilFixture,
TickerService,
};
use mithril_persistence::{sqlite::SqliteConnection, store::StakeStorer};
use mithril_persistence::{
sqlite::{SqliteConnection, SqliteConnectionPool},
store::StakeStorer,
};

use crate::{
configuration::*,
Expand Down Expand Up @@ -48,8 +50,8 @@ pub struct DependencyContainer {
/// Configuration structure.
pub config: Configuration,

/// Signed entity configuration.
pub signed_entity_config: SignedEntityConfig,
/// List of signed entity discriminants that are allowed to be processed
pub allowed_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,

/// SQLite database connection
///
Expand Down Expand Up @@ -194,19 +196,16 @@ impl DependencyContainer {
///
/// Fill the stores of a [DependencyManager] in a way to simulate an aggregator state
/// using the data from a precomputed fixture.
pub async fn init_state_from_fixture(
&self,
fixture: &MithrilFixture,
cardano_transactions_signing_config: &CardanoTransactionsSigningConfig,
target_epochs: &[Epoch],
) {
pub async fn init_state_from_fixture(&self, fixture: &MithrilFixture, target_epochs: &[Epoch]) {
for epoch in target_epochs {
self.epoch_settings_storer
.save_epoch_settings(
*epoch,
AggregatorEpochSettings {
protocol_parameters: fixture.protocol_parameters(),
cardano_transactions_signing_config: cardano_transactions_signing_config
cardano_transactions_signing_config: self
.config
.cardano_transactions_signing_config
.clone(),
},
)
Expand Down
Loading
Loading