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
2 changes: 1 addition & 1 deletion 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.98"
version = "0.5.99"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
25 changes: 22 additions & 3 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ use crate::{
},
entities::AggregatorEpochSettings,
event_store::{EventMessage, EventStore, TransmitterService},
http_server::routes::router,
http_server::routes::{
router,
router::{RouterConfig, RouterState},
},
services::{
AggregatorSignableSeedBuilder, AggregatorUpkeepService, BufferedCertifierService,
CardanoTransactionsImporter, CertifierService, MessageService, MithrilCertifierService,
Expand Down Expand Up @@ -1405,9 +1408,9 @@ impl DependenciesBuilder {

/// Return an unconfigured [DependencyContainer]
pub async fn build_dependency_container(&mut self) -> Result<DependencyContainer> {
#[allow(deprecated)]
let dependency_manager = DependencyContainer {
config: self.configuration.clone(),
allowed_discriminants: self.get_allowed_signed_entity_types_discriminants()?,
root_logger: self.root_logger(),
sqlite_connection: self.get_sqlite_connection().await?,
sqlite_connection_cardano_transaction_pool: self
Expand Down Expand Up @@ -1491,8 +1494,24 @@ impl DependenciesBuilder {
&mut self,
) -> Result<impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone> {
let dependency_container = Arc::new(self.build_dependency_container().await?);
let router_state = RouterState::new(
dependency_container.clone(),
RouterConfig {
network: self.configuration.get_network()?,
server_url: self.configuration.get_server_url(),
allowed_discriminants: self.get_allowed_signed_entity_types_discriminants()?,
cardano_transactions_prover_max_hashes_allowed_by_request: self
.configuration
.cardano_transactions_prover_max_hashes_allowed_by_request,
cardano_transactions_signing_config: self
.configuration
.cardano_transactions_signing_config
.clone(),
snapshot_directory: self.configuration.snapshot_directory.clone(),
},
);

Ok(router::routes(dependency_container))
Ok(router::routes(Arc::new(router_state)))
}

/// Create a [CardanoTransactionsPreloader] instance.
Expand Down
12 changes: 6 additions & 6 deletions mithril-aggregator/src/dependency_injection/containers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use slog::Logger;
use std::{collections::BTreeSet, sync::Arc};
use std::sync::Arc;
use tokio::sync::RwLock;

use mithril_common::{
Expand All @@ -10,8 +10,8 @@ use mithril_common::{
crypto_helper::ProtocolGenesisVerifier,
digesters::{ImmutableDigester, ImmutableFileObserver},
entities::{
CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, SignedEntityTypeDiscriminants,
SignerWithStake, StakeDistribution,
CardanoTransactionsSigningConfig, Epoch, ProtocolParameters, SignerWithStake,
StakeDistribution,
},
era::{EraChecker, EraReader},
signable_builder::SignableBuilderService,
Expand Down Expand Up @@ -50,11 +50,10 @@ pub type EpochServiceWrapper = Arc<RwLock<dyn EpochService>>;
/// DependencyManager handles the dependencies
pub struct DependencyContainer {
/// Configuration structure.
// TODO: remove this field and only use the `Configuration` in the dependencies builder
#[deprecated]
pub config: Configuration,

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

/// Application root logger
pub root_logger: Logger,

Expand Down Expand Up @@ -209,6 +208,7 @@ impl DependencyContainer {
self.epoch_settings_storer
.save_epoch_settings(
*epoch,
#[allow(deprecated)]
AggregatorEpochSettings {
protocol_parameters: fixture.protocol_parameters(),
cardano_transactions_signing_config: self
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
use crate::http_server::routes::middlewares;
use crate::DependencyContainer;
use crate::http_server::routes::router::RouterState;
use warp::Filter;

pub fn routes(
dependency_manager: &DependencyContainer,
router_state: &RouterState,
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
artifact_cardano_stake_distributions(dependency_manager)
.or(artifact_cardano_stake_distribution_by_id(
dependency_manager,
))
.or(artifact_cardano_stake_distribution_by_epoch(
dependency_manager,
))
artifact_cardano_stake_distributions(router_state)
.or(artifact_cardano_stake_distribution_by_id(router_state))
.or(artifact_cardano_stake_distribution_by_epoch(router_state))
}

/// GET /artifact/cardano-stake-distributions
fn artifact_cardano_stake_distributions(
dependency_manager: &DependencyContainer,
router_state: &RouterState,
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("artifact" / "cardano-stake-distributions")
.and(warp::get())
.and(middlewares::with_logger(dependency_manager))
.and(middlewares::with_http_message_service(dependency_manager))
.and(middlewares::with_logger(router_state))
.and(middlewares::with_http_message_service(router_state))
.and_then(handlers::list_artifacts)
}

/// GET /artifact/cardano-stake-distribution/:id
fn artifact_cardano_stake_distribution_by_id(
dependency_manager: &DependencyContainer,
router_state: &RouterState,
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("artifact" / "cardano-stake-distribution" / String)
.and(warp::get())
.and(middlewares::with_logger(dependency_manager))
.and(middlewares::with_http_message_service(dependency_manager))
.and(middlewares::with_metrics_service(dependency_manager))
.and(middlewares::with_logger(router_state))
.and(middlewares::with_http_message_service(router_state))
.and(middlewares::with_metrics_service(router_state))
.and_then(handlers::get_artifact_by_signed_entity_id)
}

/// GET /artifact/cardano-stake-distribution/epoch/:epoch
fn artifact_cardano_stake_distribution_by_epoch(
dependency_manager: &DependencyContainer,
router_state: &RouterState,
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
warp::path!("artifact" / "cardano-stake-distribution" / "epoch" / String)
.and(warp::get())
.and(middlewares::with_logger(dependency_manager))
.and(middlewares::with_http_message_service(dependency_manager))
.and(middlewares::with_metrics_service(dependency_manager))
.and(middlewares::with_logger(router_state))
.and(middlewares::with_http_message_service(router_state))
.and(middlewares::with_metrics_service(router_state))
.and_then(handlers::get_artifact_by_epoch)
}

Expand Down Expand Up @@ -170,7 +166,7 @@ pub mod tests {
use super::*;

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

warp::any()
.and(warp::path(SERVER_BASE_PATH))
.and(routes(&dependency_manager).with(cors))
.and(routes(&state).with(cors))
}

#[tokio::test]
Expand All @@ -199,7 +195,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{path}"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -230,7 +228,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{path}"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -260,7 +260,9 @@ pub mod tests {
request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{path}"))
.reply(&setup_router(dependency_manager.clone()))
.reply(&setup_router(RouterState::new_with_dummy_config(
dependency_manager.clone(),
)))
.await;

assert_eq!(
Expand All @@ -278,7 +280,9 @@ pub mod tests {
request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
.reply(&setup_router(dependency_manager.clone()))
.reply(&setup_router(RouterState::new_with_dummy_config(
dependency_manager.clone(),
)))
.await;

assert_eq!(
Expand Down Expand Up @@ -308,7 +312,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{path}"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -339,7 +345,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{path}"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -370,7 +378,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{path}"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -402,7 +412,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand All @@ -429,7 +441,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{base_path}/invalid-epoch"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -460,7 +474,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down Expand Up @@ -491,7 +507,9 @@ pub mod tests {
let response = request()
.method(method)
.path(&format!("/{SERVER_BASE_PATH}{base_path}/123"))
.reply(&setup_router(Arc::new(dependency_manager)))
.reply(&setup_router(RouterState::new_with_dummy_config(Arc::new(
dependency_manager,
))))
.await;

APISpec::verify_conformity(
Expand Down
Loading