Skip to content

Commit

Permalink
Merge pull request input-output-hk#1333 from input-output-hk/greg/131…
Browse files Browse the repository at this point in the history
…0/lower_serialization

remove useless data from serialization to improve performances
  • Loading branch information
ghubertpalo authored Nov 10, 2023
2 parents 356a862 + f7d9ba5 commit 9bda8c1
Show file tree
Hide file tree
Showing 22 changed files with 204 additions and 157 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.4.4"
version = "0.4.5"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions mithril-aggregator/src/database/provider/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use mithril_common::{
entities::{
Beacon, Certificate, CertificateMetadata, CertificateSignature, Epoch,
HexEncodedAgregateVerificationKey, HexEncodedKey, ProtocolMessage, ProtocolParameters,
ProtocolVersion, SignerWithStake,
ProtocolVersion, StakeDistributionParty,
},
sqlite::{
EntityCursor, HydrationError, Projection, Provider, SourceAlias, SqLiteEntity,
Expand Down Expand Up @@ -56,8 +56,8 @@ pub struct CertificateRecord {
/// Structured message that is used to create the signed message
pub protocol_message: ProtocolMessage,

/// The list of the active signers with their stakes and verification keys
pub signers: Vec<SignerWithStake>,
/// The list of the active signers with their stakes
pub signers: Vec<StakeDistributionParty>,

/// Date and time when the certificate was initiated
pub initiated_at: DateTime<Utc>,
Expand Down Expand Up @@ -214,7 +214,7 @@ impl SqLiteEntity for CertificateRecord {
signers: serde_json::from_str(signers_string).map_err(
|e| {
HydrationError::InvalidData(format!(
"Could not turn string '{signers_string}' to Vec<SignerWithStake>. Error: {e}"
"Could not turn string '{signers_string}' to Vec<StakeDistributionParty>. Error: {e}"
))
},
)?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use mithril_common::entities::{Certificate, CertificateSignature};
use mithril_common::messages::{
CertificateMessage, CertificateMetadataMessagePart, SignerWithStakeMessagePart,
ToMessageAdapter,
CertificateMessage, CertificateMetadataMessagePart, ToMessageAdapter,
};

/// Adapter to convert [Certificate] to [CertificateMessage] instances
Expand All @@ -15,7 +14,7 @@ impl ToMessageAdapter<Certificate, CertificateMessage> for ToCertificateMessageA
protocol_parameters: certificate.metadata.protocol_parameters,
initiated_at: certificate.metadata.initiated_at,
sealed_at: certificate.metadata.sealed_at,
signers: SignerWithStakeMessagePart::from_signers(certificate.metadata.signers),
signers: certificate.metadata.signers,
};

let (multi_signature, genesis_signature) = match certificate.signature {
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/services/certifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use mithril_common::{
crypto_helper::{ProtocolGenesisVerifier, PROTOCOL_VERSION},
entities::{
Beacon, Certificate, CertificateMetadata, CertificateSignature, Epoch, ProtocolMessage,
SignedEntityType, SingleSignatures,
SignedEntityType, SingleSignatures, StakeDistributionParty,
},
StdResult,
};
Expand Down Expand Up @@ -358,7 +358,7 @@ impl CertifierService for MithrilCertifierService {
epoch_service.current_protocol_parameters()?.clone(),
initiated_at,
sealed_at,
signers,
StakeDistributionParty::from_signers(signers),
);
let parent_certificate_hash = self
.certificate_repository
Expand Down
16 changes: 8 additions & 8 deletions mithril-aggregator/tests/certificate_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use mithril_aggregator::Configuration;
use mithril_common::{
entities::{
Beacon, Epoch, ProtocolParameters, SignedEntityType, SignedEntityTypeDiscriminants,
StakeDistribution,
StakeDistribution, StakeDistributionParty,
},
test_utils::MithrilFixtureBuilder,
};
Expand Down Expand Up @@ -74,7 +74,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 1, 2),
&initial_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
initial_fixture.compute_and_encode_avk(),
SignedEntityType::MithrilStakeDistribution(Epoch(1)),
ExpectedCertificate::genesis_identifier(&Beacon::new("devnet".to_string(), 1, 1)),
Expand All @@ -97,7 +97,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 1, 3),
&initial_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
initial_fixture.compute_and_encode_avk(),
SignedEntityType::CardanoImmutableFilesFull(Beacon::new("devnet".to_string(), 1, 3)),
ExpectedCertificate::genesis_identifier(&Beacon::new("devnet".to_string(), 1, 1)),
Expand All @@ -122,7 +122,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 1, 4),
&initial_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
initial_fixture.compute_and_encode_avk(),
SignedEntityType::CardanoImmutableFilesFull(Beacon::new("devnet".to_string(), 1, 4)),
ExpectedCertificate::genesis_identifier(&Beacon::new("devnet".to_string(), 1, 1)),
Expand Down Expand Up @@ -186,7 +186,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 2, 4),
&initial_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
initial_fixture.compute_and_encode_avk(),
SignedEntityType::MithrilStakeDistribution(Epoch(2)),
ExpectedCertificate::genesis_identifier(&Beacon::new("devnet".to_string(), 1, 1)),
Expand Down Expand Up @@ -217,7 +217,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 3, 5),
&initial_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(initial_fixture.signers_with_stake()).as_slice(),
initial_fixture.compute_and_encode_avk(),
SignedEntityType::MithrilStakeDistribution(Epoch(3)),
ExpectedCertificate::identifier(&SignedEntityType::MithrilStakeDistribution(Epoch(2))),
Expand Down Expand Up @@ -248,7 +248,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 4, 6),
&next_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(next_fixture.signers_with_stake()).as_slice(),
next_fixture.compute_and_encode_avk(),
SignedEntityType::MithrilStakeDistribution(Epoch(4)),
ExpectedCertificate::identifier(&SignedEntityType::MithrilStakeDistribution(Epoch(3))),
Expand Down Expand Up @@ -279,7 +279,7 @@ async fn certificate_chain() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 4, 7),
&next_fixture.signers_with_stake(),
StakeDistributionParty::from_signers(next_fixture.signers_with_stake()).as_slice(),
next_fixture.compute_and_encode_avk(),
SignedEntityType::CardanoImmutableFilesFull(Beacon::new("devnet".to_string(), 4, 7)),
ExpectedCertificate::identifier(&SignedEntityType::MithrilStakeDistribution(Epoch(4))),
Expand Down
5 changes: 3 additions & 2 deletions mithril-aggregator/tests/create_certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use mithril_aggregator::Configuration;
use mithril_common::{
entities::{
Beacon, Epoch, ProtocolParameters, SignedEntityType, SignedEntityTypeDiscriminants,
StakeDistributionParty,
},
test_utils::MithrilFixtureBuilder,
};
Expand Down Expand Up @@ -72,7 +73,7 @@ async fn create_certificate() {
tester,
ExpectedCertificate::new(
Beacon::new("devnet".to_string(), 1, 2),
&fixture.signers_with_stake(),
StakeDistributionParty::from_signers(fixture.signers_with_stake()).as_slice(),
fixture.compute_and_encode_avk(),
SignedEntityType::MithrilStakeDistribution(Epoch(1)),
ExpectedCertificate::genesis_identifier(&Beacon::new("devnet".to_string(), 1, 1)),
Expand Down Expand Up @@ -103,7 +104,7 @@ async fn create_certificate() {
Beacon::new("devnet".to_string(), 1, 3),
&signers_for_immutables
.iter()
.map(|s| s.into())
.map(|s| s.signer_with_stake.clone().into())
.collect::<Vec<_>>(),
fixture.compute_and_encode_avk(),
SignedEntityType::CardanoImmutableFilesFull(Beacon::new("devnet".to_string(), 1, 3)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use mithril_common::entities::{
Beacon, HexEncodedAgregateVerificationKey, PartyId, SignedEntityType, SignerWithStake, Stake,
Beacon, HexEncodedAgregateVerificationKey, PartyId, SignedEntityType, Stake,
StakeDistributionParty,
};
use std::collections::BTreeMap;

Expand All @@ -16,7 +17,7 @@ pub struct ExpectedCertificate {
impl ExpectedCertificate {
pub fn new(
beacon: Beacon,
signers: &[SignerWithStake],
signers: &[StakeDistributionParty],
avk: HexEncodedAgregateVerificationKey,
signed_type: SignedEntityType,
previous_identifier: String,
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/tests/test_extensions/runtime_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl RuntimeTester {

ExpectedCertificate::new(
certificate.beacon,
&certificate.metadata.signers,
certificate.metadata.signers.as_slice(),
certificate.aggregate_verification_key.try_into().unwrap(),
record.signed_entity_type,
previous_cert_identifier,
Expand Down
2 changes: 1 addition & 1 deletion mithril-client-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client-cli"
version = "0.5.1"
version = "0.5.2"
description = "A Mithril Client"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl CertificateRetriever for CertificateClient {
#[cfg(test)]
mod tests {
use mithril_common::entities::CertificateSignature;
use mithril_common::messages::{CertificateMetadataMessagePart, SignerWithStakeMessagePart};
use mithril_common::messages::CertificateMetadataMessagePart;
use mithril_common::test_utils::fake_data;

use crate::aggregator_client::MockAggregatorHTTPClient;
Expand Down Expand Up @@ -102,9 +102,7 @@ mod tests {
protocol_parameters: certificate.metadata.protocol_parameters.clone(),
initiated_at: certificate.metadata.initiated_at,
sealed_at: certificate.metadata.sealed_at,
signers: SignerWithStakeMessagePart::from_signers(
certificate.metadata.signers.clone(),
),
signers: certificate.metadata.signers.clone(),
},
protocol_message: certificate.protocol_message.clone(),
signed_message: certificate.signed_message.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use anyhow::Context;
use mithril_common::entities::{Certificate, CertificateMetadata, CertificateSignature};
use mithril_common::messages::{
CertificateMessage, SignerWithStakeMessagePart, TryFromMessageAdapter,
};
use mithril_common::messages::{CertificateMessage, TryFromMessageAdapter};
use mithril_common::StdResult;

/// Adapter to convert [CertificateMessage] to [Certificate] instances
Expand All @@ -16,12 +14,7 @@ impl TryFromMessageAdapter<CertificateMessage, Certificate> for FromCertificateM
protocol_parameters: certificate_message.metadata.protocol_parameters,
initiated_at: certificate_message.metadata.initiated_at,
sealed_at: certificate_message.metadata.sealed_at,
signers: SignerWithStakeMessagePart::try_into_signers(
certificate_message.metadata.signers,
)
.with_context(|| {
"'FromCertificateMessageAdapter' can not convert the list of signers"
})?,
signers: certificate_message.metadata.signers,
};

let certificate = Certificate {
Expand Down
2 changes: 1 addition & 1 deletion mithril-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-common"
version = "0.2.130"
version = "0.2.131"
authors = { workspace = true }
edition = { workspace = true }
documentation = { workspace = true }
Expand Down
3 changes: 1 addition & 2 deletions mithril-common/src/crypto_helper/tests_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ pub fn setup_certificate_chain(
.unwrap()
}
_ => {
fake_certificate.metadata.signers = fixture.signers_with_stake();

fake_certificate.metadata.signers = fixture.stake_distribution_parties();
let single_signatures = fixture
.signers_fixture()
.iter()
Expand Down
39 changes: 17 additions & 22 deletions mithril-common/src/entities/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,24 @@ impl Debug for Certificate {
mod tests {
use super::*;
use crate::{
entities::{ProtocolMessagePartKey, ProtocolParameters, SignerWithStake},
entities::{
certificate_metadata::StakeDistributionParty, ProtocolMessagePartKey,
ProtocolParameters,
},
test_utils::fake_keys,
};
use chrono::{DateTime, Duration, Utc};

fn get_signers_with_stake() -> Vec<SignerWithStake> {
fn get_parties() -> Vec<StakeDistributionParty> {
vec![
SignerWithStake::new(
"1".to_string(),
fake_keys::signer_verification_key()[1].try_into().unwrap(),
None,
None,
None,
10,
),
SignerWithStake::new(
"2".to_string(),
fake_keys::signer_verification_key()[2].try_into().unwrap(),
None,
None,
None,
20,
),
StakeDistributionParty {
party_id: "1".to_string(),
stake: 10,
},
StakeDistributionParty {
party_id: "2".to_string(),
stake: 20,
},
]
}

Expand All @@ -214,7 +209,7 @@ mod tests {
#[test]
fn test_certificate_compute_hash() {
const HASH_EXPECTED: &str =
"af0965134ef5b2c2a33005cf401c58ca882dead8efda358540dac0575098b54e";
"5a2604a4feed7d304d1dd86858b8adbf450d8167f25d43c0858a9d93c5ca73f0";

let initiated_at = DateTime::parse_from_rfc3339("2024-02-12T13:11:47.0123043Z")
.unwrap()
Expand All @@ -229,7 +224,7 @@ mod tests {
ProtocolParameters::new(1000, 100, 0.123),
initiated_at,
sealed_at,
get_signers_with_stake(),
get_parties(),
),
get_protocol_message(),
fake_keys::aggregate_verification_key()[0]
Expand Down Expand Up @@ -317,7 +312,7 @@ mod tests {
#[test]
fn test_genesis_certificate_compute_hash() {
const HASH_EXPECTED: &str =
"e8cc8885ef7a76f35216a6ef603ab0387dcacb892e0a33df9de9f5bf98cf203b";
"fd3efd4bf091db9115b11552067deb2a2798160f22726db805bef70b9e7a547b";

let initiated_at = DateTime::parse_from_rfc3339("2024-02-12T13:11:47.0123043Z")
.unwrap()
Expand All @@ -332,7 +327,7 @@ mod tests {
ProtocolParameters::new(1000, 100, 0.123),
initiated_at,
sealed_at,
get_signers_with_stake(),
get_parties(),
),
get_protocol_message(),
fake_keys::aggregate_verification_key()[1]
Expand Down
Loading

0 comments on commit 9bda8c1

Please sign in to comment.