Skip to content

Commit f67bf3a

Browse files
committed
fix: format each file individually as cargo fmt skips files wrapped in macros
1 parent a6d5487 commit f67bf3a

26 files changed

+865
-663
lines changed

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

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ use std::path::{Path, PathBuf};
33
use std::pin::Pin;
44
use std::sync::Arc;
55

6-
use anyhow::{anyhow, Context};
6+
use anyhow::{Context, anyhow};
77
use slog::Logger;
88

99
use mithril_common::entities::{CompressionAlgorithm, ImmutableFileNumber};
1010

1111
use crate::{
12+
MithrilResult,
1213
file_downloader::{DownloadEvent, FileDownloader, FileDownloaderUri},
1314
utils::AncillaryVerifier,
14-
MithrilResult,
1515
};
1616

1717
/// The future type for downloading a file
@@ -90,8 +90,7 @@ impl DownloadTask {
9090
ancillary_verifier: &Arc<AncillaryVerifier>,
9191
logger: &Logger,
9292
) -> MithrilResult<()> {
93-
self.download_unpack_file(ancillary_files_temp_dir, logger)
94-
.await?;
93+
self.download_unpack_file(ancillary_files_temp_dir, logger).await?;
9594
let validated_manifest = ancillary_verifier.verify(ancillary_files_temp_dir).await?;
9695
validated_manifest.move_to_final_location(target_dir).await
9796
}
@@ -205,10 +204,7 @@ mod tests {
205204
kind: DownloadKind::Immutable(1),
206205
locations_to_try: create_locations_to_download(
207206
file_downloader,
208-
[
209-
"http://whatever-1/00001.tar.gz",
210-
"http://whatever-2/00001.tar.gz",
211-
],
207+
["http://whatever-1/00001.tar.gz", "http://whatever-2/00001.tar.gz"],
212208
),
213209
size_uncompressed: 0,
214210
target_dir: target_dir.clone(),
@@ -244,10 +240,7 @@ mod tests {
244240
kind: DownloadKind::Immutable(1),
245241
locations_to_try: create_locations_to_download(
246242
file_downloader,
247-
[
248-
"http://whatever-1/00001.tar.gz",
249-
"http://whatever-2/00001.tar.gz",
250-
],
243+
["http://whatever-1/00001.tar.gz", "http://whatever-2/00001.tar.gz"],
251244
),
252245
size_uncompressed: 0,
253246
target_dir: target_dir.clone(),
@@ -269,11 +262,7 @@ mod tests {
269262
use super::*;
270263

271264
fn fake_ancillary_verifier() -> AncillaryVerifier {
272-
AncillaryVerifier::new(
273-
fake_keys::manifest_verification_key()[0]
274-
.try_into()
275-
.unwrap(),
276-
)
265+
AncillaryVerifier::new(fake_keys::manifest_verification_key()[0].try_into().unwrap())
277266
}
278267

279268
#[tokio::test]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use anyhow::anyhow;
55

66
use mithril_cardano_node_internal_database::{IMMUTABLE_DIR, LEDGER_DIR, VOLATILE_DIR};
77

8-
use crate::common::ImmutableFileNumber;
98
use crate::MithrilResult;
9+
use crate::common::ImmutableFileNumber;
1010

1111
/// Options for downloading and unpacking a Cardano database
1212
#[derive(Debug, Copy, Clone)]

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ use mithril_common::messages::{
1111
AncillaryMessagePart, CardanoDatabaseSnapshotMessage, ImmutablesMessagePart,
1212
};
1313

14+
use crate::MithrilResult;
1415
use crate::cardano_database_client::ImmutableFileRange;
1516
use crate::feedback::{FeedbackSender, MithrilEvent, MithrilEventCardanoDatabase};
1617
use crate::file_downloader::{DownloadEvent, FileDownloader, FileDownloaderUri};
1718
use crate::utils::{
18-
create_bootstrap_node_files, AncillaryVerifier, UnexpectedDownloadedFileVerifier,
19-
VecDequeExtensions, ANCILLARIES_NOT_SIGNED_BY_MITHRIL,
19+
ANCILLARIES_NOT_SIGNED_BY_MITHRIL, AncillaryVerifier, UnexpectedDownloadedFileVerifier,
20+
VecDequeExtensions, create_bootstrap_node_files,
2021
};
21-
use crate::MithrilResult;
2222

23-
use super::download_task::{DownloadKind, DownloadTask, LocationToDownload};
2423
use super::DownloadUnpackOptions;
24+
use super::download_task::{DownloadKind, DownloadTask, LocationToDownload};
2525

2626
pub struct InternalArtifactDownloader {
2727
http_file_downloader: Arc<dyn FileDownloader>,
@@ -96,16 +96,17 @@ impl InternalArtifactDownloader {
9696
&download_id,
9797
)?);
9898
} else {
99-
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.");
99+
slog::warn!(
100+
self.logger,
101+
"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."
102+
);
100103
}
101104

102105
// Return the result later so unexpected file removal is always run
103106
let download_result = self
104107
.batch_download_unpack(tasks, download_unpack_options.max_parallel_downloads)
105108
.await;
106-
expected_files_after_download
107-
.remove_unexpected_files()
108-
.await?;
109+
expected_files_after_download.remove_unexpected_files().await?;
109110
download_result?;
110111

111112
create_bootstrap_node_files(&self.logger, target_dir, &cardano_database_snapshot.network)?;
@@ -538,11 +539,7 @@ mod tests {
538539
use super::*;
539540

540541
fn fake_ancillary_verifier() -> AncillaryVerifier {
541-
AncillaryVerifier::new(
542-
fake_keys::manifest_verification_key()[0]
543-
.try_into()
544-
.unwrap(),
545-
)
542+
AncillaryVerifier::new(fake_keys::manifest_verification_key()[0].try_into().unwrap())
546543
}
547544

548545
#[tokio::test]

mithril-client/src/cardano_database_client/immutable_file_range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::ops::RangeInclusive;
22

33
use anyhow::anyhow;
44

5-
use mithril_common::{entities::ImmutableFileNumber, StdResult};
5+
use mithril_common::{StdResult, entities::ImmutableFileNumber};
66

77
/// Immutable file range representation
88
#[derive(Debug, Eq, PartialEq)]

mithril-client/src/cardano_database_client/proving.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
sync::Arc,
66
};
77

8-
use anyhow::{anyhow, Context};
8+
use anyhow::{Context, anyhow};
99

1010
use mithril_cardano_node_internal_database::{
1111
digesters::{CardanoImmutableDigester, ImmutableDigester},
@@ -21,10 +21,10 @@ use mithril_common::{
2121
};
2222

2323
use crate::{
24+
MithrilResult,
2425
feedback::MithrilEvent,
2526
file_downloader::{DownloadEvent, FileDownloader, FileDownloaderUri},
2627
utils::{create_directory_if_not_exists, delete_directory, read_files_in_directory},
27-
MithrilResult,
2828
};
2929

3030
use super::immutable_file_range::ImmutableFileRange;
@@ -195,10 +195,10 @@ mod tests {
195195
use std::ops::RangeInclusive;
196196

197197
use mithril_cardano_node_internal_database::{
198-
digesters::ComputedImmutablesDigests, IMMUTABLE_DIR,
198+
IMMUTABLE_DIR, digesters::ComputedImmutablesDigests,
199199
};
200200
use mithril_common::{
201-
entities::ImmutableFileNumber, messages::DigestsMessagePart, StdResult,
201+
StdResult, entities::ImmutableFileNumber, messages::DigestsMessagePart,
202202
};
203203

204204
use super::*;
@@ -252,9 +252,7 @@ mod tests {
252252
{
253253
fs::remove_file(
254254
database_dir.join(
255-
database_dir
256-
.join(IMMUTABLE_DIR)
257-
.join(immutable_file.filename.clone()),
255+
database_dir.join(IMMUTABLE_DIR).join(immutable_file.filename.clone()),
258256
),
259257
)
260258
.unwrap();

mithril-client/src/file_downloader/http.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ use std::{
33
path::Path,
44
};
55

6-
use anyhow::{anyhow, Context};
6+
use anyhow::{Context, anyhow};
77
use async_trait::async_trait;
88
use flate2::read::GzDecoder;
99
use flume::{Receiver, Sender};
1010
use futures::StreamExt;
1111
use reqwest::{Response, StatusCode, Url};
12-
use slog::{debug, Logger};
12+
use slog::{Logger, debug};
1313
use tar::Archive;
1414
use tokio::fs::File;
1515
use tokio::io::AsyncReadExt;
1616

17-
use mithril_common::{logging::LoggerExtensions, StdResult};
17+
use mithril_common::{StdResult, logging::LoggerExtensions};
1818

1919
use crate::common::CompressionAlgorithm;
2020
use crate::feedback::FeedbackSender;
2121
use crate::utils::StreamReader;
2222

23-
use super::{interface::DownloadEvent, FileDownloader, FileDownloaderUri};
23+
use super::{FileDownloader, FileDownloaderUri, interface::DownloadEvent};
2424

2525
/// A file downloader that only handles download through HTTP.
2626
pub struct HttpFileDownloader {
@@ -94,9 +94,7 @@ impl HttpFileDownloader {
9494
}
9595
buffer.truncate(bytes_read);
9696
sender.send_async(buffer).await.with_context(|| {
97-
format!(
98-
"Local file read: could not write {bytes_read} bytes to stream."
99-
)
97+
format!("Local file read: could not write {bytes_read} bytes to stream.")
10098
})?;
10199
downloaded_bytes += bytes_read as u64;
102100
let event = download_event_type.build_download_progress_event(downloaded_bytes, size);

mithril-client/src/file_downloader/interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use anyhow::anyhow;
44
use async_trait::async_trait;
55

66
use mithril_common::{
7+
StdError, StdResult,
78
entities::{
89
AncillaryLocation, CompressionAlgorithm, DigestLocation, FileUri, ImmutableFileNumber,
910
},
10-
StdError, StdResult,
1111
};
1212

1313
use crate::feedback::{MithrilEvent, MithrilEventCardanoDatabase};

mithril-client/src/file_downloader/mock_builder.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use sha2::{Digest, Sha256};
88

99
use mithril_cardano_node_internal_database::entities::AncillaryFilesManifest;
1010
use mithril_common::{
11+
StdResult,
1112
crypto_helper::ManifestSigner,
1213
entities::{CompressionAlgorithm, FileUri},
13-
StdResult,
1414
};
1515

1616
use super::{DownloadEvent, FileDownloaderUri, MockFileDownloader};
@@ -91,9 +91,7 @@ impl MockFileDownloaderBuilder {
9191
) -> Self {
9292
self.with_returning(Box::new(move |_, _, target_dir: &Path, _, _| {
9393
for filename in [
94-
fake_ancillary_file_builder
95-
.files_in_manifest_to_create
96-
.as_slice(),
94+
fake_ancillary_file_builder.files_in_manifest_to_create.as_slice(),
9795
fake_ancillary_file_builder
9896
.files_not_in_manifest_to_create
9997
.as_ref()
@@ -178,10 +176,7 @@ impl MockFileDownloaderBuilder {
178176
.unwrap_or(true)
179177
});
180178
let predicate_target_dir = predicate::function(move |u| {
181-
self.param_target_dir
182-
.as_ref()
183-
.map(|x| x == u)
184-
.unwrap_or(true)
179+
self.param_target_dir.as_ref().map(|x| x == u).unwrap_or(true)
185180
});
186181
let predicate_compression_algorithm = predicate::function(move |u| {
187182
self.param_compression_algorithm
@@ -272,9 +267,7 @@ mod tests {
272267
verifier
273268
.verify(
274269
&ancillary_manifest.compute_hash(),
275-
&ancillary_manifest
276-
.signature()
277-
.expect("Manifest should be signed"),
270+
&ancillary_manifest.signature().expect("Manifest should be signed"),
278271
)
279272
.expect("Signed manifest should have a valid signature");
280273

mithril-client/src/file_downloader/retry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{path::Path, sync::Arc, time::Duration};
22

33
use async_trait::async_trait;
4-
use mithril_common::{entities::CompressionAlgorithm, StdResult};
4+
use mithril_common::{StdResult, entities::CompressionAlgorithm};
55

66
use super::{DownloadEvent, FileDownloader, FileDownloaderUri};
77

mithril-client/src/utils/ancillary_verifier.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ mod tests {
175175
let temp_dir = temp_dir_create!();
176176

177177
let ancillary_verifier = AncillaryVerifier::new(
178-
fake_keys::manifest_verification_key()[0]
179-
.try_into()
180-
.unwrap(),
178+
fake_keys::manifest_verification_key()[0].try_into().unwrap(),
181179
);
182180

183181
let err = ancillary_verifier.verify(&temp_dir).await.unwrap_err();
@@ -196,9 +194,7 @@ mod tests {
196194
write!(&manifest_file, "invalid json").unwrap();
197195

198196
let ancillary_verifier = AncillaryVerifier::new(
199-
fake_keys::manifest_verification_key()[0]
200-
.try_into()
201-
.unwrap(),
197+
fake_keys::manifest_verification_key()[0].try_into().unwrap(),
202198
);
203199

204200
let err = ancillary_verifier.verify(&temp_dir).await.unwrap_err();
@@ -261,9 +257,7 @@ mod tests {
261257
signable_manifest: SignableManifest {
262258
// Note: This is a valid signature, but for different data
263259
signature: Some(
264-
fake_keys::signable_manifest_signature()[0]
265-
.try_into()
266-
.unwrap(),
260+
fake_keys::signable_manifest_signature()[0].try_into().unwrap(),
267261
),
268262
..valid_manifest(&temp_dir, &signer).signable_manifest
269263
},
@@ -326,10 +320,7 @@ mod tests {
326320
ancillary_files: vec![file_in_root_dir.clone(), file_in_subdir.clone()],
327321
};
328322

329-
validated_manifest
330-
.move_to_final_location(&target_dir)
331-
.await
332-
.unwrap();
323+
validated_manifest.move_to_final_location(&target_dir).await.unwrap();
333324

334325
assert_dir_eq!(
335326
&source_dir,
@@ -363,10 +354,7 @@ mod tests {
363354
};
364355

365356
assert!(target_dir.join(&existing_file_path).exists());
366-
validated_manifest
367-
.move_to_final_location(&target_dir)
368-
.await
369-
.unwrap();
357+
validated_manifest.move_to_final_location(&target_dir).await.unwrap();
370358

371359
assert!(!source_dir.join(&existing_file_path).exists());
372360
let final_content =

0 commit comments

Comments
 (0)