Skip to content

Commit

Permalink
feat: add current and next Protocol parameters to the /status rout…
Browse files Browse the repository at this point in the history
…e response
  • Loading branch information
dlachaume committed Nov 13, 2024
1 parent 5149f3f commit d76af04
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
51 changes: 49 additions & 2 deletions mithril-aggregator/src/http_server/routes/aggregator_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ 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,
cardano_era,
mithril_era,
cardano_node_version,
aggregator_node_version,
protocol_parameters,
next_protocol_parameters,
};

Ok(message)
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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
);
}
}
27 changes: 25 additions & 2 deletions mithril-common/src/messages/aggregator_status.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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)]
Expand All @@ -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 {
Expand All @@ -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,
},
}
}

Expand Down
12 changes: 11 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -662,6 +664,8 @@ components:
- mithril_era
- cardano_node_version
- aggregator_node_version
- protocol
- next_protocol
properties:
epoch:
$ref: "#/components/schemas/Epoch"
Expand All @@ -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:
Expand Down

0 comments on commit d76af04

Please sign in to comment.