Skip to content

Commit

Permalink
Add signed_entity_type to certificate list message
Browse files Browse the repository at this point in the history
  • Loading branch information
Alenar committed Mar 27, 2024
1 parent 2c397e7 commit c1c6cc6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
1 change: 1 addition & 0 deletions mithril-aggregator/src/database/provider/certificate.rs
Expand Up @@ -250,6 +250,7 @@ impl From<CertificateRecord> for CertificateListItemMessage {
hash: value.certificate_id,
previous_hash: value.parent_certificate_id.unwrap_or_default(),
beacon,
signed_entity_type: value.signed_entity_type,
metadata,
protocol_message: value.protocol_message,
signed_message: value.message,
Expand Down
8 changes: 3 additions & 5 deletions mithril-common/src/messages/certificate.rs
Expand Up @@ -33,8 +33,6 @@ pub struct CertificateMessage {
pub beacon: CardanoDbBeacon,

/// The signed entity type of the message.
///
/// Only available if the message is a MultiSignature.
pub signed_entity_type: SignedEntityType,

/// Certificate metadata
Expand Down Expand Up @@ -76,13 +74,13 @@ impl CertificateMessage {
ProtocolMessagePartKey::NextAggregateVerificationKey,
fake_keys::aggregate_verification_key()[1].to_owned(),
);
let beacon = CardanoDbBeacon::new("testnet".to_string(), 10, 100);
let epoch = crate::entities::Epoch(10);

Self {
hash: "hash".to_string(),
previous_hash: "previous_hash".to_string(),
beacon: beacon.clone(),
signed_entity_type: SignedEntityType::MithrilStakeDistribution(beacon.epoch),
beacon: CardanoDbBeacon::new("testnet".to_string(), *epoch, 100),
signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch),
metadata: CertificateMetadataMessagePart::dummy(),
protocol_message: protocol_message.clone(),
signed_message: "signed_message".to_string(),
Expand Down
77 changes: 45 additions & 32 deletions mithril-common/src/messages/certificate_list.rs
Expand Up @@ -4,13 +4,14 @@ use std::fmt::{Debug, Formatter};

use crate::entities::{
CardanoDbBeacon, ProtocolMessage, ProtocolMessagePartKey, ProtocolParameters, ProtocolVersion,
SignedEntityType,
};

/// Message structure of a certificate list
pub type CertificateListMessage = Vec<CertificateListItemMessage>;

/// CertificateListItemMessage represents the metadata associated to a CertificateListItemMessage
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct CertificateListItemMessageMetadata {
/// Protocol Version (semver)
/// Useful to achieve backward compatibility of the certificates (including of the multi signature)
Expand Down Expand Up @@ -38,9 +39,8 @@ pub struct CertificateListItemMessageMetadata {
pub total_signers: usize,
}

///bbb/// todo: add signed_entity_type
/// Message structure of a certificate list item
#[derive(Clone, PartialEq, Default, Serialize, Deserialize)]
#[derive(Clone, PartialEq, Serialize, Deserialize)]
pub struct CertificateListItemMessage {
/// Hash of the current certificate
/// Computed from the other fields of the certificate
Expand All @@ -57,6 +57,9 @@ pub struct CertificateListItemMessage {
/// aka BEACON(p,n)
pub beacon: CardanoDbBeacon,

/// The signed entity type of the message.
pub signed_entity_type: SignedEntityType,

/// Certificate metadata
/// aka METADATA(p,n)
pub metadata: CertificateListItemMessageMetadata,
Expand Down Expand Up @@ -87,10 +90,13 @@ impl CertificateListItemMessage {
ProtocolMessagePartKey::NextAggregateVerificationKey,
"next-avk-123".to_string(),
);
let epoch = crate::entities::Epoch(10);

Self {
hash: "hash".to_string(),
previous_hash: "previous_hash".to_string(),
beacon: CardanoDbBeacon::new("testnet".to_string(), 10, 100),
beacon: CardanoDbBeacon::new("testnet".to_string(), *epoch, 100),
signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch),
metadata: CertificateListItemMessageMetadata {
protocol_version: "0.1.0".to_string(),
protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
Expand All @@ -117,6 +123,10 @@ impl Debug for CertificateListItemMessage {
.field("hash", &self.hash)
.field("previous_hash", &self.previous_hash)
.field("beacon", &format_args!("{:?}", self.beacon))
.field(
"signed_entity_type",
&format_args!("{:?}", self.signed_entity_type),
)
.field("metadata", &format_args!("{:?}", self.metadata))
.field(
"protocol_message",
Expand Down Expand Up @@ -150,10 +160,12 @@ mod tests {
ProtocolMessagePartKey::NextAggregateVerificationKey,
"next-avk-123".to_string(),
);
let epoch = crate::entities::Epoch(10);
vec![CertificateListItemMessage {
hash: "hash".to_string(),
previous_hash: "previous_hash".to_string(),
beacon: CardanoDbBeacon::new("testnet".to_string(), 10, 100),
beacon: CardanoDbBeacon::new("testnet".to_string(), *epoch, 100),
signed_entity_type: SignedEntityType::MithrilStakeDistribution(epoch),
metadata: CertificateListItemMessageMetadata {
protocol_version: "0.1.0".to_string(),
protocol_parameters: ProtocolParameters::new(1000, 100, 0.123),
Expand All @@ -175,33 +187,34 @@ mod tests {
#[test]
fn test_v1() {
let json = r#"[{
"hash": "hash",
"previous_hash": "previous_hash",
"beacon": {
"network": "testnet",
"epoch": 10,
"immutable_file_number": 100
},
"metadata": {
"version": "0.1.0",
"parameters": {
"k": 1000,
"m": 100,
"phi_f": 0.123
},
"initiated_at": "2024-02-12T13:11:47Z",
"sealed_at": "2024-02-12T13:12:57Z",
"total_signers": 2
},
"protocol_message": {
"message_parts": {
"snapshot_digest": "snapshot-digest-123",
"next_aggregate_verification_key": "next-avk-123"
}
},
"signed_message": "signed_message",
"aggregate_verification_key": "aggregate_verification_key"
}]"#;
"hash": "hash",
"previous_hash": "previous_hash",
"beacon": {
"network": "testnet",
"epoch": 10,
"immutable_file_number": 100
},
"signed_entity_type": { "MithrilStakeDistribution": 10 },
"metadata": {
"version": "0.1.0",
"parameters": {
"k": 1000,
"m": 100,
"phi_f": 0.123
},
"initiated_at": "2024-02-12T13:11:47Z",
"sealed_at": "2024-02-12T13:12:57Z",
"total_signers": 2
},
"protocol_message": {
"message_parts": {
"snapshot_digest": "snapshot-digest-123",
"next_aggregate_verification_key": "next-avk-123"
}
},
"signed_message": "signed_message",
"aggregate_verification_key": "aggregate_verification_key"
}]"#;

let message: CertificateListMessage = serde_json::from_str(json).expect(
"This JSON is expected to be succesfully parsed into a CertificateListMessage instance.",
Expand Down

0 comments on commit c1c6cc6

Please sign in to comment.