Skip to content

Commit c6f32d0

Browse files
authored
Merge pull request #1727 from input-output-hk/ensemble/1697/chain_point_beacon_in_cardano_transaction
Use a Block Number beacon for Cardano transaction
2 parents 3b542fd + 70a8a61 commit c6f32d0

File tree

83 files changed

+2817
-1823
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2817
-1823
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ As a minor extension, we have adopted a slightly different versioning convention
2323

2424
- Implement a Resource Pool and use it for caching Block Range Merkle maps used by the Cardano transactions prover and improving the throughput.
2525

26+
- Change the beacon of the Cardano Transactions to a block number instead of an immutable file number.
27+
2628
- Crates versions:
2729

2830
| Crate | Version |

Cargo.lock

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

docs/website/root/manual/developer-docs/nodes/mithril-aggregator.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ Here is a list of the available parameters:
446446
| `snapshot_compression_algorithm` | `--snapshot-compression-algorithm` | - | `SNAPSHOT_COMPRESSION_ALGORITHM` | Compression algorithm of the snapshot archive | `zstandard` | `gzip` or `zstandard` | - |
447447
| `zstandard_parameters` | - | - | `ZSTANDARD_PARAMETERS__LEVEL` and `ZSTANDARD_PARAMETERS__NUMBER_OF_WORKERS` | Zstandard specific parameters | - | `{ level: 9, number_of_workers: 4 }` | - |
448448
| `allow_unparsable_block` | `--allow-unparsable-block` | - | `ALLOW_UNPARSABLE_BLOCK` | If set no error is returned in case of unparsable block and an error log is written instead. Will be ignored on (pre)production networks. | `false` | - | - |
449+
| `cardano_transactions_signing_config` | - | - | `CARDANO_TRANSACTIONS_SIGNING_CONFIG__SECURITY_PARAMETER` and `CARDANO_TRANSACTIONS_SIGNING_CONFIG__STEP` | Cardano transactions signing configuration | - | `{ security_parameter: 3000, step: 120 }` | - |
449450

450451
`genesis bootstrap` command:
451452

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.1"
3+
version = "0.2.2"
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: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! Shared hydrator helpers for persistence
22
3+
use serde::Deserialize;
4+
35
use mithril_common::entities::{
4-
CardanoDbBeacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants,
6+
BlockNumber, CardanoDbBeacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants,
57
};
68

79
use crate::sqlite::HydrationError;
@@ -69,15 +71,39 @@ impl Hydrator {
6971
SignedEntityType::CardanoImmutableFilesFull(beacon)
7072
}
7173
SignedEntityTypeDiscriminants::CardanoTransactions => {
72-
let beacon: CardanoDbBeacon = serde_json::from_str(beacon_str).map_err(|e| {
73-
HydrationError::InvalidData(format!(
74+
#[derive(Deserialize)]
75+
struct CardanoTransactionsBeacon {
76+
epoch: Epoch,
77+
block_number: BlockNumber,
78+
}
79+
80+
let beacon: CardanoTransactionsBeacon =
81+
serde_json::from_str(beacon_str).map_err(|e| {
82+
HydrationError::InvalidData(format!(
7483
"Invalid Beacon JSON in open_message.beacon: '{beacon_str}'. Error: {e}"
7584
))
76-
})?;
77-
SignedEntityType::CardanoTransactions(beacon)
85+
})?;
86+
SignedEntityType::CardanoTransactions(beacon.epoch, beacon.block_number)
7887
}
7988
};
8089

8190
Ok(signed_entity)
8291
}
8392
}
93+
94+
#[cfg(test)]
95+
mod tests {
96+
use super::*;
97+
98+
#[test]
99+
fn hydrate_cardano_transaction_signed_entity_type() {
100+
let expected = SignedEntityType::CardanoTransactions(Epoch(35), 77);
101+
let signed_entity = Hydrator::hydrate_signed_entity_type(
102+
SignedEntityTypeDiscriminants::CardanoTransactions.index(),
103+
&expected.get_json_beacon().unwrap(),
104+
)
105+
.unwrap();
106+
107+
assert_eq!(expected, signed_entity);
108+
}
109+
}

internal/mithril-persistence/src/database/query/cardano_transaction/get_cardano_transaction.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ impl GetCardanoTransactionQuery {
6464

6565
Self { condition }
6666
}
67+
68+
pub fn with_highest_block_number() -> Self {
69+
Self {
70+
condition: WhereCondition::new(
71+
"block_number = (select max(block_number) from cardano_tx)",
72+
vec![],
73+
),
74+
}
75+
}
6776
}
6877

6978
impl Query for GetCardanoTransactionQuery {
@@ -80,3 +89,49 @@ impl Query for GetCardanoTransactionQuery {
8089
format!("select {projection} from cardano_tx where {condition} order by block_number, transaction_hash")
8190
}
8291
}
92+
93+
#[cfg(test)]
94+
mod tests {
95+
use crate::database::query::InsertCardanoTransactionQuery;
96+
use crate::database::test_helper::cardano_tx_db_connection;
97+
use crate::sqlite::{ConnectionExtensions, SqliteConnection};
98+
99+
use super::*;
100+
101+
fn insert_transactions(connection: &SqliteConnection, records: Vec<CardanoTransactionRecord>) {
102+
connection
103+
.fetch_first(InsertCardanoTransactionQuery::insert_many(records).unwrap())
104+
.unwrap();
105+
}
106+
107+
#[test]
108+
fn with_highest_block_number() {
109+
let connection = cardano_tx_db_connection().unwrap();
110+
111+
let cursor = connection
112+
.fetch(GetCardanoTransactionQuery::with_highest_block_number())
113+
.unwrap();
114+
assert_eq!(0, cursor.count());
115+
116+
insert_transactions(
117+
&connection,
118+
vec![
119+
CardanoTransactionRecord::new("tx-hash-0", 10, 50, "block-hash-10", 1),
120+
CardanoTransactionRecord::new("tx-hash-1", 10, 51, "block-hash-10", 1),
121+
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11", 1),
122+
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11", 1),
123+
],
124+
);
125+
126+
let records: Vec<CardanoTransactionRecord> = connection
127+
.fetch_collect(GetCardanoTransactionQuery::with_highest_block_number())
128+
.unwrap();
129+
assert_eq!(
130+
vec![
131+
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11", 1),
132+
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11", 1),
133+
],
134+
records
135+
);
136+
}
137+
}

0 commit comments

Comments
 (0)