Skip to content

Commit 2cddffa

Browse files
committed
feat: add warning about ancilary fast boostrap feature and signature origin in client library
1 parent 0a7d0da commit 2cddffa

File tree

3 files changed

+155
-10
lines changed

3 files changed

+155
-10
lines changed

mithril-client/src/cardano_database_client/download_unpack/internal_downloader.rs

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use mithril_common::messages::{
1414
use crate::cardano_database_client::ImmutableFileRange;
1515
use crate::feedback::{FeedbackSender, MithrilEvent, MithrilEventCardanoDatabase};
1616
use crate::file_downloader::{DownloadEvent, FileDownloader, FileDownloaderUri};
17-
use crate::utils::{create_bootstrap_node_files, AncillaryVerifier, VecDequeExtensions};
17+
use crate::utils::{
18+
create_bootstrap_node_files, AncillaryVerifier, VecDequeExtensions,
19+
ANCILLARIES_NOT_SIGNED_BY_MITHRIL,
20+
};
1821
use crate::MithrilResult;
1922

2023
use super::download_task::{DownloadKind, DownloadTask, LocationToDownload};
@@ -77,11 +80,14 @@ impl InternalArtifactDownloader {
7780
&download_id,
7881
)?);
7982
if download_unpack_options.include_ancillary {
83+
slog::warn!(self.logger, "{}", ANCILLARIES_NOT_SIGNED_BY_MITHRIL);
8084
tasks.push_back(self.new_ancillary_download_task(
8185
&cardano_database_snapshot.ancillary,
8286
target_dir,
8387
&download_id,
8488
)?);
89+
} else {
90+
slog::warn!(self.logger, "The fast bootstrap of the Cardano node is not available with the current parameters used in this command: the ledger state will be recomputed from genesis at startup of the Cardano node. Set the include_ancillary entry to true in the DownloadUnpackOptions.");
8591
}
8692
self.batch_download_unpack(tasks, download_unpack_options.max_parallel_downloads)
8793
.await?;
@@ -463,7 +469,7 @@ mod tests {
463469
}
464470

465471
mod building_download_tasks {
466-
use mithril_common::test_utils::fake_keys;
472+
use mithril_common::{entities::CompressionAlgorithm, test_utils::fake_keys};
467473

468474
use crate::file_downloader::MockFileDownloader;
469475

@@ -507,6 +513,115 @@ mod tests {
507513
);
508514
}
509515

