From 66638f72566ed89de10a6591896ef4b6b4322cd7 Mon Sep 17 00:00:00 2001 From: Damien Lachaume <135982616+dlachaume@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:31:22 +0100 Subject: [PATCH] feat: make the ancillary archive name more precise --- .../src/artifact_builder/cardano_database.rs | 7 ++-- .../cardano_database_artifacts/ancillary.rs | 39 ++++++++++++------- .../src/dependency_injection/builder.rs | 1 + 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/mithril-aggregator/src/artifact_builder/cardano_database.rs b/mithril-aggregator/src/artifact_builder/cardano_database.rs index 4b13d7f505..b7da766c12 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database.rs @@ -61,10 +61,7 @@ impl ArtifactBuilder for CardanoDataba })?; let total_db_size_uncompressed = compute_uncompressed_database_size(&self.db_directory)?; - let ancillary_locations = self - .ancillary_builder - .upload(beacon.immutable_file_number) - .await?; + let ancillary_locations = self.ancillary_builder.upload(&beacon).await?; let locations = ArtifactsLocations { ancillary: ancillary_locations, @@ -118,6 +115,7 @@ mod tests { digesters::DummyCardanoDbBuilder, entities::{AncillaryLocation, ProtocolMessage, ProtocolMessagePartKey}, test_utils::{fake_data, TempDir}, + CardanoNetwork, }; use crate::{ @@ -183,6 +181,7 @@ mod tests { Arc::new(AncillaryArtifactBuilder::new( vec![Arc::new(ancillary_uploader)], Arc::new(DumbSnapshotter::new()), + CardanoNetwork::DevNet(123), CompressionAlgorithm::Gzip, TestLogger::stdout(), )), diff --git a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs index 1d969922e1..89aa77ef9f 100644 --- a/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs +++ b/mithril-aggregator/src/artifact_builder/cardano_database_artifacts/ancillary.rs @@ -9,9 +9,9 @@ use slog::{debug, Logger}; use mithril_common::{ digesters::{IMMUTABLE_DIR, LEDGER_DIR, VOLATILE_DIR}, - entities::{AncillaryLocation, CompressionAlgorithm, ImmutableFileNumber}, + entities::{AncillaryLocation, CardanoDbBeacon, CompressionAlgorithm}, logging::LoggerExtensions, - StdResult, + CardanoNetwork, StdResult, }; use crate::{snapshotter::OngoingSnapshot, FileUploader, LocalUploader, Snapshotter}; @@ -38,6 +38,7 @@ impl AncillaryFileUploader for LocalUploader { pub struct AncillaryArtifactBuilder { uploaders: Vec>, snapshotter: Arc, + cardano_network: CardanoNetwork, compression_algorithm: CompressionAlgorithm, logger: Logger, } @@ -47,19 +48,21 @@ impl AncillaryArtifactBuilder { pub fn new( uploaders: Vec>, snapshotter: Arc, + cardano_network: CardanoNetwork, compression_algorithm: CompressionAlgorithm, logger: Logger, ) -> Self { Self { uploaders, logger: logger.new_with_component_name::(), + cardano_network, compression_algorithm, snapshotter, } } - pub async fn upload(&self, immutable_file_number: u64) -> StdResult> { - let snapshot = self.create_ancillary_archive(immutable_file_number)?; + pub async fn upload(&self, beacon: &CardanoDbBeacon) -> StdResult> { + let snapshot = self.create_ancillary_archive(beacon)?; let locations = self .upload_ancillary_archive(snapshot.get_file_path()) @@ -86,19 +89,21 @@ impl AncillaryArtifactBuilder { } /// Creates an archive for the Cardano database ancillary files for the given immutable file number. - fn create_ancillary_archive( - &self, - immutable_file_number: ImmutableFileNumber, - ) -> StdResult { + fn create_ancillary_archive(&self, beacon: &CardanoDbBeacon) -> StdResult { debug!( self.logger, - "Creating ancillary archive for immutable file number: {}", immutable_file_number + "Creating ancillary archive for immutable file number: {}", + beacon.immutable_file_number ); - let paths_to_include = Self::get_files_and_directories_to_snapshot(immutable_file_number); + let paths_to_include = + Self::get_files_and_directories_to_snapshot(beacon.immutable_file_number); let archive_name = format!( - "ancillary.{}", + "{}-e{}-i{}.ancillary.{}", + self.cardano_network, + *beacon.epoch, + beacon.immutable_file_number, self.compression_algorithm.tar_file_extension() ); @@ -108,7 +113,7 @@ impl AncillaryArtifactBuilder { .with_context(|| { format!( "Failed to create snapshot for immutable file number: {}", - immutable_file_number + beacon.immutable_file_number ) })?; @@ -160,6 +165,7 @@ mod tests { let builder = AncillaryArtifactBuilder::new( vec![], Arc::new(DumbSnapshotter::new()), + CardanoNetwork::DevNet(123), CompressionAlgorithm::Gzip, TestLogger::stdout(), ); @@ -202,6 +208,7 @@ mod tests { let builder = AncillaryArtifactBuilder::new( uploaders, Arc::new(DumbSnapshotter::new()), + CardanoNetwork::DevNet(123), CompressionAlgorithm::Gzip, TestLogger::stdout(), ); @@ -248,11 +255,14 @@ mod tests { let builder = AncillaryArtifactBuilder::new( vec![], Arc::new(snapshotter), + CardanoNetwork::DevNet(123), CompressionAlgorithm::Gzip, TestLogger::stdout(), ); - let snapshot = builder.create_ancillary_archive(1).unwrap(); + let snapshot = builder + .create_ancillary_archive(&CardanoDbBeacon::new(99, 1)) + .unwrap(); let mut archive = { let file_tar_gz = File::open(snapshot.get_file_path()).unwrap(); @@ -306,12 +316,13 @@ mod tests { let builder = AncillaryArtifactBuilder::new( vec![Arc::new(uploader)], Arc::new(snapshotter), + CardanoNetwork::DevNet(123), CompressionAlgorithm::Gzip, TestLogger::stdout(), ); builder - .upload(1) + .upload(&CardanoDbBeacon::new(99, 1)) .await .expect_err("Should return an error when archive creation fails"); } diff --git a/mithril-aggregator/src/dependency_injection/builder.rs b/mithril-aggregator/src/dependency_injection/builder.rs index 3558e7f6d6..7c0ab65775 100644 --- a/mithril-aggregator/src/dependency_injection/builder.rs +++ b/mithril-aggregator/src/dependency_injection/builder.rs @@ -1207,6 +1207,7 @@ impl DependenciesBuilder { let ancillary_builder = Arc::new(AncillaryArtifactBuilder::new( vec![Arc::new(local_uploader)], snapshotter, + self.configuration.get_network()?, self.configuration.snapshot_compression_algorithm, logger.clone(), ));