Skip to content

Commit ef41854

Browse files
authored
Merge pull request #2081 from input-output-hk/djo/aggregator/simplify_config_usages
Streamline configurations usage in aggregator
2 parents 38ff571 + c6b9db6 commit ef41854

18 files changed

+607
-410
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.5.98"
3+
version = "0.5.99"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ use crate::{
6363
},
6464
entities::AggregatorEpochSettings,
6565
event_store::{EventMessage, EventStore, TransmitterService},
66-
http_server::routes::router,
66+
http_server::routes::{
67+
router,
68+
router::{RouterConfig, RouterState},
69+
},
6770
services::{
6871
AggregatorSignableSeedBuilder, AggregatorUpkeepService, BufferedCertifierService,
6972
CardanoTransactionsImporter, CertifierService, MessageService, MithrilCertifierService,
@@ -1405,9 +1408,9 @@ impl DependenciesBuilder {
14051408

14061409
/// Return an unconfigured [DependencyContainer]
14071410
pub async fn build_dependency_container(&mut self) -> Result<DependencyContainer> {
1411+
#[allow(deprecated)]
14081412
let dependency_manager = DependencyContainer {
14091413
config: self.configuration.clone(),
1410-
allowed_discriminants: self.get_allowed_signed_entity_types_discriminants()?,
14111414
root_logger: self.root_logger(),
14121415
sqlite_connection: self.get_sqlite_connection().await?,
14131416
sqlite_connection_cardano_transaction_pool: self
@@ -1491,8 +1494,24 @@ impl DependenciesBuilder {
14911494
&mut self,
14921495
) -> Result<impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone> {
14931496
let dependency_container = Arc::new(self.build_dependency_container().await?);
1497+
let router_state = RouterState::new(
1498+
dependency_container.clone(),
1499+
RouterConfig {
1500+
network: self.configuration.get_network()?,
1501+
server_url: self.configuration.get_server_url(),
1502+
allowed_discriminants: self.get_allowed_signed_entity_types_discriminants()?,
1503+
cardano_transactions_prover_max_hashes_allowed_by_request: self
1504+
.configuration
1505+
.cardano_transactions_prover_max_hashes_allowed_by_request,
1506+
cardano_transactions_signing_config: self
1507+
.configuration
1508+
.cardano_transactions_signing_config
1509+
.clone(),
1510+
snapshot_directory: self.configuration.snapshot_directory.clone(),
1511+
},
1512+
);
14941513

1495-
Ok(router::routes(dependency_container))
1514+
Ok(router::routes(Arc::new(router_state)))
14961515
}
14971516

14981517
/// Create a [CardanoTransactionsPreloader] instance.

mithril-aggregator/src/dependency_injection/containers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use slog::Logger;
2-
use std::{collections::BTreeSet, sync::Arc};
2+
use std::sync::Arc;
33
use tokio::sync::RwLock;
44

55
use mithril_common::{
@@ -10,8 +10,8 @@ use mithril_common::{
1010
crypto_helper::ProtocolGenesisVerifier,
1111
digesters::{ImmutableDigester, ImmutableFileObserver},
1212
entities::{
13-
CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, SignedEntityTypeDiscriminants,
14-
SignerWithStake, StakeDistribution,
13+
CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, SignerWithStake,
14+
StakeDistribution,
1515
},
1616
era::{EraChecker, EraReader},
1717
signable_builder::SignableBuilderService,
@@ -50,11 +50,10 @@ pub type EpochServiceWrapper = Arc<RwLock<dyn EpochService>>;
5050
/// DependencyManager handles the dependencies
5151
pub struct DependencyContainer {
5252
/// Configuration structure.
53+
// TODO: remove this field and only use the `Configuration` in the dependencies builder
54+
#[deprecated]
5355
pub config: Configuration,
5456

55-
/// List of signed entity discriminants that are allowed to be processed
56-
pub allowed_discriminants: BTreeSet<SignedEntityTypeDiscriminants>,
57-
5857
/// Application root logger
5958
pub root_logger: Logger,
6059

@@ -209,6 +208,7 @@ impl DependencyContainer {
209208
self.epoch_settings_storer
210209
.save_epoch_settings(
211210
*epoch,
211+
#[allow(deprecated)]
212212
AggregatorEpochSettings {
213213
protocol_parameters: fixture.protocol_parameters(),
214214
cardano_transactions_signing_config: self

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_stake_distribution.rs

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,47 @@
11
use crate::http_server::routes::middlewares;
2-
use crate::DependencyContainer;
2+
use crate::http_server::routes::router::RouterState;
33
use warp::Filter;
44

55
pub fn routes(
6-
dependency_manager: &DependencyContainer,
6+
router_state: &RouterState,
77
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
8-
artifact_cardano_stake_distributions(dependency_manager)
9-
.or(artifact_cardano_stake_distribution_by_id(
10-
dependency_manager,
11-
))
12-
.or(artifact_cardano_stake_distribution_by_epoch(
13-
dependency_manager,
14-
))
8+
artifact_cardano_stake_distributions(router_state)
9+
.or(artifact_cardano_stake_distribution_by_id(router_state))
10+
.or(artifact_cardano_stake_distribution_by_epoch(router_state))
1511
}
1612

1713
/// GET /artifact/cardano-stake-distributions
1814
fn artifact_cardano_stake_distributions(
19-
dependency_manager: &DependencyContainer,
15+
router_state: &RouterState,
2016
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
2117
warp::path!("artifact" / "cardano-stake-distributions")
2218
.and(warp::get())
23-
.and(middlewares::with_logger(dependency_manager))
24-
.and(middlewares::with_http_message_service(dependency_manager))
19+
.and(middlewares::with_logger(router_state))
20+
.and(middlewares::with_http_message_service(router_state))
2521
.and_then(handlers::list_artifacts)
2622
}
2723

2824
/// GET /artifact/cardano-stake-distribution/:id
2925
fn artifact_cardano_stake_distribution_by_id(
30-
dependency_manager: &DependencyContainer,
26+
router_state: &RouterState,
3127
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
3228
warp::path!("artifact" / "cardano-stake-distribution" / String)
3329
.and(warp::get())
34-
.and(middlewares::with_logger(dependency_manager))
35-
.and(middlewares::with_http_message_service(dependency_manager))
36-
.and(middlewares::with_metrics_service(dependency_manager))
30+
.and(middlewares::with_logger(router_state))
31+
.and(middlewares::with_http_message_service(router_state))
32+
.and(middlewares::with_metrics_service(router_state))
3733
.and_then(handlers::get_artifact_by_signed_entity_id)
3834
}
3935

4036
/// GET /artifact/cardano-stake-distribution/epoch/:epoch
4137
fn artifact_cardano_stake_distribution_by_epoch(
42-
dependency_manager: &DependencyContainer,
38+
router_state: &RouterState,
4339
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
4440
warp::path!("artifact" / "cardano-stake-distribution" / "epoch" / String)
4541
.and(warp::get())
46-
.and(middlewares::with_logger(dependency_manager))
47-
.and(middlewares::with_http_message_service(dependency_manager))
48-
.and(middlewares::with_metrics_service(dependency_manager))
42+
.and(middlewares::with_logger(router_state))
43+
.and(middlewares::with_http_message_service(router_state))
44+
.and(middlewares::with_metrics_service(router_state))
4945
.and_then(handlers::get_artifact_by_epoch)
5046
}
5147

@@ -170,7 +166,7 @@ pub mod tests {
170166
use super::*;
171167

172168
fn setup_router(
173-
dependency_manager: Arc<DependencyContainer>,
169+
state: RouterState,
174170
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
175171
let cors = warp::cors()
176172
.allow_any_origin()
@@ -179,7 +175,7 @@ pub mod tests {
179175

180176
warp::any()
181177
.and(warp::path(SERVER_BASE_PATH))
182-
.and(routes(&dependency_manager).with(cors))
178+
.and(routes(&state).with(cors))
183179
}
184180

185181
#[tokio::test]
@@ -199,7 +195,9 @@ pub mod tests {
199195
let response = request()
200196
.method(method)
201197
.path(&format!("/{SERVER_BASE_PATH}{path}"))
202-
.reply(&setup_router(Arc::new(dependency_manager)))
198+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
199+
dependency_manager,
200+
))))
203201
.await;
204202

205203
APISpec::verify_conformity(
@@ -230,7 +228,9 @@ pub mod tests {
230228
let response = request()
231229
.method(method)
232230
.path(&format!("/{SERVER_BASE_PATH}{path}"))
233-
.reply(&setup_router(Arc::new(dependency_manager)))
231+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
232+
dependency_manager,
233+
))))
234234
.await;
235235

236236
APISpec::verify_conformity(
@@ -260,7 +260,9 @@ pub mod tests {
260260
request()
261261
.method(method)
262262
.path(&format!("/{SERVER_BASE_PATH}{path}"))
263-
.reply(&setup_router(dependency_manager.clone()))
263+
.reply(&setup_router(RouterState::new_with_dummy_config(
264+
dependency_manager.clone(),
265+
)))
264266
.await;
265267

266268
assert_eq!(
@@ -278,7 +280,9 @@ pub mod tests {
278280
request()
279281
.method(method)
280282
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
281-
.reply(&setup_router(dependency_manager.clone()))
283+
.reply(&setup_router(RouterState::new_with_dummy_config(
284+
dependency_manager.clone(),
285+
)))
282286
.await;
283287

284288
assert_eq!(
@@ -308,7 +312,9 @@ pub mod tests {
308312
let response = request()
309313
.method(method)
310314
.path(&format!("/{SERVER_BASE_PATH}{path}"))
311-
.reply(&setup_router(Arc::new(dependency_manager)))
315+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
316+
dependency_manager,
317+
))))
312318
.await;
313319

314320
APISpec::verify_conformity(
@@ -339,7 +345,9 @@ pub mod tests {
339345
let response = request()
340346
.method(method)
341347
.path(&format!("/{SERVER_BASE_PATH}{path}"))
342-
.reply(&setup_router(Arc::new(dependency_manager)))
348+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
349+
dependency_manager,
350+
))))
343351
.await;
344352

345353
APISpec::verify_conformity(
@@ -370,7 +378,9 @@ pub mod tests {
370378
let response = request()
371379
.method(method)
372380
.path(&format!("/{SERVER_BASE_PATH}{path}"))
373-
.reply(&setup_router(Arc::new(dependency_manager)))
381+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
382+
dependency_manager,
383+
))))
374384
.await;
375385

376386
APISpec::verify_conformity(
@@ -402,7 +412,9 @@ pub mod tests {
402412
let response = request()
403413
.method(method)
404414
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
405-
.reply(&setup_router(Arc::new(dependency_manager)))
415+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
416+
dependency_manager,
417+
))))
406418
.await;
407419

408420
APISpec::verify_conformity(
@@ -429,7 +441,9 @@ pub mod tests {
429441
let response = request()
430442
.method(method)
431443
.path(&format!("/{SERVER_BASE_PATH}{base_path}/invalid-epoch"))
432-
.reply(&setup_router(Arc::new(dependency_manager)))
444+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
445+
dependency_manager,
446+
))))
433447
.await;
434448

435449
APISpec::verify_conformity(
@@ -460,7 +474,9 @@ pub mod tests {
460474
let response = request()
461475
.method(method)
462476
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
463-
.reply(&setup_router(Arc::new(dependency_manager)))
477+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
478+
dependency_manager,
479+
))))
464480
.await;
465481

466482
APISpec::verify_conformity(
@@ -491,7 +507,9 @@ pub mod tests {
491507
let response = request()
492508
.method(method)
493509
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
494-
.reply(&setup_router(Arc::new(dependency_manager)))
510+
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
511+
dependency_manager,
512+
))))
495513
.await;
496514

497515
APISpec::verify_conformity(

0 commit comments

Comments
 (0)