Skip to content

Commit 0ab07cd

Browse files
committed
Use chain point in common CardanoTransaction messages
1 parent 3847963 commit 0ab07cd

File tree

4 files changed

+102
-62
lines changed

4 files changed

+102
-62
lines changed

mithril-common/src/messages/cardano_transaction_snapshot.rs

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

5-
use crate::entities::CardanoDbBeacon;
6-
#[cfg(any(test, feature = "test_tools"))]
7-
use crate::test_utils::fake_data;
5+
use crate::entities::{ChainPoint, Epoch};
86

97
/// Message structure of a Cardano Transactions snapshot
10-
#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
8+
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
119
pub struct CardanoTransactionSnapshotMessage {
1210
/// Merkle root of the Cardano transactions snapshot
1311
pub merkle_root: String,
1412

15-
/// Beacon of the Cardano transactions snapshot
16-
pub beacon: CardanoDbBeacon,
13+
/// Epoch of the Cardano transactions snapshot
14+
pub epoch: Epoch,
15+
16+
/// ChainPoint of the Cardano transactions snapshot
17+
pub chain_point: ChainPoint,
1718

1819
/// Hash of the Cardano Transactions snapshot
1920
pub hash: String,
@@ -31,7 +32,8 @@ impl CardanoTransactionSnapshotMessage {
3132
pub fn dummy() -> Self {
3233
Self {
3334
merkle_root: "mkroot-123".to_string(),
34-
beacon: fake_data::beacon(),
35+
epoch: Epoch(10),
36+
chain_point: ChainPoint::dummy(),
3537
hash: "hash-123".to_string(),
3638
certificate_hash: "cert-hash-123".to_string(),
3739
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
@@ -49,7 +51,8 @@ mod tests {
4951
fn golden_message() -> CardanoTransactionSnapshotMessage {
5052
CardanoTransactionSnapshotMessage {
5153
merkle_root: "mkroot-123".to_string(),
52-
beacon: CardanoDbBeacon::new("testnet", 10, 100),
54+
epoch: Epoch(8),
55+
chain_point: ChainPoint::new(110, 6, "block_hash-6"),
5356
hash: "hash-123".to_string(),
5457
certificate_hash: "certificate-hash-123".to_string(),
5558
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
@@ -60,13 +63,14 @@ mod tests {
6063

6164
// Test the retro compatibility with possible future upgrades.
6265
#[test]
63-
fn test_v1() {
66+
fn test_v2() {
6467
let json = r#"{
6568
"merkle_root": "mkroot-123",
66-
"beacon": {
67-
"network": "testnet",
68-
"epoch": 10,
69-
"immutable_file_number": 100
69+
"epoch": 8,
70+
"chain_point": {
71+
"slot_number": 110,
72+
"block_number": 6,
73+
"block_hash": "block_hash-6"
7074
},
7175
"hash": "hash-123",
7276
"certificate_hash": "certificate-hash-123",

mithril-common/src/messages/cardano_transaction_snapshot_list.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
use chrono::{DateTime, Utc};
22
use serde::{Deserialize, Serialize};
33

4-
use crate::entities::CardanoDbBeacon;
5-
#[cfg(any(test, feature = "test_tools"))]
6-
use crate::test_utils::fake_data;
4+
use crate::entities::{ChainPoint, Epoch};
75

86
/// Message structure of a Cardano Transactions Snapshots list
97
pub type CardanoTransactionSnapshotListMessage = Vec<CardanoTransactionSnapshotListItemMessage>;
108

119
/// Message structure of a Cardano Transactions Snapshot list item
12-
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)]
10+
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1311
pub struct CardanoTransactionSnapshotListItemMessage {
1412
/// Merkle root of the Cardano transactions snapshot
1513
pub merkle_root: String,
1614

17-
/// Beacon of the Cardano transactions snapshot
18-
pub beacon: CardanoDbBeacon,
15+
/// Epoch of the Cardano transactions snapshot
16+
pub epoch: Epoch,
17+
18+
/// ChainPoint of the Cardano transactions snapshot
19+
pub chain_point: ChainPoint,
1920

2021
/// Hash of the Cardano Transactions snapshot
2122
pub hash: String,
@@ -33,7 +34,8 @@ impl CardanoTransactionSnapshotListItemMessage {
3334
pub fn dummy() -> Self {
3435
Self {
3536
merkle_root: "mkroot-123".to_string(),
36-
beacon: fake_data::beacon(),
37+
epoch: Epoch(10),
38+
chain_point: ChainPoint::dummy(),
3739
hash: "hash-123".to_string(),
3840
certificate_hash: "cert-hash-123".to_string(),
3941
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
@@ -51,7 +53,8 @@ mod tests {
5153
fn golden_message() -> CardanoTransactionSnapshotListMessage {
5254
vec![CardanoTransactionSnapshotListItemMessage {
5355
merkle_root: "mkroot-123".to_string(),
54-
beacon: CardanoDbBeacon::new("testnet", 10, 100),
56+
epoch: Epoch(7),
57+
chain_point: ChainPoint::new(100, 5, "block_hash-5"),
5558
hash: "hash-123".to_string(),
5659
certificate_hash: "certificate-hash-123".to_string(),
5760
created_at: DateTime::parse_from_rfc3339("2023-01-19T13:43:05.618857482Z")
@@ -62,19 +65,19 @@ mod tests {
6265

6366
// Test the retro compatibility with possible future upgrades.
6467
#[test]
65-
fn test_v1() {
68+
fn test_v2() {
6669
let json = r#"[{
6770
"merkle_root": "mkroot-123",
68-
"beacon": {
69-
"network": "testnet",
70-
"epoch": 10,
71-
"immutable_file_number": 100
71+
"epoch": 7,
72+
"chain_point": {
73+
"slot_number": 100,
74+
"block_number": 5,
75+
"block_hash": "block_hash-5"
7276
},
7377
"hash": "hash-123",
7478
"certificate_hash": "certificate-hash-123",
7579
"created_at": "2023-01-19T13:43:05.618857482Z"
7680
}]"#;
77-
println!("message: {:?}", golden_message());
7881

7982
let message: CardanoTransactionSnapshotListMessage = serde_json::from_str(json).expect(
8083
"This JSON is expected to be successfully parsed into a CardanoTransactionSnapshotListMessage instance.",

mithril-common/src/messages/cardano_transactions_proof.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::entities::{
2-
CardanoTransactionsSetProof, ProtocolMessage, ProtocolMessagePartKey, TransactionHash,
2+
BlockNumber, CardanoTransactionsSetProof, ProtocolMessage, ProtocolMessagePartKey,
3+
TransactionHash,
34
};
45
use crate::messages::CardanoTransactionsSetProofMessagePart;
56
use crate::StdError;
@@ -25,8 +26,8 @@ pub struct CardanoTransactionsProofsMessage {
2526
/// Transactions that could not be certified
2627
pub non_certified_transactions: Vec<TransactionHash>,
2728

28-
/// Latest immutable file number that has been certified
29-
pub latest_immutable_file_number: u64,
29+
/// Latest block number that has been certified
30+
pub latest_block_number: BlockNumber,
3031
}
3132

3233
#[cfg_attr(
@@ -53,8 +54,7 @@ pub struct VerifiedCardanoTransactions {
5354
certificate_hash: String,
5455
merkle_root: String,
5556
certified_transactions: Vec<TransactionHash>,
56-
// vvvvv - TODO: change field name to latest_block_number
57-
latest_immutable_file_number: u64,
57+
latest_block_number: BlockNumber,
5858
}
5959

6060
impl VerifiedCardanoTransactions {
@@ -78,7 +78,7 @@ impl VerifiedCardanoTransactions {
7878

7979
message.set_message_part(
8080
ProtocolMessagePartKey::LatestBlockNumber,
81-
self.latest_immutable_file_number.to_string(),
81+
self.latest_block_number.to_string(),
8282
);
8383
}
8484
}
@@ -118,13 +118,13 @@ impl CardanoTransactionsProofsMessage {
118118
certificate_hash: &str,
119119
certified_transactions: Vec<CardanoTransactionsSetProofMessagePart>,
120120
non_certified_transactions: Vec<TransactionHash>,
121-
latest_immutable_file_number: u64,
121+
latest_block_number: BlockNumber,
122122
) -> Self {
123123
Self {
124124
certificate_hash: certificate_hash.to_string(),
125125
certified_transactions,
126126
non_certified_transactions,
127-
latest_immutable_file_number,
127+
latest_block_number,
128128
}
129129
}
130130

@@ -174,16 +174,16 @@ impl CardanoTransactionsProofsMessage {
174174
.iter()
175175
.flat_map(|c| c.transactions_hashes.clone())
176176
.collect(),
177-
latest_immutable_file_number: self.latest_immutable_file_number,
177+
latest_block_number: self.latest_block_number,
178178
})
179179
}
180180
}
181181

182182
#[cfg(test)]
183183
mod tests {
184+
use crate::crypto_helper::MKProof;
184185

185186
use super::*;
186-
use crate::crypto_helper::MKProof;
187187

188188
#[test]
189189
fn verify_malformed_proofs_fail() {
@@ -234,7 +234,7 @@ mod tests {
234234
certificate_hash: "whatever".to_string(),
235235
merkle_root: set_proof.merkle_root(),
236236
certified_transactions: set_proof.transactions_hashes().to_vec(),
237-
latest_immutable_file_number: 99999,
237+
latest_block_number: 99999,
238238
};
239239
let txs_proofs = CardanoTransactionsProofsMessage::new(
240240
"whatever",
@@ -366,8 +366,7 @@ mod tests {
366366
certificate_hash: "whatever".to_string(),
367367
merkle_root: set_proof.merkle_root(),
368368
certified_transactions: set_proof.transactions_hashes().to_vec(),
369-
// vvvvv - TODO: change field name to latest_block_number
370-
latest_immutable_file_number: block_number,
369+
latest_block_number: block_number,
371370
};
372371

373372
let mut message = ProtocolMessage::new();

openapi.yaml

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,34 @@ components:
647647
example:
648648
{ "network": "mainnet", "epoch": 329, "immutable_file_number": 7060000 }
649649

650+
ChainPoint:
651+
description: A point in the Cardano chain at which a Mithril certificate of the Cardano Transactions should be produced
652+
type: object
653+
additionalProperties: true
654+
required:
655+
- slot_number
656+
- block_number
657+
- block_hash
658+
properties:
659+
slot_number:
660+
description: Cardano slot number
661+
type: integer
662+
format: int64
663+
block_number:
664+
description: Cardano block number
665+
type: integer
666+
format: int64
667+
block_hash:
668+
description: Hash of the Cardano block
669+
type: string
670+
format: bytes
671+
example:
672+
{
673+
"slot_number": 4567,
674+
"block_number": 1234,
675+
"block_hash": "9dc998101590f733f7a50e7c03b5b336e69a751cc02d811395d49618db3ba3d7"
676+
}
677+
650678
SignedEntityType:
651679
description: Entity type of the message that is signed
652680
type: object
@@ -1611,7 +1639,8 @@ components:
16111639
- hash
16121640
- certificate_hash
16131641
- merkle_root
1614-
- beacon
1642+
- epoch
1643+
- chain_point
16151644
- created_at
16161645
properties:
16171646
hash:
@@ -1626,8 +1655,10 @@ components:
16261655
description: Merkle root of the Cardano transactions set
16271656
type: string
16281657
format: bytes
1629-
beacon:
1630-
$ref: "#/components/schemas/CardanoDbBeacon"
1658+
epoch:
1659+
$ref: "#/components/schemas/Epoch"
1660+
chain_point:
1661+
$ref: "#/components/schemas/ChainPoint"
16311662
created_at:
16321663
description: Date and time at which the Cardano transactions set was created
16331664
type: string
@@ -1637,12 +1668,12 @@ components:
16371668
"hash": "6367ee65d0d1272e6e70736a1ea2cae34015874517f6328364f6b73930966732",
16381669
"certificate_hash": "7905e83ab5d7bc082c1bbc3033bfd19c539078830d19080d1f241c70aa532572",
16391670
"merkle_root": "33bfd17bc082ab5dd1fc0788241c70aa5325241c70aa532530d190809c5391bbc307905e8372",
1640-
"beacon":
1641-
{
1642-
"network": "mainnet",
1643-
"epoch": 329,
1644-
"immutable_file_number": 7060000
1645-
},
1671+
"epoch": 123,
1672+
"chain_point": {
1673+
"slot_number": 4567,
1674+
"block_number": 1234,
1675+
"block_hash": "9dc998101590f733f7a50e7c03b5b336e69a751cc02d811395d49618db3ba3d7"
1676+
},
16461677
"created_at": "2022-06-14T10:52:31Z"
16471678
}
16481679

@@ -1654,7 +1685,8 @@ components:
16541685
- hash
16551686
- certificate_hash
16561687
- merkle_root
1657-
- beacon
1688+
- epoch
1689+
- chain_point
16581690
- created_at
16591691
properties:
16601692
hash:
@@ -1669,8 +1701,10 @@ components:
16691701
description: Merkle root of the Cardano transactions set
16701702
type: string
16711703
format: bytes
1672-
beacon:
1673-
$ref: "#/components/schemas/CardanoDbBeacon"
1704+
epoch:
1705+
$ref: "#/components/schemas/Epoch"
1706+
chain_point:
1707+
$ref: "#/components/schemas/ChainPoint"
16741708
created_at:
16751709
description: Date and time at which the Cardano transactions set was created
16761710
type: string
@@ -1680,12 +1714,12 @@ components:
16801714
"hash": "6367ee65d0d1272e6e70736a1ea2cae34015874517f6328364f6b73930966732",
16811715
"certificate_hash": "7905e83ab5d7bc082c1bbc3033bfd19c539078830d19080d1f241c70aa532572",
16821716
"merkle_root": "33bfd17bc082ab5dd1fc0788241c70aa5325241c70aa532530d190809c5391bbc307905e8372",
1683-
"beacon":
1684-
{
1685-
"network": "mainnet",
1686-
"epoch": 329,
1687-
"immutable_file_number": 7060000
1688-
},
1717+
"epoch": 123,
1718+
"chain_point": {
1719+
"slot_number": 4567,
1720+
"block_number": 1234,
1721+
"block_hash": "9dc998101590f733f7a50e7c03b5b336e69a751cc02d811395d49618db3ba3d7"
1722+
},
16891723
"created_at": "2022-06-14T10:52:31Z"
16901724
}
16911725

@@ -1697,7 +1731,7 @@ components:
16971731
- certificate_hash
16981732
- certified_transactions
16991733
- non_certified_transactions
1700-
- latest_immutable_file_number
1734+
- latest_block_number
17011735
properties:
17021736
certificate_hash:
17031737
description: Hash of the certificate that validate the merkle root of this proof
@@ -1728,8 +1762,8 @@ components:
17281762
description: Hash of the non certified Cardano transactions
17291763
type: string
17301764
format: bytes
1731-
latest_immutable_file_number:
1732-
description: Last immutable file number
1765+
latest_block_number:
1766+
description: Last block number
17331767
type: integer
17341768
format: int64
17351769
example:
@@ -1740,7 +1774,7 @@ components:
17401774
"proof": "5b73136372c38302c37342c3136362c313535b5b323136362c313535b5b3232352c3230332c3235352c313030262c38322c39382c32c39332c3138342c313532352c3230332c3235352c313030262c33136362c313535b5b3232352c3230332c3235352c313030262c38322c39382c32c39332c3138342c31358322c39382c32c39332c3138342c3135362c3136362c32312c3131312c3232312c36332c3137372c3232332c3232332c31392c3537"
17411775
} ],
17421776
"non_certified_transactions": [ "732d0d1272e6e70736367ee6f6328364f6b739309666a1ea2cae34015874517" ],
1743-
"latest_immutable_file_number": 7060000
1777+
"latest_block_number": 7060000
17441778
}
17451779

17461780
Error:

0 commit comments

Comments
 (0)