Skip to content

Commit ba6f7c9

Browse files
committed
Adapt aggregator to the updated CardanoTransactionSnapshot artifact
1 parent 0ab07cd commit ba6f7c9

File tree

10 files changed

+50
-45
lines changed

10 files changed

+50
-45
lines changed

mithril-aggregator/src/artifact_builder/cardano_transactions.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ impl ArtifactBuilder<ChainPoint, CardanoTransactionsSnapshot>
4949
})?;
5050
self.prover_service.compute_cache(&beacon).await?;
5151

52-
todo!("vvvvv - update the artifact");
53-
// Ok(CardanoTransactionsSnapshot::new(
54-
// merkle_root.to_string(),
55-
// beacon,
56-
// ))
52+
Ok(CardanoTransactionsSnapshot::new(
53+
merkle_root.to_string(),
54+
beacon,
55+
))
5756
}
5857
}
5958

@@ -87,9 +86,8 @@ mod tests {
8786
.compute_artifact(beacon.clone(), &certificate)
8887
.await
8988
.unwrap();
90-
todo!("vvvvv - update the artifact");
91-
// let artifact_expected = CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon);
92-
// assert_eq!(artifact_expected, artifact);
89+
let artifact_expected = CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon);
90+
assert_eq!(artifact_expected, artifact);
9391
}
9492

9593
#[tokio::test]

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use chrono::{DateTime, Utc};
22
use serde::{Deserialize, Serialize};
33

