Skip to content

Commit 53e6d45

Browse files
authored
Merge pull request #2372 from input-output-hk/djo/2362/adapt_snapshotter
Refactor(aggregator): groundwork for ancillary signature
2 parents 308e827 + ea47643 commit 53e6d45

File tree

27 files changed

+2080
-1498
lines changed

27 files changed

+2080
-1498
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ As a minor extension, we have adopted a slightly different versioning convention
2222
- Implement the client library for the the signed entity type `CardanoDatabase` (download and prove snapshot).
2323
- Implement the client CLI commands for the signed entity type `CardanoDatabase` (snapshot list, snapshot show and download commands).
2424
- Implement an example crate for the signed entity type `CardanoDatabase`.
25+
- Lighter ancillary archive by only including what's strictly necessary: the latest ledger file and the last immutable file trio.
2526

2627
- Crates versions:
2728

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mithril-aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator"
3-
version = "0.7.15"
3+
version = "0.7.16"
44
description = "A Mithril Aggregator server"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-aggregator/src/artifact_builder/cardano_database.rs

Lines changed: 30 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::PathBuf, sync::Arc};
1+
use std::sync::Arc;
22

33
use anyhow::{anyhow, Context};
44
use async_trait::async_trait;
@@ -13,15 +13,12 @@ use mithril_common::{
1313
CardanoNetwork, StdResult,
1414
};
1515

16-
use crate::artifact_builder::{
17-
utils::compute_uncompressed_database_size, AncillaryArtifactBuilder, ArtifactBuilder,
18-
};
16+
use crate::artifact_builder::{AncillaryArtifactBuilder, ArtifactBuilder};
1917

2018
use super::{DigestArtifactBuilder, ImmutableArtifactBuilder};
2119

