Skip to content

Commit 4b89712

Browse files
committed
feature(signer): use Mithril Network configuration Provider instead of Aggregator client for the preloader checker
1 parent e7f31ca commit 4b89712

File tree

2 files changed

+72
-61
lines changed

2 files changed

+72
-61
lines changed

mithril-signer/src/dependency_injection/builder.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ use mithril_persistence::database::repository::CardanoTransactionRepository;
4141
use mithril_persistence::database::{ApplicationNodeType, SqlMigration};
4242
use mithril_persistence::sqlite::{ConnectionBuilder, SqliteConnection, SqliteConnectionPool};
4343

44-
use mithril_protocol_config::http_client::http_impl::HttpMithrilNetworkConfigurationProvider;
44+
use mithril_protocol_config::{
45+
http_client::http_impl::HttpMithrilNetworkConfigurationProvider,
46+
interface::MithrilNetworkConfigurationProvider,
47+
};
4548

4649
#[cfg(feature = "future_dmq")]
4750
use mithril_dmq::{DmqMessageBuilder, DmqPublisherClientPallas};
@@ -375,8 +378,16 @@ impl<'a> DependenciesBuilder<'a> {
375378
self.root_logger(),
376379
));
377380
let metrics_service = Arc::new(MetricsService::new(self.root_logger())?);
378-
let preloader_activation =
379-
CardanoTransactionsPreloaderActivationSigner::new(aggregator_client.clone());
381+
let network_configuration_service: Arc<dyn MithrilNetworkConfigurationProvider> =
382+
Arc::new(HttpMithrilNetworkConfigurationProvider::new(
383+
self.config.aggregator_endpoint.clone(),
384+
self.config.relay_endpoint.clone(),
385+
api_version_provider.clone(),
386+
self.root_logger(),
387+
));
388+
let preloader_activation = CardanoTransactionsPreloaderActivationSigner::new(
389+
network_configuration_service.clone(),
390+
);
380391
let cardano_transactions_preloader = Arc::new(CardanoTransactionsPreloader::new(
381392
signed_entity_type_lock.clone(),
382393
preloader_transactions_importer,
@@ -505,13 +516,6 @@ impl<'a> DependenciesBuilder<'a> {
505516
self.root_logger(),
506517
));
507518

508-
let network_configuration_service = Arc::new(HttpMithrilNetworkConfigurationProvider::new(
509-
self.config.aggregator_endpoint.clone(),
510-
self.config.relay_endpoint.clone(),
511-
api_version_provider.clone(),
512-
self.root_logger(),
513-
));
514-
515519
let services = SignerDependencyContainer {
516520
ticker_service,
517521
certificate_handler: aggregator_client,

mithril-signer/src/services/cardano_transactions/preloader_checker.rs

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@ use anyhow::Context;
44
use async_trait::async_trait;
55

66
use mithril_common::{StdResult, entities::SignedEntityTypeDiscriminants};
7+
use mithril_protocol_config::interface::MithrilNetworkConfigurationProvider;
78
use mithril_signed_entity_preloader::CardanoTransactionsPreloaderChecker;
8-
9-
use crate::services::AggregatorClient;
10-
119
/// CardanoTransactionsPreloaderActivationSigner
1210
pub struct CardanoTransactionsPreloaderActivationSigner {
13-
aggregator_client: Arc<dyn AggregatorClient>,
11+
network_configuration_provider: Arc<dyn MithrilNetworkConfigurationProvider>,
1412
}
1513

1614
impl CardanoTransactionsPreloaderActivationSigner {
1715
/// Create a new instance of `CardanoTransactionsPreloaderActivationSigner`
18-
pub fn new(aggregator_client: Arc<dyn AggregatorClient>) -> Self {
19-
Self { aggregator_client }
16+
pub fn new(
17+
network_configuration_provider: Arc<dyn MithrilNetworkConfigurationProvider>,
18+
) -> Self {
19+
Self {
20+
network_configuration_provider,
21+
}
2022
}
2123
}
2224

2325
#[async_trait]
2426
impl CardanoTransactionsPreloaderChecker for CardanoTransactionsPreloaderActivationSigner {
2527
async fn is_activated(&self) -> StdResult<bool> {
26-
let message = self
27-
.aggregator_client
28-
.retrieve_aggregator_features()
28+
let configuration = self
29+
.network_configuration_provider
30+
.get()
2931
.await
30-
.with_context(|| "An error occurred while calling the Aggregator")?;
32+
.context("An error occurred while retrieving Mithril network configuration")?;
3133

32-
let activated_signed_entity_types = message.capabilities.signed_entity_types;
34+
let activated_signed_entity_types = configuration.available_signed_entity_types;
3335

3436
Ok(activated_signed_entity_types
3537
.contains(&SignedEntityTypeDiscriminants::CardanoTransactions))
@@ -39,32 +41,38 @@ impl CardanoTransactionsPreloaderChecker for CardanoTransactionsPreloaderActivat
3941
#[cfg(test)]
4042
mod tests {
4143
use anyhow::anyhow;
44+
use mithril_common::{entities::SignedEntityTypeDiscriminants, test::double::Dummy};
45+
use mithril_protocol_config::model::MithrilNetworkConfiguration;
46+
use mockall::mock;
4247
use std::collections::BTreeSet;
4348

44-
use mithril_common::{
45-
entities::SignedEntityTypeDiscriminants, messages::AggregatorFeaturesMessage,
46-
test::double::Dummy,
47-
};
49+
use super::*;
4850

49-
use crate::services::{AggregatorClientError, MockAggregatorClient};
51+
mock! {
52+
pub MithrilNetworkConfigurationProvider {}
5053

51-
use super::*;
54+
#[async_trait]
55+
impl MithrilNetworkConfigurationProvider for MithrilNetworkConfigurationProvider {
56+
async fn get(&self) -> StdResult<MithrilNetworkConfiguration>;
57+
}
58+
}
5259

5360
#[tokio::test]
5461
async fn preloader_activation_state_activate_preloader_when_cardano_transactions_not_in_aggregator_capabilities()
5562
{
56-
let mut aggregator_client = MockAggregatorClient::new();
57-
aggregator_client
58-
.expect_retrieve_aggregator_features()
59-
.times(1)
60-
.returning(|| {
61-
let mut message = AggregatorFeaturesMessage::dummy();
62-
message.capabilities.signed_entity_types =
63-
BTreeSet::from([SignedEntityTypeDiscriminants::MithrilStakeDistribution]);
64-
Ok(message)
65-
});
66-
let preloader =
67-
CardanoTransactionsPreloaderActivationSigner::new(Arc::new(aggregator_client));
63+
let mut network_configuration_provider = MockMithrilNetworkConfigurationProvider::new();
64+
network_configuration_provider.expect_get().times(1).returning(|| {
65+
Ok(MithrilNetworkConfiguration {
66+
available_signed_entity_types: BTreeSet::from([
67+
SignedEntityTypeDiscriminants::MithrilStakeDistribution,
68+
]),
69+
..Dummy::dummy()
70+
})
71+
});
72+
73+
let preloader = CardanoTransactionsPreloaderActivationSigner::new(Arc::new(
74+
network_configuration_provider,
75+
));
6876

6977
let is_activated = preloader.is_activated().await.unwrap();
7078

@@ -74,18 +82,19 @@ mod tests {
7482
#[tokio::test]
7583
async fn preloader_activation_state_activate_preloader_when_cardano_transactions_in_aggregator_capabilities()
7684
{
77-
let mut aggregator_client = MockAggregatorClient::new();
78-
aggregator_client
79-
.expect_retrieve_aggregator_features()
80-
.times(1)
81-
.returning(|| {
82-
let mut message = AggregatorFeaturesMessage::dummy();
83-
message.capabilities.signed_entity_types =
84-
BTreeSet::from([SignedEntityTypeDiscriminants::CardanoTransactions]);
85-
Ok(message)
86-
});
87-
let preloader =
88-
CardanoTransactionsPreloaderActivationSigner::new(Arc::new(aggregator_client));
85+
let mut network_configuration_provider = MockMithrilNetworkConfigurationProvider::new();
86+
network_configuration_provider.expect_get().times(1).returning(|| {
87+
Ok(MithrilNetworkConfiguration {
88+
available_signed_entity_types: BTreeSet::from([
89+
SignedEntityTypeDiscriminants::CardanoTransactions,
90+
]),
91+
..Dummy::dummy()
92+
})
93+
});
94+
95+
let preloader = CardanoTransactionsPreloaderActivationSigner::new(Arc::new(
96+
network_configuration_provider,
97+
));
8998

9099
let is_activated = preloader.is_activated().await.unwrap();
91100

@@ -94,17 +103,15 @@ mod tests {
94103

95104
#[tokio::test]
96105
async fn preloader_activation_state_activate_preloader_when_aggregator_call_fails() {
97-
let mut aggregator_client = MockAggregatorClient::new();
98-
aggregator_client
99-
.expect_retrieve_aggregator_features()
106+
let mut network_configuration_provider = MockMithrilNetworkConfigurationProvider::new();
107+
network_configuration_provider
108+
.expect_get()
100109
.times(1)
101-
.returning(|| {
102-
Err(AggregatorClientError::RemoteServerTechnical(anyhow!(
103-
"Aggregator call failed"
104-
)))
105-
});
106-
let preloader =
107-
CardanoTransactionsPreloaderActivationSigner::new(Arc::new(aggregator_client));
110+
.returning(|| Err(anyhow!("Aggregator call failure")));
111+
112+
let preloader = CardanoTransactionsPreloaderActivationSigner::new(Arc::new(
113+
network_configuration_provider,
114+
));
108115

109116
preloader
110117
.is_activated()

0 commit comments

Comments
 (0)