Skip to content

Commit 5b3bcbe

Browse files
committed
feat: add current_cardano_transactions_signing_config to EpochSettingsMessage
- Add optional `current_cardano_transactions_signing_config` field, used only when 'CardanoTransactions' is activated by the aggregator. - Add retro compatibility test with the original 'EpochSettingsMessage' structure, identified as 'Legacy', and the previous 'EpochSettingsMessage', identified as 'Previous'.
1 parent 27fdfa0 commit 5b3bcbe

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

mithril-common/src/messages/epoch_settings.rs

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::entities::{Epoch, ProtocolParameters};
1+
use crate::entities::{CardanoTransactionsSigningConfig, Epoch, ProtocolParameters};
22
use crate::messages::SignerMessagePart;
33
use serde::{Deserialize, Serialize};
44

@@ -21,6 +21,10 @@ pub struct EpochSettingsMessage {
2121

2222
/// Signers that will be able to sign on the next epoch
2323
pub next_signers: Vec<SignerMessagePart>,
24+
25+
/// Cardano transactions signing configuration for the current epoch
26+
#[serde(skip_serializing_if = "Option::is_none")]
27+
pub current_cardano_transactions_signing_config: Option<CardanoTransactionsSigningConfig>,
2428
}
2529

2630
impl EpochSettingsMessage {
@@ -41,6 +45,7 @@ impl EpochSettingsMessage {
4145
},
4246
current_signers: [SignerMessagePart::dummy()].to_vec(),
4347
next_signers: [SignerMessagePart::dummy()].to_vec(),
48+
current_cardano_transactions_signing_config: None,
4449
}
4550
}
4651
}
@@ -49,6 +54,8 @@ impl EpochSettingsMessage {
4954
#[cfg(test)]
5055
mod tests {
5156

57+
use crate::entities::BlockNumber;
58+
5259
use super::*;
5360

5461
const ACTUAL_JSON: &str = r#"{
@@ -68,10 +75,28 @@ mod tests {
6875
"verification_key_signature":"signature_456",
6976
"operational_certificate":"certificate_456",
7077
"kes_period":45
71-
}]
78+
}],
79+
"current_cardano_transactions_signing_config": {
80+
"security_parameter": 70,
81+
"step": 20
82+
}
7283
7384
}"#;
7485

86+
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
87+
pub struct EpochSettingsMessageLegacyVersion {
88+
/// Current Epoch
89+
pub epoch: Epoch,
90+
91+
/// Current Protocol parameters
92+
#[serde(rename = "protocol")]
93+
pub protocol_parameters: ProtocolParameters,
94+
95+
/// Next Protocol parameters
96+
#[serde(rename = "next_protocol")]
97+
pub next_protocol_parameters: ProtocolParameters,
98+
}
99+
75100
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
76101
pub struct EpochSettingsMessagePreviousVersion {
77102
/// Current Epoch
@@ -84,6 +109,28 @@ mod tests {
84109
/// Next Protocol parameters
85110
#[serde(rename = "next_protocol")]
86111
pub next_protocol_parameters: ProtocolParameters,
112+
113+
/// Current Signers
114+
pub current_signers: Vec<SignerMessagePart>,
115+
116+
/// Signers that will be able to sign on the next epoch
117+
pub next_signers: Vec<SignerMessagePart>,
118+
}
119+
120+
fn golden_legacy_message() -> EpochSettingsMessageLegacyVersion {
121+
EpochSettingsMessageLegacyVersion {
122+
epoch: Epoch(10),
123+
protocol_parameters: ProtocolParameters {
124+
k: 5,
125+
m: 100,
126+
phi_f: 0.65,
127+
},
128+
next_protocol_parameters: ProtocolParameters {
129+
k: 50,
130+
m: 1000,
131+
phi_f: 0.65,
132+
},
133+
}
87134
}
88135

89136
fn golden_previous_message() -> EpochSettingsMessagePreviousVersion {
@@ -99,6 +146,20 @@ mod tests {
99146
m: 1000,
100147
phi_f: 0.65,
101148
},
149+
current_signers: vec![SignerMessagePart {
150+
party_id: "123".to_string(),
151+
verification_key: "key_123".to_string(),
152+
verification_key_signature: Some("signature_123".to_string()),
153+
operational_certificate: Some("certificate_123".to_string()),
154+
kes_period: Some(12),
155+
}],
156+
next_signers: vec![SignerMessagePart {
157+
party_id: "456".to_string(),
158+
verification_key: "key_456".to_string(),
159+
verification_key_signature: Some("signature_456".to_string()),
160+
operational_certificate: Some("certificate_456".to_string()),
161+
kes_period: Some(45),
162+
}],
102163
}
103164
}
104165

@@ -129,9 +190,24 @@ mod tests {
129190
operational_certificate: Some("certificate_456".to_string()),
130191
kes_period: Some(45),
131192
}],
193+
current_cardano_transactions_signing_config: Some(CardanoTransactionsSigningConfig {
194+
security_parameter: BlockNumber(70),
195+
step: BlockNumber(20),
196+
}),
132197
}
133198
}
134199

200+
// Test the backward compatibility with legacy structure.
201+
#[test]
202+
fn test_actual_json_deserialized_into_legacy_message() {
203+
let json = ACTUAL_JSON;
204+
let message: EpochSettingsMessageLegacyVersion = serde_json::from_str(json).expect(
205+
"This JSON is expected to be successfully parsed into a EpochSettingsMessageLegacyVersion instance.",
206+
);
207+
208+
assert_eq!(golden_legacy_message(), message);
209+
}
210+
135211
// Test the backward compatibility with previous structure.
136212
#[test]
137213
fn test_actual_json_deserialized_into_previous_message() {

0 commit comments

Comments
 (0)