44
use mithril_common::crypto_helper::ProtocolParameters;
5-
use mithril_common::entities::{CardanoDbBeacon, Epoch, SignedEntity, SignedEntityType, Snapshot};
5+
use mithril_common::entities::{ChainPoint, Epoch, SignedEntity, SignedEntityType, Snapshot};
66
use mithril_common::messages::{
77
CardanoTransactionSnapshotListItemMessage, CardanoTransactionSnapshotMessage,
88
MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage,
@@ -172,13 +172,14 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionSnapshotMessage {
172172
#[derive(Deserialize)]
173173
struct TmpCardanoTransaction {
174174
merkle_root: String,
175-
beacon: CardanoDbBeacon,
175+
chain_point: ChainPoint,
176176
hash: String,
177177
}
178178
let artifact = serde_json::from_str::<TmpCardanoTransaction>(&value.artifact)?;
179179
let cardano_transaction_message = CardanoTransactionSnapshotMessage {
180180
merkle_root: artifact.merkle_root,
181-
beacon: artifact.beacon,
181+
epoch: value.signed_entity_type.get_epoch(),
182+
chain_point: artifact.chain_point,
182183
hash: artifact.hash,
183184
certificate_hash: value.certificate_id,
184185
created_at: value.created_at,
@@ -195,13 +196,14 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionSnapshotListItemMessage {
195196
#[derive(Deserialize)]
196197
struct TmpCardanoTransaction {
197198
merkle_root: String,
198-
beacon: CardanoDbBeacon,
199+
chain_point: ChainPoint,
199200
hash: String,
200201
}
201202
let artifact = serde_json::from_str::<TmpCardanoTransaction>(&value.artifact)?;
202203
let message = CardanoTransactionSnapshotListItemMessage {
203204
merkle_root: artifact.merkle_root,
204-
beacon: artifact.beacon,
205+
epoch: value.signed_entity_type.get_epoch(),
206+
chain_point: artifact.chain_point,
205207
hash: artifact.hash,
206208
certificate_hash: value.certificate_id,
207209
created_at: value.created_at,

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ impl DependenciesBuilder {
11041104
.await?
11051105
{
11061106
prover_service
1107-
.compute_cache(&signed_entity.artifact.beacon)
1107+
.compute_cache(&signed_entity.artifact.chain_point)
11081108
.await?;
11091109
}
11101110

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub mod tests {
9797
};
9898
use mithril_common::entities::{ChainPoint, Epoch};
9999
use mithril_common::{
100-
entities::{CardanoDbBeacon, SignedEntityType},
100+
entities::SignedEntityType,
101101
messages::ToMessageAdapter,
102102
test_utils::{apispec::APISpec, fake_data},
103103
};

mithril-aggregator/src/http_server/routes/proof_routes.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ mod handlers {
9797
) -> StdResult<CardanoTransactionsProofsMessage> {
9898
let transactions_set_proofs = prover_service
9999
.compute_transactions_proofs(
100-
&signed_entity.artifact.beacon,
100+
&signed_entity.artifact.chain_point,
101101
transaction_hashes.as_slice(),
102102
)
103103
.await?;
@@ -113,29 +113,29 @@ mod handlers {
113113

114114
#[cfg(test)]
115115
mod tests {
116-
use super::*;
116+
use anyhow::anyhow;
117+
use serde_json::Value::Null;
117118
use std::vec;
119+
use warp::{
120+
http::{Method, StatusCode},
121+
test::request,
122+
};
118123

119124
use mithril_common::{
120125
entities::{
121-
CardanoDbBeacon, CardanoTransactionsSetProof, CardanoTransactionsSnapshot, SignedEntity,
126+
CardanoTransactionsSetProof, CardanoTransactionsSnapshot, ChainPoint, SignedEntity,
122127
},
123128
test_utils::apispec::APISpec,
124129
};
125130

126-
use anyhow::anyhow;
127-
use serde_json::Value::Null;
128-
use warp::{
129-
http::{Method, StatusCode},
130-
test::request,
131-
};
132-
133131
use crate::services::MockSignedEntityService;
134132
use crate::{
135133
dependency_injection::DependenciesBuilder, http_server::SERVER_BASE_PATH,
136134
services::MockProverService, Configuration,
137135
};
138136

137+
use super::*;
138+
139139
fn setup_router(
140140
dependency_manager: Arc<DependencyContainer>,
141141
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
@@ -159,11 +159,11 @@ mod tests {
159159

160160
let cardano_transactions_snapshot = {
161161
let merkle_root = String::new();
162-
let beacon = CardanoDbBeacon {
163-
immutable_file_number: 2309,
164-
..CardanoDbBeacon::default()
162+
let chain_point = ChainPoint {
163+
block_number: 2309,
164+
..ChainPoint::dummy()
165165
};
166-
CardanoTransactionsSnapshot::new(merkle_root, beacon)
166+
CardanoTransactionsSnapshot::new(merkle_root, chain_point)
167167
};
168168

169169
let signed_entity = SignedEntity::<CardanoTransactionsSnapshot> {
@@ -182,7 +182,7 @@ mod tests {
182182
.unwrap();
183183

184184
// Assert
185-
assert_eq!(message.latest_immutable_file_number, 2309)
185+
assert_eq!(message.latest_block_number, 2309)
186186
}
187187

188188
#[tokio::test]

mithril-aggregator/src/message_adapters/to_cardano_transaction_list_message.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ impl
2121
snapshots
2222
.into_iter()
2323
.map(|entity| CardanoTransactionSnapshotListItemMessage {
24-
merkle_root: entity.artifact.merkle_root.clone(),
25-
beacon: entity.artifact.beacon.clone(),
24+
merkle_root: entity.artifact.merkle_root,
25+
epoch: entity.signed_entity_type.get_epoch(),
26+
chain_point: entity.artifact.chain_point,
2627
hash: entity.artifact.hash,
2728
certificate_hash: entity.certificate_id,
2829
created_at: entity.created_at,
@@ -41,7 +42,8 @@ mod tests {
4142
let mithril_stake_distribution_list_message_expected =
4243
vec![CardanoTransactionSnapshotListItemMessage {
4344
merkle_root: signed_entity.artifact.merkle_root.clone(),
44-
beacon: signed_entity.artifact.beacon.clone(),
45+
epoch: signed_entity.signed_entity_type.get_epoch(),
46+
chain_point: signed_entity.artifact.chain_point.clone(),
4547
hash: signed_entity.artifact.hash.clone(),
4648
certificate_hash: signed_entity.certificate_id.clone(),
4749
created_at: signed_entity.created_at,

mithril-aggregator/src/message_adapters/to_cardano_transaction_message.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ impl ToMessageAdapter<SignedEntity<CardanoTransactionsSnapshot>, CardanoTransact
1111
/// Method to trigger the conversion
1212
fn adapt(from: SignedEntity<CardanoTransactionsSnapshot>) -> CardanoTransactionSnapshotMessage {
1313
CardanoTransactionSnapshotMessage {
14-
merkle_root: from.artifact.merkle_root.clone(),
15-
beacon: from.artifact.beacon,
14+
merkle_root: from.artifact.merkle_root,
15+
epoch: from.signed_entity_type.get_epoch(),
16+
chain_point: from.artifact.chain_point,
1617
hash: from.artifact.hash,
1718
certificate_hash: from.certificate_id,
1819
created_at: from.created_at,
@@ -29,7 +30,8 @@ mod tests {
2930
let signed_entity = SignedEntity::<CardanoTransactionsSnapshot>::dummy();
3031
let cardano_stake_distribution_message_expected = CardanoTransactionSnapshotMessage {
3132
merkle_root: signed_entity.artifact.merkle_root.clone(),
32-
beacon: signed_entity.artifact.beacon.clone(),
33+
epoch: signed_entity.signed_entity_type.get_epoch(),
34+
chain_point: signed_entity.artifact.chain_point.clone(),
3335
hash: signed_entity.artifact.hash.clone(),
3436
certificate_hash: signed_entity.certificate_id.clone(),
3537
created_at: signed_entity.created_at,

mithril-aggregator/src/message_adapters/to_cardano_transactions_proof_message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl ToCardanoTransactionsProofsMessageAdapter {
2525
&signed_entity.certificate_id,
2626
try_adapt_set_proof_message(transactions_set_proofs)?,
2727
transactions_hashes_not_certified,
28-
signed_entity.artifact.beacon.immutable_file_number,
28+
signed_entity.artifact.chain_point.block_number,
2929
))
3030
}
3131
}
@@ -104,7 +104,7 @@ mod tests {
104104
&signed_entity.certificate_id,
105105
transactions_set_proof_message_part,
106106
transactions_hashes_non_certified.to_vec(),
107-
signed_entity.artifact.beacon.immutable_file_number,
107+
signed_entity.artifact.chain_point.block_number,
108108
);
109109
assert_eq!(expected_message, message);
110110
}

mithril-aggregator/src/services/message.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ mod tests {
424424
let record = SignedEntityRecord {
425425
signed_entity_id: entity.signed_entity_id.clone(),
426426
signed_entity_type: SignedEntityType::CardanoTransactions(
427-
entity.artifact.beacon.clone(),
427+
entity.signed_entity_type.get_epoch(),
428+
entity.artifact.chain_point.clone(),
428429
),
429430
certificate_id: entity.certificate_id.clone(),
430431
artifact: serde_json::to_string(&entity.artifact).unwrap(),
@@ -474,7 +475,8 @@ mod tests {
474475
let records = vec![SignedEntityRecord {
475476
signed_entity_id: entity.signed_entity_id.clone(),
476477
signed_entity_type: SignedEntityType::CardanoTransactions(
477-
entity.artifact.beacon.clone(),
478+
entity.signed_entity_type.get_epoch(),
479+
entity.artifact.chain_point.clone(),
478480
),
479481
certificate_id: entity.certificate_id.clone(),
480482
artifact: serde_json::to_string(&entity.artifact).unwrap(),

mithril-aggregator/src/services/signed_entity.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl MithrilSignedEntityService {
129129
})?,
130130
)),
131131
SignedEntityType::CardanoStakeDistribution(_) => todo!(),
132-
SignedEntityType::CardanoTransactions(epoch, chain_point) => Ok(Arc::new(
132+
SignedEntityType::CardanoTransactions(_epoch, chain_point) => Ok(Arc::new(
133133
self.cardano_transactions_artifact_builder
134134
.compute_artifact(chain_point.clone(), certificate)
135135
.await
@@ -444,9 +444,8 @@ mod tests {
444444
async fn build_cardano_transactions_snapshot_artifact_when_given_cardano_transactions_type() {
445445
let mut mock_container = MockDependencyInjector::new();
446446

447-
// vvvvv - when updating to chain point make sure that the same beacon is used in the expected
448447
let expected =
449-
CardanoTransactionsSnapshot::new("merkle_root".to_string(), CardanoDbBeacon::default());
448+
CardanoTransactionsSnapshot::new("merkle_root".to_string(), ChainPoint::dummy());
450449

451450
mock_container
452451
.mock_cardano_transactions_artifact_builder
@@ -455,7 +454,7 @@ mod tests {
455454
.returning(|_, _| {
456455
Ok(CardanoTransactionsSnapshot::new(
457456
"merkle_root".to_string(),
458-
CardanoDbBeacon::default(),
457+
ChainPoint::dummy(),
459458
))
460459
});
461460

@@ -476,7 +475,7 @@ mod tests {
476475
async fn should_store_the_artifact_when_creating_artifact_for_cardano_transactions() {
477476
generic_test_that_the_artifact_is_stored(
478477
SignedEntityType::CardanoTransactions(Epoch(1), ChainPoint::dummy()),
479-
CardanoTransactionsSnapshot::new("merkle_root".to_string(), CardanoDbBeacon::default()),
478+
CardanoTransactionsSnapshot::new("merkle_root".to_string(), ChainPoint::dummy()),
480479
&|mock_injector| &mut mock_injector.mock_cardano_transactions_artifact_builder,
481480
)
482481
.await;

0 commit comments

Comments
 (0)