Skip to content

Commit

Permalink
Merge pull request input-output-hk#1489 from input-output-hk/ensemble…
Browse files Browse the repository at this point in the history
…/1468/cardano-tx-in-client-lib

Add Cardano transactions proofs support to mithril-client
  • Loading branch information
Alenar authored Feb 8, 2024
2 parents fa1c45e + 44b4198 commit 6cd739a
Show file tree
Hide file tree
Showing 45 changed files with 1,191 additions and 299 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: ./.github/workflows/actions/build-upload-mithril-artifact
with:
binaries-build-args: --bin mithril-aggregator --bin mithril-signer --bin mithril-client --bin mithril-relay --features bundle_openssl,full
libraries-build-args: --package mithril-stm --package mithril-client --features full
libraries-build-args: --package mithril-stm --package mithril-client --features full,unstable

- name: Build Debian packages
shell: bash
Expand Down Expand Up @@ -83,12 +83,12 @@ jobs:
# Only build client on windows & mac
- os: macos-12
binaries-build-args: --bin mithril-client --features bundle_openssl
libraries-build-args: --package mithril-stm --package mithril-client --features full
libraries-build-args: --package mithril-stm --package mithril-client --features full,unstable
- os: windows-latest
# Use `--bins --package <package>` instead of `--bin <package>`, otherwise the 'windows' compatibility
# hack in mithril common cargo.toml doesn't apply (we have no idea why).
binaries-build-args: --bins --package mithril-client-cli --features bundle_openssl
libraries-build-args: --package mithril-stm --package mithril-client --no-default-features --features num-integer-backend,full
libraries-build-args: --package mithril-stm --package mithril-client --no-default-features --features num-integer-backend,full,unstable
runs-on: ${{ matrix.os }}

steps:
Expand Down Expand Up @@ -169,12 +169,12 @@ jobs:

include:
- os: ubuntu-22.04
test-args: --features portable,full --workspace
test-args: --features portable,full,unstable --workspace
# Only test client on windows & mac (since its the only binaries supported for those os for now)
- os: macos-12
test-args: --package mithril-client --package mithril-client-cli --features full
test-args: --package mithril-client --package mithril-client-cli --features full,unstable
- os: windows-latest
test-args: --package mithril-client --package mithril-client-cli --features full
test-args: --package mithril-client --package mithril-client-cli --features full,unstable

runs-on: ${{ matrix.os }}

Expand Down
10 changes: 5 additions & 5 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 @@ -30,7 +30,7 @@ Mithril aggregator is responsible for collecting individual signatures from the
## Resources

