Skip to content

Commit b790062

Browse files
authored
Merge pull request #2656 from input-output-hk/ctl/2621-document-immutable-folder-discovery-is-recursive
Document immutables folder discovery is recursive
2 parents 78f6fcd + 7d9b465 commit b790062

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

Cargo.lock

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

internal/cardano-node/mithril-cardano-node-internal-database/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-cardano-node-internal-database"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = "Mechanisms that allow Mithril nodes to read the files of a Cardano node internal database and compute digests from them"
55
authors.workspace = true
66
documentation.workspace = true

internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl ImmutableFile {
133133
Ok(hasher.finalize())
134134
}
135135

136-
/// List all [`ImmutableFile`] in a given directory.
136+
/// List all [`ImmutableFile`] in a given directory by recursively searching a immutable directory.
137137
pub fn list_all_in_dir(dir: &Path) -> Result<Vec<ImmutableFile>, ImmutableFileListingError> {
138138
let immutable_dir = find_immutables_dir(dir).ok_or(
139139
ImmutableFileListingError::MissingImmutableFolder(dir.to_path_buf()),
@@ -169,7 +169,7 @@ impl ImmutableFile {
169169
}
170170
}
171171

172-
/// Check if at least one immutable file exists in the given directory
172+
/// Check if at least one immutable file exists in the given directory by recursively searching a immutable directory
173173
pub fn at_least_one_immutable_files_exist_in_dir(
174174
dir: &Path,
175175
) -> Result<(), ImmutableFileListingError> {
@@ -426,6 +426,33 @@ mod tests {
426426
);
427427
}
428428

429+
#[test]
430+
fn find_immutables_dir_returns_none_if_no_immutable_dir_found() {
431+
let database_path = temp_dir_create!();
432+
assert!(find_immutables_dir(&database_path).is_none());
433+
}
434+
435+
#[test]
436+
fn find_immutables_dir_returns_immutable_dir_if_found_at_root() {
437+
let database_path = temp_dir_create!();
438+
fs::create_dir(database_path.join(IMMUTABLE_DIR)).unwrap();
439+
440+
let immutable_dir =
441+
find_immutables_dir(&database_path).expect("Immutable directory should be found");
442+
assert_eq!(immutable_dir, database_path.join(IMMUTABLE_DIR));
443+
}
444+
445+
#[test]
446+
fn find_immutables_dir_returns_immutable_dir_if_found_at_any_depth() {
447+
let database_path = temp_dir_create!();
448+
let subdir = database_path.join("one/two/three");
449+
fs::create_dir_all(subdir.join(IMMUTABLE_DIR)).unwrap();
450+
451+
let immutable_dir =
452+
find_immutables_dir(&database_path).expect("Immutable directory should be found");
453+
assert_eq!(immutable_dir, subdir.join(IMMUTABLE_DIR));
454+
}
455+
429456
#[test]
430457
fn at_least_one_immutable_files_exist_in_dir_throw_error_if_immutable_dir_is_empty() {
431458
let database_path = temp_dir_create!();

mithril-client/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-client"
3-
version = "0.12.24"
3+
version = "0.12.25"
44
description = "Mithril client library"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client/src/cardano_database_client/proving.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ impl InternalArtifactProver {
4444
}
4545

4646
/// Compute the Merkle proof of membership for the given immutable file range.
47+
///
48+
/// It will recursively search for immutables directory inside the provided `database_dir`.
4749
pub async fn compute_merkle_proof(
4850
&self,
4951
certificate: &CertificateMessage,

0 commit comments

Comments
 (0)