From 059a8ad008656606d48a775599abb0d474b3df13 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 26 Apr 2023 18:44:28 +0200 Subject: [PATCH 1/8] Add registration epoch in RegisterSignerMessage --- .../src/messages/register_signer.rs | 93 ++++++++++++++++++- .../to_register_signer_message.rs | 1 + 2 files changed, 90 insertions(+), 4 deletions(-) diff --git a/mithril-common/src/messages/register_signer.rs b/mithril-common/src/messages/register_signer.rs index c32938e584c..a54af002a6a 100644 --- a/mithril-common/src/messages/register_signer.rs +++ b/mithril-common/src/messages/register_signer.rs @@ -1,15 +1,82 @@ -use super::SignerMessage; +use serde::{Deserialize, Serialize}; + +use crate::{ + crypto_helper::KESPeriod, + entities::{ + Epoch, HexEncodedOpCert, HexEncodedVerificationKey, HexEncodedVerificationKeySignature, + PartyId, + }, +}; /// Register Signer Message -pub type RegisterSignerMessage = SignerMessage; +#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] +pub struct RegisterSignerMessage { + /// Epoch at which registration is sent + /// #[serde(skip_serializing_if = "Option::is_none")] + pub epoch: Option, + + /// The unique identifier of the signer + // TODO: Should be removed once the signer certification is fully deployed + pub party_id: PartyId, + + /// The public key used to authenticate signer signature + pub verification_key: HexEncodedVerificationKey, + + /// The encoded signer 'Mithril verification key' signature (signed by the + /// Cardano node KES secret key). + // TODO: Option should be removed once the signer certification is fully + // deployed. + #[serde(skip_serializing_if = "Option::is_none")] + pub verification_key_signature: Option, + + /// The encoded operational certificate of stake pool operator attached to + /// the signer node. + // TODO: Option should be removed once the signer certification is fully + // deployed. + #[serde(skip_serializing_if = "Option::is_none")] + pub operational_certificate: Option, + + /// The KES period used to compute the verification key signature + // TODO: This KES period should not be used as is and should probably be + // within an allowed range of KES periods for the epoch. + #[serde(skip_serializing_if = "Option::is_none")] + pub kes_period: Option, +} + +impl RegisterSignerMessage { + /// Return a dummy test entity (test-only). + pub fn dummy() -> Self { + Self { + epoch: Some(Epoch(1)), + party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), + verification_key: "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d".to_string(), + verification_key_signature: Some("7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a5b33322c3235332c3134372c3132382c39302c3137372c31322c3231302c3232312c37332c31332c3234332c31302c36342c39322c3139322c3131342c3231302c3231372c3133312c3131322c3137322c3231362c3138372c38382c3138362c32372c31342c3134302c3230362c38312c3234332c3132342c3131342c3234362c3130342c35362c3131342c372c3131342c35372c3232392c3135362c32332c39342c32382c3137372c36302c3131302c34332c3136362c392c3139392c3233302c3133342c37302c3233322c3131362c3130302c36382c39342c3135332c3136342c31345d2c226c68735f706b223a5b3136332c3234362c39382c3232362c31302c36302c3131322c3234312c3136372c36322c3230302c3234382c39392c3133382c3136322c3137322c3137352c31332c3138392c392c302c3234392c34322c3232392c3231312c3230362c3235302c3136372c33382c36332c3138392c3134335d2c227268735f706b223a5b3137322c3138392c3138352c3233302c3234382c39342c3235312c3138312c3137392c38362c38342c32332c3137382c3230352c3232362c382c3233312c3230372c3231302c38332c36382c3231342c3231362c37342c3135362c3130322c32382c3233302c382c35322c3130312c3234355d7d2c226c68735f706b223a5b3134302c3230372c39382c3133362c3134312c3233312c3231352c3230342c35322c3135352c38392c3232332c34382c3134392c3138352c3135352c3131342c3235352c39332c3137352c3234332c37302c3137362c3134332c32342c3132352c32392c3231392c3135302c33362c3232352c33375d2c227268735f706b223a5b3137312c3232392c3139332c3130352c3233342c31382c3232392c38312c3235352c3139322c3133302c32352c33322c3138342c312c33392c39332c3138372c382c3233332c36392c37342c35362c3130312c37302c3231332c3232342c33322c31382c3130322c3235332c35355d7d2c226c68735f706b223a5b34322c302c31382c36382c3135332c3234312c3231342c3133352c3139342c34332c3231322c35382c36322c332c3136302c3133332c34342c37342c3131312c37382c3136322c3133322c35372c32362c3138392c36372c3132372c3232352c37352c3137312c31342c3131345d2c227268735f706b223a5b3133372c3135302c39302c3139362c3232322c3234312c3137392c3133372c3130362c33362c3130322c37322c35372c37312c3130392c3235302c392c33362c3134362c3234372c37342c3231362c31322c342c35322c33372c3233342c37302c3233342c37302c36362c34315d7d2c226c68735f706b223a5b3132312c3134352c3233352c3230392c3135322c39302c3135372c3231392c35312c34302c3136372c322c3137372c3138372c39372c3135332c3138392c3130392c3234392c38392c3231372c3135302c3139322c3131302c3232322c3138332c3134362c39392c3134352c35392c3132352c3132305d2c227268735f706b223a5b32362c38352c3137332c3235302c34382c36322c33382c3231392c39312c3138392c3136382c35322c3137392c34342c39332c39362c31362c3136392c38372c31302c3137302c312c3138392c322c3235352c3131312c3230342c3233372c3138312c3137342c31362c3231385d7d2c226c68735f706b223a5b372c37382c3233342c34362c32372c3234322c332c3234312c3231342c3131322c372c34302c3131372c39372c39332c3234322c3130342c3137302c39352c3138372c37382c3134312c3233382c35392c3231302c352c3133342c3234392c3231372c31302c3132312c33345d2c227268735f706b223a5b3134312c3130332c3232332c3233332c3230322c34302c3231352c3135362c3131342c36342c3231332c35392c3233332c33362c3234372c3132342c3130392c3138312c3230302c3136342c3232302c3230352c32392c3133332c3132302c3232342c3132312c3132362c36362c3235322c37312c3233325d7d2c226c68735f706b223a5b3134352c3139352c3234312c35332c3139392c3133362c33322c3235342c3131362c3132302c3137352c3232332c31382c37352c3134362c35312c3131362c3235332c3137342c3132312c3235342c3134302c3136392c33302c3135312c33332c3134392c3131342c3130322c3132332c3139302c33325d2c227268735f706b223a5b32362c3233332c3137382c3138372c3234342c33382c3138372c3132332c3133382c33312c34352c39382c37302c38322c3232392c39302c3137372c36352c3133332c3135372c39372c3233302c35302c37382c3134362c37302c3230322c3130312c35362c32302c3234372c3231375d7d".to_string()), + operational_certificate: Some("5b5b5b3230332c3130392c34302c32382c3235312c39342c35322c32342c3231322c3131362c3134392c38302c3138332c3136322c312c36322c352c3133332c35372c3230342c31352c3137322c3134372c38362c3132352c35392c31322c3235332c3130312c3138342c32332c31355d2c322c3132382c5b3133382c3131302c3139322c35302c38362c332c3136382c33342c3137322c31392c39312c3133392c3139302c3134302c31382c3137372c33312c34362c3132322c3130362c3233342c3137372c3130382c3232352c3230372c342c302c35392c3233372c3133352c3130342c39382c3133332c3133312c32392c3231322c3137312c3139342c3234342c3139312c3137392c3131392c34322c37352c3135302c36312c3232362c3132312c35342c3232332c3139332c3133382c3139302c32372c3138322c3135322c35362c32312c3136302c3230372c33352c3233372c3130322c31325d5d2c5b3230372c31322c3136382c3139302c34362c3131362c3139362c3133332c3139362c3233312c3132342c3235302c3134372c33372c3137352c3231312c3234372c3139382c3134302c3133392c3234362c3130342c3132342c3232372c34392c352c3235332c3232382c3130372c39332c3133362c3134345d5d".to_string()), + kes_period: Some(6), + } + } +} #[cfg(test)] mod tests { use super::*; // reference structure to compare with what should be deserialized. - fn golden_message() -> RegisterSignerMessage { + fn golden_message_v1() -> RegisterSignerMessage { RegisterSignerMessage { + epoch: None, + party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), + verification_key: "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d".to_string(), + verification_key_signature: Some("7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a5b33322c3235332c3134372c3132382c39302c3137372c31322c3231302c3232312c37332c31332c3234332c31302c36342c39322c3139322c3131342c3231302c3231372c3133312c3131322c3137322c3231362c3138372c38382c3138362c32372c31342c3134302c3230362c38312c3234332c3132342c3131342c3234362c3130342c35362c3131342c372c3131342c35372c3232392c3135362c32332c39342c32382c3137372c36302c3131302c34332c3136362c392c3139392c3233302c3133342c37302c3233322c3131362c3130302c36382c39342c3135332c3136342c31345d2c226c68735f706b223a5b3136332c3234362c39382c3232362c31302c36302c3131322c3234312c3136372c36322c3230302c3234382c39392c3133382c3136322c3137322c3137352c31332c3138392c392c302c3234392c34322c3232392c3231312c3230362c3235302c3136372c33382c36332c3138392c3134335d2c227268735f706b223a5b3137322c3138392c3138352c3233302c3234382c39342c3235312c3138312c3137392c38362c38342c32332c3137382c3230352c3232362c382c3233312c3230372c3231302c38332c36382c3231342c3231362c37342c3135362c3130322c32382c3233302c382c35322c3130312c3234355d7d2c226c68735f706b223a5b3134302c3230372c39382c3133362c3134312c3233312c3231352c3230342c35322c3135352c38392c3232332c34382c3134392c3138352c3135352c3131342c3235352c39332c3137352c3234332c37302c3137362c3134332c32342c3132352c32392c3231392c3135302c33362c3232352c33375d2c227268735f706b223a5b3137312c3232392c3139332c3130352c3233342c31382c3232392c38312c3235352c3139322c3133302c32352c33322c3138342c312c33392c39332c3138372c382c3233332c36392c37342c35362c3130312c37302c3231332c3232342c33322c31382c3130322c3235332c35355d7d2c226c68735f706b223a5b34322c302c31382c36382c3135332c3234312c3231342c3133352c3139342c34332c3231322c35382c36322c332c3136302c3133332c34342c37342c3131312c37382c3136322c3133322c35372c32362c3138392c36372c3132372c3232352c37352c3137312c31342c3131345d2c227268735f706b223a5b3133372c3135302c39302c3139362c3232322c3234312c3137392c3133372c3130362c33362c3130322c37322c35372c37312c3130392c3235302c392c33362c3134362c3234372c37342c3231362c31322c342c35322c33372c3233342c37302c3233342c37302c36362c34315d7d2c226c68735f706b223a5b3132312c3134352c3233352c3230392c3135322c39302c3135372c3231392c35312c34302c3136372c322c3137372c3138372c39372c3135332c3138392c3130392c3234392c38392c3231372c3135302c3139322c3131302c3232322c3138332c3134362c39392c3134352c35392c3132352c3132305d2c227268735f706b223a5b32362c38352c3137332c3235302c34382c36322c33382c3231392c39312c3138392c3136382c35322c3137392c34342c39332c39362c31362c3136392c38372c31302c3137302c312c3138392c322c3235352c3131312c3230342c3233372c3138312c3137342c31362c3231385d7d2c226c68735f706b223a5b372c37382c3233342c34362c32372c3234322c332c3234312c3231342c3131322c372c34302c3131372c39372c39332c3234322c3130342c3137302c39352c3138372c37382c3134312c3233382c35392c3231302c352c3133342c3234392c3231372c31302c3132312c33345d2c227268735f706b223a5b3134312c3130332c3232332c3233332c3230322c34302c3231352c3135362c3131342c36342c3231332c35392c3233332c33362c3234372c3132342c3130392c3138312c3230302c3136342c3232302c3230352c32392c3133332c3132302c3232342c3132312c3132362c36362c3235322c37312c3233325d7d2c226c68735f706b223a5b3134352c3139352c3234312c35332c3139392c3133362c33322c3235342c3131362c3132302c3137352c3232332c31382c37352c3134362c35312c3131362c3235332c3137342c3132312c3235342c3134302c3136392c33302c3135312c33332c3134392c3131342c3130322c3132332c3139302c33325d2c227268735f706b223a5b32362c3233332c3137382c3138372c3234342c33382c3138372c3132332c3133382c33312c34352c39382c37302c38322c3232392c39302c3137372c36352c3133332c3135372c39372c3233302c35302c37382c3134362c37302c3230322c3130312c35362c32302c3234372c3231375d7d".to_string()), + operational_certificate: Some("5b5b5b3230332c3130392c34302c32382c3235312c39342c35322c32342c3231322c3131362c3134392c38302c3138332c3136322c312c36322c352c3133332c35372c3230342c31352c3137322c3134372c38362c3132352c35392c31322c3235332c3130312c3138342c32332c31355d2c322c3132382c5b3133382c3131302c3139322c35302c38362c332c3136382c33342c3137322c31392c39312c3133392c3139302c3134302c31382c3137372c33312c34362c3132322c3130362c3233342c3137372c3130382c3232352c3230372c342c302c35392c3233372c3133352c3130342c39382c3133332c3133312c32392c3231322c3137312c3139342c3234342c3139312c3137392c3131392c34322c37352c3135302c36312c3232362c3132312c35342c3232332c3139332c3133382c3139302c32372c3138322c3135322c35362c32312c3136302c3230372c33352c3233372c3130322c31325d5d2c5b3230372c31322c3136382c3139302c34362c3131362c3139362c3133332c3139362c3233312c3132342c3235302c3134372c33372c3137352c3231312c3234372c3139382c3134302c3133392c3234362c3130342c3132342c3232372c34392c352c3235332c3232382c3130372c39332c3133362c3134345d5d".to_string()), + kes_period: Some(6), + } + } + + // reference structure to compare with what should be deserialized. + fn golden_message_v2() -> RegisterSignerMessage { + RegisterSignerMessage { + epoch: Some(Epoch(123)), party_id: "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx".to_string(), verification_key: "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d".to_string(), verification_key_signature: Some("7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a5b33322c3235332c3134372c3132382c39302c3137372c31322c3231302c3232312c37332c31332c3234332c31302c36342c39322c3139322c3131342c3231302c3231372c3133312c3131322c3137322c3231362c3138372c38382c3138362c32372c31342c3134302c3230362c38312c3234332c3132342c3131342c3234362c3130342c35362c3131342c372c3131342c35372c3232392c3135362c32332c39342c32382c3137372c36302c3131302c34332c3136362c392c3139392c3233302c3133342c37302c3233322c3131362c3130302c36382c39342c3135332c3136342c31345d2c226c68735f706b223a5b3136332c3234362c39382c3232362c31302c36302c3131322c3234312c3136372c36322c3230302c3234382c39392c3133382c3136322c3137322c3137352c31332c3138392c392c302c3234392c34322c3232392c3231312c3230362c3235302c3136372c33382c36332c3138392c3134335d2c227268735f706b223a5b3137322c3138392c3138352c3233302c3234382c39342c3235312c3138312c3137392c38362c38342c32332c3137382c3230352c3232362c382c3233312c3230372c3231302c38332c36382c3231342c3231362c37342c3135362c3130322c32382c3233302c382c35322c3130312c3234355d7d2c226c68735f706b223a5b3134302c3230372c39382c3133362c3134312c3233312c3231352c3230342c35322c3135352c38392c3232332c34382c3134392c3138352c3135352c3131342c3235352c39332c3137352c3234332c37302c3137362c3134332c32342c3132352c32392c3231392c3135302c33362c3232352c33375d2c227268735f706b223a5b3137312c3232392c3139332c3130352c3233342c31382c3232392c38312c3235352c3139322c3133302c32352c33322c3138342c312c33392c39332c3138372c382c3233332c36392c37342c35362c3130312c37302c3231332c3232342c33322c31382c3130322c3235332c35355d7d2c226c68735f706b223a5b34322c302c31382c36382c3135332c3234312c3231342c3133352c3139342c34332c3231322c35382c36322c332c3136302c3133332c34342c37342c3131312c37382c3136322c3133322c35372c32362c3138392c36372c3132372c3232352c37352c3137312c31342c3131345d2c227268735f706b223a5b3133372c3135302c39302c3139362c3232322c3234312c3137392c3133372c3130362c33362c3130322c37322c35372c37312c3130392c3235302c392c33362c3134362c3234372c37342c3231362c31322c342c35322c33372c3233342c37302c3233342c37302c36362c34315d7d2c226c68735f706b223a5b3132312c3134352c3233352c3230392c3135322c39302c3135372c3231392c35312c34302c3136372c322c3137372c3138372c39372c3135332c3138392c3130392c3234392c38392c3231372c3135302c3139322c3131302c3232322c3138332c3134362c39392c3134352c35392c3132352c3132305d2c227268735f706b223a5b32362c38352c3137332c3235302c34382c36322c33382c3231392c39312c3138392c3136382c35322c3137392c34342c39332c39362c31362c3136392c38372c31302c3137302c312c3138392c322c3235352c3131312c3230342c3233372c3138312c3137342c31362c3231385d7d2c226c68735f706b223a5b372c37382c3233342c34362c32372c3234322c332c3234312c3231342c3131322c372c34302c3131372c39372c39332c3234322c3130342c3137302c39352c3138372c37382c3134312c3233382c35392c3231302c352c3133342c3234392c3231372c31302c3132312c33345d2c227268735f706b223a5b3134312c3130332c3232332c3233332c3230322c34302c3231352c3135362c3131342c36342c3231332c35392c3233332c33362c3234372c3132342c3130392c3138312c3230302c3136342c3232302c3230352c32392c3133332c3132302c3232342c3132312c3132362c36362c3235322c37312c3233325d7d2c226c68735f706b223a5b3134352c3139352c3234312c35332c3139392c3133362c33322c3235342c3131362c3132302c3137352c3232332c31382c37352c3134362c35312c3131362c3235332c3137342c3132312c3235342c3134302c3136392c33302c3135312c33332c3134392c3131342c3130322c3132332c3139302c33325d2c227268735f706b223a5b32362c3233332c3137382c3138372c3234342c33382c3138372c3132332c3133382c33312c34352c39382c37302c38322c3232392c39302c3137372c36352c3133332c3135372c39372c3233302c35302c37382c3134362c37302c3230322c3130312c35362c32302c3234372c3231375d7d".to_string()), @@ -32,6 +99,24 @@ mod tests { "This JSON is expected to be succesfully parsed into a RegisterSignerMessage instance.", ); - assert_eq!(golden_message(), message); + assert_eq!(golden_message_v1(), message); + } + + // Test the retro compatibility with possible future upgrades. + #[test] + fn test_v2() { + let json = r#"{ +"epoch": 123, +"party_id": "pool1m8crhnqj5k2kyszf5j2scshupystyxc887zdfrpzh6ty6eun4fx", +"verification_key": "7b22766b223a5b3134352c32332c3135382c31322c3138332c3230392c33322c3134302c33372c3132342c3136362c3231352c3136302c3231352c3235302c3133342c3135342c3235302c3234312c3230362c3139342c3232322c382c35392c33332c392c35382c322c3235312c31302c33322c3135352c3232372c3134332c3232362c35372c3135312c37342c3139392c3131372c37352c3136382c3134302c34362c3233392c3134352c37322c31362c32312c3138312c3139332c3134362c38362c3231332c3230342c3139332c3232332c32352c3135372c33342c33332c3232372c35312c3132362c3132362c3135362c36342c3232302c3139392c3231332c31362c34352c3131302c3234332c33352c3134382c37312c3231382c3132342c3132332c31362c3132312c3135322c31382c32362c3231322c3231342c3230312c3139302c3137342c3131352c39372c3234392c3235342c3131362c3234335d2c22706f70223a5b3138332c3134352c3133392c3234322c3132302c3136302c35362c3131382c3234322c3230342c39312c38392c32312c3138342c382c34372c3231332c3130352c36332c3135302c32312c3231372c352c382c3231392c3138382c3131342c3230352c3136362c31362c3234302c3234302c3231342c31362c3230342c3231382c3139332c3138312c32342c35362c34352c39392c3234342c38312c32352c35322c3232342c36372c3136382c3136392c3130392c3132322c38372c34392c3137302c3138312c3135312c31352c3235322c3139352c3231312c3233342c3139352c34392c39312c31392c35312c3234312c33332c35382c3134302c3235322c3234322c362c342c34302c32312c3136372c3234392c3235312c33362c38372c36302c39362c36392c3135322c3231302c39382c3136352c352c362c34312c39362c3233352c37352c3138335d7d", +"verification_key_signature": "7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a7b227369676d61223a5b33322c3235332c3134372c3132382c39302c3137372c31322c3231302c3232312c37332c31332c3234332c31302c36342c39322c3139322c3131342c3231302c3231372c3133312c3131322c3137322c3231362c3138372c38382c3138362c32372c31342c3134302c3230362c38312c3234332c3132342c3131342c3234362c3130342c35362c3131342c372c3131342c35372c3232392c3135362c32332c39342c32382c3137372c36302c3131302c34332c3136362c392c3139392c3233302c3133342c37302c3233322c3131362c3130302c36382c39342c3135332c3136342c31345d2c226c68735f706b223a5b3136332c3234362c39382c3232362c31302c36302c3131322c3234312c3136372c36322c3230302c3234382c39392c3133382c3136322c3137322c3137352c31332c3138392c392c302c3234392c34322c3232392c3231312c3230362c3235302c3136372c33382c36332c3138392c3134335d2c227268735f706b223a5b3137322c3138392c3138352c3233302c3234382c39342c3235312c3138312c3137392c38362c38342c32332c3137382c3230352c3232362c382c3233312c3230372c3231302c38332c36382c3231342c3231362c37342c3135362c3130322c32382c3233302c382c35322c3130312c3234355d7d2c226c68735f706b223a5b3134302c3230372c39382c3133362c3134312c3233312c3231352c3230342c35322c3135352c38392c3232332c34382c3134392c3138352c3135352c3131342c3235352c39332c3137352c3234332c37302c3137362c3134332c32342c3132352c32392c3231392c3135302c33362c3232352c33375d2c227268735f706b223a5b3137312c3232392c3139332c3130352c3233342c31382c3232392c38312c3235352c3139322c3133302c32352c33322c3138342c312c33392c39332c3138372c382c3233332c36392c37342c35362c3130312c37302c3231332c3232342c33322c31382c3130322c3235332c35355d7d2c226c68735f706b223a5b34322c302c31382c36382c3135332c3234312c3231342c3133352c3139342c34332c3231322c35382c36322c332c3136302c3133332c34342c37342c3131312c37382c3136322c3133322c35372c32362c3138392c36372c3132372c3232352c37352c3137312c31342c3131345d2c227268735f706b223a5b3133372c3135302c39302c3139362c3232322c3234312c3137392c3133372c3130362c33362c3130322c37322c35372c37312c3130392c3235302c392c33362c3134362c3234372c37342c3231362c31322c342c35322c33372c3233342c37302c3233342c37302c36362c34315d7d2c226c68735f706b223a5b3132312c3134352c3233352c3230392c3135322c39302c3135372c3231392c35312c34302c3136372c322c3137372c3138372c39372c3135332c3138392c3130392c3234392c38392c3231372c3135302c3139322c3131302c3232322c3138332c3134362c39392c3134352c35392c3132352c3132305d2c227268735f706b223a5b32362c38352c3137332c3235302c34382c36322c33382c3231392c39312c3138392c3136382c35322c3137392c34342c39332c39362c31362c3136392c38372c31302c3137302c312c3138392c322c3235352c3131312c3230342c3233372c3138312c3137342c31362c3231385d7d2c226c68735f706b223a5b372c37382c3233342c34362c32372c3234322c332c3234312c3231342c3131322c372c34302c3131372c39372c39332c3234322c3130342c3137302c39352c3138372c37382c3134312c3233382c35392c3231302c352c3133342c3234392c3231372c31302c3132312c33345d2c227268735f706b223a5b3134312c3130332c3232332c3233332c3230322c34302c3231352c3135362c3131342c36342c3231332c35392c3233332c33362c3234372c3132342c3130392c3138312c3230302c3136342c3232302c3230352c32392c3133332c3132302c3232342c3132312c3132362c36362c3235322c37312c3233325d7d2c226c68735f706b223a5b3134352c3139352c3234312c35332c3139392c3133362c33322c3235342c3131362c3132302c3137352c3232332c31382c37352c3134362c35312c3131362c3235332c3137342c3132312c3235342c3134302c3136392c33302c3135312c33332c3134392c3131342c3130322c3132332c3139302c33325d2c227268735f706b223a5b32362c3233332c3137382c3138372c3234342c33382c3138372c3132332c3133382c33312c34352c39382c37302c38322c3232392c39302c3137372c36352c3133332c3135372c39372c3233302c35302c37382c3134362c37302c3230322c3130312c35362c32302c3234372c3231375d7d", +"operational_certificate": "5b5b5b3230332c3130392c34302c32382c3235312c39342c35322c32342c3231322c3131362c3134392c38302c3138332c3136322c312c36322c352c3133332c35372c3230342c31352c3137322c3134372c38362c3132352c35392c31322c3235332c3130312c3138342c32332c31355d2c322c3132382c5b3133382c3131302c3139322c35302c38362c332c3136382c33342c3137322c31392c39312c3133392c3139302c3134302c31382c3137372c33312c34362c3132322c3130362c3233342c3137372c3130382c3232352c3230372c342c302c35392c3233372c3133352c3130342c39382c3133332c3133312c32392c3231322c3137312c3139342c3234342c3139312c3137392c3131392c34322c37352c3135302c36312c3232362c3132312c35342c3232332c3139332c3133382c3139302c32372c3138322c3135322c35362c32312c3136302c3230372c33352c3233372c3130322c31325d5d2c5b3230372c31322c3136382c3139302c34362c3131362c3139362c3133332c3139362c3233312c3132342c3235302c3134372c33372c3137352c3231312c3234372c3139382c3134302c3133392c3234362c3130342c3132342c3232372c34392c352c3235332c3232382c3130372c39332c3133362c3134345d5d", +"kes_period": 6 +}"#; + let message: RegisterSignerMessage = serde_json::from_str(json).expect( + "This JSON is expected to be succesfully parsed into a RegisterSignerMessage instance.", + ); + + assert_eq!(golden_message_v2(), message); } } diff --git a/mithril-signer/src/message_adapters/to_register_signer_message.rs b/mithril-signer/src/message_adapters/to_register_signer_message.rs index 0521ce59579..ef79e9d87ad 100644 --- a/mithril-signer/src/message_adapters/to_register_signer_message.rs +++ b/mithril-signer/src/message_adapters/to_register_signer_message.rs @@ -7,6 +7,7 @@ impl ToRegisterSignerMessageAdapter { /// Method to trigger the conversion. pub fn adapt(signer: Signer) -> RegisterSignerMessage { RegisterSignerMessage { + epoch: None, party_id: signer.party_id, verification_key: signer.verification_key, verification_key_signature: signer.verification_key_signature, From 12e64d51e7691fc7b36f0ff5fc334d69e78aca17 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 26 Apr 2023 18:47:45 +0200 Subject: [PATCH 2/8] Update SignerRegisterer trait to expose current round And enforce epoch compliance when registering. --- mithril-aggregator/src/signer_registerer.rs | 35 ++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/mithril-aggregator/src/signer_registerer.rs b/mithril-aggregator/src/signer_registerer.rs index 6a5418b6f3e..6ec8bee5ea7 100644 --- a/mithril-aggregator/src/signer_registerer.rs +++ b/mithril-aggregator/src/signer_registerer.rs @@ -24,6 +24,15 @@ pub enum SignerRegistrationError { #[error("a signer registration round has not yet to be opened")] RegistrationRoundNotYetOpened, + /// Registration round for unexpected epoch + #[error("unexpected signer registration round epoch: current_round_epoch: {current_round_epoch}, received_epoch: {received_epoch}")] + RegistrationRoundUnexpectedEpoch { + /// Epoch of the current round + current_round_epoch: Epoch, + /// Epoch of the received signer registration + received_epoch: Epoch, + }, + /// Codec error. #[error("codec error: '{0}'")] Codec(String), @@ -52,7 +61,9 @@ pub enum SignerRegistrationError { /// Represents the information needed to handle a signer registration round #[derive(Debug, Clone, PartialEq, Eq)] pub struct SignerRegistrationRound { - epoch: Epoch, + /// Registration round epoch + pub epoch: Epoch, + stake_distribution: StakeDistribution, } @@ -73,8 +84,12 @@ pub trait SignerRegisterer: Sync + Send { /// Register a signer async fn register_signer( &self, + epoch: Epoch, signer: &Signer, ) -> Result; + + /// Get current open round if exists + async fn get_current_round(&self) -> Option; } /// Trait to open a signer registration round @@ -171,12 +186,19 @@ impl SignerRegistrationRoundOpener for MithrilSignerRegisterer { impl SignerRegisterer for MithrilSignerRegisterer { async fn register_signer( &self, + epoch: Epoch, signer: &Signer, ) -> Result { let registration_round = self.current_round.read().await; let registration_round = registration_round .as_ref() .ok_or(SignerRegistrationError::RegistrationRoundNotYetOpened)?; + if registration_round.epoch != epoch { + return Err(SignerRegistrationError::RegistrationRoundUnexpectedEpoch { + current_round_epoch: registration_round.epoch, + received_epoch: epoch, + }); + } let mut key_registration = ProtocolKeyRegistration::init( ®istration_round @@ -245,6 +267,10 @@ impl SignerRegisterer for MithrilSignerRegisterer { None => Ok(signer_save), } } + + async fn get_current_round(&self) -> Option { + self.current_round.read().await.as_ref().cloned() + } } #[cfg(test)] @@ -293,7 +319,7 @@ mod tests { .expect("signer registration round opening should not fail"); signer_registerer - .register_signer(&signer_to_register) + .register_signer(registration_epoch, &signer_to_register) .await .expect("signer registration should not fail"); @@ -342,7 +368,7 @@ mod tests { .expect("signer registration round opening should not fail"); signer_registerer - .register_signer(&signer_to_register) + .register_signer(registration_epoch, &signer_to_register) .await .expect("signer registration should not fail"); @@ -373,11 +399,12 @@ mod tests { verification_key_store.clone(), Arc::new(signer_recorder), ); + let registration_epoch = Epoch(1); let fixture = MithrilFixtureBuilder::default().with_signers(5).build(); let signer_to_register: Signer = fixture.signers()[0].to_owned(); signer_registerer - .register_signer(&signer_to_register) + .register_signer(registration_epoch, &signer_to_register) .await .expect_err("signer registration should fail if no round opened"); } From 32123843ec7ac41c5f9644e8c021e20cf4df9136 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Wed, 26 Apr 2023 18:48:57 +0200 Subject: [PATCH 3/8] Update signer registration route --- .../src/http_server/routes/signer_routes.rs | 41 ++++++++++++++++--- openapi.yaml | 8 +++- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/mithril-aggregator/src/http_server/routes/signer_routes.rs b/mithril-aggregator/src/http_server/routes/signer_routes.rs index ce7b10f3440..c29ba979d12 100644 --- a/mithril-aggregator/src/http_server/routes/signer_routes.rs +++ b/mithril-aggregator/src/http_server/routes/signer_routes.rs @@ -54,11 +54,25 @@ mod handlers { "⇄ HTTP SERVER: register_signer/{:?}", register_signer_message ); + + let registration_epoch = match register_signer_message.epoch { + Some(epoch) => epoch, + None => match signer_registerer.get_current_round().await { + Some(round) => round.epoch, + None => { + let err = SignerRegistrationError::RegistrationRoundNotYetOpened; + warn!("register_signer::error"; "error" => ?err); + return Ok(reply::internal_server_error(err.to_string())); + } + }, + }; + let signer = FromRegisterSignerAdapter::adapt(register_signer_message); let mut headers: Vec<(&str, &str)> = match signer_node_version.as_ref() { Some(version) => vec![("signer-node-version", version)], None => Vec::new(), }; + let epoch_str = match beacon_provider.get_current_beacon().await { Ok(beacon) => format!("{}", beacon.epoch), Err(e) => { @@ -67,11 +81,14 @@ mod handlers { String::new() } }; - if !epoch_str.is_empty() { headers.push(("epoch", epoch_str.as_str())); } - match signer_registerer.register_signer(&signer).await { + + match signer_registerer + .register_signer(registration_epoch, &signer) + .await + { Ok(signer_with_stake) => { let _ = event_transmitter.send_event_message( "HTTP::signer_register", @@ -147,7 +164,10 @@ mod tests { let mut mock_signer_registerer = MockSignerRegisterer::new(); mock_signer_registerer .expect_register_signer() - .return_once(|_| Ok(signer_with_stake)); + .return_once(|_, _| Ok(signer_with_stake)); + mock_signer_registerer + .expect_get_current_round() + .return_once(|| None); let (mut dependency_manager, _) = initialize_dependencies().await; dependency_manager.signer_registerer = Arc::new(mock_signer_registerer); @@ -179,7 +199,10 @@ mod tests { let mut mock_signer_registerer = MockSignerRegisterer::new(); mock_signer_registerer .expect_register_signer() - .return_once(|_| Err(SignerRegistrationError::ExistingSigner(signer_with_stake))); + .return_once(|_, _| Err(SignerRegistrationError::ExistingSigner(signer_with_stake))); + mock_signer_registerer + .expect_get_current_round() + .return_once(|| None); let (mut dependency_manager, _) = initialize_dependencies().await; dependency_manager.signer_registerer = Arc::new(mock_signer_registerer); @@ -210,11 +233,14 @@ mod tests { let mut mock_signer_registerer = MockSignerRegisterer::new(); mock_signer_registerer .expect_register_signer() - .return_once(|_| { + .return_once(|_, _| { Err(SignerRegistrationError::FailedSignerRegistration( ProtocolRegistrationError::OpCertInvalid, )) }); + mock_signer_registerer + .expect_get_current_round() + .return_once(|| None); let (mut dependency_manager, _) = initialize_dependencies().await; dependency_manager.signer_registerer = Arc::new(mock_signer_registerer); @@ -245,11 +271,14 @@ mod tests { let mut mock_signer_registerer = MockSignerRegisterer::new(); mock_signer_registerer .expect_register_signer() - .return_once(|_| { + .return_once(|_, _| { Err(SignerRegistrationError::ChainObserver( "an error occurred".to_string(), )) }); + mock_signer_registerer + .expect_get_current_round() + .return_once(|| None); let (mut dependency_manager, _) = initialize_dependencies().await; dependency_manager.signer_registerer = Arc::new(mock_signer_registerer); diff --git a/openapi.yaml b/openapi.yaml index 254cf031e05..7a4dd67fa3f 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -4,7 +4,7 @@ info: # `mithril-common/src/lib.rs` file. If you plan to update it # here to reflect changes in the API, please also update the constant in the # Rust file. - version: 0.1.3 + version: 0.1.4 title: Mithril Aggregator Server description: | The REST API provided by a Mithril Aggregator Node in a Mithril network. @@ -403,6 +403,12 @@ components: RegisterSignerMessage: description: This message represents a signing participant in the network. + additionalProperties: true + properties: + epoch: + description: Cardano chain epoch number + type: integer + format: int64 allOf: - $ref: "#/components/schemas/Signer" From 0b41bf9bda419da93feac279131da1499f9e1a46 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Thu, 27 Apr 2023 11:12:25 +0200 Subject: [PATCH 4/8] Update signer to send registration epoch --- mithril-signer/src/certificate_handler.rs | 41 +++++++++++++++---- .../to_register_signer_message.rs | 12 ++++-- mithril-signer/src/runtime/runner.rs | 2 +- .../test_extensions/certificate_handler.rs | 26 ++++++++---- .../test_extensions/state_machine_tester.rs | 10 ++++- 5 files changed, 69 insertions(+), 22 deletions(-) diff --git a/mithril-signer/src/certificate_handler.rs b/mithril-signer/src/certificate_handler.rs index 843e952d549..7ad051b8957 100644 --- a/mithril-signer/src/certificate_handler.rs +++ b/mithril-signer/src/certificate_handler.rs @@ -6,7 +6,7 @@ use thiserror::Error; use mithril_common::{ api_version::APIVersionProvider, - entities::{CertificatePending, EpochSettings, Signer, SingleSignatures}, + entities::{CertificatePending, Epoch, EpochSettings, Signer, SingleSignatures}, messages::{CertificatePendingMessage, EpochSettingsMessage}, MITHRIL_API_VERSION_HEADER, MITHRIL_SIGNER_VERSION_HEADER, }; @@ -70,7 +70,11 @@ pub trait CertificateHandler: Sync + Send { ) -> Result, CertificateHandlerError>; /// Registers signer with the aggregator. - async fn register_signer(&self, signer: &Signer) -> Result<(), CertificateHandlerError>; + async fn register_signer( + &self, + epoch: Epoch, + signer: &Signer, + ) -> Result<(), CertificateHandlerError>; /// Registers single signatures with the aggregator. async fn register_signatures( @@ -182,10 +186,15 @@ impl CertificateHandler for CertificateHandlerHTTPClient { } } - async fn register_signer(&self, signer: &Signer) -> Result<(), CertificateHandlerError> { + async fn register_signer( + &self, + epoch: Epoch, + signer: &Signer, + ) -> Result<(), CertificateHandlerError> { debug!("Register signer"); let url = format!("{}/register-signer", self.aggregator_endpoint); - let register_signer_message = ToRegisterSignerMessageAdapter::adapt(signer.to_owned()); + let register_signer_message = + ToRegisterSignerMessageAdapter::adapt(epoch, signer.to_owned()); let response = self .prepare_request_builder(Client::new().post(url.clone())) .json(®ister_signer_message) @@ -322,7 +331,11 @@ pub(crate) mod dumb { } /// Registers signer with the aggregator - async fn register_signer(&self, signer: &Signer) -> Result<(), CertificateHandlerError> { + async fn register_signer( + &self, + _epoch: Epoch, + signer: &Signer, + ) -> Result<(), CertificateHandlerError> { let mut last_registered_signer = self.last_registered_signer.write().await; let signer = signer.clone(); *last_registered_signer = Some(signer); @@ -512,6 +525,7 @@ mod tests { #[tokio::test] async fn test_register_signer_ok_201() { + let epoch = Epoch(1); let single_signers = fake_data::signers(1); let single_signer = single_signers.first().unwrap(); let (server, config, api_version_provider) = setup_test(); @@ -523,12 +537,15 @@ mod tests { config.aggregator_endpoint, Arc::new(api_version_provider), ); - let register_signer = certificate_handler.register_signer(single_signer).await; + let register_signer = certificate_handler + .register_signer(epoch, single_signer) + .await; register_signer.expect("unexpected error"); } #[tokio::test] async fn test_register_signer_ko_412() { + let epoch = Epoch(1); let (server, config, api_version_provider) = setup_test(); let _snapshots_mock = server.mock(|when, then| { when.method(POST).path("/register-signer"); @@ -542,7 +559,7 @@ mod tests { Arc::new(api_version_provider), ); let error = certificate_handler - .register_signer(single_signer) + .register_signer(epoch, single_signer) .await .unwrap_err(); @@ -551,6 +568,7 @@ mod tests { #[tokio::test] async fn test_register_signer_ko_400() { + let epoch = Epoch(1); let single_signers = fake_data::signers(1); let single_signer = single_signers.first().unwrap(); let (server, config, api_version_provider) = setup_test(); @@ -568,7 +586,9 @@ mod tests { config.aggregator_endpoint, Arc::new(api_version_provider), ); - let register_signer = certificate_handler.register_signer(single_signer).await; + let register_signer = certificate_handler + .register_signer(epoch, single_signer) + .await; assert_eq!( CertificateHandlerError::RemoteServerLogical( "bad request: {\"label\":\"error\",\"message\":\"an error\"}".to_string() @@ -580,6 +600,7 @@ mod tests { #[tokio::test] async fn test_register_signer_ko_500() { + let epoch = Epoch(1); let single_signers = fake_data::signers(1); let single_signer = single_signers.first().unwrap(); let (server, config, api_version_provider) = setup_test(); @@ -591,7 +612,9 @@ mod tests { config.aggregator_endpoint, Arc::new(api_version_provider), ); - let register_signer = certificate_handler.register_signer(single_signer).await; + let register_signer = certificate_handler + .register_signer(epoch, single_signer) + .await; assert_eq!( CertificateHandlerError::RemoteServerTechnical("an error occurred".to_string()) .to_string(), diff --git a/mithril-signer/src/message_adapters/to_register_signer_message.rs b/mithril-signer/src/message_adapters/to_register_signer_message.rs index ef79e9d87ad..21f9bb488f6 100644 --- a/mithril-signer/src/message_adapters/to_register_signer_message.rs +++ b/mithril-signer/src/message_adapters/to_register_signer_message.rs @@ -1,13 +1,16 @@ -use mithril_common::{entities::Signer, messages::RegisterSignerMessage}; +use mithril_common::{ + entities::{Epoch, Signer}, + messages::RegisterSignerMessage, +}; /// Adapter to create [RegisterSignerMessage] from [Signer] instance. pub struct ToRegisterSignerMessageAdapter; impl ToRegisterSignerMessageAdapter { /// Method to trigger the conversion. - pub fn adapt(signer: Signer) -> RegisterSignerMessage { + pub fn adapt(epoch: Epoch, signer: Signer) -> RegisterSignerMessage { RegisterSignerMessage { - epoch: None, + epoch: Some(epoch), party_id: signer.party_id, verification_key: signer.verification_key, verification_key_signature: signer.verification_key_signature, @@ -25,8 +28,9 @@ mod tests { #[test] fn adapt_ok() { + let epoch = Epoch(1); let signer = fake_data::signers(1)[0].to_owned(); - let message = ToRegisterSignerMessageAdapter::adapt(signer); + let message = ToRegisterSignerMessageAdapter::adapt(epoch, signer); assert_eq!("0".to_string(), message.party_id); } diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index ab81706d47b..7b970bd0e35 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -224,7 +224,7 @@ impl Runner for SignerRunner { ); self.services .certificate_handler - .register_signer(&signer) + .register_signer(epoch, &signer) .await?; self.services .protocol_initializer_store diff --git a/mithril-signer/tests/test_extensions/certificate_handler.rs b/mithril-signer/tests/test_extensions/certificate_handler.rs index 3f688536687..f5655e9f92f 100644 --- a/mithril-signer/tests/test_extensions/certificate_handler.rs +++ b/mithril-signer/tests/test_extensions/certificate_handler.rs @@ -90,8 +90,12 @@ impl CertificateHandler for FakeAggregator { } /// Registers signer with the aggregator - async fn register_signer(&self, signer: &Signer) -> Result<(), CertificateHandlerError> { - let epoch = self.get_beacon().await?.epoch.offset_to_recording_epoch(); + async fn register_signer( + &self, + epoch: Epoch, + signer: &Signer, + ) -> Result<(), CertificateHandlerError> { + let epoch = epoch.offset_to_recording_epoch(); let mut store = self.registered_signers.write().await; let mut signers = store.get(&epoch).cloned().unwrap_or_default(); @@ -138,12 +142,13 @@ mod tests { #[tokio::test] async fn register_signer() { + let epoch = Epoch(1); let (_, fake_aggregator) = init().await; let fake_signers = fake_data::signers(2); assert_eq!(2, fake_signers.len()); fake_aggregator - .register_signer(&fake_signers.as_slice()[0]) + .register_signer(epoch, &fake_signers.as_slice()[0]) .await .expect("certificate handler should not fail while registering a user"); let signers = fake_aggregator @@ -154,7 +159,7 @@ mod tests { assert_eq!(1, signers.len()); fake_aggregator - .register_signer(&fake_signers.as_slice()[1]) + .register_signer(epoch, &fake_signers.as_slice()[1]) .await .expect("certificate handler should not fail while registering a user"); let signers = fake_aggregator @@ -167,6 +172,7 @@ mod tests { #[tokio::test] async fn retrieve_pending_certificate() { + let epoch = Epoch(1); let (chain_observer, fake_aggregator) = init().await; let cert = fake_aggregator .retrieve_pending_certificate() @@ -179,7 +185,10 @@ mod tests { ); for signer in fake_data::signers(3) { - fake_aggregator.register_signer(&signer).await.unwrap(); + fake_aggregator + .register_signer(epoch, &signer) + .await + .unwrap(); } let cert = fake_aggregator @@ -192,7 +201,7 @@ mod tests { assert_eq!(0, cert.next_signers.len()); assert_eq!(1, cert.beacon.epoch); - chain_observer.next_epoch().await; + let epoch = chain_observer.next_epoch().await.unwrap(); let cert = fake_aggregator .retrieve_pending_certificate() @@ -205,7 +214,10 @@ mod tests { assert_eq!(2, cert.beacon.epoch); for signer in fake_data::signers(2) { - fake_aggregator.register_signer(&signer).await.unwrap(); + fake_aggregator + .register_signer(epoch, &signer) + .await + .unwrap(); } chain_observer.next_epoch().await; diff --git a/mithril-signer/tests/test_extensions/state_machine_tester.rs b/mithril-signer/tests/test_extensions/state_machine_tester.rs index 1cc2c05f22d..c177014cd82 100644 --- a/mithril-signer/tests/test_extensions/state_machine_tester.rs +++ b/mithril-signer/tests/test_extensions/state_machine_tester.rs @@ -334,9 +334,17 @@ impl StateMachineTester { &mut self, signers_with_stake: &[SignerWithStake], ) -> Result<&mut Self> { + let epoch = self + .chain_observer + .current_beacon + .read() + .await + .as_ref() + .unwrap() + .epoch; for signer_with_stake in signers_with_stake { self.certificate_handler - .register_signer(&signer_with_stake.to_owned().into()) + .register_signer(epoch, &signer_with_stake.to_owned().into()) .await .map_err(|e| TestError::SubsystemError(e.into()))?; } From 50b3e77b326048e94b459b421d15f1db201506cc Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Thu, 27 Apr 2023 16:13:36 +0200 Subject: [PATCH 5/8] Fix aggregator integration tests --- mithril-aggregator/tests/certificate_chain.rs | 2 ++ .../tests/test_extensions/runtime_tester.rs | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/mithril-aggregator/tests/certificate_chain.rs b/mithril-aggregator/tests/certificate_chain.rs index 2981ce3d09a..de96cac0ce0 100644 --- a/mithril-aggregator/tests/certificate_chain.rs +++ b/mithril-aggregator/tests/certificate_chain.rs @@ -193,6 +193,7 @@ async fn certificate_chain() { current_epoch = tester.increase_epoch().await.unwrap(); tester.increase_immutable_number().await.unwrap(); cycle!(tester, "ready"); + tester.register_signers(&signers).await.unwrap(); cycle!(tester, "signing"); let signed_entity_type = tester @@ -214,6 +215,7 @@ async fn certificate_chain() { tester.increase_epoch().await.unwrap(); tester.increase_immutable_number().await.unwrap(); cycle!(tester, "ready"); + tester.register_signers(&signers).await.unwrap(); cycle!(tester, "signing"); let signed_entity_type = tester .open_message_observer diff --git a/mithril-aggregator/tests/test_extensions/runtime_tester.rs b/mithril-aggregator/tests/test_extensions/runtime_tester.rs index 85f21741d0b..3729cab29e8 100644 --- a/mithril-aggregator/tests/test_extensions/runtime_tester.rs +++ b/mithril-aggregator/tests/test_extensions/runtime_tester.rs @@ -13,7 +13,7 @@ use tokio::sync::mpsc::UnboundedReceiver; use crate::test_extensions::open_message_observer::OpenMessageObserver; use mithril_aggregator::{ AggregatorRuntime, Configuration, DumbSnapshotUploader, DumbSnapshotter, - ProtocolParametersStorer, SignerRegisterer, + ProtocolParametersStorer, SignerRegisterer, SignerRegistrationError, }; use mithril_common::crypto_helper::{ProtocolClerk, ProtocolGenesisSigner}; use mithril_common::digesters::DumbImmutableFileObserver; @@ -248,14 +248,27 @@ impl RuntimeTester { /// Register the given signers in the registerer pub async fn register_signers(&mut self, signers: &[SignerFixture]) -> Result<(), String> { + let registration_epoch = self + .chain_observer + .current_beacon + .read() + .await + .as_ref() + .unwrap() + .epoch + .offset_to_recording_epoch(); + let signer_registerer = self.deps_builder.get_mithril_registerer().await.unwrap(); for signer_with_stake in signers.iter().map(|f| &f.signer_with_stake) { - self.deps_builder - .get_mithril_registerer() + match signer_registerer + .register_signer(registration_epoch, &signer_with_stake.to_owned().into()) .await - .unwrap() - .register_signer(&signer_with_stake.to_owned().into()) - .await - .map_err(|e| format!("Registering a signer should not fail: {e:?}"))?; + { + Ok(_) => {} + Err(SignerRegistrationError::ExistingSigner(_)) => {} + Err(e) => { + return Err(format!("Registering a signer should not fail: {e:?}")); + } + } } Ok(()) From 52b25039740a8e8db677f0e2bee945e36393800a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Thu, 27 Apr 2023 16:13:57 +0200 Subject: [PATCH 6/8] Fix signer integration tests --- mithril-signer/src/runtime/runner.rs | 4 +-- .../test_extensions/certificate_handler.rs | 31 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mithril-signer/src/runtime/runner.rs b/mithril-signer/src/runtime/runner.rs index 7b970bd0e35..08f83d3d0bb 100644 --- a/mithril-signer/src/runtime/runner.rs +++ b/mithril-signer/src/runtime/runner.rs @@ -224,11 +224,11 @@ impl Runner for SignerRunner { ); self.services .certificate_handler - .register_signer(epoch, &signer) + .register_signer(epoch_offset_to_recording_epoch, &signer) .await?; self.services .protocol_initializer_store - .save_protocol_initializer(epoch.offset_to_recording_epoch(), protocol_initializer) + .save_protocol_initializer(epoch_offset_to_recording_epoch, protocol_initializer) .await?; Ok(()) diff --git a/mithril-signer/tests/test_extensions/certificate_handler.rs b/mithril-signer/tests/test_extensions/certificate_handler.rs index f5655e9f92f..97129eca4a5 100644 --- a/mithril-signer/tests/test_extensions/certificate_handler.rs +++ b/mithril-signer/tests/test_extensions/certificate_handler.rs @@ -95,8 +95,6 @@ impl CertificateHandler for FakeAggregator { epoch: Epoch, signer: &Signer, ) -> Result<(), CertificateHandlerError> { - let epoch = epoch.offset_to_recording_epoch(); - let mut store = self.registered_signers.write().await; let mut signers = store.get(&epoch).cloned().unwrap_or_default(); signers.push(signer.clone()); @@ -117,8 +115,8 @@ impl CertificateHandler for FakeAggregator { #[cfg(test)] mod tests { use mithril_common::{ - chain_observer::FakeObserver, digesters::DumbImmutableFileObserver, test_utils::fake_data, - CardanoNetwork, + chain_observer::ChainObserver, chain_observer::FakeObserver, + digesters::DumbImmutableFileObserver, test_utils::fake_data, CardanoNetwork, }; use super::*; @@ -142,28 +140,35 @@ mod tests { #[tokio::test] async fn register_signer() { - let epoch = Epoch(1); - let (_, fake_aggregator) = init().await; + let (chain_observer, fake_aggregator) = init().await; let fake_signers = fake_data::signers(2); + let epoch = chain_observer.get_current_epoch().await.unwrap().unwrap(); + let registration_epoch = Epoch(2); assert_eq!(2, fake_signers.len()); fake_aggregator - .register_signer(epoch, &fake_signers.as_slice()[0]) + .register_signer( + epoch.offset_to_recording_epoch(), + &fake_signers.as_slice()[0], + ) .await .expect("certificate handler should not fail while registering a user"); let signers = fake_aggregator - .get_registered_signers(&Epoch(1).offset_to_recording_epoch()) + .get_registered_signers(®istration_epoch) .await .expect("we should have a result, None found!"); assert_eq!(1, signers.len()); fake_aggregator - .register_signer(epoch, &fake_signers.as_slice()[1]) + .register_signer( + epoch.offset_to_recording_epoch(), + &fake_signers.as_slice()[1], + ) .await .expect("certificate handler should not fail while registering a user"); let signers = fake_aggregator - .get_registered_signers(&Epoch(1).offset_to_recording_epoch()) + .get_registered_signers(®istration_epoch) .await .expect("we should have a result, None found!"); @@ -172,8 +177,8 @@ mod tests { #[tokio::test] async fn retrieve_pending_certificate() { - let epoch = Epoch(1); let (chain_observer, fake_aggregator) = init().await; + let epoch = chain_observer.get_current_epoch().await.unwrap().unwrap(); let cert = fake_aggregator .retrieve_pending_certificate() .await @@ -186,7 +191,7 @@ mod tests { for signer in fake_data::signers(3) { fake_aggregator - .register_signer(epoch, &signer) + .register_signer(epoch.offset_to_recording_epoch(), &signer) .await .unwrap(); } @@ -215,7 +220,7 @@ mod tests { for signer in fake_data::signers(2) { fake_aggregator - .register_signer(epoch, &signer) + .register_signer(epoch.offset_to_recording_epoch(), &signer) .await .unwrap(); } From 8fb72a300954fc9d73fd377cdfde0fc9f4cc99f6 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Thu, 27 Apr 2023 17:12:46 +0200 Subject: [PATCH 7/8] Add 'era_deprecate' macro --- mithril-common/src/era/mod.rs | 6 ++++++ mithril-common/src/lib.rs | 1 + mithril-common/src/messages/register_signature.rs | 1 + mithril-common/src/messages/register_signer.rs | 1 + 4 files changed, 9 insertions(+) diff --git a/mithril-common/src/era/mod.rs b/mithril-common/src/era/mod.rs index 2e640ac1f53..15bb037c363 100644 --- a/mithril-common/src/era/mod.rs +++ b/mithril-common/src/era/mod.rs @@ -8,3 +8,9 @@ mod supported_era; pub use era_checker::EraChecker; pub use era_reader::*; pub use supported_era::*; + +/// Macro used to mark the code that should be cleaned up when the new era is activated +#[macro_export] +macro_rules! era_deprecate { + ( $comment:literal ) => {}; +} diff --git a/mithril-common/src/lib.rs b/mithril-common/src/lib.rs index e3ac68cafd2..9def287d8b9 100644 --- a/mithril-common/src/lib.rs +++ b/mithril-common/src/lib.rs @@ -18,6 +18,7 @@ pub mod crypto_helper; pub mod database; pub mod digesters; pub mod entities; +#[macro_use] pub mod era; pub mod messages; pub mod signable_builder; diff --git a/mithril-common/src/messages/register_signature.rs b/mithril-common/src/messages/register_signature.rs index 4c11a4da8b9..49a3a3fff72 100644 --- a/mithril-common/src/messages/register_signature.rs +++ b/mithril-common/src/messages/register_signature.rs @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::entities::{HexEncodedSingleSignature, LotteryIndex, PartyId, SignedEntityType}; +era_deprecate!("make signed_entity_type of RegisterSignatureMessage not optional"); /// Message structure to register single signature. #[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct RegisterSignatureMessage { diff --git a/mithril-common/src/messages/register_signer.rs b/mithril-common/src/messages/register_signer.rs index a54af002a6a..e966bd5a16d 100644 --- a/mithril-common/src/messages/register_signer.rs +++ b/mithril-common/src/messages/register_signer.rs @@ -8,6 +8,7 @@ use crate::{ }, }; +era_deprecate!("make epoch of RegisterSignerMessage not optional"); /// Register Signer Message #[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] pub struct RegisterSignerMessage { From e1cd99d528f56c713c1a1fde361b4e9d5d4285fc Mon Sep 17 00:00:00 2001 From: Jean-Philippe Raynaud Date: Thu, 27 Apr 2023 16:23:00 +0200 Subject: [PATCH 8/8] Bump crate versions --- Cargo.lock | 6 +++--- mithril-aggregator/Cargo.toml | 2 +- mithril-common/Cargo.toml | 2 +- mithril-signer/Cargo.toml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bca4b5e37a3..dd1c51613b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2063,7 +2063,7 @@ dependencies = [ [[package]] name = "mithril-aggregator" -version = "0.3.1" +version = "0.3.2" dependencies = [ "async-trait", "chrono", @@ -2126,7 +2126,7 @@ dependencies = [ [[package]] name = "mithril-common" -version = "0.2.41" +version = "0.2.42" dependencies = [ "async-trait", "bech32", @@ -2193,7 +2193,7 @@ dependencies = [ [[package]] name = "mithril-signer" -version = "0.2.34" +version = "0.2.35" dependencies = [ "async-trait", "clap 4.2.2", diff --git a/mithril-aggregator/Cargo.toml b/mithril-aggregator/Cargo.toml index 37d7ade038c..067ddd5ecc6 100644 --- a/mithril-aggregator/Cargo.toml +++ b/mithril-aggregator/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-aggregator" -version = "0.3.1" +version = "0.3.2" description = "A Mithril Aggregator server" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-common/Cargo.toml b/mithril-common/Cargo.toml index 6103d267091..fc25d18d085 100644 --- a/mithril-common/Cargo.toml +++ b/mithril-common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-common" -version = "0.2.41" +version = "0.2.42" authors = { workspace = true } edition = { workspace = true } documentation = { workspace = true } diff --git a/mithril-signer/Cargo.toml b/mithril-signer/Cargo.toml index cefd886f6f8..a3c7cd3558c 100644 --- a/mithril-signer/Cargo.toml +++ b/mithril-signer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-signer" -version = "0.2.34" +version = "0.2.35" description = "A Mithril Signer" authors = { workspace = true } edition = { workspace = true }