-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1244 from input-output-hk/ensemble/1127-fix-recor…
…d-statistics Fix record download statistics
- Loading branch information
Showing
12 changed files
with
208 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod from_certificate_message_adapter; | ||
mod from_mithril_stake_distribution_message; | ||
mod from_snapshot_message; | ||
mod to_snapshot_download_message; | ||
|
||
pub use from_certificate_message_adapter::FromCertificateMessageAdapter; | ||
pub use from_mithril_stake_distribution_message::FromMithrilStakeDistributionMessageAdapter; | ||
pub use from_snapshot_message::FromSnapshotMessageAdapter; | ||
pub use to_snapshot_download_message::ToSnapshotDownloadMessageAdapter; |
35 changes: 35 additions & 0 deletions
35
mithril-client/src/message_adapters/to_snapshot_download_message.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use mithril_common::entities::Snapshot; | ||
use mithril_common::messages::{SnapshotDownloadMessage, ToMessageAdapter}; | ||
|
||
/// Adapter to convert [Snapshot] to [SnapshotDownloadMessage] instances | ||
pub struct ToSnapshotDownloadMessageAdapter; | ||
|
||
impl ToMessageAdapter<&Snapshot, SnapshotDownloadMessage> for ToSnapshotDownloadMessageAdapter { | ||
/// Method to trigger the conversion | ||
fn adapt(snapshot: &Snapshot) -> SnapshotDownloadMessage { | ||
SnapshotDownloadMessage { | ||
digest: snapshot.digest.clone(), | ||
beacon: snapshot.beacon.clone(), | ||
size: snapshot.size, | ||
locations: snapshot.locations.clone(), | ||
compression_algorithm: snapshot.compression_algorithm, | ||
cardano_node_version: snapshot.cardano_node_version.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use mithril_common::test_utils::fake_data; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn adapt_ok() { | ||
let mut snapshot = fake_data::snapshots(1)[0].to_owned(); | ||
snapshot.digest = "digest123".to_string(); | ||
let snapshot_download_message = ToSnapshotDownloadMessageAdapter::adapt(&snapshot); | ||
|
||
assert_eq!("digest123".to_string(), snapshot_download_message.digest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::entities::{Beacon, CompressionAlgorithm, Epoch}; | ||
|
||
/// Message structure of a snapshot | ||
#[derive(Clone, Debug, PartialEq, Eq, Default, Serialize, Deserialize)] | ||
pub struct SnapshotDownloadMessage { | ||
/// Digest that is signed by the signer participants | ||
pub digest: String, | ||
|
||
/// Mithril beacon on the Cardano chain | ||
pub beacon: Beacon, | ||
|
||
/// Size of the snapshot file in Bytes | ||
pub size: u64, | ||
|
||
/// Locations where the binary content of the snapshot can be retrieved | ||
pub locations: Vec<String>, | ||
|
||
/// Compression algorithm of the snapshot archive | ||
pub compression_algorithm: CompressionAlgorithm, | ||
|
||
/// Cardano node version | ||
pub cardano_node_version: String, | ||
} | ||
|
||
impl SnapshotDownloadMessage { | ||
/// Return a dummy test entity (test-only). | ||
pub fn dummy() -> Self { | ||
Self { | ||
digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(), | ||
beacon: Beacon { | ||
network: "preview".to_string(), | ||
epoch: Epoch(86), | ||
immutable_file_number: 1728, | ||
}, | ||
size: 807803196, | ||
locations: vec!["https://host/certificate.tar.gz".to_string()], | ||
compression_algorithm: CompressionAlgorithm::Gzip, | ||
cardano_node_version: "0.0.1".to_string(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
fn golden_message_v1() -> SnapshotDownloadMessage { | ||
SnapshotDownloadMessage { | ||
digest: "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6".to_string(), | ||
beacon: Beacon { | ||
network: "preview".to_string(), | ||
epoch: Epoch(86), | ||
immutable_file_number: 1728, | ||
}, | ||
size: 807803196, | ||
locations: vec!["https://host/certificate.tar.gz".to_string()], | ||
compression_algorithm: CompressionAlgorithm::Gzip, | ||
cardano_node_version: "0.0.1".to_string(), | ||
} | ||
} | ||
|
||
// Test the retro compatibility with possible future upgrades. | ||
#[test] | ||
fn test_v1() { | ||
let json = r#"{ | ||
"digest": "0b9f5ad7f33cc523775c82249294eb8a1541d54f08eb3107cafc5638403ec7c6", | ||
"beacon": { | ||
"network": "preview", | ||
"epoch": 86, | ||
"immutable_file_number": 1728 | ||
}, | ||
"size": 807803196, | ||
"locations": [ | ||
"https://host/certificate.tar.gz" | ||
], | ||
"compression_algorithm": "gzip", | ||
"cardano_node_version": "0.0.1" | ||
} | ||
"#; | ||
let message: SnapshotDownloadMessage = serde_json::from_str(json).expect( | ||
"This JSON is expected to be succesfully parsed into a SnapshotDownloadMessage instance.", | ||
); | ||
|
||
assert_eq!(golden_message_v1(), message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters