diff --git a/Cargo.lock b/Cargo.lock index 15953ca692e..7481cb5c561 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4059,7 +4059,7 @@ dependencies = [ [[package]] name = "mithril-cardano-node-internal-database" -version = "0.1.3" +version = "0.1.4" dependencies = [ "anyhow", "async-trait", @@ -4090,7 +4090,7 @@ dependencies = [ [[package]] name = "mithril-client" -version = "0.12.24" +version = "0.12.25" dependencies = [ "anyhow", "async-recursion", diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml b/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml index ba22abdd22e..265181a7f9f 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml +++ b/internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-cardano-node-internal-database" -version = "0.1.3" +version = "0.1.4" description = "Mechanisms that allow Mithril nodes to read the files of a Cardano node internal database and compute digests from them" authors.workspace = true documentation.workspace = true diff --git a/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs b/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs index 09f9eed3c3e..1e97aef1913 100644 --- a/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs +++ b/internal/cardano-node/mithril-cardano-node-internal-database/src/entities/immutable_file.rs @@ -133,7 +133,7 @@ impl ImmutableFile { Ok(hasher.finalize()) } - /// List all [`ImmutableFile`] in a given directory. + /// List all [`ImmutableFile`] in a given directory by recursively searching a immutable directory. pub fn list_all_in_dir(dir: &Path) -> Result, ImmutableFileListingError> { let immutable_dir = find_immutables_dir(dir).ok_or( ImmutableFileListingError::MissingImmutableFolder(dir.to_path_buf()), @@ -169,7 +169,7 @@ impl ImmutableFile { } } - /// Check if at least one immutable file exists in the given directory + /// Check if at least one immutable file exists in the given directory by recursively searching a immutable directory pub fn at_least_one_immutable_files_exist_in_dir( dir: &Path, ) -> Result<(), ImmutableFileListingError> { @@ -426,6 +426,33 @@ mod tests { ); } + #[test] + fn find_immutables_dir_returns_none_if_no_immutable_dir_found() { + let database_path = temp_dir_create!(); + assert!(find_immutables_dir(&database_path).is_none()); + } + + #[test] + fn find_immutables_dir_returns_immutable_dir_if_found_at_root() { + let database_path = temp_dir_create!(); + fs::create_dir(database_path.join(IMMUTABLE_DIR)).unwrap(); + + let immutable_dir = + find_immutables_dir(&database_path).expect("Immutable directory should be found"); + assert_eq!(immutable_dir, database_path.join(IMMUTABLE_DIR)); + } + + #[test] + fn find_immutables_dir_returns_immutable_dir_if_found_at_any_depth() { + let database_path = temp_dir_create!(); + let subdir = database_path.join("one/two/three"); + fs::create_dir_all(subdir.join(IMMUTABLE_DIR)).unwrap(); + + let immutable_dir = + find_immutables_dir(&database_path).expect("Immutable directory should be found"); + assert_eq!(immutable_dir, subdir.join(IMMUTABLE_DIR)); + } + #[test] fn at_least_one_immutable_files_exist_in_dir_throw_error_if_immutable_dir_is_empty() { let database_path = temp_dir_create!(); diff --git a/mithril-client/Cargo.toml b/mithril-client/Cargo.toml index f9c27c73a67..1c8a93c1e22 100644 --- a/mithril-client/Cargo.toml +++ b/mithril-client/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mithril-client" -version = "0.12.24" +version = "0.12.25" description = "Mithril client library" authors = { workspace = true } edition = { workspace = true } diff --git a/mithril-client/src/cardano_database_client/proving.rs b/mithril-client/src/cardano_database_client/proving.rs index ff8be6882d4..0548fcffb63 100644 --- a/mithril-client/src/cardano_database_client/proving.rs +++ b/mithril-client/src/cardano_database_client/proving.rs @@ -44,6 +44,8 @@ impl InternalArtifactProver { } /// Compute the Merkle proof of membership for the given immutable file range. + /// + /// It will recursively search for immutables directory inside the provided `database_dir`. pub async fn compute_merkle_proof( &self, certificate: &CertificateMessage,