Skip to content

Commit 64fffb8

Browse files
chore(rust-version): update Rust version and fix Clippy lints (#28)
1 parent 977d393 commit 64fffb8

File tree

9 files changed

+46
-84
lines changed

9 files changed

+46
-84
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build-and-test:
99
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
1010
with:
11-
rust-version: '1.85.0'
11+
rust-version: '1.88.0'
1212
working-directory: "."
1313
enable-cache: true
1414
publish-crates-io: false

src/api/worker_api.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl WorkerApiClient {
8989
)
9090
.unwrap_or_else(|_| DEFAULT_WORKER_HOST.to_string());
9191

92-
let base_url = format!("http://{}", &worker_host);
92+
let base_url = format!("http://{worker_host}");
9393
Self::new(&base_url)
9494
}
9595

@@ -129,7 +129,7 @@ impl WorkerApiClient {
129129
/// &exit_message,
130130
/// ) {
131131
/// Ok(()) => println!("Exit cause reported successfully"),
132-
/// Err(error) => eprintln!("Failed to report exit cause: {}", error),
132+
/// Err(error) => eprintln!("Failed to report exit cause: {error}"),
133133
/// }
134134
/// ```
135135
pub fn send_exit_cause_for_pre_compute_stage(
@@ -138,7 +138,7 @@ impl WorkerApiClient {
138138
chain_task_id: &str,
139139
exit_cause: &ExitMessage,
140140
) -> Result<(), ReplicateStatusCause> {
141-
let url = format!("{}/compute/pre/{}/exit", self.base_url, chain_task_id);
141+
let url = format!("{}/compute/pre/{chain_task_id}/exit", self.base_url);
142142
match self
143143
.client
144144
.post(&url)
@@ -152,18 +152,12 @@ impl WorkerApiClient {
152152
Ok(())
153153
} else {
154154
let body = resp.text().unwrap_or_default();
155-
error!(
156-
"Failed to send exit cause: [status:{}, body:{}]",
157-
status, body
158-
);
155+
error!("Failed to send exit cause: [status:{status}, body:{body}]");
159156
Err(ReplicateStatusCause::PreComputeFailedUnknownIssue)
160157
}
161158
}
162159
Err(err) => {
163-
error!(
164-
"HTTP request failed when sending exit cause to {}: {:?}",
165-
url, err
166-
);
160+
error!("HTTP request failed when sending exit cause to {url}: {err:?}");
167161
Err(ReplicateStatusCause::PreComputeFailedUnknownIssue)
168162
}
169163
}
@@ -224,7 +218,7 @@ mod tests {
224218
fn should_get_worker_api_client_without_env_var() {
225219
temp_env::with_vars_unset(vec![WorkerHostEnvVar.name()], || {
226220
let client = WorkerApiClient::from_env();
227-
assert_eq!(client.base_url, format!("http://{}", DEFAULT_WORKER_HOST));
221+
assert_eq!(client.base_url, format!("http://{DEFAULT_WORKER_HOST}"));
228222
});
229223
}
230224
// endregion
@@ -243,7 +237,7 @@ mod tests {
243237
});
244238

245239
Mock::given(method("POST"))
246-
.and(path(format!("/compute/pre/{}/exit", CHAIN_TASK_ID)))
240+
.and(path(format!("/compute/pre/{CHAIN_TASK_ID}/exit")))
247241
.and(header("Authorization", CHALLENGE))
248242
.and(body_json(&expected_body))
249243
.respond_with(ResponseTemplate::new(200))
@@ -274,7 +268,7 @@ mod tests {
274268
let server_url = mock_server.uri();
275269

276270
Mock::given(method("POST"))
277-
.and(path(format!("/compute/pre/{}/exit", CHAIN_TASK_ID)))
271+
.and(path(format!("/compute/pre/{CHAIN_TASK_ID}/exit")))
278272
.respond_with(ResponseTemplate::new(503).set_body_string("Service Unavailable"))
279273
.expect(1)
280274
.mount(&mock_server)

src/compute/app_runner.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ pub fn start_with_app<A: PreComputeAppTrait>(pre_compute_app: &mut A) -> ExitMod
4848
match get_env_var_or_error(IexecTaskId, ReplicateStatusCause::PreComputeTaskIdMissing) {
4949
Ok(id) => id,
5050
Err(e) => {
51-
error!(
52-
"TEE pre-compute cannot proceed without taskID context: {:?}",
53-
e
54-
);
51+
error!("TEE pre-compute cannot proceed without taskID context: {e:?}");
5552
return ExitMode::InitializationFailure;
5653
}
5754
};
@@ -62,17 +59,14 @@ pub fn start_with_app<A: PreComputeAppTrait>(pre_compute_app: &mut A) -> ExitMod
6259
return ExitMode::Success;
6360
}
6461
Err(exit_cause) => {
65-
error!(
66-
"TEE pre-compute failed with known exit cause [{:?}]",
67-
exit_cause
68-
);
62+
error!("TEE pre-compute failed with known exit cause [{exit_cause:?}]");
6963
}
7064
}
7165

