diff --git a/mithril-aggregator/src/http_server/routes/aggregator_status.rs b/mithril-aggregator/src/http_server/routes/aggregator_status.rs index d04eb5892e5..e688ad28afe 100644 --- a/mithril-aggregator/src/http_server/routes/aggregator_status.rs +++ b/mithril-aggregator/src/http_server/routes/aggregator_status.rs @@ -37,6 +37,8 @@ async fn get_aggregator_status_message( let cardano_era = epoch_service.cardano_era()?; let mithril_era = epoch_service.mithril_era()?; let aggregator_node_version = env!("CARGO_PKG_VERSION").to_string(); + let protocol_parameters = epoch_service.current_protocol_parameters()?.clone(); + let next_protocol_parameters = epoch_service.next_protocol_parameters()?.clone(); let message = AggregatorStatusMessage { epoch, @@ -44,6 +46,8 @@ async fn get_aggregator_status_message( mithril_era, cardano_node_version, aggregator_node_version, + protocol_parameters, + next_protocol_parameters, }; Ok(message) @@ -91,11 +95,15 @@ mod tests { }; use mithril_common::{ - entities::Epoch, test_utils::apispec::APISpec, test_utils::MithrilFixtureBuilder, + entities::{Epoch, ProtocolParameters}, + test_utils::{apispec::APISpec, MithrilFixtureBuilder}, }; use crate::{ - http_server::SERVER_BASE_PATH, initialize_dependencies, services::FakeEpochService, + entities::AggregatorEpochSettings, + http_server::SERVER_BASE_PATH, + initialize_dependencies, + services::{FakeEpochService, FakeEpochServiceBuilder}, }; use super::*; @@ -168,4 +176,43 @@ mod tests { ) .unwrap(); } + + #[tokio::test] + async fn retrieves_correct_protocol_parameters_from_epoch_service() { + let current_epoch_settings = AggregatorEpochSettings { + protocol_parameters: ProtocolParameters::new(101, 10, 0.5), + ..AggregatorEpochSettings::dummy() + }; + let next_epoch_settings = AggregatorEpochSettings { + protocol_parameters: ProtocolParameters::new(102, 20, 0.5), + ..AggregatorEpochSettings::dummy() + }; + let signer_registration_epoch_settings = AggregatorEpochSettings { + protocol_parameters: ProtocolParameters::new(103, 30, 0.5), + ..AggregatorEpochSettings::dummy() + }; + + let epoch_service = FakeEpochServiceBuilder { + current_epoch_settings: current_epoch_settings.clone(), + next_epoch_settings: next_epoch_settings.clone(), + signer_registration_epoch_settings, + ..FakeEpochServiceBuilder::dummy(Epoch(3)) + } + .build(); + + let message = + get_aggregator_status_message(Arc::new(RwLock::new(epoch_service)), String::new()) + .await + .unwrap(); + + assert_eq!( + message.protocol_parameters, + current_epoch_settings.protocol_parameters + ); + + assert_eq!( + message.next_protocol_parameters, + next_epoch_settings.protocol_parameters + ); + } } diff --git a/mithril-common/src/messages/aggregator_status.rs b/mithril-common/src/messages/aggregator_status.rs index 54d19cdd4c1..b73699c587c 100644 --- a/mithril-common/src/messages/aggregator_status.rs +++ b/mithril-common/src/messages/aggregator_status.rs @@ -1,6 +1,9 @@ use serde::{Deserialize, Serialize}; -use crate::{entities::Epoch, era::SupportedEra}; +use crate::{ + entities::{Epoch, ProtocolParameters}, + era::SupportedEra, +}; /// Message advertised by an Aggregator to inform about its status #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] @@ -19,6 +22,14 @@ pub struct AggregatorStatusMessage { /// Aggregator node version pub aggregator_node_version: String, + + /// Current Protocol parameters + #[serde(rename = "protocol")] + pub protocol_parameters: ProtocolParameters, + + /// Next Protocol parameters + #[serde(rename = "next_protocol")] + pub next_protocol_parameters: ProtocolParameters, } #[cfg(test)] @@ -30,7 +41,9 @@ mod tests { "cardano_era": "conway", "mithril_era": "pythagoras", "cardano_node_version": "1.2.3", - "aggregator_node_version": "4.5.6" + "aggregator_node_version": "4.5.6", + "protocol": { "k": 5, "m": 100, "phi_f": 0.65 }, + "next_protocol": { "k": 50, "m": 1000, "phi_f": 0.65 } }"#; fn golden_actual_message() -> AggregatorStatusMessage { @@ -40,6 +53,16 @@ mod tests { mithril_era: SupportedEra::Pythagoras, cardano_node_version: "1.2.3".to_string(), aggregator_node_version: "4.5.6".to_string(), + protocol_parameters: ProtocolParameters { + k: 5, + m: 100, + phi_f: 0.65, + }, + next_protocol_parameters: ProtocolParameters { + k: 50, + m: 1000, + phi_f: 0.65, + }, } } diff --git a/openapi.yaml b/openapi.yaml index d60af679768..ca9fc36d6d0 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -58,6 +58,8 @@ paths: * Current Mithril era * Cardano node version * Aggregator node version + * Protocol parameters for current epoch + * Protocol parameters for next epoch responses: "200": description: aggregator status found @@ -662,6 +664,8 @@ components: - mithril_era - cardano_node_version - aggregator_node_version + - protocol + - next_protocol properties: epoch: $ref: "#/components/schemas/Epoch" @@ -677,13 +681,19 @@ components: aggregator_node_version: description: Version of the Aggregator node type: string + protocol: + $ref: "#/components/schemas/ProtocolParameters" + next_protocol: + $ref: "#/components/schemas/ProtocolParameters" examples: { "epoch": 329, "cardano_era": "conway", "mithril_era": "pythagoras", "cardano_node_version": "1.2.3", - "aggregator_node_version": "4.5.6" + "aggregator_node_version": "4.5.6", + "protocol": { "k": 857, "m": 6172, "phi_f": 0.2 }, + "next_protocol": { "k": 2422, "m": 20973, "phi_f": 0.2 } } AggregatorFeaturesMessage: