Skip to content

Commit 94495a4

Browse files
authored
Merge pull request #2142 from input-output-hk/dlachaume/2121/create-new-signed-entity-type-for-incremental-cardano-db
Feat: create new signed entity type for Incremental Cardano DB
2 parents 67d7501 + 8fb92fa commit 94495a4

File tree

18 files changed

+215
-14
lines changed

18 files changed

+215
-14
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ As a minor extension, we have adopted a slightly different versioning convention
2222

2323
- Add a one line shell installation script for the Mithril nodes.
2424

25+
- **UNSTABLE** Cardano database incremental certification:
26+
27+
- Implement the new signed entity type `CardanoDatabase`.
28+
2529
- Crates versions:
2630

2731
| Crate | Version |

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/mithril-persistence/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-persistence"
3-
version = "0.2.35"
3+
version = "0.2.36"
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

+20
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ impl Hydrator {
8585
})?;
8686
SignedEntityType::CardanoTransactions(beacon.epoch, beacon.block_number)
8787
}
88+
SignedEntityTypeDiscriminants::CardanoDatabase => {
89+
let beacon: CardanoDbBeacon = serde_json::from_str(beacon_str).map_err(|e| {
90+
HydrationError::InvalidData(format!(
91+
"Invalid Beacon JSON in open_message.beacon: '{beacon_str}'. Error: {e}"
92+
))
93+
})?;
94+
SignedEntityType::CardanoDatabase(beacon)
95+
}
8896
};
8997

9098
Ok(signed_entity)
@@ -106,4 +114,16 @@ mod tests {
106114

107115
assert_eq!(expected, signed_entity);
108116
}
117+
118+
#[test]
119+
fn hydrate_cardano_database_signed_entity_type() {
120+
let expected = SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(84, 239));
121+
let signed_entity = Hydrator::hydrate_signed_entity_type(
122+
SignedEntityTypeDiscriminants::CardanoDatabase.index(),
123+
&expected.get_json_beacon().unwrap(),
124+
)
125+
.unwrap();
126+
127+
assert_eq!(expected, signed_entity);
128+
}
109129
}

mithril-aggregator/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.5.113"
3+
version = "0.5.114"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/database/migration.rs

+9
Original file line numberDiff line numberDiff line change
@@ -847,5 +847,14 @@ update certificate
847847
where certificate.signed_entity_type_id = 2;
848848
"#,
849849
),
850+
// Migration 32
851+
// Add the `signed_entity_type` record for 'CardanoDatabase'
852+
SqlMigration::new(
853+
32,
854+
r#"
855+
insert into signed_entity_type (signed_entity_type_id, name)
856+
values (4, 'Cardano Database');
857+
"#,
858+
),
850859
]
851860
}

mithril-aggregator/src/metrics/service.rs

+4
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ build_metrics_service!(
6666
"mithril_aggregator_artifact_cardano_transaction_total_produced_since_startup",
6767
"Number of Cardano transaction artifacts produced since startup on a Mithril aggregator node"
6868
),
69+
artifact_cardano_database_total_produced_since_startup:MetricCounter(
70+
"mithril_aggregator_artifact_cardano_database_total_produced_since_startup",
71+
"Number of Cardano database artifacts produced since startup on a Mithril aggregator node"
72+
),
6973
runtime_cycle_success_since_startup:MetricCounter(
7074
"mithril_aggregator_runtime_cycle_success_since_startup",
7175
"Number of successful runtime cycles since startup on a Mithril aggregator"

mithril-aggregator/src/runtime/runner.rs

+3
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ impl AggregatorRunner {
191191
SignedEntityType::CardanoTransactions(_, _) => {
192192
metrics.get_artifact_cardano_transaction_total_produced_since_startup()
193193
}
194+
SignedEntityType::CardanoDatabase(_) => {
195+
metrics.get_artifact_cardano_database_total_produced_since_startup()
196+
}
194197
};
195198

196199
metric_counter.increment();

mithril-aggregator/src/services/signed_entity.rs

+19
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ impl MithrilSignedEntityService {
210210
)
211211
})?,
212212
)),
213+
SignedEntityType::CardanoDatabase(_) => {
214+
Err(anyhow::anyhow!(
215+
"Signable builder service can not compute artifact for Cardano database because it is not yet implemented."
216+
))
217+
}
213218
}
214219
}
215220

