Skip to content

Commit 45c44b7

Browse files
committed
refactor: support in memory ledger state in DummyCardanoDbBuilder
by adding a path for all ledger state snapshot variant (+ the 'non' file) + add unit tests to the builder
1 parent 65a718a commit 45c44b7

File tree

8 files changed

+338
-50
lines changed

8 files changed

+338
-50
lines changed

mithril-aggregator/src/artifact_builder/cardano_database.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod tests {
169169
.with_immutables(&[0, 1, 2, 3])
170170
.append_immutable_trio()
171171
.set_immutable_trio_file_size(immutable_trio_file_size)
172-
.with_ledger_files(&["437"])
172+
.with_legacy_ledger_snapshots(&[437])
173173
.set_ledger_file_size(ledger_file_size)
174174
.with_volatile_files(&["blocks-0.dat"])
175175
.set_volatile_file_size(volatile_file_size)

mithril-aggregator/src/services/snapshotter/compressed_archive_snapshotter.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ mod tests {
449449
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
450450
.with_immutables(&[1, 2, 3])
451451
.append_immutable_trio()
452-
.with_ledger_files(&["437"])
452+
.with_legacy_ledger_snapshots(&[437])
453453
.with_volatile_files(&["blocks-0.dat"])
454454
.with_non_immutables(&["random_file.txt", "00002.trap"])
455455
.build();
@@ -492,7 +492,7 @@ mod tests {
492492
let test_dir = temp_dir_create!();
493493
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
494494
.with_immutables(&[1, 2, 3])
495-
.with_ledger_files(&["437"])
495+
.with_legacy_ledger_snapshots(&[437])
496496
.with_volatile_files(&["blocks-0.dat"])
497497
.with_non_immutables(&["random_file.txt", "00002.trap"])
498498
.build();
@@ -532,7 +532,7 @@ mod tests {
532532
let test_dir = temp_dir_create!();
533533
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
534534
.with_immutables(&[1, 2])
535-
.with_ledger_files(&["737"])
535+
.with_legacy_ledger_snapshots(&[737])
536536
.build();
537537
let snapshotter =
538538
snapshotter_for_test(&test_dir, cardano_db.get_dir(), CompressionAlgorithm::Gzip);
@@ -579,7 +579,7 @@ mod tests {
579579
let test_dir = temp_dir_create!();
580580
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
581581
.with_immutables(&[1, 2])
582-
.with_ledger_files(&["637"])
582+
.with_legacy_ledger_snapshots(&[637])
583583
.build();
584584
let snapshotter = CompressedArchiveSnapshotter {
585585
ancillary_signer: Arc::new(MockAncillarySigner::that_succeeds_with_signature(
@@ -607,7 +607,7 @@ mod tests {
607607
let test_dir = temp_dir_create!();
608608
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
609609
.with_immutables(&[1, 2])
610-
.with_ledger_files(&["637"])
610+
.with_legacy_ledger_snapshots(&[637])
611611
.build();
612612
let snapshotter = CompressedArchiveSnapshotter {
613613
ancillary_signer: Arc::new(MockAncillarySigner::that_fails_with_message("failure")),
@@ -633,7 +633,8 @@ mod tests {
633633
let test_dir = temp_dir_create!();
634634
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
635635
.with_immutables(&[1, 2, 3])
636-
.with_ledger_files(&["437", "537", "637", "737", "9not_included"])
636+
.with_legacy_ledger_snapshots(&[437, 537, 637, 737])
637+
.with_non_ledger_files(&["9not_included"])
637638
.with_volatile_files(&["blocks-0.dat", "blocks-1.dat", "blocks-2.dat"])
638639
.build();
639640
fs::create_dir(cardano_db.get_dir().join("whatever")).unwrap();
@@ -673,7 +674,7 @@ mod tests {
673674
let test_dir = temp_dir_create!();
674675
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
675676
.with_immutables(&[1, 2])
676-
.with_ledger_files(&["737"])
677+
.with_legacy_ledger_snapshots(&[737])
677678
.build();
678679

679680
let snapshotter = CompressedArchiveSnapshotter {
@@ -698,7 +699,7 @@ mod tests {
698699
let test_dir = temp_dir_create!();
699700
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
700701
.with_immutables(&[1, 2, 3])
701-
.with_ledger_files(&["537", "637", "737"])
702+
.with_legacy_ledger_snapshots(&[537, 637, 737])
702703
.with_non_immutables(&["not_to_include.txt"])
703704
.build();
704705
File::create(cardano_db.get_dir().join("not_to_include_as_well.txt")).unwrap();
@@ -758,7 +759,7 @@ mod tests {
758759
let cardano_db = DummyCardanoDbBuilder::new(current_function!())
759760
.with_immutables(&[1, 2, 3])
760761
.set_immutable_trio_file_size(immutable_trio_file_size)
761-
.with_ledger_files(&["737"])
762+
.with_legacy_ledger_snapshots(&[737])
762763
.set_ledger_file_size(6666)
763764
.with_volatile_files(&["blocks-0.dat"])
764765
.set_volatile_file_size(99)

mithril-aggregator/src/tools/file_archiver/appender.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ mod tests {
390390
let cardano_db = DummyCardanoDbBuilder::new(test_dir)
391391
.with_immutables(&[1, 2, 3])
392392
.set_immutable_trio_file_size(immutable_trio_file_size)
393-
.with_ledger_files(&["437", "537", "637", "737"])
393+
.with_legacy_ledger_snapshots(&[437, 537, 637, 737])
394394
.set_ledger_file_size(ledger_file_size)
395395
.with_volatile_files(&["blocks-0.dat", "blocks-1.dat", "blocks-2.dat"])
396396
.set_volatile_file_size(volatile_file_size)
@@ -480,7 +480,7 @@ mod tests {
480480
let cardano_db = DummyCardanoDbBuilder::new(test_dir)
481481
.with_immutables(&[1, 2])
482482
.set_immutable_trio_file_size(immutable_trio_file_size)
483-
.with_ledger_files(&["437", "537", "637"])
483+
.with_legacy_ledger_snapshots(&[437, 537, 637])
484484
.set_ledger_file_size(ledger_file_size)
485485
.with_volatile_files(&["blocks-0.dat"])
486486
.set_volatile_file_size(volatile_file_size)

mithril-client/tests/cardano_db_snapshot_list_get_download_verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn cardano_db_snapshot_list_get_download_verify() {
2929
let cardano_db = DummyCardanoDbBuilder::new("cardano_db_snapshot_list_get_download_verify_db")
3030
.with_immutables(&[1, 2, 3, 4])
3131
.append_immutable_trio()
32-
.with_ledger_files(&["437", "537", "637"])
32+
.with_legacy_ledger_snapshots(&[437, 537, 637])
3333
.with_volatile_files(&["blocks-0.dat", "blocks-1.dat"])
3434
.build();
3535
let digester =

mithril-client/tests/extensions/snapshot_archives.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33

44
use mithril_common::crypto_helper::{ManifestSigner, ManifestVerifierSecretKey};
55
use mithril_common::digesters::{
6-
immutable_trio_names, ComputedImmutablesDigests, DummyCardanoDb, IMMUTABLE_DIR,
6+
immutable_trio_names, ComputedImmutablesDigests, DummyCardanoDb, IMMUTABLE_DIR, LEDGER_DIR,
77
};
88
use mithril_common::entities::{AncillaryFilesManifest, CompressionAlgorithm, ImmutableFileNumber};
99
use mithril_common::messages::CardanoDatabaseDigestListItemMessage;
@@ -107,8 +107,8 @@ pub async fn build_ancillary_files_archive(
107107
) {
108108
let db_dir = cardano_db.get_dir();
109109
let ancillary_immutable_number = cardano_db.last_immutable_number().unwrap() + 1;
110-
let last_ledger_file_path = cardano_db
111-
.get_ledger_files()
110+
let last_ledger_state_snapshot = cardano_db
111+
.get_ledger_state_snapshots()
112112
.last()
113113
.expect("Given db should have at least one ledger file");
114114
let archive_name = format!(
@@ -120,15 +120,18 @@ pub async fn build_ancillary_files_archive(
120120
let enc = zstd::Encoder::new(tar_file, 3).unwrap();
121121
let mut tar = tar::Builder::new(enc);
122122

123-
let files_to_include = vec![
124-
PathBuf::from(format!(
125-
"ledger/{}",
126-
last_ledger_file_path.file_name().unwrap().to_string_lossy()
127-
)),
123+
let mut files_to_include = vec![
128124
PathBuf::from(IMMUTABLE_DIR).join(format!("{ancillary_immutable_number:05}.chunk")),
129125
PathBuf::from(IMMUTABLE_DIR).join(format!("{ancillary_immutable_number:05}.primary")),
130126
PathBuf::from(IMMUTABLE_DIR).join(format!("{ancillary_immutable_number:05}.secondary")),
131127
];
128+
files_to_include.extend(
129+
last_ledger_state_snapshot
130+
.get_files_relative_path()
131+
.into_iter()
132+
.map(|p| PathBuf::from(LEDGER_DIR).join(p)),
133+
);
134+
132135
let ancillary_manifest = build_ancillary_manifest(
133136
db_dir,
134137
files_to_include.clone(),

mithril-client/tests/snapshot_list_get_show_download_verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async fn snapshot_list_get_show_download_verify() {
2222
let cardano_db = DummyCardanoDbBuilder::new("snapshot_list_get_show_download_verify_db")
2323
.with_immutables(&[1, 2, 3])
2424
.append_immutable_trio()
25-
.with_ledger_files(&["506", "562"])
25+
.with_legacy_ledger_snapshots(&[506, 562])
2626
.build();
2727
let fake_aggregator = FakeAggregator::new();
2828
let test_http_server = fake_aggregator

0 commit comments

Comments
 (0)