516+
#[tokio::test]
517+
async fn download_unpack_must_warn_that_ancillary_not_signed_by_mithril_when_included() {
518+
let (logger, log_inspector) = TestLogger::memory();
519+
let total_immutable_files = 2;
520+
let immutable_file_range = ImmutableFileRange::Range(1, total_immutable_files);
521+
let target_dir = temp_dir_create!();
522+
let artifact_downloader = InternalArtifactDownloader::new(
523+
Arc::new(MockFileDownloader::new()),
524+
None,
525+
FeedbackSender::new(&[]),
526+
logger,
527+
);
528+
529+
let download_unpack_options = DownloadUnpackOptions {
530+
include_ancillary: true,
531+
..DownloadUnpackOptions::default()
532+
};
533+
let cardano_database_snapshot = CardanoDatabaseSnapshot {
534+
hash: "hash-123".to_string(),
535+
immutables: ImmutablesMessagePart {
536+
average_size_uncompressed: 512,
537+
locations: vec![ImmutablesLocation::CloudStorage {
538+
uri: MultiFilesUri::Template(TemplateUri(
539+
"http://whatever/{immutable_file_number}.tar.gz".to_string(),
540+
)),
541+
compression_algorithm: Some(CompressionAlgorithm::Gzip),
542+
}],
543+
},
544+
ancillary: AncillaryMessagePart {
545+
size_uncompressed: 2048,
546+
locations: vec![AncillaryLocation::Unknown {}],
547+
},
548+
beacon: CardanoDbBeacon {
549+
epoch: Epoch(123),
550+
immutable_file_number: 2,
551+
},
552+
..CardanoDatabaseSnapshot::dummy()
553+
};
554+
555+
let _ = artifact_downloader
556+
.download_unpack(
557+
&cardano_database_snapshot,
558+
&immutable_file_range,
559+
target_dir.as_path(),
560+
download_unpack_options,
561+
)
562+
.await;
563+
564+
assert!(
565+
log_inspector.contains_log(&format!("WARN {}", ANCILLARIES_NOT_SIGNED_BY_MITHRIL)),
566+
"Expected log message not found, logs: {log_inspector}"
567+
);
568+
}
569+
570+
#[tokio::test]
571+
async fn download_unpack_without_ancillary_must_warn_that_fast_boostrap_wont_be_available()
572+
{
573+
let (logger, log_inspector) = TestLogger::memory();
574+
let total_immutable_files = 2;
575+
let immutable_file_range = ImmutableFileRange::Range(1, total_immutable_files);
576+
let target_dir = temp_dir_create!();
577+
let artifact_downloader = InternalArtifactDownloader::new(
578+
Arc::new(MockFileDownloader::new()),
579+
None,
580+
FeedbackSender::new(&[]),
581+
logger,
582+
);
583+
584+
let download_unpack_options = DownloadUnpackOptions {
585+
include_ancillary: false,
586+
..DownloadUnpackOptions::default()
587+
};
588+
let cardano_database_snapshot = CardanoDatabaseSnapshot {
589+
hash: "hash-123".to_string(),
590+
immutables: ImmutablesMessagePart {
591+
average_size_uncompressed: 512,
592+
locations: vec![ImmutablesLocation::CloudStorage {
593+
uri: MultiFilesUri::Template(TemplateUri(
594+
"http://whatever/{immutable_file_number}.tar.gz".to_string(),
595+
)),
596+
compression_algorithm: Some(CompressionAlgorithm::Gzip),
597+
}],
598+
},
599+
ancillary: AncillaryMessagePart {
600+
size_uncompressed: 2048,
601+
locations: vec![AncillaryLocation::Unknown {}],
602+
},
603+
beacon: CardanoDbBeacon {
604+
epoch: Epoch(123),
605+
immutable_file_number: 2,
606+
},
607+
..CardanoDatabaseSnapshot::dummy()
608+
};
609+
610+
let _ = artifact_downloader
611+
.download_unpack(
612+
&cardano_database_snapshot,
613+
&immutable_file_range,
614+
target_dir.as_path(),
615+
download_unpack_options,
616+
)
617+
.await;
618+
619+
assert!(
620+
log_inspector.contains_log("The fast bootstrap of the Cardano node is not available with the current parameters used in this command: the ledger state will be recomputed from genesis at startup of the Cardano node. Set the include_ancillary entry to true in the DownloadUnpackOptions."),
621+
"Expected log message not found, logs: {log_inspector}"
622+
);
623+
}
624+
510625
#[tokio::test]
511626
async fn building_ancillary_download_tasks_fails_if_all_locations_are_unknown() {
512627
let target_dir = temp_dir_create!();

mithril-client/src/snapshot_client.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ use crate::file_downloader::{DownloadEvent, FileDownloader};
121121
use crate::utils::create_bootstrap_node_files;
122122
#[cfg(feature = "fs")]
123123
use crate::utils::AncillaryVerifier;
124+
use crate::utils::ANCILLARIES_NOT_SIGNED_BY_MITHRIL;
124125
use crate::{MithrilResult, Snapshot, SnapshotListItem};
125126

126127
/// Error for the Snapshot client
@@ -255,6 +256,10 @@ impl SnapshotClient {
255256
snapshot: &Snapshot,
256257
target_dir: &Path,
257258
) -> MithrilResult<()> {
259+
slog::warn!(
260+
self.logger,
261+
"The fast bootstrap of the Cardano node is not available with the current parameters used in this command: the ledger state will be recomputed from genesis at startup of the Cardano node. Use the extra function download_unpack_full to allow it."
262+
);
258263
use crate::feedback::MithrilEvent;
259264
let download_id = MithrilEvent::new_snapshot_download_id();
260265
self.download_unpack_immutables_files(snapshot, target_dir, &download_id)
@@ -296,10 +301,7 @@ impl SnapshotClient {
296301
target_dir: &Path,
297302
download_id: &str,
298303
) -> MithrilResult<()> {
299-
slog::info!(
300-
self.logger,
301-
"Ancillary verification doesn't use the Mithril certification: it is done with a signature made with an IOG owned key."
302-
);
304+
slog::warn!(self.logger, "{}", ANCILLARIES_NOT_SIGNED_BY_MITHRIL);
303305

304306
match &snapshot.ancillary_locations {
305307
None => Ok(()),
@@ -622,6 +624,35 @@ mod tests {
622624
}
623625
}
624626

627+
mod download_unpack {
628+
use super::*;
629+
630+
#[tokio::test]
631+
async fn warn_that_fast_boostrap_is_not_available_without_ancillary_files() {
632+
let (logger, log_inspector) = TestLogger::memory();
633+
let snapshot = Snapshot::dummy();
634+
635+
let mut mock_downloader = MockFileDownloader::new();
636+
mock_downloader
637+
.expect_download_unpack()
638+
.returning(|_, _, _, _, _| Ok(()));
639+
640+
let client = SnapshotClient {
641+
logger,
642+
..setup_snapshot_client(Arc::new(mock_downloader), None)
643+
};
644+
645+
let _result = client
646+
.download_unpack(&snapshot, &PathBuf::from("/whatever"))
647+
.await;
648+
649+
assert!(
650+
log_inspector.contains_log("WARN The fast bootstrap of the Cardano node is not available with the current parameters used in this command: the ledger state will be recomputed from genesis at startup of the Cardano node. Use the extra function download_unpack_full to allow it."),
651+
"Expected log message not found, logs: {log_inspector}"
652+
);
653+
}
654+
}
655+
625656
mod download_unpack_ancillary {
626657
use mithril_common::crypto_helper::ManifestSigner;
627658
use mithril_common::test_utils::fake_keys;
@@ -660,10 +691,7 @@ mod tests {
660691
.unwrap();
661692

662693
assert!(
663-
log_inspector.contains_log(
664-
"Ancillary verification doesn't use the Mithril certification: it is \
665-
done with a signature made with an IOG owned key."
666-
),
694+
log_inspector.contains_log(&format!("WARN {}", ANCILLARIES_NOT_SIGNED_BY_MITHRIL)),
667695
"Expected log message not found, logs: {log_inspector}"
668696
);
669697
}

mithril-client/src/utils/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Utilities module
22
//! This module contains tools needed mostly for the snapshot download and unpack.
33
4+
pub const ANCILLARIES_NOT_SIGNED_BY_MITHRIL:&str = "Ancillary verification does not use the Mithril certification: as a mitigation, IOG owned keys are used to sign these files.";
5+
46
cfg_fs! {
57
mod ancillary_verifier;
68
mod stream_reader;

0 commit comments

Comments
 (0)