Skip to content

Commit 02cc3b9

Browse files
authored
Merge pull request #2473 from input-output-hk/ctl/2459/Add_warning_in_client_when_not_downloading_ancillary_files
Add warnings and prints in clients about ancillary files
2 parents 8b40a70 + 11c5ae7 commit 02cc3b9

File tree

9 files changed

+193
-18
lines changed

9 files changed

+193
-18
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.

mithril-client-cli/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-cli"
3-
version = "0.12.1"
3+
version = "0.12.2"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-cli/src/commands/cardano_db/download.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
commands::{client_builder, SharedArgs},
1414
configuration::{ConfigError, ConfigSource},
1515
utils::{
16-
self, CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils, IndicatifFeedbackReceiver,
17-
ProgressOutputType, ProgressPrinter,
16+
self, AncillaryLogMessage, CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils,
17+
IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter,
1818
},
1919
CommandContext,
2020
};
@@ -67,6 +67,12 @@ impl CardanoDbDownloadCommand {
6767

6868
/// Command execution
6969
pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> {
70+
if self.include_ancillary {
71+
AncillaryLogMessage::warn_ancillary_not_signed_by_mithril();
72+
} else {
73+
AncillaryLogMessage::warn_fast_bootstrap_not_available();
74+
}
75+
7076
let params = context.config_parameters()?.add_source(self)?;
7177
let download_dir: &String = &params.require("download_dir")?;
7278
let db_dir = Path::new(download_dir).join("db");

mithril-client-cli/src/commands/cardano_db_v2/download.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use crate::{
2020
commands::{client_builder, SharedArgs},
2121
configuration::{ConfigError, ConfigSource},
2222
utils::{
23-
self, CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils, IndicatifFeedbackReceiver,
24-
ProgressOutputType, ProgressPrinter,
23+
self, AncillaryLogMessage, CardanoDbDownloadChecker, CardanoDbUtils, ExpanderUtils,
24+
IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter,
2525
},
2626
CommandContext,
2727
};
@@ -107,6 +107,12 @@ impl CardanoDbV2DownloadCommand {
107107

108108
/// Command execution
109109
pub async fn execute(&self, context: CommandContext) -> MithrilResult<()> {
110+
if self.include_ancillary {
111+
AncillaryLogMessage::warn_ancillary_not_signed_by_mithril();
112+
} else {
113+
AncillaryLogMessage::warn_fast_bootstrap_not_available();
114+
}
115+
110116
let params = context.config_parameters()?.add_source(self)?;
111117
let download_dir: &String = &params.require("download_dir")?;
112118
let restoration_options = RestorationOptions {

mithril-client-cli/src/utils/cardano_db.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ impl CardanoDbUtils {
4747
}
4848
}
4949

50+
pub struct AncillaryLogMessage {}
51+
52+
impl AncillaryLogMessage {
53+
/// This method provides guidance on how to enable fast bootstrap by including ancillary files
54+
pub fn warn_fast_bootstrap_not_available() {
55+
println!("The fast bootstrap of the Cardano node is not available with the current parameters used in this command: this means that the ledger state will be recomputed from genesis at startup of the Cardano node.
56+
57+
In order to activate the fast bootstrap of the Cardano node, add the following parameters to the command:
58+
59+
--include-ancillary
60+
and --ancillary-verification-key (or environment variable ANCILLARY_VERIFICATION_KEY). Caution: The ancillary files, including the ledger state, are not currently signed by Mithril. As a mitigation, IOG owned keys are used to sign these files. For more information, please refer to the network configuration page of the documentation (https://mithril.network/doc/manual/getting-started/network-configurations).");
61+
}
62+
63+
pub fn warn_ancillary_not_signed_by_mithril() {
64+
println!("Ancillary verification does not use the Mithril certification: as a mitigation, IOG owned keys are used to sign these files.");
65+
}
66+
}
67+
5068
#[cfg(test)]
5169
mod test {
5270
use super::*;

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.2"
3+
version = "0.12.3"
44
description = "Mithril client library"
55
authors = { workspace = true }
66
edition = { workspace = true }

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)