7266
let authorization = match get_challenge(&chain_task_id) {
7367
Ok(auth) => auth,
7468
Err(_) => {
75-
error!("Failed to sign exitCause message [{:?}]", exit_cause);
69+
error!("Failed to sign exitCause message [{exit_cause:?}]");
7670
return ExitMode::UnreportedFailure;
7771
}
7872
};
@@ -88,7 +82,7 @@ pub fn start_with_app<A: PreComputeAppTrait>(pre_compute_app: &mut A) -> ExitMod
8882
) {
8983
Ok(_) => ExitMode::ReportedFailure,
9084
Err(_) => {
91-
error!("Failed to report exitCause [{:?}]", exit_cause);
85+
error!("Failed to report exitCause [{exit_cause:?}]");
9286
ExitMode::UnreportedFailure
9387
}
9488
}
@@ -197,7 +191,7 @@ mod pre_compute_start_with_app_tests {
197191
let mock_server = MockServer::start().await;
198192

199193
Mock::given(method("POST"))
200-
.and(path(format!("/compute/pre/{}/exit", CHAIN_TASK_ID)))
194+
.and(path(format!("/compute/pre/{CHAIN_TASK_ID}/exit")))
201195
.respond_with(ResponseTemplate::new(500))
202196
.mount(&mock_server)
203197
.await;
@@ -243,7 +237,7 @@ mod pre_compute_start_with_app_tests {
243237

244238
// Mock the worker API to return success
245239
Mock::given(method("POST"))
246-
.and(path(format!("/compute/pre/{}/exit", CHAIN_TASK_ID)))
240+
.and(path(format!("/compute/pre/{CHAIN_TASK_ID}/exit")))
247241
.and(body_json(expected_exit_message_payload))
248242
.respond_with(ResponseTemplate::new(200))
249243
.mount(&mock_server)

src/compute/pre_compute_app.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,13 @@ impl PreComputeAppTrait for PreComputeApp {
9191

9292
let chain_task_id = self.chain_task_id.as_deref().unwrap_or("unknown");
9393

94-
info!(
95-
"Checking output folder [chainTaskId:{}, path:{}]",
96-
chain_task_id, output_dir
97-
);
94+
info!("Checking output folder [chainTaskId:{chain_task_id}, path:{output_dir}]");
9895

9996
if Path::new(&output_dir).is_dir() {
10097
return Ok(());
10198
}
10299

103-
error!(
104-
"Output folder not found [chainTaskId:{}, path:{}]",
105-
chain_task_id, output_dir
106-
);
100+
error!("Output folder not found [chainTaskId:{chain_task_id}, path:{output_dir}]");
107101

108102
Err(ReplicateStatusCause::PreComputeOutputFolderNotFound)
109103
}
@@ -140,10 +134,7 @@ impl PreComputeAppTrait for PreComputeApp {
140134
let chain_task_id = self.chain_task_id.as_ref().unwrap();
141135

142136
for url in &args.input_files {
143-
info!(
144-
"Downloading input file [chainTaskId: {}, url: {}]",
145-
chain_task_id, url
146-
);
137+
info!("Downloading input file [chainTaskId:{chain_task_id}, url:{url}]");
147138

148139
let filename = sha256(url.to_string());
149140
if download_file(url, &args.output_dir, &filename).is_none() {
@@ -176,20 +167,19 @@ impl PreComputeAppTrait for PreComputeApp {
176167
let encrypted_dataset_url = args.encrypted_dataset_url.as_ref().unwrap();
177168

178169
info!(
179-
"Downloading encrypted dataset file [chainTaskId: {}, url: {}]",
180-
chain_task_id, encrypted_dataset_url
170+
"Downloading encrypted dataset file [chainTaskId:{chain_task_id}, url:{encrypted_dataset_url}]",
181171
);
182172

183173
let encrypted_content = if is_multi_address(encrypted_dataset_url) {
184174
IPFS_GATEWAYS.iter().find_map(|gateway| {
185-
let full_url = format!("{}{}", gateway, encrypted_dataset_url);
186-
info!("Attempting to download dataset from {}", full_url);
175+
let full_url = format!("{gateway}{encrypted_dataset_url}");
176+
info!("Attempting to download dataset from {full_url}");
187177

188178
if let Some(content) = download_from_url(&full_url) {
189-
info!("Successfully downloaded from {}", full_url);
179+
info!("Successfully downloaded from {full_url}");
190180
Some(content)
191181
} else {
192-
info!("Failed to download from {}", full_url);
182+
info!("Failed to download from {full_url}");
193183
None
194184
}
195185
})
@@ -198,10 +188,7 @@ impl PreComputeAppTrait for PreComputeApp {
198188
}
199189
.ok_or(ReplicateStatusCause::PreComputeDatasetDownloadFailed)?;
200190

201-
info!(
202-
"Checking encrypted dataset checksum [chainTaskId: {}]",
203-
chain_task_id
204-
);
191+
info!("Checking encrypted dataset checksum [chainTaskId:{chain_task_id}]");
205192
let expected_checksum = args
206193
.encrypted_dataset_checksum
207194
.as_ref()
@@ -210,8 +197,7 @@ impl PreComputeAppTrait for PreComputeApp {
210197

211198
if actual_checksum != *expected_checksum {
212199
error!(
213-
"Invalid dataset checksum [chainTaskId: {}, expected: {}, actual: {}]",
214-
chain_task_id, expected_checksum, actual_checksum
200+
"Invalid dataset checksum [chainTaskId:{chain_task_id}, expected:{expected_checksum}, actual:{actual_checksum}]"
215201
);
216202
return Err(ReplicateStatusCause::PreComputeInvalidDatasetChecksum);
217203
}
@@ -303,15 +289,14 @@ impl PreComputeAppTrait for PreComputeApp {
303289
path.push(plain_dataset_filename);
304290

305291
info!(
306-
"Saving plain dataset file [chain_task_id:{}, path:{}]",
307-
chain_task_id,
292+
"Saving plain dataset file [chain_task_id:{chain_task_id}, path:{}]",
308293
path.display()
309294
);
310295

311296
write_file(
312297
plain_dataset,
313298
&path,
314-
&format!("chainTaskId:{}", chain_task_id),
299+
&format!("chainTaskId:{chain_task_id}"),
315300
)
316301
.map_err(|_| ReplicateStatusCause::PreComputeSavingPlainDatasetFailed)
317302
}

src/compute/pre_compute_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ mod tests {
154154
for i in 1..=count {
155155
vars.insert(
156156
IexecInputFileUrlPrefix(i).name(),
157-
format!("https://input-{}.txt", i),
157+
format!("https://input-{i}.txt"),
158158
);
159159
}
160160
vars

src/compute/signer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use alloy_signer_local::PrivateKeySigner;
3333
/// let private_key = "0xdd3b993ec21c71c1f6d63a5240850e0d4d8dd83ff70d29e49247958548c1d479";
3434
///
3535
/// match sign_enclave_challenge(message_hash, private_key) {
36-
/// Ok(signature) => println!("Signature: {}", signature),
37-
/// Err(e) => eprintln!("Error: {:?}", e),
36+
/// Ok(signature) => println!("Signature: {signature}"),
37+
/// Err(e) => eprintln!("Error: {e:?}"),
3838
/// }
3939
/// ```
4040
pub fn sign_enclave_challenge(
@@ -89,8 +89,8 @@ pub fn sign_enclave_challenge(
8989
/// let chain_task_id = "0x123456789abcdef";
9090
///
9191
/// match challenge(chain_task_id) {
92-
/// Ok(signature) => println!("Challenge signature: {}", signature),
93-
/// Err(e) => eprintln!("Error generating challenge: {:?}", e),
92+
/// Ok(signature) => println!("Challenge signature: {signature}"),
93+
/// Err(e) => eprintln!("Error generating challenge: {e:?}"),
9494
/// }
9595
/// ```
9696
pub fn get_challenge(chain_task_id: &str) -> Result<String, ReplicateStatusCause> {

src/compute/utils/env_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl TeeSessionEnvironmentVariable {
2828
TeeSessionEnvironmentVariable::IexecDatasetKey => "IEXEC_DATASET_KEY".to_string(),
2929
TeeSessionEnvironmentVariable::IexecDatasetUrl => "IEXEC_DATASET_URL".to_string(),
3030
TeeSessionEnvironmentVariable::IexecInputFileUrlPrefix(index) => {
31-
format!("IEXEC_INPUT_FILE_URL_{}", index)
31+
format!("IEXEC_INPUT_FILE_URL_{index}")
3232
}
3333
TeeSessionEnvironmentVariable::IexecInputFilesNumber => {
3434
"IEXEC_INPUT_FILES_NUMBER".to_string()

src/compute/utils/file_utils.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,14 @@ pub fn write_file(content: &[u8], file_path: &Path, context: &str) -> Result<(),
3232
match fs::write(file_path, content) {
3333
Ok(_) => {
3434
info!(
35-
"File written successfully [{}, path:{}]",
36-
context,
35+
"File written successfully [{context}, path:{}]",
3736
file_path.display()
3837
);
3938
Ok(())
4039
}
4140
Err(_) => {
4241
error!(
43-
"Failed to write file [{}, path:{}]",
44-
context,
42+
"Failed to write file [{context}, path:{}]",
4543
file_path.display()
4644
);
4745
Err(())
@@ -82,28 +80,22 @@ pub fn write_file(content: &[u8], file_path: &Path, context: &str) -> Result<(),
8280
/// - The downloaded content is fully loaded into memory before being written to disk.
8381
pub fn download_file(url: &str, parent_dir: &str, filename: &str) -> Option<PathBuf> {
8482
if url.is_empty() {
85-
error!("Invalid file url [url:{}]", url);
83+
error!("Invalid file url [url:{url}]");
8684
return None;
8785
}
8886
if parent_dir.is_empty() {
89-
error!(
90-
"Invalid parent folder path [url:{}, parent_dir:{}]",
91-
url, parent_dir
92-
);
87+
error!("Invalid parent folder path [url:{url}, parent_dir:{parent_dir}]");
9388
return None;
9489
}
9590
if filename.is_empty() {
96-
error!(
97-
"Invalid output filename [url:{}, parent_dir:{}, filename:{}]",
98-
url, parent_dir, filename
99-
);
91+
error!("Invalid output filename [url:{url}, parent_dir:{parent_dir}, filename:{filename}]");
10092
return None;
10193
}
10294

10395
let bytes = match download_from_url(url) {
10496
Some(b) => b,
10597
None => {
106-
error!("Failed to download file [url:{}]", url);
98+
error!("Failed to download file [url:{url}]");
10799
return None;
108100
}
109101
};
@@ -112,16 +104,13 @@ pub fn download_file(url: &str, parent_dir: &str, filename: &str) -> Option<Path
112104
let parent_existed = parent_path.exists();
113105

114106
if !parent_existed && fs::create_dir_all(parent_path).is_err() {
115-
error!(
116-
"Failed to create parent folder [url:{}, parent_dir:{}]",
117-
url, parent_dir
118-
);
107+
error!("Failed to create parent folder [url:{url}, parent_dir:{parent_dir}]");
119108
return None;
120109
}
121110

122111
let file_path = parent_path.join(filename);
123112

124-
if write_file(&bytes, &file_path, &format!("url:{}", url)).is_ok() {
113+
if write_file(&bytes, &file_path, &format!("url:{url}")).is_ok() {
125114
Some(file_path)
126115
} else {
127116
if !parent_existed {
@@ -175,18 +164,18 @@ pub fn download_from_url(url: &str) -> Option<Vec<u8>> {
175164
return None;
176165
}
177166

178-
info!("Attempting to download from {}", url);
167+
info!("Attempting to download from {url}");
179168

180169
match get(url)
181170
.and_then(|response| response.error_for_status())
182171
.and_then(|response| response.bytes())
183172
{
184173
Ok(bytes) => {
185-
info!("Successfully downloaded {} bytes from {}", bytes.len(), url);
174+
info!("Successfully downloaded {} bytes from {url}", bytes.len());
186175
Some(bytes.to_vec())
187176
}
188177
Err(e) => {
189-
error!("Failed to download from {}: {}", url, e);
178+
error!("Failed to download from {url}: {e}");
190179
None
191180
}
192181
}
@@ -331,7 +320,7 @@ mod tests {
331320
});
332321

333322
let server_uri = mock_server.uri();
334-
let result = download_from_url(&format!("{}/error", server_uri));
323+
let result = download_from_url(&format!("{server_uri}/error"));
335324

336325
assert!(result.is_none());
337326
}

src/compute/utils/hash_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use sha256::digest;
44
pub fn concatenate_and_hash(hexa_strings: &[&str]) -> String {
55
let mut hasher = Keccak256::default();
66
for hexa_string in hexa_strings {
7-
println!("value {}", hexa_string);
7+
println!("value {hexa_string}");
88
hasher.update(hex_string_to_byte_array(hexa_string));
99
}
1010
format!("0x{:x}", hasher.finalize())

0 commit comments

Comments
 (0)