Skip to content

Commit

Permalink
Merge pull request #1593 from input-output-hk/ensemble/1562/rename-be…
Browse files Browse the repository at this point in the history
…acon

Rename `Beacon` common entity to  `CardanoDbBeacon`
  • Loading branch information
Alenar authored Mar 26, 2024
2 parents ffdfceb + 0e35689 commit f1bd564
Show file tree
Hide file tree
Showing 81 changed files with 621 additions and 489 deletions.
14 changes: 7 additions & 7 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 internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-persistence"
version = "0.1.4"
version = "0.1.5"
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Signed Entity helpers for persistence

use mithril_common::entities::{Beacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants};
use mithril_common::entities::{
CardanoDbBeacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants,
};

use crate::sqlite::HydrationError;

Expand Down Expand Up @@ -34,15 +36,15 @@ impl SignedEntityTypeHydrator {
SignedEntityType::CardanoStakeDistribution(epoch)
}
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull => {
let beacon: Beacon = serde_json::from_str(beacon_str).map_err(|e| {
let beacon: CardanoDbBeacon = serde_json::from_str(beacon_str).map_err(|e| {
HydrationError::InvalidData(format!(
"Invalid Beacon JSON in open_message.beacon: '{beacon_str}'. Error: {e}"
))
})?;
SignedEntityType::CardanoImmutableFilesFull(beacon)
}
SignedEntityTypeDiscriminants::CardanoTransactions => {
let beacon: Beacon = serde_json::from_str(beacon_str).map_err(|e| {
let beacon: CardanoDbBeacon = serde_json::from_str(beacon_str).map_err(|e| {
HydrationError::InvalidData(format!(
"Invalid Beacon JSON in open_message.beacon: '{beacon_str}'. Error: {e}"
))
Expand Down
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.49"
version = "0.4.50"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
use super::ArtifactBuilder;
use mithril_common::{
entities::{
Beacon, Certificate, CompressionAlgorithm, ProtocolMessage, ProtocolMessagePartKey,
Snapshot,
CardanoDbBeacon, Certificate, CompressionAlgorithm, ProtocolMessage,
ProtocolMessagePartKey, Snapshot,
},
StdResult,
};
Expand All @@ -25,7 +25,7 @@ use mithril_common::{
pub enum CardanoImmutableFilesFullArtifactError {
/// Protocol message part is missing
#[error("Missing protocol message for beacon: '{0}'.")]
MissingProtocolMessage(Beacon),
MissingProtocolMessage(CardanoDbBeacon),
}

/// A [CardanoImmutableFilesFullArtifact] builder
Expand Down Expand Up @@ -54,7 +54,7 @@ impl CardanoImmutableFilesFullArtifactBuilder {

async fn create_snapshot_archive(
&self,
beacon: &Beacon,
beacon: &CardanoDbBeacon,
protocol_message: &ProtocolMessage,
) -> StdResult<OngoingSnapshot> {
debug!("CardanoImmutableFilesFullArtifactBuilder: create snapshot archive");
Expand Down Expand Up @@ -135,10 +135,10 @@ impl CardanoImmutableFilesFullArtifactBuilder {
}

#[async_trait]
impl ArtifactBuilder<Beacon, Snapshot> for CardanoImmutableFilesFullArtifactBuilder {
impl ArtifactBuilder<CardanoDbBeacon, Snapshot> for CardanoImmutableFilesFullArtifactBuilder {
async fn compute_artifact(
&self,
beacon: Beacon,
beacon: CardanoDbBeacon,
certificate: &Certificate,
) -> StdResult<Snapshot> {
let ongoing_snapshot = self
Expand Down Expand Up @@ -244,7 +244,7 @@ mod tests {

#[tokio::test]
async fn snapshot_archive_name_after_beacon_values() {
let beacon = Beacon::new("network".to_string(), 20, 145);
let beacon = CardanoDbBeacon::new("network".to_string(), 20, 145);
let mut message = ProtocolMessage::new();
message.set_message_part(
ProtocolMessagePartKey::SnapshotDigest,
Expand Down Expand Up @@ -293,7 +293,7 @@ mod tests {
);

let ongoing_snapshot = cardano_immutable_files_full_artifact_builder
.create_snapshot_archive(&Beacon::default(), &message)
.create_snapshot_archive(&CardanoDbBeacon::default(), &message)
.await
.expect("create_snapshot_archive should not fail");
let file_name = ongoing_snapshot
Expand Down
11 changes: 7 additions & 4 deletions mithril-aggregator/src/artifact_builder/cardano_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use super::ArtifactBuilder;
use anyhow::{anyhow, Context};
use mithril_common::{
entities::{
Beacon, CardanoTransactionsSnapshot, Certificate, ProtocolMessagePartKey, SignedEntityType,
CardanoDbBeacon, CardanoTransactionsSnapshot, Certificate, ProtocolMessagePartKey,
SignedEntityType,
},
StdResult,
};
Expand All @@ -20,10 +21,12 @@ impl CardanoTransactionsArtifactBuilder {
}

#[async_trait]
impl ArtifactBuilder<Beacon, CardanoTransactionsSnapshot> for CardanoTransactionsArtifactBuilder {
impl ArtifactBuilder<CardanoDbBeacon, CardanoTransactionsSnapshot>
for CardanoTransactionsArtifactBuilder
{
async fn compute_artifact(
&self,
beacon: Beacon,
beacon: CardanoDbBeacon,
certificate: &Certificate,
) -> StdResult<CardanoTransactionsSnapshot> {
let merkle_root = certificate
Expand Down Expand Up @@ -89,7 +92,7 @@ mod tests {

let cardano_transaction_artifact_builder = CardanoTransactionsArtifactBuilder::new();
cardano_transaction_artifact_builder
.compute_artifact(Beacon::default(), &certificate)
.compute_artifact(CardanoDbBeacon::default(), &certificate)
.await
.expect_err("The artifact building must fail since there is no CardanoTransactionsMerkleRoot part in its message.");
}
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::path::PathBuf;
use std::str::FromStr;

use mithril_common::entities::{
Beacon, CompressionAlgorithm, HexEncodedGenesisVerificationKey, ProtocolParameters,
CardanoDbBeacon, CompressionAlgorithm, HexEncodedGenesisVerificationKey, ProtocolParameters,
SignedEntityType, SignedEntityTypeDiscriminants,
};
use mithril_common::{CardanoNetwork, StdResult};
Expand Down Expand Up @@ -285,7 +285,7 @@ impl Configuration {
/// The signed entity types are discarded if they are not declared in the [SignedEntityType] enum.
pub fn list_allowed_signed_entity_types(
&self,
beacon: &Beacon,
beacon: &CardanoDbBeacon,
) -> StdResult<Vec<SignedEntityType>> {
let allowed_discriminants = self.list_allowed_signed_entity_types_discriminants()?;
let signed_entity_types = allowed_discriminants
Expand Down
23 changes: 14 additions & 9 deletions mithril-aggregator/src/database/provider/cardano_transaction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use mithril_common::{
entities::{Beacon, BlockNumber, CardanoTransaction, ImmutableFileNumber, TransactionHash},
entities::{
BlockNumber, CardanoDbBeacon, CardanoTransaction, ImmutableFileNumber, TransactionHash,
},
signable_builder::TransactionStore,
StdResult,
};
Expand Down Expand Up @@ -103,7 +105,10 @@ impl<'client> CardanoTransactionProvider<'client> {
)
}

pub(crate) fn get_transaction_up_to_beacon_condition(&self, beacon: &Beacon) -> WhereCondition {
pub(crate) fn get_transaction_up_to_beacon_condition(
&self,
beacon: &CardanoDbBeacon,
) -> WhereCondition {
WhereCondition::new(
"immutable_file_number <= ?*",
vec![Value::Integer(beacon.immutable_file_number as i64)],
Expand Down Expand Up @@ -216,7 +221,7 @@ impl CardanoTransactionRepository {
/// chronological order.
pub async fn get_transactions_up_to(
&self,
beacon: &Beacon,
beacon: &CardanoDbBeacon,
) -> StdResult<Vec<CardanoTransactionRecord>> {
let provider = CardanoTransactionProvider::new(&self.connection);
let filters = provider.get_transaction_up_to_beacon_condition(beacon);
Expand Down Expand Up @@ -283,7 +288,7 @@ impl TransactionStore for CardanoTransactionRepository {

#[async_trait]
impl TransactionsRetriever for CardanoTransactionRepository {
async fn get_up_to(&self, beacon: &Beacon) -> StdResult<Vec<CardanoTransaction>> {
async fn get_up_to(&self, beacon: &CardanoDbBeacon) -> StdResult<Vec<CardanoTransaction>> {
self.get_transactions_up_to(beacon).await.map(|v| {
v.into_iter()
.map(|record| record.into())
Expand Down Expand Up @@ -345,9 +350,9 @@ mod tests {
let connection = Connection::open_thread_safe(":memory:").unwrap();
let provider = CardanoTransactionProvider::new(&connection);
let (expr, params) = provider
.get_transaction_up_to_beacon_condition(&Beacon {
.get_transaction_up_to_beacon_condition(&CardanoDbBeacon {
immutable_file_number: 2309,
..Beacon::default()
..CardanoDbBeacon::default()
})
.expand();

Expand Down Expand Up @@ -546,14 +551,14 @@ mod tests {
.unwrap();

let transaction_result = repository
.get_up_to(&Beacon::new("".to_string(), 1, 34))
.get_up_to(&CardanoDbBeacon::new("".to_string(), 1, 34))
.await
.unwrap();

assert_eq!(cardano_transactions[0..=14].to_vec(), transaction_result);

let transaction_result = repository
.get_up_to(&Beacon::new("".to_string(), 1, 300))
.get_up_to(&CardanoDbBeacon::new("".to_string(), 1, 300))
.await
.unwrap();

Expand All @@ -563,7 +568,7 @@ mod tests {
);

let transaction_result = repository
.get_up_to(&Beacon::new("".to_string(), 1, 19))
.get_up_to(&CardanoDbBeacon::new("".to_string(), 1, 19))
.await
.unwrap();

Expand Down
Loading

0 comments on commit f1bd564

Please sign in to comment.