2220
pub struct CardanoDatabaseArtifactBuilder {
2321
network: CardanoNetwork,
24-
db_directory: PathBuf,
2522
cardano_node_version: Version,
2623
ancillary_builder: Arc<AncillaryArtifactBuilder>,
2724
immutable_builder: Arc<ImmutableArtifactBuilder>,
@@ -31,15 +28,13 @@ pub struct CardanoDatabaseArtifactBuilder {
3128
impl CardanoDatabaseArtifactBuilder {
3229
pub fn new(
3330
network: CardanoNetwork,
34-
db_directory: PathBuf,
3531
cardano_node_version: &Version,
3632
ancillary_builder: Arc<AncillaryArtifactBuilder>,
3733
immutable_builder: Arc<ImmutableArtifactBuilder>,
3834
digest_builder: Arc<DigestArtifactBuilder>,
3935
) -> Self {
4036
Self {
4137
network,
42-
db_directory,
4338
cardano_node_version: cardano_node_version.clone(),
4439
ancillary_builder,
4540
immutable_builder,
@@ -67,55 +62,27 @@ impl ArtifactBuilder<CardanoDbBeacon, CardanoDatabaseSnapshot> for CardanoDataba
6762
SignedEntityType::CardanoDatabase(beacon.clone())
6863
)
6964
})?;
70-
let total_db_size_uncompressed = {
71-
let db_directory = self.db_directory.clone();
72-
tokio::task::spawn_blocking(move || -> StdResult<u64> {
73-
compute_uncompressed_database_size(&db_directory)
74-
})
75-
.await??
76-
};
77-
78-
let ancillary_locations = self.ancillary_builder.upload(&beacon).await?;
79-
let ancillary_builder = self.ancillary_builder.clone();
80-
let ancillary_size = {
81-
let db_directory = self.db_directory.clone();
82-
let beacon = beacon.clone();
83-
tokio::task::spawn_blocking(move || -> StdResult<u64> {
84-
ancillary_builder.compute_uncompressed_size(&db_directory, &beacon)
85-
})
86-
.await??
87-
};
8865

89-
let immutables_locations = self
66+
let ancillary_upload = self.ancillary_builder.upload(&beacon).await?;
67+
let immutables_upload = self
9068
.immutable_builder
9169
.upload(beacon.immutable_file_number)
9270
.await?;
93-
let immutable_average_size = {
94-
let db_directory = self.db_directory.clone();
95-
let immutable_file_number = beacon.immutable_file_number;
96-
let immutable_builder = self.immutable_builder.clone();
97-
tokio::task::spawn_blocking(move || -> StdResult<u64> {
98-
immutable_builder
99-
.compute_average_uncompressed_size(&db_directory, immutable_file_number)
100-
})
101-
.await??
102-
};
103-
10471
let digest_upload = self.digest_builder.upload(&beacon).await?;
10572

10673
let content = CardanoDatabaseSnapshotArtifactData {
107-
total_db_size_uncompressed,
74+
total_db_size_uncompressed: ancillary_upload.size + immutables_upload.total_size,
10875
digests: DigestsLocations {
10976
size_uncompressed: digest_upload.size,
11077
locations: digest_upload.locations,
11178
},
11279
immutables: ImmutablesLocations {
113-
average_size_uncompressed: immutable_average_size,
114-
locations: immutables_locations,
80+
average_size_uncompressed: immutables_upload.average_size,
81+
locations: immutables_upload.locations,
11582
},
11683
ancillary: AncillaryLocations {
117-
size_uncompressed: ancillary_size,
118-
locations: ancillary_locations,
84+
size_uncompressed: ancillary_upload.size,
85+
locations: ancillary_upload.locations,
11986
},
12087
};
12188

@@ -151,9 +118,9 @@ mod tests {
151118
DigestSnapshotter, MockAncillaryFileUploader, MockImmutableFilesUploader,
152119
},
153120
immutable_file_digest_mapper::MockImmutableFileDigestMapper,
154-
services::{DumbSnapshotter, FakeSnapshotter},
121+
services::CompressedArchiveSnapshotter,
155122
test_tools::TestLogger,
156-
tools::url_sanitizer::SanitizedUrlWithTrailingSlash,
123+
tools::{file_archiver::FileArchiver, url_sanitizer::SanitizedUrlWithTrailingSlash},
157124
};
158125

159126
use super::*;
@@ -162,29 +129,6 @@ mod tests {
162129
TempDir::create("cardano_database", dir_name)
163130
}
164131

165-
#[test]
166-
fn should_compute_the_size_of_the_uncompressed_database_only_immutable_ledger_and_volatile() {
167-
let test_dir = get_test_directory("should_compute_the_size_of_the_uncompressed_database_only_immutable_ledger_and_volatile");
168-
169-
let immutable_trio_file_size = 777;
170-
let ledger_file_size = 6666;
171-
let volatile_file_size = 99;
172-
DummyCardanoDbBuilder::new(test_dir.as_os_str().to_str().unwrap())
173-
.with_immutables(&[1, 2])
174-
.set_immutable_trio_file_size(immutable_trio_file_size)
175-
.with_ledger_files(&["blocks-0.dat", "blocks-1.dat", "blocks-2.dat"])
176-
.set_ledger_file_size(ledger_file_size)
177-
.with_volatile_files(&["437", "537", "637", "737"])
178-
.set_volatile_file_size(volatile_file_size)
179-
.build();
180-
let expected_total_size =
181-
(2 * immutable_trio_file_size) + (3 * ledger_file_size) + (4 * volatile_file_size);
182-
183-
let total_size = compute_uncompressed_database_size(&test_dir).unwrap();
184-
185-
assert_eq!(expected_total_size, total_size);
186-
}
187-
188132
#[tokio::test]
189133
async fn should_compute_valid_artifact() {
190134
let test_dir = get_test_directory("should_compute_valid_artifact");
@@ -198,18 +142,25 @@ mod tests {
198142
.with_immutables(&[1, 2, 3])
199143
.append_immutable_trio()
200144
.set_immutable_trio_file_size(immutable_trio_file_size)
201-
.with_ledger_files(&["blocks-0.dat"])
145+
.with_ledger_files(&["437"])
202146
.set_ledger_file_size(ledger_file_size)
203-
.with_volatile_files(&["437"])
147+
.with_volatile_files(&["blocks-0.dat"])
204148
.set_volatile_file_size(volatile_file_size)
205149
.build();
206150
let expected_average_immutable_size = immutable_trio_file_size;
207-
let expected_ancillary_size =
208-
immutable_trio_file_size + ledger_file_size + volatile_file_size;
209-
let expected_total_size =
210-
4 * immutable_trio_file_size + ledger_file_size + volatile_file_size;
151+
let expected_ancillary_size = immutable_trio_file_size + ledger_file_size;
152+
let expected_total_size = 4 * immutable_trio_file_size + ledger_file_size;
211153

212-
let snapshotter = Arc::new(FakeSnapshotter::new(test_dir.join("fake_snapshots")));
154+
let snapshotter = Arc::new(
155+
CompressedArchiveSnapshotter::new(
156+
cardano_db.get_dir().to_path_buf(),
157+
test_dir.join("ongoing_snapshots"),
158+
CompressionAlgorithm::Gzip,
159+
Arc::new(FileArchiver::new_for_test(test_dir.join("verification"))),
160+
TestLogger::stdout(),
161+
)
162+
.unwrap(),
163+
);
213164

214165
let ancillary_artifact_builder = {
215166
let mut ancillary_uploader = MockAncillaryFileUploader::new();
@@ -224,7 +175,6 @@ mod tests {
224175
vec![Arc::new(ancillary_uploader)],
225176
snapshotter.clone(),
226177
network,
227-
CompressionAlgorithm::Gzip,
228178
TestLogger::stdout(),
229179
)
230180
.unwrap()
@@ -253,10 +203,9 @@ mod tests {
253203
});
254204

255205
ImmutableArtifactBuilder::new(
256-
test_dir.join("immutable"),
206+
cardano_db.get_immutable_dir().to_path_buf(),
257207
vec![Arc::new(immutable_uploader)],
258208
snapshotter,
259-
CompressionAlgorithm::Gzip,
260209
TestLogger::stdout(),
261210
)
262211
.unwrap()
@@ -273,7 +222,10 @@ mod tests {
273222
SanitizedUrlWithTrailingSlash::parse("http://aggregator_uri").unwrap(),
274223
vec![],
275224
DigestSnapshotter {
276-
snapshotter: Arc::new(DumbSnapshotter::new()),
225+
file_archiver: Arc::new(FileArchiver::new_for_test(
226+
test_dir.join("verification"),
227+
)),
228+
target_location: test_dir.clone(),
277229
compression_algorithm: CompressionAlgorithm::Gzip,
278230
},
279231
network,
@@ -286,7 +238,6 @@ mod tests {
286238

287239
let cardano_database_artifact_builder = CardanoDatabaseArtifactBuilder::new(
288240
network,
289-
cardano_db.get_dir().to_owned(),
290241
&Version::parse("1.0.0").unwrap(),
291242
Arc::new(ancillary_artifact_builder),
292243
Arc::new(immutable_artifact_builder),

0 commit comments

Comments
 (0)