Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize namings cardano transactions #1542

Merged
merged 12 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions internal/mithril-build-script/src/fake_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub struct FakeAggregatorData {
msds_list: FileContent,
individual_msds: BTreeMap<ArtifactId, FileContent>,

ctx_commitments_list: FileContent,
individual_ctx_commitments: BTreeMap<ArtifactId, FileContent>,
ctx_snapshots_list: FileContent,
individual_ctx_snapshots: BTreeMap<ArtifactId, FileContent>,
ctx_proofs: BTreeMap<ArtifactId, FileContent>,
}

Expand Down Expand Up @@ -58,8 +58,8 @@ impl FakeAggregatorData {
"certificates.json" => {
data.certificates_list = file_content;
}
"ctx-commitments.json" => {
data.ctx_commitments_list = file_content;
"ctx-snapshots.json" => {
data.ctx_snapshots_list = file_content;
}
_ if filename.starts_with("mithril-stake-distribution-") => {
data.individual_msds.insert(
Expand All @@ -75,9 +75,9 @@ impl FakeAggregatorData {
data.individual_certificates
.insert(extract_artifact_id(&filename, "certificate-"), file_content);
}
_ if filename.starts_with("ctx-commitment-") => {
data.individual_ctx_commitments.insert(
extract_artifact_id(&filename, "ctx-commitment-"),
_ if filename.starts_with("ctx-snapshot-") => {
data.individual_ctx_snapshots.insert(
extract_artifact_id(&filename, "ctx-snapshot-"),
file_content,
);
}
Expand Down Expand Up @@ -109,8 +109,8 @@ impl FakeAggregatorData {
BTreeSet::from_iter(self.individual_certificates.keys().cloned()),
),
generate_ids_array(
"ctx_commitment_hashes",
BTreeSet::from_iter(self.individual_ctx_commitments.keys().cloned()),
"ctx_snapshot_hashes",
BTreeSet::from_iter(self.individual_ctx_snapshots.keys().cloned()),
),
generate_ids_array(
"proof_transaction_hashes",
Expand Down Expand Up @@ -144,11 +144,11 @@ impl FakeAggregatorData {
generate_artifact_getter("certificates", self.individual_certificates),
generate_list_getter("certificate_list", self.certificates_list),
generate_ids_array(
"ctx_commitment_hashes",
BTreeSet::from_iter(self.individual_ctx_commitments.keys().cloned()),
"ctx_snapshot_hashes",
BTreeSet::from_iter(self.individual_ctx_snapshots.keys().cloned()),
),
generate_artifact_getter("ctx_commitments", self.individual_ctx_commitments),
generate_list_getter("ctx_commitments_list", self.ctx_commitments_list),
generate_artifact_getter("ctx_snapshots", self.individual_ctx_snapshots),
generate_list_getter("ctx_snapshots_list", self.ctx_snapshots_list),
generate_ids_array(
"proof_transaction_hashes",
BTreeSet::from_iter(self.ctx_proofs.keys().cloned()),
Expand Down
11 changes: 5 additions & 6 deletions mithril-aggregator/src/artifact_builder/cardano_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use super::ArtifactBuilder;
use anyhow::{anyhow, Context};
use mithril_common::{
entities::{
Beacon, CardanoTransactionsCommitment, Certificate, ProtocolMessagePartKey,
SignedEntityType,
Beacon, CardanoTransactionsSnapshot, Certificate, ProtocolMessagePartKey, SignedEntityType,
},
StdResult,
};
Expand All @@ -21,12 +20,12 @@ impl CardanoTransactionsArtifactBuilder {
}

#[async_trait]
impl ArtifactBuilder<Beacon, CardanoTransactionsCommitment> for CardanoTransactionsArtifactBuilder {
impl ArtifactBuilder<Beacon, CardanoTransactionsSnapshot> for CardanoTransactionsArtifactBuilder {
async fn compute_artifact(
&self,
beacon: Beacon,
certificate: &Certificate,
) -> StdResult<CardanoTransactionsCommitment> {
) -> StdResult<CardanoTransactionsSnapshot> {
let merkle_root = certificate
.protocol_message
.get_message_part(&ProtocolMessagePartKey::CardanoTransactionsMerkleRoot)
Expand All @@ -40,7 +39,7 @@ impl ArtifactBuilder<Beacon, CardanoTransactionsCommitment> for CardanoTransacti
)
})?;

Ok(CardanoTransactionsCommitment::new(
Ok(CardanoTransactionsSnapshot::new(
merkle_root.to_string(),
beacon,
))
Expand Down Expand Up @@ -75,7 +74,7 @@ mod tests {
.await
.unwrap();
let artifact_expected =
CardanoTransactionsCommitment::new("merkleroot".to_string(), certificate.beacon);
CardanoTransactionsSnapshot::new("merkleroot".to_string(), certificate.beacon);
assert_eq!(artifact_expected, artifact);
}

Expand Down
10 changes: 5 additions & 5 deletions mithril-aggregator/src/database/provider/signed_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mithril_common::{
Beacon, Epoch, SignedEntity, SignedEntityType, SignedEntityTypeDiscriminants, Snapshot,
},
messages::{
CardanoTransactionCommitmentListItemMessage, CardanoTransactionCommitmentMessage,
CardanoTransactionSnapshotListItemMessage, CardanoTransactionSnapshotMessage,
MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage,
SignerWithStakeMessagePart, SnapshotListItemMessage, SnapshotMessage,
},
Expand Down Expand Up @@ -140,7 +140,7 @@ impl TryFrom<SignedEntityRecord> for MithrilStakeDistributionListItemMessage {
}
}

impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentMessage {
impl TryFrom<SignedEntityRecord> for CardanoTransactionSnapshotMessage {
type Error = StdError;

fn try_from(value: SignedEntityRecord) -> Result<Self, Self::Error> {
Expand All @@ -151,7 +151,7 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentMessage {
hash: String,
}
let artifact = serde_json::from_str::<TmpCardanoTransaction>(&value.artifact)?;
let cardano_transaction_message = CardanoTransactionCommitmentMessage {
let cardano_transaction_message = CardanoTransactionSnapshotMessage {
merkle_root: artifact.merkle_root,
beacon: artifact.beacon,
hash: artifact.hash,
Expand All @@ -163,7 +163,7 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentMessage {
}
}

impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentListItemMessage {
impl TryFrom<SignedEntityRecord> for CardanoTransactionSnapshotListItemMessage {
type Error = StdError;

fn try_from(value: SignedEntityRecord) -> Result<Self, Self::Error> {
Expand All @@ -174,7 +174,7 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentListItemMessage
hash: String,
}
let artifact = serde_json::from_str::<TmpCardanoTransaction>(&value.artifact)?;
let message = CardanoTransactionCommitmentListItemMessage {
let message = CardanoTransactionSnapshotListItemMessage {
merkle_root: artifact.merkle_root,
beacon: artifact.beacon,
hash: artifact.hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub mod tests {
async fn test_cardano_transactions_get_ok() {
let signed_entity_records = create_signed_entities(
SignedEntityType::CardanoTransactions(Beacon::default()),
fake_data::cardano_transactions_commitment(5),
fake_data::cardano_transactions_snapshot(5),
);
let message = ToCardanoTransactionListMessageAdapter::adapt(signed_entity_records);
let mut mock_http_message_service = MockMessageService::new();
Expand Down Expand Up @@ -186,7 +186,7 @@ pub mod tests {
async fn test_cardano_transaction_get_ok() {
let signed_entity = create_signed_entities(
SignedEntityType::CardanoTransactions(Beacon::default()),
fake_data::cardano_transactions_commitment(1),
fake_data::cardano_transactions_snapshot(1),
)
.first()
.unwrap()
Expand Down
10 changes: 5 additions & 5 deletions mithril-aggregator/src/http_server/routes/proof_routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod handlers {

match unwrap_to_internal_server_error!(
signed_entity_service
.get_last_cardano_transaction_commitment()
.get_last_cardano_transaction_snapshot()
.await,
"proof_cardano_transaction::error"
) {
Expand Down Expand Up @@ -109,7 +109,7 @@ mod tests {

use anyhow::anyhow;
use mithril_common::entities::{
CardanoTransactionsCommitment, CardanoTransactionsSetProof, SignedEntity,
CardanoTransactionsSetProof, CardanoTransactionsSnapshot, SignedEntity,
};
use serde_json::Value::Null;
use warp::{http::Method, test::request};
Expand Down Expand Up @@ -140,8 +140,8 @@ mod tests {
let mut dependency_manager = builder.build_dependency_container().await.unwrap();
let mut mock_signed_entity_service = MockSignedEntityService::new();
mock_signed_entity_service
.expect_get_last_cardano_transaction_commitment()
.returning(|| Ok(Some(SignedEntity::<CardanoTransactionsCommitment>::dummy())));
.expect_get_last_cardano_transaction_snapshot()
.returning(|| Ok(Some(SignedEntity::<CardanoTransactionsSnapshot>::dummy())));
dependency_manager.signed_entity_service = Arc::new(mock_signed_entity_service);

let mut mock_prover_service = MockProverService::new();
Expand Down Expand Up @@ -205,7 +205,7 @@ mod tests {
let mut dependency_manager = builder.build_dependency_container().await.unwrap();
let mut mock_signed_entity_service = MockSignedEntityService::new();
mock_signed_entity_service
.expect_get_last_cardano_transaction_commitment()
.expect_get_last_cardano_transaction_snapshot()
.returning(|| Err(anyhow!("Error")));
dependency_manager.signed_entity_service = Arc::new(mock_signed_entity_service);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
use mithril_common::entities::{CardanoTransactionsCommitment, SignedEntity};
use mithril_common::entities::{CardanoTransactionsSnapshot, SignedEntity};
use mithril_common::messages::{
CardanoTransactionCommitmentListItemMessage, CardanoTransactionCommitmentListMessage,
CardanoTransactionSnapshotListItemMessage, CardanoTransactionSnapshotListMessage,
ToMessageAdapter,
};

/// Adapter to convert a list of [CardanoTransaction] to [CardanoTransactionCommitmentListMessage] instances
/// Adapter to convert a list of [CardanoTransaction] to [CardanoTransactionSnapshotListMessage] instances
pub struct ToCardanoTransactionListMessageAdapter;

impl
ToMessageAdapter<
Vec<SignedEntity<CardanoTransactionsCommitment>>,
CardanoTransactionCommitmentListMessage,
Vec<SignedEntity<CardanoTransactionsSnapshot>>,
CardanoTransactionSnapshotListMessage,
> for ToCardanoTransactionListMessageAdapter
{
/// Method to trigger the conversion
fn adapt(
snapshots: Vec<SignedEntity<CardanoTransactionsCommitment>>,
) -> CardanoTransactionCommitmentListMessage {
snapshots: Vec<SignedEntity<CardanoTransactionsSnapshot>>,
) -> CardanoTransactionSnapshotListMessage {
snapshots
.into_iter()
.map(|entity| CardanoTransactionCommitmentListItemMessage {
.map(|entity| CardanoTransactionSnapshotListItemMessage {
merkle_root: entity.artifact.merkle_root.clone(),
beacon: entity.artifact.beacon.clone(),
hash: entity.artifact.hash,
Expand All @@ -36,9 +36,9 @@ mod tests {

#[test]
fn adapt_ok() {
let signed_entity = SignedEntity::<CardanoTransactionsCommitment>::dummy();
let signed_entity = SignedEntity::<CardanoTransactionsSnapshot>::dummy();
let mithril_stake_distribution_list_message_expected =
vec![CardanoTransactionCommitmentListItemMessage {
vec![CardanoTransactionSnapshotListItemMessage {
merkle_root: signed_entity.artifact.merkle_root.clone(),
beacon: signed_entity.artifact.beacon.clone(),
hash: signed_entity.artifact.hash.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use mithril_common::entities::{CardanoTransactionsCommitment, SignedEntity};
use mithril_common::messages::{CardanoTransactionCommitmentMessage, ToMessageAdapter};
use mithril_common::entities::{CardanoTransactionsSnapshot, SignedEntity};
use mithril_common::messages::{CardanoTransactionSnapshotMessage, ToMessageAdapter};

/// Adapter to convert [CardanoTransaction] to [CardanoTransactionCommitmentMessage] instances
/// Adapter to convert [CardanoTransaction] to [CardanoTransactionSnapshotMessage] instances
pub struct ToCardanoTransactionMessageAdapter;

impl
ToMessageAdapter<
SignedEntity<CardanoTransactionsCommitment>,
CardanoTransactionCommitmentMessage,
> for ToCardanoTransactionMessageAdapter
impl ToMessageAdapter<SignedEntity<CardanoTransactionsSnapshot>, CardanoTransactionSnapshotMessage>
for ToCardanoTransactionMessageAdapter
{
/// Method to trigger the conversion
fn adapt(
from: SignedEntity<CardanoTransactionsCommitment>,
) -> CardanoTransactionCommitmentMessage {
CardanoTransactionCommitmentMessage {
fn adapt(from: SignedEntity<CardanoTransactionsSnapshot>) -> CardanoTransactionSnapshotMessage {
CardanoTransactionSnapshotMessage {
merkle_root: from.artifact.merkle_root.clone(),
beacon: from.artifact.beacon,
hash: from.artifact.hash,
Expand All @@ -30,8 +25,8 @@ mod tests {

#[test]
fn adapt_ok() {
let signed_entity = SignedEntity::<CardanoTransactionsCommitment>::dummy();
let cardano_stake_distribution_message_expected = CardanoTransactionCommitmentMessage {
let signed_entity = SignedEntity::<CardanoTransactionsSnapshot>::dummy();
let cardano_stake_distribution_message_expected = CardanoTransactionSnapshotMessage {
merkle_root: signed_entity.artifact.merkle_root.clone(),
beacon: signed_entity.artifact.beacon.clone(),
hash: signed_entity.artifact.hash.clone(),
Expand Down
16 changes: 8 additions & 8 deletions mithril-aggregator/src/services/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use thiserror::Error;
use mithril_common::{
entities::SignedEntityTypeDiscriminants,
messages::{
CardanoTransactionCommitmentListMessage, CardanoTransactionCommitmentMessage,
CardanoTransactionSnapshotListMessage, CardanoTransactionSnapshotMessage,
CertificateListMessage, CertificateMessage, MithrilStakeDistributionListMessage,
MithrilStakeDistributionMessage, SnapshotListMessage, SnapshotMessage,
},
Expand Down Expand Up @@ -67,13 +67,13 @@ pub trait MessageService: Sync + Send {
async fn get_cardano_transaction_message(
&self,
signed_entity_id: &str,
) -> StdResult<Option<CardanoTransactionCommitmentMessage>>;
) -> StdResult<Option<CardanoTransactionSnapshotMessage>>;

/// Return the list of the last Cardano transactions set message
async fn get_cardano_transaction_list_message(
&self,
limit: usize,
) -> StdResult<CardanoTransactionCommitmentListMessage>;
) -> StdResult<CardanoTransactionSnapshotListMessage>;
}

/// Implementation of the [MessageService]
Expand Down Expand Up @@ -165,7 +165,7 @@ impl MessageService for MithrilMessageService {
async fn get_cardano_transaction_message(
&self,
signed_entity_id: &str,
) -> StdResult<Option<CardanoTransactionCommitmentMessage>> {
) -> StdResult<Option<CardanoTransactionSnapshotMessage>> {
let signed_entity = self
.signed_entity_storer
.get_signed_entity(signed_entity_id)
Expand All @@ -177,7 +177,7 @@ impl MessageService for MithrilMessageService {
async fn get_cardano_transaction_list_message(
&self,
limit: usize,
) -> StdResult<CardanoTransactionCommitmentListMessage> {
) -> StdResult<CardanoTransactionSnapshotListMessage> {
let signed_entity_type_id = SignedEntityTypeDiscriminants::CardanoTransactions;
let entities = self
.signed_entity_storer
Expand All @@ -194,7 +194,7 @@ mod tests {

use mithril_common::{
entities::{
Beacon, CardanoTransactionsCommitment, MithrilStakeDistribution, SignedEntity,
Beacon, CardanoTransactionsSnapshot, MithrilStakeDistribution, SignedEntity,
SignedEntityType, Snapshot,
},
messages::ToMessageAdapter,
Expand Down Expand Up @@ -440,7 +440,7 @@ mod tests {

#[tokio::test]
async fn get_cardano_transaction() {
let entity = SignedEntity::<CardanoTransactionsCommitment>::dummy();
let entity = SignedEntity::<CardanoTransactionsSnapshot>::dummy();
let record = SignedEntityRecord {
signed_entity_id: entity.signed_entity_id.clone(),
signed_entity_type: SignedEntityType::CardanoTransactions(
Expand Down Expand Up @@ -490,7 +490,7 @@ mod tests {

#[tokio::test]
async fn get_cardano_transaction_list_message() {
let entity = SignedEntity::<CardanoTransactionsCommitment>::dummy();
let entity = SignedEntity::<CardanoTransactionsSnapshot>::dummy();
let records = vec![SignedEntityRecord {
signed_entity_id: entity.signed_entity_id.clone(),
signed_entity_type: SignedEntityType::CardanoTransactions(
Expand Down
Loading