@@ -721,6 +726,20 @@ mod tests {
721726
.await;
722727
}
723728

729+
#[tokio::test]
730+
async fn build_cardano_database_artifact_when_given_cardano_database_entity_type_return_error()
731+
{
732+
let mock_container = MockDependencyInjector::new();
733+
let artifact_builder_service = mock_container.build_artifact_builder_service();
734+
let certificate = fake_data::certificate("hash".to_string());
735+
let signed_entity_type = SignedEntityType::CardanoDatabase(CardanoDbBeacon::default());
736+
737+
artifact_builder_service
738+
.compute_artifact(signed_entity_type.clone(), &certificate)
739+
.await
740+
.expect_err("Should return error because CardanoDatabase is not implemented yet.");
741+
}
742+
724743
async fn generic_test_that_the_artifact_is_stored<
725744
T: Artifact + Clone + Serialize + 'static,
726745
U: signable_builder::Beacon,

mithril-aggregator/src/tools/certificates_hash_migrator.rs

+6
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ mod test {
288288
SignedEntityType::CardanoTransactions(epoch, block_number) => {
289289
format!("cardano-transactions-{epoch}-{block_number}",)
290290
}
291+
SignedEntityType::CardanoDatabase(beacon) => {
292+
format!(
293+
"cardano-database-{}-{}",
294+
beacon.epoch, beacon.immutable_file_number
295+
)
296+
}
291297
};
292298

293299
let signed_entity_record = SignedEntityRecord {

mithril-aggregator/tests/test_extensions/aggregator_observer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ impl AggregatorObserver {
138138
.await?
139139
.first()
140140
.map(|s| &s.signed_entity_type)),
141+
// TODO: This case will be implemented once the signable and artifact builders are available.
142+
SignedEntityType::CardanoDatabase(_) => Ok(false),
141143
}
142144
}
143145
}

mithril-common/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-common"
3-
version = "0.4.88"
3+
version = "0.4.89"
44
description = "Common types, interfaces, and utilities for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-common/src/entities/signed_entity_config.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ impl SignedEntityConfig {
8484
.compute_block_number_to_be_signed(time_point.chain_point.block_number),
8585
)
8686
}
87+
SignedEntityTypeDiscriminants::CardanoDatabase => SignedEntityType::CardanoDatabase(
88+
CardanoDbBeacon::new(*time_point.epoch, time_point.immutable_file_number),
89+
),
8790
};
8891

8992
Ok(signed_entity_type)
@@ -239,6 +242,16 @@ mod tests {
239242
)
240243
.unwrap()
241244
);
245+
246+
assert_eq!(
247+
SignedEntityType::CardanoDatabase(CardanoDbBeacon::new(1, 5)),
248+
config
249+
.time_point_to_signed_entity(
250+
SignedEntityTypeDiscriminants::CardanoDatabase,
251+
&time_point
252+
)
253+
.unwrap()
254+
);
242255
}
243256

244257
#[test]
@@ -372,6 +385,7 @@ mod tests {
372385
allowed_discriminants: BTreeSet::from([
373386
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
374387
SignedEntityTypeDiscriminants::CardanoTransactions,
388+
SignedEntityTypeDiscriminants::CardanoDatabase,
375389
]),
376390
..SignedEntityConfig::dummy()
377391
};
@@ -381,11 +395,13 @@ mod tests {
381395
assert_eq!(
382396
BTreeSet::from_iter(
383397
[
384-
SignedEntityConfig::DEFAULT_ALLOWED_DISCRIMINANTS,
398+
SignedEntityConfig::DEFAULT_ALLOWED_DISCRIMINANTS.as_slice(),
385399
[
386400
SignedEntityTypeDiscriminants::CardanoStakeDistribution,
387401
SignedEntityTypeDiscriminants::CardanoTransactions,
402+
SignedEntityTypeDiscriminants::CardanoDatabase
388403
]
404+
.as_slice()
389405
]
390406
.concat()
391407
),

0 commit comments

Comments
 (0)