Skip to content

Commit 9072d5b

Browse files
authored
Merge pull request #2922 from input-output-hk/djo/2905/new_cardano_blocks_txs_signed_entity
feat: add new `CardanoBlocksTransactions` to `SignedEntityTypes`
2 parents c05fc54 + f229137 commit 9072d5b

File tree

16 files changed

+276
-55
lines changed

16 files changed

+276
-55
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mithril-persistence/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-persistence"
3-
version = "0.2.60"
3+
version = "0.2.61"
44
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }

internal/mithril-persistence/src/database/hydrator.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ impl Hydrator {
8585
})?;
8686
SignedEntityType::CardanoTransactions(beacon.epoch, beacon.block_number)
8787
}
88+
SignedEntityTypeDiscriminants::CardanoBlocksTransactions => {
89+
#[derive(Deserialize)]
90+
struct CardanoBlocksTransactionsBeacon {
91+
epoch: Epoch,
92+
block_number: BlockNumber,
93+
}
94+
95+
let beacon: CardanoBlocksTransactionsBeacon = serde_json::from_str(beacon_str)
96+
.map_err(|e| {
97+
HydrationError::InvalidData(format!(
98+
"Invalid Beacon JSON in open_message.beacon: '{beacon_str}'. Error: {e}"
99+
))
100+
})?;
101+
SignedEntityType::CardanoBlocksTransactions(beacon.epoch, beacon.block_number)
102+
}
88103
SignedEntityTypeDiscriminants::CardanoDatabase => {
89104
let beacon: CardanoDbBeacon = serde_json::from_str(beacon_str).map_err(|e| {
90105
HydrationError::InvalidData(format!(
@@ -104,7 +119,7 @@ mod tests {
104119
use super::*;
105120

106121
#[test]
107-
fn hydrate_cardano_transaction_signed_entity_type() {
122+
fn hydrate_cardano_transactions_signed_entity_type() {
108123
let expected = SignedEntityType::CardanoTransactions(Epoch(35), BlockNumber(77));
109124
let signed_entity = Hydrator::hydrate_signed_entity_type(
110125
SignedEntityTypeDiscriminants::CardanoTransactions.index(),
@@ -115,6 +130,18 @@ mod tests {
115130
assert_eq!(expected, signed_entity);
116131
}
117132

133+
#[test]
134+
fn hydrate_cardano_blocks_transactions_signed_entity_type() {
135+
let expected = SignedEntityType::CardanoBlocksTransactions(Epoch(37), BlockNumber(79));
136+
let signed_entity = Hydrator::hydrate_signed_entity_type(
137+
SignedEntityTypeDiscriminants::CardanoBlocksTransactions.index(),
138+
&expected.get_json_beacon().unwrap(),
139+
)
140+
.unwrap();
141+
142+
assert_eq!(expected, signed_entity);
143+
}
144+
118145
#[test]
119146
fn hydrate_cardano_database_signed_entity_type() {
120147
let expected = SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(84, 239));

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.8.9"
3+
version = "0.8.10"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/database/migration.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,14 @@ pragma foreign_key_check;
276276
pragma foreign_keys=true;
277277
"#,
278278
),
279+
// Migration 38
280+
// Add the `signed_entity_type` record for 'CardanoBlocksTransactions'
281+
SqlMigration::new(
282+
38,
283+
r#"
284+
insert into signed_entity_type (signed_entity_type_id, name)
285+
values (5, 'Cardano Blocks and Transactions');
286+
"#,
287+
),
279288
]
280289
}

mithril-aggregator/src/database/record/signed_entity.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ impl SignedEntityRecord {
113113
let artifact = fake_data::cardano_transactions_snapshot(block_number);
114114
get_id_and_artifact(&artifact)
115115
}
116+
SignedEntityType::CardanoBlocksTransactions(_epoch, _block_number) => {
117+
panic!("Cardano blocks transactions is not supported yet")
118+
}
116119
};
117120

118121
SignedEntityRecord {

mithril-aggregator/src/metrics/service.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ build_metrics_service!(
123123
"mithril_aggregator_artifact_cardano_transaction_total_produced_since_startup",
124124
"Number of Cardano transaction artifacts produced since startup on a Mithril aggregator node"
125125
),
126+
artifact_cardano_blocks_transactions_total_produced_since_startup:MetricCounter(
127+
"mithril_aggregator_artifact_cardano_blocks_transactions_total_produced_since_startup",
128+
"Number of Cardano blocks transactions artifacts produced since startup on a Mithril aggregator node"
129+
),
126130
runtime_cycle_success_since_startup:MetricCounter(
127131
"mithril_aggregator_runtime_cycle_success_since_startup",
128132
"Number of successful runtime cycles since startup on a Mithril aggregator"

mithril-aggregator/src/services/signed_entity.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ impl MithrilSignedEntityService {
265265
)
266266
})?,
267267
)),
268+
SignedEntityType::CardanoBlocksTransactions(_epoch, _block_number) =>
269+
Err(anyhow!("Cardano blocks transactions is not supported yet")),
268270
SignedEntityType::CardanoDatabase(beacon) => Ok(Arc::new(
269271
self.cardano_database_artifact_builder
270272
.compute_artifact(beacon, certificate)
@@ -299,19 +301,22 @@ impl MithrilSignedEntityService {
299301
) {
300302
let metrics = self.metrics_service.clone();
301303
let metric_counter = match signed_entity_type {
302-
SignedEntityType::MithrilStakeDistribution(_) => {
304+
SignedEntityType::MithrilStakeDistribution(..) => {
303305
metrics.get_artifact_mithril_stake_distribution_total_produced_since_startup()
304306
}
305-
SignedEntityType::CardanoImmutableFilesFull(_) => {
307+
SignedEntityType::CardanoImmutableFilesFull(..) => {
306308
metrics.get_artifact_cardano_immutable_files_full_total_produced_since_startup()
307309
}
308-
SignedEntityType::CardanoStakeDistribution(_) => {
310+
SignedEntityType::CardanoStakeDistribution(..) => {
309311
metrics.get_artifact_cardano_stake_distribution_total_produced_since_startup()
310312
}
311-
SignedEntityType::CardanoTransactions(_, _) => {
313+
SignedEntityType::CardanoTransactions(..) => {
312314
metrics.get_artifact_cardano_transaction_total_produced_since_startup()
313315
}
314-
SignedEntityType::CardanoDatabase(_) => {
316+
SignedEntityType::CardanoBlocksTransactions(..) => {
317+
metrics.get_artifact_cardano_blocks_transactions_total_produced_since_startup()
318+
}
319+
SignedEntityType::CardanoDatabase(..) => {
315320
metrics.get_artifact_cardano_database_total_produced_since_startup()
316321
}
317322
};
@@ -697,19 +702,22 @@ mod tests {
697702
signed_entity_type: &SignedEntityType,
698703
) -> CounterValue {
699704
match signed_entity_type {
700-
SignedEntityType::MithrilStakeDistribution(_) => metrics_service
705+
SignedEntityType::MithrilStakeDistribution(..) => metrics_service
701706
.get_artifact_mithril_stake_distribution_total_produced_since_startup()
702707
.get(),
703-
SignedEntityType::CardanoImmutableFilesFull(_) => metrics_service
708+
SignedEntityType::CardanoImmutableFilesFull(..) => metrics_service
704709
.get_artifact_cardano_immutable_files_full_total_produced_since_startup()
705710
.get(),
706-
SignedEntityType::CardanoStakeDistribution(_) => metrics_service
711+
SignedEntityType::CardanoStakeDistribution(..) => metrics_service
707712
.get_artifact_cardano_stake_distribution_total_produced_since_startup()
708713
.get(),
709-
SignedEntityType::CardanoTransactions(_, _) => metrics_service
714+
SignedEntityType::CardanoTransactions(..) => metrics_service
710715
.get_artifact_cardano_transaction_total_produced_since_startup()
711716
.get(),
712-
SignedEntityType::CardanoDatabase(_) => metrics_service
717+
SignedEntityType::CardanoBlocksTransactions(..) => metrics_service
718+
.get_artifact_cardano_blocks_transactions_total_produced_since_startup()
719+
.get(),
720+
SignedEntityType::CardanoDatabase(..) => metrics_service
713721
.get_artifact_cardano_database_total_produced_since_startup()
714722
.get(),
715723
}

mithril-aggregator/src/tools/certificates_hash_migrator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ mod test {
295295
SignedEntityType::CardanoTransactions(epoch, block_number) => {
296296
format!("cardano-transactions-{epoch}-{block_number}",)
297297
}
298+
SignedEntityType::CardanoBlocksTransactions(epoch, block_number) => {
299+
format!("cardano-blocks-transactions-{epoch}-{block_number}",)
300+
}
298301
SignedEntityType::CardanoDatabase(beacon) => {
299302
format!(
300303
"cardano-database-{}-{}",

mithril-aggregator/tests/test_extensions/aggregator_observer.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Context;
1+
use anyhow::{Context, anyhow};
22
use std::sync::Arc;
33

44
use mithril_aggregator::{
@@ -113,35 +113,40 @@ impl AggregatorObserver {
113113
signed_entity_type_expected: &SignedEntityType,
114114
) -> StdResult<bool> {
115115
match signed_entity_type_expected {
116-
SignedEntityType::CardanoImmutableFilesFull(_) => Ok(Some(signed_entity_type_expected)
117-
== self
118-
.signed_entity_service
119-
.get_last_signed_snapshots(1)
120-
.await?
121-
.first()
122-
.map(|s| &s.signed_entity_type)),
123-
SignedEntityType::MithrilStakeDistribution(_) => Ok(Some(signed_entity_type_expected)
116+
SignedEntityType::CardanoImmutableFilesFull(..) => {
117+
Ok(Some(signed_entity_type_expected)
118+
== self
119+
.signed_entity_service
120+
.get_last_signed_snapshots(1)
121+
.await?
122+
.first()
123+
.map(|s| &s.signed_entity_type))
124+
}
125+
SignedEntityType::MithrilStakeDistribution(..) => Ok(Some(signed_entity_type_expected)
124126
== self
125127
.signed_entity_service
126128
.get_last_signed_mithril_stake_distributions(1)
127129
.await?
128130
.first()
129131
.map(|s| &s.signed_entity_type)),
130-
SignedEntityType::CardanoTransactions(_, _) => Ok(Some(signed_entity_type_expected)
132+
SignedEntityType::CardanoTransactions(..) => Ok(Some(signed_entity_type_expected)
131133
== self
132134
.signed_entity_service
133135
.get_last_cardano_transaction_snapshot()
134136
.await?
135137
.map(|s| s.signed_entity_type)
136138
.as_ref()),
137-
SignedEntityType::CardanoStakeDistribution(_) => Ok(Some(signed_entity_type_expected)
139+
SignedEntityType::CardanoBlocksTransactions(..) => {
140+
Err(anyhow!("Cardano blocks transactions is not supported yet"))
141+
}
142+
SignedEntityType::CardanoStakeDistribution(..) => Ok(Some(signed_entity_type_expected)
138143
== self
139144
.signed_entity_service
140145
.get_last_signed_cardano_stake_distributions(1)
141146
.await?
142147
.first()
143148
.map(|s| &s.signed_entity_type)),
144-
SignedEntityType::CardanoDatabase(_) => Ok(Some(signed_entity_type_expected)
149+
SignedEntityType::CardanoDatabase(..) => Ok(Some(signed_entity_type_expected)
145150
== self
146151
.signed_entity_service
147152
.get_last_signed_cardano_database_snapshots(1)

0 commit comments

Comments
 (0)