| Node | Source repository | Rust documentation | Docker packages | REST API
|:-:|:-----------------:|:------------------:|:---------------:|
|:----:|:-----------------:|:------------------:|:---------------:|:--------:|
**Mithril aggregator** | [:arrow_upper_right:](https://github.com/input-output-hk/mithril/tree/main/mithril-aggregator) | [:arrow_upper_right:](https://mithril.network/rust-doc/mithril_aggregator/index.html) | [:arrow_upper_right:](https://github.com/input-output-hk/mithril/pkgs/container/mithril-aggregator) | [:arrow_upper_right:](/doc/aggregator-api)

## Pre-requisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Mithril aggregator is responsible for collecting individual signatures from the
## Resources

| Node | Source repository | Rust documentation | Docker packages | REST API
|:-:|:-----------------:|:------------------:|:---------------:|
|:----:|:-----------------:|:------------------:|:---------------:|:--------:|
**Mithril aggregator** | [:arrow_upper_right:](https://github.com/input-output-hk/mithril/tree/main/mithril-aggregator) | [:arrow_upper_right:](https://mithril.network/rust-doc/mithril_aggregator/index.html) | [:arrow_upper_right:](https://github.com/input-output-hk/mithril/pkgs/container/mithril-aggregator) | [:arrow_upper_right:](/doc/aggregator-api)

## Pre-requisites
Expand Down
2 changes: 1 addition & 1 deletion mithril-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-aggregator"
version = "0.4.33"
version = "0.4.34"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions mithril-aggregator/src/database/provider/signed_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use mithril_common::{
Beacon, Epoch, SignedEntity, SignedEntityType, SignedEntityTypeDiscriminants, Snapshot,
},
messages::{
CardanoTransactionListItemMessage, CardanoTransactionMessage,
CardanoTransactionCommitmentListItemMessage, CardanoTransactionCommitmentMessage,
MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage,
SignerWithStakeMessagePart, SnapshotListItemMessage, SnapshotMessage,
},
Expand Down Expand Up @@ -137,7 +137,7 @@ impl TryFrom<SignedEntityRecord> for MithrilStakeDistributionListItemMessage {
}
}

impl TryFrom<SignedEntityRecord> for CardanoTransactionMessage {
impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentMessage {
type Error = StdError;

fn try_from(value: SignedEntityRecord) -> Result<Self, Self::Error> {
Expand All @@ -148,7 +148,7 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionMessage {
hash: String,
}
let artifact = serde_json::from_str::<TmpCardanoTransaction>(&value.artifact)?;
let cardano_transaction_message = CardanoTransactionMessage {
let cardano_transaction_message = CardanoTransactionCommitmentMessage {
merkle_root: artifact.merkle_root,
beacon: artifact.beacon,
hash: artifact.hash,
Expand All @@ -160,7 +160,7 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionMessage {
}
}

impl TryFrom<SignedEntityRecord> for CardanoTransactionListItemMessage {
impl TryFrom<SignedEntityRecord> for CardanoTransactionCommitmentListItemMessage {
type Error = StdError;

fn try_from(value: SignedEntityRecord) -> Result<Self, Self::Error> {
Expand All @@ -171,7 +171,7 @@ impl TryFrom<SignedEntityRecord> for CardanoTransactionListItemMessage {
hash: String,
}
let artifact = serde_json::from_str::<TmpCardanoTransaction>(&value.artifact)?;
let message = CardanoTransactionListItemMessage {
let message = CardanoTransactionCommitmentListItemMessage {
merkle_root: artifact.merkle_root,
beacon: artifact.beacon,
hash: artifact.hash,
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use warp::Filter;

use mithril_common::{
api_version::APIVersionProvider,
cardano_transaction_parser::TransactionParser,
cardano_transaction_parser::{CardanoTransactionParser, TransactionParser},
certificate_chain::{CertificateVerifier, MithrilCertificateVerifier},
chain_observer::{CardanoCliRunner, ChainObserver, ChainObserverBuilder, FakeObserver},
crypto_helper::{
Expand All @@ -41,7 +41,7 @@ use mithril_common::{
},
sqlite::SqliteConnection,
store::adapter::{MemoryAdapter, SQLiteAdapter, StoreAdapter},
BeaconProvider, BeaconProviderImpl, CardanoTransactionParser,
BeaconProvider, BeaconProviderImpl,
};

use crate::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use mithril_common::entities::{CardanoTransactionsCommitment, SignedEntity};
use mithril_common::messages::{
CardanoTransactionListItemMessage, CardanoTransactionListMessage, ToMessageAdapter,
CardanoTransactionCommitmentListItemMessage, CardanoTransactionCommitmentListMessage,
ToMessageAdapter,
};

/// Adapter to convert a list of [CardanoTransaction] to [CardanoTransactionListMessage] instances
/// Adapter to convert a list of [CardanoTransaction] to [CardanoTransactionCommitmentListMessage] instances
pub struct ToCardanoTransactionListMessageAdapter;

impl
ToMessageAdapter<
Vec<SignedEntity<CardanoTransactionsCommitment>>,
CardanoTransactionListMessage,
CardanoTransactionCommitmentListMessage,
> for ToCardanoTransactionListMessageAdapter
{
/// Method to trigger the conversion
fn adapt(
snapshots: Vec<SignedEntity<CardanoTransactionsCommitment>>,
) -> CardanoTransactionListMessage {
) -> CardanoTransactionCommitmentListMessage {
snapshots
.into_iter()
.map(|entity| CardanoTransactionListItemMessage {
.map(|entity| CardanoTransactionCommitmentListItemMessage {
merkle_root: entity.artifact.merkle_root.clone(),
beacon: entity.artifact.beacon.clone(),
hash: entity.artifact.hash,
Expand All @@ -37,7 +38,7 @@ mod tests {
fn adapt_ok() {
let signed_entity = SignedEntity::<CardanoTransactionsCommitment>::dummy();
let mithril_stake_distribution_list_message_expected =
vec![CardanoTransactionListItemMessage {
vec![CardanoTransactionCommitmentListItemMessage {
merkle_root: signed_entity.artifact.merkle_root.clone(),
beacon: signed_entity.artifact.beacon.clone(),
hash: signed_entity.artifact.hash.clone(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use mithril_common::entities::{CardanoTransactionsCommitment, SignedEntity};
use mithril_common::messages::{CardanoTransactionMessage, ToMessageAdapter};
use mithril_common::messages::{CardanoTransactionCommitmentMessage, ToMessageAdapter};

/// Adapter to convert [CardanoTransaction] to [CardanoTransactionMessage] instances
/// Adapter to convert [CardanoTransaction] to [CardanoTransactionCommitmentMessage] instances
pub struct ToCardanoTransactionMessageAdapter;

impl ToMessageAdapter<SignedEntity<CardanoTransactionsCommitment>, CardanoTransactionMessage>
for ToCardanoTransactionMessageAdapter
impl
ToMessageAdapter<
SignedEntity<CardanoTransactionsCommitment>,
CardanoTransactionCommitmentMessage,
> for ToCardanoTransactionMessageAdapter
{
/// Method to trigger the conversion
fn adapt(from: SignedEntity<CardanoTransactionsCommitment>) -> CardanoTransactionMessage {
CardanoTransactionMessage {
fn adapt(
from: SignedEntity<CardanoTransactionsCommitment>,
) -> CardanoTransactionCommitmentMessage {
CardanoTransactionCommitmentMessage {
merkle_root: from.artifact.merkle_root.clone(),
beacon: from.artifact.beacon,
hash: from.artifact.hash,
Expand All @@ -26,7 +31,7 @@ mod tests {
#[test]
fn adapt_ok() {
let signed_entity = SignedEntity::<CardanoTransactionsCommitment>::dummy();
let cardano_stake_distribution_message_expected = CardanoTransactionMessage {
let cardano_stake_distribution_message_expected = CardanoTransactionCommitmentMessage {
merkle_root: signed_entity.artifact.merkle_root.clone(),
beacon: signed_entity.artifact.beacon.clone(),
hash: signed_entity.artifact.hash.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,10 @@ fn try_adapt_set_proof_message(

#[cfg(test)]
mod tests {
use anyhow::Context;
use mithril_common::{
crypto_helper::{MKProof, MKTree, MKTreeNode, MKTreeStore},
StdResult,
};
use mithril_common::crypto_helper::MKProof;

use super::*;

fn build_proof(leaves: &[MKTreeNode]) -> StdResult<MKProof> {
let store = MKTreeStore::default();
let mktree =
MKTree::new(leaves, &store).with_context(|| "MKTree creation should not fail")?;
mktree.compute_proof(leaves)
}

#[test]
fn test_simple_message() {
let transaction_hashes = &[
Expand All @@ -89,14 +78,7 @@ mod tests {

let mut transactions_set_proofs = Vec::new();
for transaction_hashes_in_chunk in transactions_hashes_certified.chunks(2) {
let mk_proof = build_proof(
transaction_hashes_in_chunk
.iter()
.map(|h| h.to_owned().into())
.collect::<Vec<_>>()
.as_slice(),
)
.unwrap();
let mk_proof = MKProof::from_leaves(transaction_hashes_in_chunk).unwrap();
transactions_set_proofs.push(CardanoTransactionsSetProof::new(
transaction_hashes_in_chunk.to_vec(),
mk_proof,
Expand Down
16 changes: 8 additions & 8 deletions mithril-aggregator/src/services/message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This service is responsible of providing HTTP server with messages as fast as possible.
//! This service is responsible for providing HTTP server with messages as fast as possible.

use std::sync::Arc;

Expand All @@ -8,9 +8,9 @@ use thiserror::Error;
use mithril_common::{
entities::SignedEntityTypeDiscriminants,
messages::{
CardanoTransactionListMessage, CardanoTransactionMessage, CertificateListMessage,
CertificateMessage, MithrilStakeDistributionListMessage, MithrilStakeDistributionMessage,
SnapshotListMessage, SnapshotMessage,
CardanoTransactionCommitmentListMessage, CardanoTransactionCommitmentMessage,
CertificateListMessage, CertificateMessage, MithrilStakeDistributionListMessage,
MithrilStakeDistributionMessage, SnapshotListMessage, SnapshotMessage,
},
StdResult,
};
Expand Down Expand Up @@ -67,13 +67,13 @@ pub trait MessageService: Sync + Send {
async fn get_cardano_transaction_message(
&self,
signed_entity_id: &str,
) -> StdResult<Option<CardanoTransactionMessage>>;
) -> StdResult<Option<CardanoTransactionCommitmentMessage>>;

/// Return the list of the last Cardano transactions set message
async fn get_cardano_transaction_list_message(
&self,
limit: usize,
) -> StdResult<CardanoTransactionListMessage>;
) -> StdResult<CardanoTransactionCommitmentListMessage>;
}

/// Implementation of the [MessageService]
Expand Down Expand Up @@ -165,7 +165,7 @@ impl MessageService for MithrilMessageService {
async fn get_cardano_transaction_message(
&self,
signed_entity_id: &str,
) -> StdResult<Option<CardanoTransactionMessage>> {
) -> StdResult<Option<CardanoTransactionCommitmentMessage>> {
let signed_entity = self
.signed_entity_storer
.get_signed_entity(signed_entity_id)
Expand All @@ -177,7 +177,7 @@ impl MessageService for MithrilMessageService {
async fn get_cardano_transaction_list_message(
&self,
limit: usize,
) -> StdResult<CardanoTransactionListMessage> {
) -> StdResult<CardanoTransactionCommitmentListMessage> {
let signed_entity_type_id = SignedEntityTypeDiscriminants::CardanoTransactions;
let entities = self
.signed_entity_storer
Expand Down
8 changes: 7 additions & 1 deletion mithril-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mithril-client"
version = "0.5.18"
version = "0.6.0"
description = "Mithril client library"
authors = { workspace = true }
edition = { workspace = true }
Expand All @@ -18,6 +18,11 @@ name = "snapshot_list_get_show_download_verify"
path = "tests/snapshot_list_get_show_download_verify.rs"
required-features = ["fs"]

[[test]]
name = "cardano_transaction_proof"
path = "tests/cardano_transaction_proof.rs"
required-features = ["unstable"]

[dependencies]
anyhow = "1.0.79"
async-recursion = "1.0.5"
Expand Down Expand Up @@ -72,6 +77,7 @@ full = ["fs"]
# Enable file system releated functionnality, right now that mean ony snapshot download
fs = ["flate2", "flume", "tar", "tokio/rt", "zstd"]
portable = ["mithril-common/portable"]
unstable = []

[package.metadata.docs.rs]
all-features = true
Expand Down
Loading

0 comments on commit 6cd739a

Please sign in to comment.