Skip to content

Commit b005c51

Browse files
committed
Make aggregator services & cardano transaction artifact builder use ChainPoint
Note: not compiling, we still need to update the `CardanoTransactionsSnapshot`.
1 parent fabb426 commit b005c51

File tree

4 files changed

+53
-48
lines changed

4 files changed

+53
-48
lines changed

mithril-aggregator/src/artifact_builder/cardano_transactions.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use std::sync::Arc;
22

3-
use async_trait::async_trait;
4-
5-
use crate::services::ProverService;
6-
7-
use super::ArtifactBuilder;
83
use anyhow::{anyhow, Context};
4+
use async_trait::async_trait;
95
use mithril_common::{
106
entities::{
11-
CardanoDbBeacon, CardanoTransactionsSnapshot, Certificate, ProtocolMessagePartKey,
7+
CardanoTransactionsSnapshot, Certificate, ChainPoint, ProtocolMessagePartKey,
128
SignedEntityType,
139
},
1410
StdResult,
1511
};
1612

13+
use crate::services::ProverService;
14+
15+
use super::ArtifactBuilder;
16+
1717
/// A [CardanoTransactionsArtifact] builder
1818
pub struct CardanoTransactionsArtifactBuilder {
1919
prover_service: Arc<dyn ProverService>,
@@ -27,12 +27,12 @@ impl CardanoTransactionsArtifactBuilder {
2727
}
2828

2929
#[async_trait]
30-
impl ArtifactBuilder<CardanoDbBeacon, CardanoTransactionsSnapshot>
30+
impl ArtifactBuilder<ChainPoint, CardanoTransactionsSnapshot>
3131
for CardanoTransactionsArtifactBuilder
3232
{
3333
async fn compute_artifact(
3434
&self,
35-
beacon: CardanoDbBeacon,
35+
beacon: ChainPoint,
3636
certificate: &Certificate,
3737
) -> StdResult<CardanoTransactionsSnapshot> {
3838
let merkle_root = certificate
@@ -44,15 +44,16 @@ impl ArtifactBuilder<CardanoDbBeacon, CardanoTransactionsSnapshot>
4444
.with_context(|| {
4545
format!(
4646
"Can not compute CardanoTransactionsCommitment artifact for signed_entity: {:?}",
47-
SignedEntityType::CardanoTransactions(beacon.clone())
47+
SignedEntityType::CardanoTransactions(certificate.epoch, beacon.clone())
4848
)
4949
})?;
5050
self.prover_service.compute_cache(&beacon).await?;
5151

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

@@ -77,7 +78,7 @@ mod tests {
7778
certificate
7879
};
7980

80-
let beacon = certificate.as_cardano_db_beacon();
81+
let beacon = ChainPoint::dummy();
8182
let mut mock_prover = MockProverService::new();
8283
mock_prover.expect_compute_cache().returning(|_| Ok(()));
8384
let cardano_transaction_artifact_builder =
@@ -86,8 +87,9 @@ mod tests {
8687
.compute_artifact(beacon.clone(), &certificate)
8788
.await
8889
.unwrap();
89-
let artifact_expected = CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon);
90-
assert_eq!(artifact_expected, artifact);
90+
todo!("vvvvv - update the artifact");
91+
// let artifact_expected = CardanoTransactionsSnapshot::new("merkleroot".to_string(), beacon);
92+
// assert_eq!(artifact_expected, artifact);
9193
}
9294

9395
#[tokio::test]
@@ -104,7 +106,7 @@ mod tests {
104106
let cardano_transaction_artifact_builder =
105107
CardanoTransactionsArtifactBuilder::new(Arc::new(mock_prover));
106108
cardano_transaction_artifact_builder
107-
.compute_artifact(CardanoDbBeacon::default(), &certificate)
109+
.compute_artifact(ChainPoint::dummy(), &certificate)
108110
.await
109111
.expect_err("The artifact building must fail since there is no CardanoTransactionsMerkleRoot part in its message.");
110112
}

mithril-aggregator/src/services/prover.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
use mithril_common::{
1111
crypto_helper::{MKMap, MKMapNode, MKTree},
1212
entities::{
13-
BlockRange, CardanoDbBeacon, CardanoTransaction, CardanoTransactionsSetProof,
13+
BlockRange, CardanoDbBeacon, CardanoTransaction, CardanoTransactionsSetProof, ChainPoint,
1414
TransactionHash,
1515
},
1616
resource_pool::ResourcePool,
@@ -25,12 +25,12 @@ pub trait ProverService: Sync + Send {
2525
/// Compute the cryptographic proofs for the given transactions
2626
async fn compute_transactions_proofs(
2727
&self,
28-
up_to: &CardanoDbBeacon,
28+
up_to: &ChainPoint,
2929
transaction_hashes: &[TransactionHash],
3030
) -> StdResult<Vec<CardanoTransactionsSetProof>>;
3131

3232
/// Compute the cache
33-
async fn compute_cache(&self, up_to: &CardanoDbBeacon) -> StdResult<()>;
33+
async fn compute_cache(&self, up_to: &ChainPoint) -> StdResult<()>;
3434
}
3535

3636
/// Transactions retriever
@@ -118,7 +118,7 @@ impl MithrilProverService {
118118
impl ProverService for MithrilProverService {
119119
async fn compute_transactions_proofs(
120120
&self,
121-
_up_to: &CardanoDbBeacon,
121+
_up_to: &ChainPoint,
122122
transaction_hashes: &[TransactionHash],
123123
) -> StdResult<Vec<CardanoTransactionsSetProof>> {
124124
// 1 - Compute the set of block ranges with transactions to prove
@@ -164,15 +164,15 @@ impl ProverService for MithrilProverService {
164164
}
165165
}
166166

167-
async fn compute_cache(&self, up_to: &CardanoDbBeacon) -> StdResult<()> {
167+
async fn compute_cache(&self, up_to: &ChainPoint) -> StdResult<()> {
168168
let pool_size = self.mk_map_pool.size();
169169
info!(
170170
self.logger,
171171
"Prover starts computing the Merkle map pool resource of size {pool_size}"
172172
);
173173
let mk_map_cache = self
174174
.block_range_root_retriever
175-
.compute_merkle_map_from_block_range_roots(up_to.immutable_file_number)
175+
.compute_merkle_map_from_block_range_roots(up_to)
176176
.await?;
177177
let discriminant_new = self.mk_map_pool.discriminant()? + 1;
178178
self.mk_map_pool.set_discriminant(discriminant_new)?;
@@ -201,7 +201,7 @@ impl ProverService for MithrilProverService {
201201
mod tests {
202202
use anyhow::anyhow;
203203
use mithril_common::crypto_helper::{MKMap, MKMapNode, MKTreeNode};
204-
use mithril_common::entities::{CardanoTransaction, ImmutableFileNumber};
204+
use mithril_common::entities::CardanoTransaction;
205205
use mithril_common::test_utils::CardanoTransactionsBuilder;
206206
use mockall::mock;
207207
use mockall::predicate::eq;
@@ -215,12 +215,12 @@ mod tests {
215215
impl BlockRangeRootRetriever for BlockRangeRootRetrieverImpl {
216216
async fn retrieve_block_range_roots(
217217
&self,
218-
up_to_beacon: ImmutableFileNumber,
218+
up_to_beacon: &ChainPoint,
219219
) -> StdResult<Box<dyn Iterator<Item = (BlockRange, MKTreeNode)>>>;
220220

221221
async fn compute_merkle_map_from_block_range_roots(
222222
&self,
223-
up_to_beacon: ImmutableFileNumber,
223+
up_to_beacon: &ChainPoint,
224224
) -> StdResult<MKMap<BlockRange, MKMapNode<BlockRange>>>;
225225
}
226226
}
@@ -296,21 +296,21 @@ mod tests {
296296
.unwrap()
297297
}
298298

299-
pub fn compute_beacon_from_transactions(
300-
transactions: &[CardanoTransaction],
301-
) -> CardanoDbBeacon {
302-
CardanoDbBeacon {
303-
immutable_file_number: transactions.last().unwrap().immutable_file_number,
304-
..CardanoDbBeacon::default()
305-
}
299+
pub fn compute_beacon_from_transactions(transactions: &[CardanoTransaction]) -> ChainPoint {
300+
let max_transaction = transactions.iter().max_by_key(|t| t.block_number).unwrap();
301+
ChainPoint::new(
302+
max_transaction.slot_number,
303+
max_transaction.block_number,
304+
max_transaction.block_hash.clone(),
305+
)
306306
}
307307

308308
pub struct TestData {
309309
pub transaction_hashes_to_prove: Vec<TransactionHash>,
310310
pub block_ranges_map: BTreeMap<BlockRange, Vec<CardanoTransaction>>,
311311
pub block_ranges_to_prove: Vec<BlockRange>,
312312
pub all_transactions_in_block_ranges_to_prove: Vec<CardanoTransaction>,
313-
pub beacon: CardanoDbBeacon,
313+
pub beacon: ChainPoint,
314314
}
315315

316316
pub fn build_test_data(

mithril-aggregator/src/services/signed_entity.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ use std::sync::Arc;
1010

1111
use mithril_common::{
1212
entities::{
13-
CardanoDbBeacon, CardanoTransactionsSnapshot, Certificate, Epoch, MithrilStakeDistribution,
14-
SignedEntity, SignedEntityType, SignedEntityTypeDiscriminants, Snapshot,
13+
CardanoDbBeacon, CardanoTransactionsSnapshot, Certificate, ChainPoint, Epoch,
14+
MithrilStakeDistribution, SignedEntity, SignedEntityType, SignedEntityTypeDiscriminants,
15+
Snapshot,
1516
},
1617
signable_builder::Artifact,
1718
StdResult,
@@ -75,7 +76,7 @@ pub struct MithrilSignedEntityService {
7576
cardano_immutable_files_full_artifact_builder:
7677
Arc<dyn ArtifactBuilder<CardanoDbBeacon, Snapshot>>,
7778
cardano_transactions_artifact_builder:
78-
Arc<dyn ArtifactBuilder<CardanoDbBeacon, CardanoTransactionsSnapshot>>,
79+
Arc<dyn ArtifactBuilder<ChainPoint, CardanoTransactionsSnapshot>>,
7980
}
8081

8182
impl MithrilSignedEntityService {
@@ -89,7 +90,7 @@ impl MithrilSignedEntityService {
8990
dyn ArtifactBuilder<CardanoDbBeacon, Snapshot>,
9091
>,
9192
cardano_transactions_artifact_builder: Arc<
92-
dyn ArtifactBuilder<CardanoDbBeacon, CardanoTransactionsSnapshot>,
93+
dyn ArtifactBuilder<ChainPoint, CardanoTransactionsSnapshot>,
9394
>,
9495
) -> Self {
9596
Self {
@@ -128,13 +129,13 @@ impl MithrilSignedEntityService {
128129
})?,
129130
)),
130131
SignedEntityType::CardanoStakeDistribution(_) => todo!(),
131-
SignedEntityType::CardanoTransactions(beacon) => Ok(Arc::new(
132+
SignedEntityType::CardanoTransactions(epoch, chain_point) => Ok(Arc::new(
132133
self.cardano_transactions_artifact_builder
133-
.compute_artifact(beacon.clone(), certificate)
134+
.compute_artifact(chain_point.clone(), certificate)
134135
.await
135136
.with_context(|| {
136137
format!(
137-
"Signed Entity Service can not compute artifact for entity type: '{signed_entity_type}'"
138+
"Signed Entity Service can not compute artifact for entity type: '{chain_point}'"
138139
)
139140
})?,
140141
)),
@@ -337,7 +338,7 @@ mod tests {
337338
mock_cardano_immutable_files_full_artifact_builder:
338339
MockArtifactBuilder<CardanoDbBeacon, Snapshot>,
339340
mock_cardano_transactions_artifact_builder:
340-
MockArtifactBuilder<CardanoDbBeacon, CardanoTransactionsSnapshot>,
341+
MockArtifactBuilder<ChainPoint, CardanoTransactionsSnapshot>,
341342
}
342343

343344
impl MockDependencyInjector {
@@ -353,7 +354,7 @@ mod tests {
353354
Snapshot,
354355
>::new(),
355356
mock_cardano_transactions_artifact_builder: MockArtifactBuilder::<
356-
CardanoDbBeacon,
357+
ChainPoint,
357358
CardanoTransactionsSnapshot,
358359
>::new(),
359360
}
@@ -443,6 +444,7 @@ mod tests {
443444
async fn build_cardano_transactions_snapshot_artifact_when_given_cardano_transactions_type() {
444445
let mut mock_container = MockDependencyInjector::new();
445446

447+
// vvvvv - when updating to chain point make sure that the same beacon is used in the expected
446448
let expected =
447449
CardanoTransactionsSnapshot::new("merkle_root".to_string(), CardanoDbBeacon::default());
448450

@@ -460,7 +462,8 @@ mod tests {
460462
let artifact_builder_service = mock_container.build_artifact_builder_service();
461463

462464
let certificate = fake_data::certificate("hash".to_string());
463-
let signed_entity_type = SignedEntityType::CardanoTransactions(CardanoDbBeacon::default());
465+
let signed_entity_type =
466+
SignedEntityType::CardanoTransactions(Epoch(1), ChainPoint::dummy());
464467
let artifact = artifact_builder_service
465468
.compute_artifact(signed_entity_type.clone(), &certificate)
466469
.await
@@ -472,7 +475,7 @@ mod tests {
472475
#[tokio::test]
473476
async fn should_store_the_artifact_when_creating_artifact_for_cardano_transactions() {
474477
generic_test_that_the_artifact_is_stored(
475-
SignedEntityType::CardanoTransactions(CardanoDbBeacon::default()),
478+
SignedEntityType::CardanoTransactions(Epoch(1), ChainPoint::dummy()),
476479
CardanoTransactionsSnapshot::new("merkle_root".to_string(), CardanoDbBeacon::default()),
477480
&|mock_injector| &mut mock_injector.mock_cardano_transactions_artifact_builder,
478481
)

mithril-aggregator/tests/test_extensions/aggregator_observer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ impl AggregatorObserver {
9595
SignedEntityTypeDiscriminants::CardanoImmutableFilesFull => {
9696
Ok(SignedEntityType::CardanoImmutableFilesFull(beacon))
9797
}
98-
SignedEntityTypeDiscriminants::CardanoTransactions => {
99-
Ok(SignedEntityType::CardanoTransactions(beacon))
100-
}
98+
SignedEntityTypeDiscriminants::CardanoTransactions => Ok(
99+
SignedEntityType::CardanoTransactions(time_point.epoch, time_point.chain_point),
100+
),
101101
}
102102
}
103103
}

0 commit comments

Comments
 (0)