diff --git a/Cargo.lock b/Cargo.lock index 4b3025d12af..ea77e0c8c85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3853,7 +3853,7 @@ dependencies = [ [[package]] name = "mithril-signer" -version = "0.2.174" +version = "0.2.175" dependencies = [ "anyhow", "async-trait", diff --git a/mithril-signer/Cargo.toml b/mithril-signer/Cargo.toml index cfea892d5f3..fbc4723ff89 100644 --- a/mithril-signer/Cargo.toml +++ b/mithril-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signer" -version = "0.2.174" +version = "0.2.175" description = "A Mithril Signer" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-signer/benches/mktree_store_sqlite.rs b/mithril-signer/benches/mktree_store_sqlite.rs index 3c848199a0d..804e882f08f 100644 --- a/mithril-signer/benches/mktree_store_sqlite.rs +++ b/mithril-signer/benches/mktree_store_sqlite.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use mithril_common::crypto_helper::{MKTree, MKTreeNode}; -use mithril_signer::MKTreeStoreSqlite; +use mithril_signer::store::MKTreeStoreSqlite; // Shortcuts for magnitudes: K for thousand, M for million const K: usize = 1_000; diff --git a/mithril-signer/src/database/repository/cardano_transaction_repository.rs b/mithril-signer/src/database/repository/cardano_transaction_repository.rs index 9d2c039c255..9119e0711d1 100644 --- a/mithril-signer/src/database/repository/cardano_transaction_repository.rs +++ b/mithril-signer/src/database/repository/cardano_transaction_repository.rs @@ -9,7 +9,7 @@ use mithril_common::entities::{ use mithril_common::StdResult; use mithril_persistence::database::repository::CardanoTransactionRepository; -use crate::{HighestTransactionBlockNumberGetter, TransactionPruner, TransactionStore}; +use crate::services::{HighestTransactionBlockNumberGetter, TransactionPruner, TransactionStore}; #[async_trait] impl TransactionStore for CardanoTransactionRepository { diff --git a/mithril-signer/src/runtime/signer_services.rs b/mithril-signer/src/dependency_injection/builder.rs similarity index 75% rename from mithril-signer/src/runtime/signer_services.rs rename to mithril-signer/src/dependency_injection/builder.rs index 90ac1dbee0d..d806df4b1c5 100644 --- a/mithril-signer/src/runtime/signer_services.rs +++ b/mithril-signer/src/dependency_injection/builder.rs @@ -1,78 +1,71 @@ +use std::fs; +use std::sync::Arc; +use std::time::Duration; + use anyhow::{anyhow, Context}; -use async_trait::async_trait; -use std::{fs, sync::Arc, time::Duration}; use tokio::sync::Mutex; -use mithril_common::{ - api_version::APIVersionProvider, - cardano_block_scanner::CardanoBlockScanner, - cardano_transactions_preloader::CardanoTransactionsPreloader, - chain_observer::{CardanoCliRunner, ChainObserver, ChainObserverBuilder, ChainObserverType}, - chain_reader::PallasChainReader, - crypto_helper::{OpCert, ProtocolPartyId, SerDeShelleyFileFormat}, - digesters::{ - cache::{ImmutableFileDigestCacheProvider, JsonImmutableFileDigestCacheProviderBuilder}, - CardanoImmutableDigester, ImmutableDigester, ImmutableFileObserver, - ImmutableFileSystemObserver, - }, - era::{EraChecker, EraReader}, - signable_builder::{ - CardanoImmutableFilesFullSignableBuilder, CardanoStakeDistributionSignableBuilder, - CardanoTransactionsSignableBuilder, MithrilSignableBuilderService, - MithrilStakeDistributionSignableBuilder, SignableBuilderService, - }, - signed_entity_type_lock::SignedEntityTypeLock, - MithrilTickerService, StdResult, TickerService, +use mithril_common::api_version::APIVersionProvider; +use mithril_common::cardano_block_scanner::CardanoBlockScanner; +use mithril_common::cardano_transactions_preloader::CardanoTransactionsPreloader; +use mithril_common::chain_observer::{ + CardanoCliRunner, ChainObserver, ChainObserverBuilder, ChainObserverType, +}; +use mithril_common::chain_reader::PallasChainReader; +use mithril_common::crypto_helper::{OpCert, ProtocolPartyId, SerDeShelleyFileFormat}; +use mithril_common::digesters::cache::{ + ImmutableFileDigestCacheProvider, JsonImmutableFileDigestCacheProviderBuilder, }; -use mithril_persistence::{ - database::{repository::CardanoTransactionRepository, ApplicationNodeType, SqlMigration}, - sqlite::{ConnectionBuilder, SqliteConnection, SqliteConnectionPool}, - store::{adapter::SQLiteAdapter, StakeStore}, +use mithril_common::digesters::{ + CardanoImmutableDigester, ImmutableFileObserver, ImmutableFileSystemObserver, }; +use mithril_common::era::{EraChecker, EraReader}; +use mithril_common::signable_builder::{ + CardanoImmutableFilesFullSignableBuilder, CardanoStakeDistributionSignableBuilder, + CardanoTransactionsSignableBuilder, MithrilSignableBuilderService, + MithrilStakeDistributionSignableBuilder, +}; +use mithril_common::signed_entity_type_lock::SignedEntityTypeLock; +use mithril_common::{MithrilTickerService, StdResult, TickerService}; -use crate::{ - aggregator_client::AggregatorClient, metrics::MetricsService, single_signer::SingleSigner, +use mithril_persistence::database::repository::CardanoTransactionRepository; +use mithril_persistence::database::{ApplicationNodeType, SqlMigration}; +use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnection, SqliteConnectionPool}; +use mithril_persistence::store::adapter::SQLiteAdapter; +use mithril_persistence::store::StakeStore; + +use crate::dependency_injection::SignerDependencyContainer; +use crate::services::{ AggregatorHTTPClient, CardanoTransactionsImporter, - CardanoTransactionsPreloaderActivationSigner, Configuration, MKTreeStoreSqlite, - MithrilSingleSigner, ProtocolInitializerStore, ProtocolInitializerStorer, SignerUpkeepService, + CardanoTransactionsPreloaderActivationSigner, MithrilSingleSigner, SignerUpkeepService, TransactionsImporterByChunk, TransactionsImporterWithPruner, TransactionsImporterWithVacuum, - UpkeepService, HTTP_REQUEST_TIMEOUT_DURATION, SQLITE_FILE, SQLITE_FILE_CARDANO_TRANSACTION, +}; +use crate::store::{MKTreeStoreSqlite, ProtocolInitializerStore}; +use crate::{ + Configuration, MetricsService, HTTP_REQUEST_TIMEOUT_DURATION, SQLITE_FILE, + SQLITE_FILE_CARDANO_TRANSACTION, }; -type StakeStoreService = Arc; -type CertificateHandlerService = Arc; -type ChainObserverService = Arc; -type DigesterService = Arc; -type SingleSignerService = Arc; -type TimePointProviderService = Arc; -type ProtocolInitializerStoreService = Arc; - -/// The ServiceBuilder is intended to manage Services instance creation. +/// The `DependenciesBuilder` is intended to manage Services instance creation. +/// /// The goal of this is to put all this code out of the way of business code. -#[async_trait] -pub trait ServiceBuilder { - /// Create a SignerService instance. - async fn build(&self) -> StdResult; -} - -/// Create a SignerService instance for Production environment. -pub struct ProductionServiceBuilder<'a> { +pub struct DependenciesBuilder<'a> { config: &'a Configuration, - chain_observer_builder: fn(&Configuration) -> StdResult, + chain_observer_builder: fn(&Configuration) -> StdResult>, immutable_file_observer_builder: fn(&Configuration) -> StdResult>, } -impl<'a> ProductionServiceBuilder<'a> { - /// Create a new production service builder. +impl<'a> DependenciesBuilder<'a> { + /// Create a new `DependenciesBuilder`. pub fn new(config: &'a Configuration) -> Self { - let chain_observer_builder: fn(&Configuration) -> StdResult = + let chain_observer_builder: fn(&Configuration) -> StdResult> = |config: &Configuration| { let chain_observer_type = ChainObserverType::Pallas; let cardano_cli_path = &config.cardano_cli_path; let cardano_node_socket_path = &config.cardano_node_socket_path; let cardano_network = &config.get_network().with_context(|| { - "Production Service Builder can not get Cardano network while building the chain observer" + "Dependencies Builder can not get Cardano network while building the chain observer" })?; let cardano_cli_runner = &CardanoCliRunner::new( cardano_cli_path.to_owned(), @@ -121,7 +114,7 @@ impl<'a> ProductionServiceBuilder<'a> { /// Override default chain observer builder. pub fn override_chain_observer_builder( &mut self, - builder: fn(&Configuration) -> StdResult, + builder: fn(&Configuration) -> StdResult>, ) -> &mut Self { self.chain_observer_builder = builder; @@ -182,12 +175,9 @@ impl<'a> ProductionServiceBuilder<'a> { Ok(connection) } -} -#[async_trait] -impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> { - /// Build a Services for the Production environment. - async fn build(&self) -> StdResult { + /// Build dependencies for the Production environment. + pub async fn build(&self) -> StdResult { if !self.config.data_stores_directory.exists() { fs::create_dir_all(self.config.data_stores_directory.clone()).with_context(|| { format!( @@ -331,7 +321,7 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> { cardano_transactions_builder, cardano_stake_distribution_signable_builder, )); - let metrics_service = Arc::new(MetricsService::new().unwrap()); + let metrics_service = Arc::new(MetricsService::new()?); let preloader_activation = CardanoTransactionsPreloaderActivationSigner::new(aggregator_client.clone()); let cardano_transactions_preloader = Arc::new(CardanoTransactionsPreloader::new( @@ -349,7 +339,7 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> { slog_scope::logger(), )); - let services = SignerServices { + let services = SignerDependencyContainer { ticker_service, certificate_handler: aggregator_client, chain_observer, @@ -371,54 +361,6 @@ impl<'a> ServiceBuilder for ProductionServiceBuilder<'a> { } } -/// This structure groups all the services required by the state machine. -pub struct SignerServices { - /// Time point provider service - pub ticker_service: TimePointProviderService, - - /// Stake store service - pub stake_store: StakeStoreService, - - /// Certificate handler service - pub certificate_handler: CertificateHandlerService, - - /// Chain Observer service - pub chain_observer: ChainObserverService, - - /// Digester service - pub digester: DigesterService, - - /// SingleSigner service - pub single_signer: SingleSignerService, - - /// ProtocolInitializer store - pub protocol_initializer_store: ProtocolInitializerStoreService, - - /// Era checker service - pub era_checker: Arc, - - /// Era reader service - pub era_reader: Arc, - - /// API version provider - pub api_version_provider: Arc, - - /// Signable Builder Service - pub signable_builder_service: Arc, - - /// Metrics service - pub metrics_service: Arc, - - /// Signed entity type lock - pub signed_entity_type_lock: Arc, - - /// Cardano transactions preloader - pub cardano_transactions_preloader: Arc, - - /// Upkeep service - pub upkeep_service: Arc, -} - #[cfg(test)] mod tests { use std::path::PathBuf; @@ -443,7 +385,7 @@ mod tests { }; assert!(!stores_dir.exists()); - let chain_observer_builder: fn(&Configuration) -> StdResult = + let chain_observer_builder: fn(&Configuration) -> StdResult> = |_config| Ok(Arc::new(FakeObserver::new(Some(TimePoint::dummy())))); let immutable_file_observer_builder: fn( &Configuration, @@ -451,8 +393,8 @@ mod tests { -> StdResult> = |_config: &Configuration| Ok(Arc::new(DumbImmutableFileObserver::default())); - let mut service_builder = ProductionServiceBuilder::new(&config); - service_builder + let mut dependencies_builder = DependenciesBuilder::new(&config); + dependencies_builder .override_chain_observer_builder(chain_observer_builder) .override_immutable_file_observer_builder(immutable_file_observer_builder) .build() diff --git a/mithril-signer/src/dependency_injection/containers.rs b/mithril-signer/src/dependency_injection/containers.rs new file mode 100644 index 00000000000..c5d25df41e0 --- /dev/null +++ b/mithril-signer/src/dependency_injection/containers.rs @@ -0,0 +1,71 @@ +use std::sync::Arc; + +use mithril_common::api_version::APIVersionProvider; +use mithril_common::cardano_transactions_preloader::CardanoTransactionsPreloader; +use mithril_common::chain_observer::ChainObserver; +use mithril_common::digesters::ImmutableDigester; +use mithril_common::era::{EraChecker, EraReader}; +use mithril_common::signable_builder::SignableBuilderService; +use mithril_common::signed_entity_type_lock::SignedEntityTypeLock; +use mithril_common::TickerService; +use mithril_persistence::store::StakeStore; + +use crate::services::{AggregatorClient, SingleSigner, UpkeepService}; +use crate::store::ProtocolInitializerStorer; +use crate::MetricsService; + +type StakeStoreService = Arc; +type CertificateHandlerService = Arc; +type ChainObserverService = Arc; +type DigesterService = Arc; +type SingleSignerService = Arc; +type TimePointProviderService = Arc; +type ProtocolInitializerStoreService = Arc; + +/// This structure groups all the dependencies required by the state machine. +pub struct SignerDependencyContainer { + /// Time point provider service + pub ticker_service: TimePointProviderService, + + /// Stake store service + pub stake_store: StakeStoreService, + + /// Certificate handler service + pub certificate_handler: CertificateHandlerService, + + /// Chain Observer service + pub chain_observer: ChainObserverService, + + /// Digester service + pub digester: DigesterService, + + /// SingleSigner service + pub single_signer: SingleSignerService, + + /// ProtocolInitializer store + pub protocol_initializer_store: ProtocolInitializerStoreService, + + /// Era checker service + pub era_checker: Arc, + + /// Era reader service + pub era_reader: Arc, + + /// API version provider + pub api_version_provider: Arc, + + /// Signable Builder Service + pub signable_builder_service: Arc, + + /// Metrics service + pub metrics_service: Arc, + + /// Signed entity type lock + pub signed_entity_type_lock: Arc, + + /// Cardano transactions preloader + pub cardano_transactions_preloader: Arc, + + /// Upkeep service + pub upkeep_service: Arc, +} diff --git a/mithril-signer/src/dependency_injection/mod.rs b/mithril-signer/src/dependency_injection/mod.rs new file mode 100644 index 00000000000..8153527e641 --- /dev/null +++ b/mithril-signer/src/dependency_injection/mod.rs @@ -0,0 +1,20 @@ +//! Dependency injection module. +//! +//! This module provides tools to initialize and share resources and services +//! amongst different threads. +//! +//! It takes all its inputs from the configuration which should combine inputs from: +//! +//! * environment +//! * command line +//! * configuration files +//! * default values +//! +//! The Builder ensure every service has required dependencies to build and +//! provide services containers for each sub process. + +mod builder; +mod containers; + +pub use builder::*; +pub use containers::*; diff --git a/mithril-signer/src/lib.rs b/mithril-signer/src/lib.rs index f77311c7e7b..f68b90916f5 100644 --- a/mithril-signer/src/lib.rs +++ b/mithril-signer/src/lib.rs @@ -6,40 +6,21 @@ //! See the [Mithril documentation](https://mithril.network/doc/manual/developer-docs/nodes/mithril-signer) //! for more information on how it works. -mod aggregator_client; -mod cardano_transactions_importer; -mod cardano_transactions_preloader_checker; mod configuration; pub mod database; +pub mod dependency_injection; mod message_adapters; pub mod metrics; -mod mktree_store_sqlite; -mod protocol_initializer_store; mod runtime; -mod single_signer; -mod transactions_importer_by_chunk; -mod transactions_importer_with_pruner; -mod transactions_importer_with_vacuum; -mod upkeep_service; +pub mod services; +pub mod store; -#[cfg(test)] -pub use aggregator_client::dumb::DumbAggregatorClient; -pub use aggregator_client::*; -pub use cardano_transactions_importer::*; -pub use cardano_transactions_preloader_checker::*; pub use configuration::{Configuration, DefaultConfiguration}; pub use message_adapters::{ FromEpochSettingsAdapter, FromPendingCertificateMessageAdapter, ToRegisterSignerMessageAdapter, }; pub use metrics::*; -pub use mktree_store_sqlite::*; -pub use protocol_initializer_store::{ProtocolInitializerStore, ProtocolInitializerStorer}; pub use runtime::*; -pub use single_signer::*; -pub use transactions_importer_by_chunk::*; -pub use transactions_importer_with_pruner::*; -pub use transactions_importer_with_vacuum::*; -pub use upkeep_service::*; /// HTTP request timeout duration in milliseconds const HTTP_REQUEST_TIMEOUT_DURATION: u64 = 30000; diff --git a/mithril-signer/src/main.rs b/mithril-signer/src/main.rs index 79b7f41485b..cdd0b151ba4 100644 --- a/mithril-signer/src/main.rs +++ b/mithril-signer/src/main.rs @@ -15,9 +15,9 @@ use tokio::{ use mithril_common::StdResult; use mithril_doc::{Documenter, DocumenterDefault, GenerateDocCommands, StructDoc}; +use mithril_signer::dependency_injection::DependenciesBuilder; use mithril_signer::{ - Configuration, DefaultConfiguration, MetricsServer, ProductionServiceBuilder, ServiceBuilder, - SignerRunner, SignerState, StateMachine, + Configuration, DefaultConfiguration, MetricsServer, SignerRunner, SignerState, StateMachine, }; /// CLI args @@ -158,7 +158,7 @@ async fn main() -> StdResult<()> { .try_deserialize() .with_context(|| "configuration deserialize error")?; - let services = ProductionServiceBuilder::new(&config) + let services = DependenciesBuilder::new(&config) .build() .await .with_context(|| "services initialization error")?; diff --git a/mithril-signer/src/runtime/mod.rs b/mithril-signer/src/runtime/mod.rs index 288886248bb..a5e87f07ee1 100644 --- a/mithril-signer/src/runtime/mod.rs +++ b/mithril-signer/src/runtime/mod.rs @@ -1,9 +1,7 @@ mod error; mod runner; -mod signer_services; mod state_machine; pub use error::*; pub use runner::*; -pub use signer_services::*; pub use state_machine::*; diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 5ee99d16986..a1a77b6d879 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -14,9 +14,9 @@ use mithril_common::entities::{ use mithril_common::StdResult; use mithril_persistence::store::StakeStorer; -use crate::{Configuration, MithrilProtocolInitializerBuilder}; - -use super::signer_services::SignerServices; +use crate::dependency_injection::SignerDependencyContainer; +use crate::services::MithrilProtocolInitializerBuilder; +use crate::Configuration; /// This trait is mainly intended for mocking. #[async_trait] @@ -100,12 +100,12 @@ pub enum RunnerError { /// Controller methods for the Signer's state machine. pub struct SignerRunner { config: Configuration, - services: SignerServices, + services: SignerDependencyContainer, } impl SignerRunner { /// Create a new Runner instance. - pub fn new(config: Configuration, services: SignerServices) -> Self { + pub fn new(config: Configuration, services: SignerDependencyContainer) -> Self { Self { services, config } } } @@ -492,11 +492,12 @@ mod tests { use mockall::mock; use std::{path::Path, sync::Arc}; - use crate::{ - metrics::MetricsService, AggregatorClient, CardanoTransactionsImporter, - DumbAggregatorClient, MithrilSingleSigner, MockAggregatorClient, MockTransactionStore, - MockUpkeepService, ProtocolInitializerStore, SingleSigner, + use crate::metrics::MetricsService; + use crate::services::{ + AggregatorClient, CardanoTransactionsImporter, DumbAggregatorClient, MithrilSingleSigner, + MockAggregatorClient, MockTransactionStore, MockUpkeepService, SingleSigner, }; + use crate::store::ProtocolInitializerStore; use super::*; @@ -528,7 +529,7 @@ mod tests { } } - async fn init_services() -> SignerServices { + async fn init_services() -> SignerDependencyContainer { let adapter: MemoryAdapter = MemoryAdapter::new(None).unwrap(); let stake_distribution_signers = fake_data::signers_with_stakes(2); let party_id = stake_distribution_signers[1].party_id.clone(); @@ -596,7 +597,7 @@ mod tests { )); let upkeep_service = Arc::new(MockUpkeepService::new()); - SignerServices { + SignerDependencyContainer { stake_store, certificate_handler: Arc::new(DumbAggregatorClient::default()), chain_observer, @@ -619,7 +620,7 @@ mod tests { } async fn init_runner( - maybe_services: Option, + maybe_services: Option, maybe_config: Option, ) -> SignerRunner { SignerRunner::new( diff --git a/mithril-signer/src/aggregator_client.rs b/mithril-signer/src/services/aggregator_client.rs similarity index 100% rename from mithril-signer/src/aggregator_client.rs rename to mithril-signer/src/services/aggregator_client.rs diff --git a/mithril-signer/src/transactions_importer_by_chunk.rs b/mithril-signer/src/services/cardano_transactions/importer/importer_by_chunk.rs similarity index 100% rename from mithril-signer/src/transactions_importer_by_chunk.rs rename to mithril-signer/src/services/cardano_transactions/importer/importer_by_chunk.rs diff --git a/mithril-signer/src/transactions_importer_with_pruner.rs b/mithril-signer/src/services/cardano_transactions/importer/importer_with_pruner.rs similarity index 100% rename from mithril-signer/src/transactions_importer_with_pruner.rs rename to mithril-signer/src/services/cardano_transactions/importer/importer_with_pruner.rs diff --git a/mithril-signer/src/transactions_importer_with_vacuum.rs b/mithril-signer/src/services/cardano_transactions/importer/importer_with_vacuum.rs similarity index 100% rename from mithril-signer/src/transactions_importer_with_vacuum.rs rename to mithril-signer/src/services/cardano_transactions/importer/importer_with_vacuum.rs diff --git a/mithril-signer/src/services/cardano_transactions/importer/mod.rs b/mithril-signer/src/services/cardano_transactions/importer/mod.rs new file mode 100644 index 00000000000..8abf337edff --- /dev/null +++ b/mithril-signer/src/services/cardano_transactions/importer/mod.rs @@ -0,0 +1,9 @@ +mod importer_by_chunk; +mod importer_with_pruner; +mod importer_with_vacuum; +mod service; + +pub use importer_by_chunk::*; +pub use importer_with_pruner::*; +pub use importer_with_vacuum::*; +pub use service::*; diff --git a/mithril-signer/src/cardano_transactions_importer.rs b/mithril-signer/src/services/cardano_transactions/importer/service.rs similarity index 100% rename from mithril-signer/src/cardano_transactions_importer.rs rename to mithril-signer/src/services/cardano_transactions/importer/service.rs diff --git a/mithril-signer/src/services/cardano_transactions/mod.rs b/mithril-signer/src/services/cardano_transactions/mod.rs new file mode 100644 index 00000000000..233c280c562 --- /dev/null +++ b/mithril-signer/src/services/cardano_transactions/mod.rs @@ -0,0 +1,5 @@ +mod importer; +mod preloader_checker; + +pub use importer::*; +pub use preloader_checker::*; diff --git a/mithril-signer/src/cardano_transactions_preloader_checker.rs b/mithril-signer/src/services/cardano_transactions/preloader_checker.rs similarity index 97% rename from mithril-signer/src/cardano_transactions_preloader_checker.rs rename to mithril-signer/src/services/cardano_transactions/preloader_checker.rs index c26111728b5..74508423ff6 100644 --- a/mithril-signer/src/cardano_transactions_preloader_checker.rs +++ b/mithril-signer/src/services/cardano_transactions/preloader_checker.rs @@ -8,7 +8,7 @@ use mithril_common::{ entities::SignedEntityTypeDiscriminants, StdResult, }; -use crate::AggregatorClient; +use crate::services::AggregatorClient; /// CardanoTransactionsPreloaderActivationSigner pub struct CardanoTransactionsPreloaderActivationSigner { @@ -47,7 +47,7 @@ mod tests { entities::SignedEntityTypeDiscriminants, messages::AggregatorFeaturesMessage, }; - use crate::{AggregatorClientError, MockAggregatorClient}; + use crate::services::{AggregatorClientError, MockAggregatorClient}; use super::*; diff --git a/mithril-signer/src/services/mod.rs b/mithril-signer/src/services/mod.rs new file mode 100644 index 00000000000..c4a3fdc36ad --- /dev/null +++ b/mithril-signer/src/services/mod.rs @@ -0,0 +1,22 @@ +//! # Services +//! +//! This module regroups services. Services are adapters in charge of the different bounded contexts of the application: +//! +//! * Aggregator Client: communicate with the Aggregator +//! * Cardano Transactions: handle Cardano transactions (import, preload, etc.) +//! * Single Signer: create single signatures +//! * Upkeep: perform maintenance tasks +//! +//! Each service is defined by a public API (a trait) that is used in the controllers (runtimes). + +mod aggregator_client; +mod cardano_transactions; +mod single_signer; +mod upkeep_service; + +#[cfg(test)] +pub use aggregator_client::dumb::DumbAggregatorClient; +pub use aggregator_client::*; +pub use cardano_transactions::*; +pub use single_signer::*; +pub use upkeep_service::*; diff --git a/mithril-signer/src/single_signer.rs b/mithril-signer/src/services/single_signer.rs similarity index 100% rename from mithril-signer/src/single_signer.rs rename to mithril-signer/src/services/single_signer.rs diff --git a/mithril-signer/src/upkeep_service.rs b/mithril-signer/src/services/upkeep_service.rs similarity index 100% rename from mithril-signer/src/upkeep_service.rs rename to mithril-signer/src/services/upkeep_service.rs diff --git a/mithril-signer/src/mktree_store_sqlite.rs b/mithril-signer/src/store/mktree_store_sqlite.rs similarity index 100% rename from mithril-signer/src/mktree_store_sqlite.rs rename to mithril-signer/src/store/mktree_store_sqlite.rs diff --git a/mithril-signer/src/store/mod.rs b/mithril-signer/src/store/mod.rs new file mode 100644 index 00000000000..ebcd46647c9 --- /dev/null +++ b/mithril-signer/src/store/mod.rs @@ -0,0 +1,7 @@ +//! Alternative storage backends when relational database capabilities are not needed. + +mod mktree_store_sqlite; +mod protocol_initializer_store; + +pub use mktree_store_sqlite::*; +pub use protocol_initializer_store::*; diff --git a/mithril-signer/src/protocol_initializer_store.rs b/mithril-signer/src/store/protocol_initializer_store.rs similarity index 100% rename from mithril-signer/src/protocol_initializer_store.rs rename to mithril-signer/src/store/protocol_initializer_store.rs diff --git a/mithril-signer/tests/test_extensions/certificate_handler.rs b/mithril-signer/tests/test_extensions/certificate_handler.rs index 7e24411c400..6a073a132db 100644 --- a/mithril-signer/tests/test_extensions/certificate_handler.rs +++ b/mithril-signer/tests/test_extensions/certificate_handler.rs @@ -11,7 +11,7 @@ use mithril_common::{ test_utils::fake_data, MithrilTickerService, TickerService, }; -use mithril_signer::{AggregatorClient, AggregatorClientError}; +use mithril_signer::services::{AggregatorClient, AggregatorClientError}; use tokio::sync::RwLock; pub struct FakeAggregator { diff --git a/mithril-signer/tests/test_extensions/state_machine_tester.rs b/mithril-signer/tests/test_extensions/state_machine_tester.rs index c5bc6f40d84..54d8a05cef3 100644 --- a/mithril-signer/tests/test_extensions/state_machine_tester.rs +++ b/mithril-signer/tests/test_extensions/state_machine_tester.rs @@ -34,10 +34,13 @@ use mithril_persistence::{ store::{StakeStore, StakeStorer}, }; use mithril_signer::{ - metrics::*, AggregatorClient, CardanoTransactionsImporter, Configuration, MKTreeStoreSqlite, - MetricsService, MithrilSingleSigner, ProductionServiceBuilder, ProtocolInitializerStore, - ProtocolInitializerStorer, RuntimeError, SignerRunner, SignerServices, SignerState, - SignerUpkeepService, StateMachine, + dependency_injection::{DependenciesBuilder, SignerDependencyContainer}, + metrics::*, + services::{ + AggregatorClient, CardanoTransactionsImporter, MithrilSingleSigner, SignerUpkeepService, + }, + store::{MKTreeStoreSqlite, ProtocolInitializerStore, ProtocolInitializerStorer}, + Configuration, MetricsService, RuntimeError, SignerRunner, SignerState, StateMachine, }; use super::FakeAggregator; @@ -94,9 +97,9 @@ impl StateMachineTester { let selected_signer_party_id = selected_signer_with_stake.party_id.clone(); let config = Configuration::new_sample(&selected_signer_party_id); - let production_service_builder = ProductionServiceBuilder::new(&config); + let dependencies_builder = DependenciesBuilder::new(&config); let sqlite_connection = Arc::new( - production_service_builder + dependencies_builder .build_sqlite_connection( ":memory:", mithril_signer::database::migration::get_migrations(), @@ -104,7 +107,7 @@ impl StateMachineTester { .await .unwrap(), ); - let transaction_sqlite_connection = production_service_builder + let transaction_sqlite_connection = dependencies_builder .build_sqlite_connection( ":memory:", mithril_persistence::database::cardano_transaction_migration::get_migrations(), @@ -226,7 +229,7 @@ impl StateMachineTester { slog_scope::logger(), )); - let services = SignerServices { + let services = SignerDependencyContainer { certificate_handler: certificate_handler.clone(), ticker_service: ticker_service.clone(), chain_observer: chain_observer.clone(),