Skip to content

Commit e7f15cc

Browse files
committed
feat(aggregator): return cardano network in status route
1 parent bd894a0 commit e7f15cc

File tree

2 files changed

+89
-7
lines changed

2 files changed

+89
-7
lines changed

mithril-aggregator/src/http_server/routes/status.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ fn status(
2424
.and(middlewares::extract_config(router_state, |config| {
2525
config.cardano_node_version.clone()
2626
}))
27+
.and(middlewares::extract_config(router_state, |config| {
28+
config.network.to_string()
29+
}))
2730
.and_then(handlers::status)
2831
}
2932

3033
async fn get_aggregator_status_message(
3134
epoch_service: EpochServiceWrapper,
3235
cardano_node_version: String,
36+
cardano_network: String,
3337
) -> StdResult<AggregatorStatusMessage> {
3438
let epoch_service = epoch_service.read().await;
3539

@@ -49,6 +53,7 @@ async fn get_aggregator_status_message(
4953
let message = AggregatorStatusMessage {
5054
epoch,
5155
cardano_era,
56+
cardano_network,
5257
mithril_era,
5358
cardano_node_version,
5459
aggregator_node_version,
@@ -81,9 +86,11 @@ mod handlers {
8186
logger: Logger,
8287
epoch_service: EpochServiceWrapper,
8388
cardano_node_version: String,
89+
cardano_network: String,
8490
) -> Result<impl warp::Reply, Infallible> {
8591
let aggregator_status_message =
86-
get_aggregator_status_message(epoch_service, cardano_node_version).await;
92+
get_aggregator_status_message(epoch_service, cardano_node_version, cardano_network)
93+
.await;
8794

8895
match aggregator_status_message {
8996
Ok(message) => Ok(reply::json(&message, StatusCode::OK)),
@@ -211,11 +218,11 @@ mod tests {
211218
..FakeEpochServiceBuilder::dummy(Epoch(3))
212219
}
213220
.build();
221+
let epoch_service = Arc::new(RwLock::new(epoch_service));
214222

215-
let message =
216-
get_aggregator_status_message(Arc::new(RwLock::new(epoch_service)), String::new())
217-
.await
218-
.unwrap();
223+
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
224+
.await
225+
.unwrap();
219226

220227
assert_eq!(
221228
message.protocol_parameters,
@@ -240,7 +247,7 @@ mod tests {
240247
.build();
241248
let epoch_service = Arc::new(RwLock::new(epoch_service));
242249

243-
let message = get_aggregator_status_message(epoch_service.clone(), String::new())
250+
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
244251
.await
245252
.unwrap();
246253

@@ -266,11 +273,28 @@ mod tests {
266273
.build();
267274
let epoch_service = Arc::new(RwLock::new(epoch_service));
268275

269-
let message = get_aggregator_status_message(epoch_service.clone(), String::new())
276+
let message = get_aggregator_status_message(epoch_service, String::new(), String::new())
270277
.await
271278
.unwrap();
272279

273280
assert_eq!(message.total_stakes_signers, total_stakes_signers);
274281
assert_eq!(message.total_next_stakes_signers, total_next_stakes_signers);
275282
}
283+
284+
#[tokio::test]
285+
async fn retrieves_node_version_and_network_from_parameters() {
286+
let epoch_service = FakeEpochServiceBuilder::dummy(Epoch(3)).build();
287+
let epoch_service = Arc::new(RwLock::new(epoch_service));
288+
289+
let message = get_aggregator_status_message(
290+
epoch_service,
291+
"1.0.4".to_string(),
292+
"network".to_string(),
293+
)
294+
.await
295+
.unwrap();
296+
297+
assert_eq!(message.cardano_node_version, "1.0.4");
298+
assert_eq!(message.cardano_network, "network");
299+
}
276300
}

mithril-common/src/messages/aggregator_status.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct AggregatorStatusMessage {
1414
/// Current Cardano era
1515
pub cardano_era: CardanoEra,
1616

17+
/// Cardano network
18+
pub cardano_network: String,
19+
1720
/// Current Mithril era
1821
pub mithril_era: SupportedEra,
1922

@@ -57,6 +60,7 @@ mod tests {
5760
const ACTUAL_JSON: &str = r#"{
5861
"epoch": 48,
5962
"cardano_era": "conway",
63+
"cardano_network": "mainnet",
6064
"mithril_era": "pythagoras",
6165
"cardano_node_version": "1.2.3",
6266
"aggregator_node_version": "4.5.6",
@@ -70,10 +74,56 @@ mod tests {
7074
"total_cardano_stake": 888888888
7175
}"#;
7276

77+
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
78+
pub struct AggregatorStatusMessageUntilV0_1_37 {
79+
pub epoch: Epoch,
80+
pub cardano_era: CardanoEra,
81+
pub mithril_era: SupportedEra,
82+
pub cardano_node_version: String,
83+
pub aggregator_node_version: String,
84+
#[serde(rename = "protocol")]
85+
pub protocol_parameters: ProtocolParameters,
86+
#[serde(rename = "next_protocol")]
87+
pub next_protocol_parameters: ProtocolParameters,
88+
pub total_signers: usize,
89+
pub total_next_signers: usize,
90+
pub total_stakes_signers: Stake,
91+
pub total_next_stakes_signers: Stake,
92+
pub total_cardano_spo: TotalSPOs,
93+
pub total_cardano_stake: Stake,
94+
}
95+
96+
fn golden_message_until_open_api_0_1_37() -> AggregatorStatusMessageUntilV0_1_37 {
97+
AggregatorStatusMessageUntilV0_1_37 {
98+
epoch: Epoch(48),
99+
cardano_era: "conway".to_string(),
100+
mithril_era: SupportedEra::Pythagoras,
101+
cardano_node_version: "1.2.3".to_string(),
102+
aggregator_node_version: "4.5.6".to_string(),
103+
protocol_parameters: ProtocolParameters {
104+
k: 5,
105+
m: 100,
106+
phi_f: 0.65,
107+
},
108+
next_protocol_parameters: ProtocolParameters {
109+
k: 50,
110+
m: 1000,
111+
phi_f: 0.65,
112+
},
113+
total_signers: 1234,
114+
total_next_signers: 56789,
115+
total_stakes_signers: 123456789,
116+
total_next_stakes_signers: 987654321,
117+
total_cardano_spo: 7777,
118+
total_cardano_stake: 888888888,
119+
}
120+
}
121+
73122
fn golden_actual_message() -> AggregatorStatusMessage {
74123
AggregatorStatusMessage {
75124
epoch: Epoch(48),
76125
cardano_era: "conway".to_string(),
126+
cardano_network: "mainnet".to_string(),
77127
mithril_era: SupportedEra::Pythagoras,
78128
cardano_node_version: "1.2.3".to_string(),
79129
aggregator_node_version: "4.5.6".to_string(),
@@ -96,6 +146,14 @@ mod tests {
96146
}
97147
}
98148

149+
#[test]
150+
fn test_actual_json_deserialized_into_message_supported_until_open_api_0_1_37() {
151+
let json = ACTUAL_JSON;
152+
let message: AggregatorStatusMessageUntilV0_1_37 = serde_json::from_str(json).unwrap();
153+
154+
assert_eq!(golden_message_until_open_api_0_1_37(), message);
155+
}
156+
99157
// Test the compatibility with current structure.
100158
#[test]
101159
fn test_actual_json_deserialized_into_actual_message() {

0 commit comments

Comments
 (0)