Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Number beacon in cardano transaction #1727

Merged
merged 31 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ad690a7
Implement `Display` into `ChainPoint`
Alenar May 29, 2024
f9479f9
Change CardanoTransactions signed entity beacon to `(Epoch,ChainPoint)`
Alenar May 29, 2024
765309d
Update `hydrate_signed_entity_type` in `mithril-persistence`
Alenar May 29, 2024
d680428
Partialy adapt aggregator
Alenar May 29, 2024
b0697b1
Make CardanoTransactionsSignableBuilder use ChainPoint beacon
Alenar May 29, 2024
203ceaf
Rename `LatestImmutableFileNumber` protocol message part to `LatestBl…
Alenar May 29, 2024
754ca9a
Update BlockScanner signature to 'from BlockNumber until ChainPoint'
Alenar May 30, 2024
cf581e1
Make CardanoBlockScanner ignore it's upper bound
Alenar May 30, 2024
a16aef2
Make CardanoBlockScanner find it's lower bound using a trait
Alenar May 30, 2024
488cf82
Add `get_transaction_highest_block_number` to shared CardanoTransacti…
Alenar May 30, 2024
017b28b
Adapt Signer to the ChainPoint based Scanner & BlockRange retriever
Alenar May 30, 2024
0e1abf4
Update aggregator dependency construction
Alenar May 31, 2024
fabb426
Make aggregator TransactionImporter use ChainPoint
Alenar May 31, 2024
b005c51
Make aggregator services & cardano transaction artifact builder use C…
Alenar May 31, 2024
3847963
Make CardanoTransactionSnapshot entity use a ChainPoint beacon
Alenar May 31, 2024
0ab07cd
Use chain point in common CardanoTransaction messages
Alenar May 31, 2024
ba6f7c9
Adapt aggregator to the updated CardanoTransactionSnapshot artifact
Alenar May 31, 2024
7c7da5a
Adapt client, client-cli and end-to-end to the ChainPoint beacon
Alenar May 31, 2024
6eade6c
Remove now unused repository method fetching data using Immutables
Alenar May 31, 2024
686e219
Simplify CardanoTransaction signed entity type to `Epoch,BlockNumber`
Alenar Jun 3, 2024
8d1e1b8
Make SignableBuilder use a BlockNumber as target
Alenar Jun 3, 2024
dcceb41
Transfer immutable offsetting responsability to block scanner
Alenar Jun 3, 2024
e95a839
Introduce CardanoTransactionSigning config
Alenar Jun 3, 2024
6505bc7
Add `cardano_transactions_signing_config` to Aggregator configuration
Alenar Jun 4, 2024
865d9f3
Cleanup CardanoDbBeacon based certificate & signed entity of CardanoT…
Alenar Jun 4, 2024
a5b5e4c
Update aggregator fake default data
Alenar Jun 4, 2024
fc41440
Update explorer to new CardanoTransaction signed entity beacon
Alenar Jun 4, 2024
8840169
Add `cardano_transactions_signing_config` in aggregator docusaurus doc
Alenar Jun 5, 2024
c80f17e
Adjustements from PR reviews & fix broken doc tests
Alenar Jun 5, 2024
026f3d6
PR Review adjusments: enhance tests
Alenar Jun 5, 2024
70a8a61
Upgrade crates versions and update Changelog
Alenar Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ As a minor extension, we have adopted a slightly different versioning convention

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

- Change the beacon of the Cardano Transactions to a block number instead of an immutable file number.

- Crates versions:

| Crate | Version |
Expand Down
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ Here is a list of the available parameters:
| `snapshot_compression_algorithm` | `--snapshot-compression-algorithm` | - | `SNAPSHOT_COMPRESSION_ALGORITHM` | Compression algorithm of the snapshot archive | `zstandard` | `gzip` or `zstandard` | - |
| `zstandard_parameters` | - | - | `ZSTANDARD_PARAMETERS__LEVEL` and `ZSTANDARD_PARAMETERS__NUMBER_OF_WORKERS` | Zstandard specific parameters | - | `{ level: 9, number_of_workers: 4 }` | - |
| `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` | - | - |
| `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 }` | - |

`genesis bootstrap` command:

Expand Down
2 changes: 1 addition & 1 deletion internal/mithril-persistence/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-persistence"
version = "0.2.1"
version = "0.2.2"
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
authors = { workspace = true }
edition = { workspace = true }
Expand Down
36 changes: 31 additions & 5 deletions internal/mithril-persistence/src/database/hydrator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Shared hydrator helpers for persistence

use serde::Deserialize;

use mithril_common::entities::{
CardanoDbBeacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants,
BlockNumber, CardanoDbBeacon, Epoch, SignedEntityType, SignedEntityTypeDiscriminants,
};

use crate::sqlite::HydrationError;
Expand Down Expand Up @@ -69,15 +71,39 @@ impl Hydrator {
SignedEntityType::CardanoImmutableFilesFull(beacon)
}
SignedEntityTypeDiscriminants::CardanoTransactions => {
let beacon: CardanoDbBeacon = serde_json::from_str(beacon_str).map_err(|e| {
HydrationError::InvalidData(format!(
#[derive(Deserialize)]
struct CardanoTransactionsBeacon {
epoch: Epoch,
block_number: BlockNumber,
}

let beacon: CardanoTransactionsBeacon =
serde_json::from_str(beacon_str).map_err(|e| {
HydrationError::InvalidData(format!(
"Invalid Beacon JSON in open_message.beacon: '{beacon_str}'. Error: {e}"
))
})?;
SignedEntityType::CardanoTransactions(beacon)
})?;
SignedEntityType::CardanoTransactions(beacon.epoch, beacon.block_number)
}
};

Ok(signed_entity)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn hydrate_cardano_transaction_signed_entity_type() {
let expected = SignedEntityType::CardanoTransactions(Epoch(35), 77);
let signed_entity = Hydrator::hydrate_signed_entity_type(
SignedEntityTypeDiscriminants::CardanoTransactions.index(),
&expected.get_json_beacon().unwrap(),
)
.unwrap();

assert_eq!(expected, signed_entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ impl GetCardanoTransactionQuery {

Self { condition }
}

pub fn with_highest_block_number() -> Self {
Self {
condition: WhereCondition::new(
"block_number = (select max(block_number) from cardano_tx)",
vec![],
),
}
}
}

impl Query for GetCardanoTransactionQuery {
Expand All @@ -80,3 +89,49 @@ impl Query for GetCardanoTransactionQuery {
format!("select {projection} from cardano_tx where {condition} order by block_number, transaction_hash")
}
}

#[cfg(test)]
mod tests {
use crate::database::query::InsertCardanoTransactionQuery;
use crate::database::test_helper::cardano_tx_db_connection;
use crate::sqlite::{ConnectionExtensions, SqliteConnection};

use super::*;

fn insert_transactions(connection: &SqliteConnection, records: Vec<CardanoTransactionRecord>) {
connection
.fetch_first(InsertCardanoTransactionQuery::insert_many(records).unwrap())
.unwrap();
}

#[test]
fn with_highest_block_number() {
let connection = cardano_tx_db_connection().unwrap();

let cursor = connection
.fetch(GetCardanoTransactionQuery::with_highest_block_number())
.unwrap();
assert_eq!(0, cursor.count());

insert_transactions(
&connection,
vec![
CardanoTransactionRecord::new("tx-hash-0", 10, 50, "block-hash-10", 1),
CardanoTransactionRecord::new("tx-hash-1", 10, 51, "block-hash-10", 1),
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11", 1),
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11", 1),
],
);

let records: Vec<CardanoTransactionRecord> = connection
.fetch_collect(GetCardanoTransactionQuery::with_highest_block_number())
.unwrap();
assert_eq!(
vec![
CardanoTransactionRecord::new("tx-hash-2", 11, 54, "block-hash-11", 1),
CardanoTransactionRecord::new("tx-hash-3", 11, 55, "block-hash-11", 1),
],
records
);
}
}
Loading
Loading