Skip to content

Commit

Permalink
Merge pull request #2187 from input-output-hk/jpraynaud/2152-cardano-…
Browse files Browse the repository at this point in the history
…db-artifact-routes

Feat: implement `CardanoDatabase` artifact routes
  • Loading branch information
jpraynaud authored Dec 20, 2024
2 parents 6cb9d30 + 57efde6 commit d3e21fb
Show file tree
Hide file tree
Showing 30 changed files with 1,543 additions and 139 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ As a minor extension, we have adopted a slightly different versioning convention

- Build and publish both a `stable` version (for release networks) and an `unstable` version (for testing networks) of the explorer.

- **UNSTABLE** Cardano database incremental certification:

- Implement the artifact routes of the aggregator for the signed entity type `CardanoDatabase`.

- Crates versions:

| Crate | Version |
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

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

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.6.4"
version = "0.6.5"
description = "A Mithril Aggregator server"
authors = { workspace = true }
edition = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions mithril-aggregator/src/artifact_builder/cardano_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl ArtifactBuilder<CardanoDbBeacon, CardanoDatabaseSnapshot> for CardanoDataba

let locations = ArtifactsLocations {
ancillary: vec![],
digest: vec![],
digests: vec![],
immutables: vec![],
};

Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
expected_total_size,
ArtifactsLocations {
ancillary: vec![],
digest: vec![],
digests: vec![],
immutables: vec![],
},
CompressionAlgorithm::Zstandard,
Expand Down
26 changes: 26 additions & 0 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ impl Configuration {

Ok(allowed_discriminants)
}

/// Check if the HTTP server can serve static directories.
// TODO: This function should be completed when the configuration of the uploaders for the Cardano database is done.
pub fn allow_http_serve_directory(&self) -> bool {
match self.snapshot_uploader_type {
SnapshotUploaderType::Local => true,
SnapshotUploaderType::Gcp => false,
}
}
}

/// Default configuration with all the default values for configurations.
Expand Down Expand Up @@ -599,4 +608,21 @@ mod test {
BTreeSet::from(SignedEntityConfig::DEFAULT_ALLOWED_DISCRIMINANTS)
);
}

#[test]
fn allow_http_serve_directory() {
let config = Configuration {
snapshot_uploader_type: SnapshotUploaderType::Local,
..Configuration::new_sample()
};

assert!(config.allow_http_serve_directory());

let config = Configuration {
snapshot_uploader_type: SnapshotUploaderType::Gcp,
..Configuration::new_sample()
};

assert!(!config.allow_http_serve_directory());
}
}
43 changes: 42 additions & 1 deletion mithril-aggregator/src/database/record/signed_entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ use serde::{Deserialize, Serialize};

use mithril_common::crypto_helper::ProtocolParameters;
use mithril_common::entities::{
BlockNumber, Epoch, SignedEntity, SignedEntityType, Snapshot, StakeDistribution,
BlockNumber, CardanoDatabaseSnapshot, Epoch, SignedEntity, SignedEntityType, Snapshot,
StakeDistribution,
};
#[cfg(test)]
use mithril_common::entities::{CardanoStakeDistribution, MithrilStakeDistribution};
use mithril_common::messages::{
CardanoDatabaseSnapshotListItemMessage, CardanoDatabaseSnapshotMessage,
CardanoStakeDistributionListItemMessage, CardanoStakeDistributionMessage,
CardanoTransactionSnapshotListItemMessage, CardanoTransactionSnapshotMessage,
MithrilStakeDistributionListItemMessage, MithrilStakeDistributionMessage,
Expand Down Expand Up @@ -169,6 +171,45 @@ impl TryFrom<SignedEntityRecord> for SnapshotMessage {
}
}

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

fn try_from(value: SignedEntityRecord) -> Result<Self, Self::Error> {
let artifact = serde_json::from_str::<CardanoDatabaseSnapshot>(&value.artifact)?;
let cardano_database_snapshot_message = CardanoDatabaseSnapshotMessage {
merkle_root: artifact.merkle_root,
beacon: artifact.beacon,
certificate_hash: value.certificate_id,
total_db_size_uncompressed: artifact.total_db_size_uncompressed,
created_at: value.created_at,
locations: artifact.locations.into(),
compression_algorithm: artifact.compression_algorithm,
cardano_node_version: artifact.cardano_node_version,
};

Ok(cardano_database_snapshot_message)
}
}

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

fn try_from(value: SignedEntityRecord) -> Result<Self, Self::Error> {
let artifact = serde_json::from_str::<CardanoDatabaseSnapshot>(&value.artifact)?;
let cardano_database_snapshot_list_item_message = CardanoDatabaseSnapshotListItemMessage {
merkle_root: artifact.merkle_root,
beacon: artifact.beacon,
certificate_hash: value.certificate_id,
total_db_size_uncompressed: artifact.total_db_size_uncompressed,
created_at: value.created_at,
compression_algorithm: artifact.compression_algorithm,
cardano_node_version: artifact.cardano_node_version,
};

Ok(cardano_database_snapshot_list_item_message)
}
}

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

Expand Down
1 change: 1 addition & 0 deletions mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,6 +1556,7 @@ impl DependenciesBuilder {
.clone(),
snapshot_directory: self.configuration.get_snapshot_dir()?,
cardano_node_version: self.configuration.cardano_node_version.clone(),
allow_http_serve_directory: self.configuration.allow_http_serve_directory(),
},
);

Expand Down
Loading

0 comments on commit d3e21fb

Please sign in to comment.