Skip to content

Commit 83715ec

Browse files
authored
feat: Read and update computed.json file (#10)
1 parent 7b695a3 commit 83715ec

File tree

10 files changed

+941
-13
lines changed

10 files changed

+941
-13
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ alloy-signer-local = "0.15.9"
99
log = "0.4.27"
1010
reqwest = { version = "0.12.15", features = ["blocking", "json"] }
1111
serde = "1.0.219"
12+
serde_json = "1.0.140"
1213
sha256 = "1.6.0"
1314
sha3 = "0.10.8"
1415
thiserror = "2.0.12"
1516

1617
[dev-dependencies]
17-
serde_json = "1.0.140"
1818
temp-env = "0.3.6"
19+
tempfile = "3.20.0"
1920
tokio = "1.45.0"
2021
wiremock = "0.6.3"

src/compute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod app_runner;
2+
pub mod computed_file;
23
pub mod errors;
34
pub mod signer;
45
pub mod utils;

src/compute/app_runner.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::api::worker_api::{ExitMessage, WorkerApiClient};
2+
use crate::compute::computed_file::build_result_digest_in_computed_file;
23
use crate::compute::{
4+
computed_file::read_computed_file,
35
errors::ReplicateStatusCause,
46
signer::get_challenge,
57
utils::env_utils::{TeeSessionEnvironmentVariable, get_env_var_or_error},
@@ -41,8 +43,32 @@ impl DefaultPostComputeRunner {
4143
}
4244

4345
impl PostComputeRunnerInterface for DefaultPostComputeRunner {
44-
fn run_post_compute(&self, _chain_task_id: &str) -> Result<(), Box<dyn Error>> {
45-
Err("run_post_compute not implemented yet".into())
46+
fn run_post_compute(&self, chain_task_id: &str) -> Result<(), Box<dyn Error>> {
47+
let should_callback: bool = match get_env_var_or_error(
48+
TeeSessionEnvironmentVariable::RESULT_STORAGE_CALLBACK,
49+
ReplicateStatusCause::PostComputeFailedUnknownIssue, //TODO: Update this error cause to a more specific one
50+
) {
51+
Ok(value) => match value.parse::<bool>() {
52+
Ok(parsed_value) => parsed_value,
53+
Err(e) => {
54+
error!(
55+
"Failed to parse RESULT_STORAGE_CALLBACK environment variable as a boolean [callback_env_var:{}]",
56+
value
57+
);
58+
return Err(Box::new(e));
59+
}
60+
},
61+
Err(e) => {
62+
error!("Failed to get RESULT_STORAGE_CALLBACK environment variable");
63+
return Err(Box::new(e));
64+
}
65+
};
66+
67+
let mut computed_file = read_computed_file(chain_task_id, "/iexec_out").unwrap();
68+
build_result_digest_in_computed_file(&mut computed_file, should_callback)
69+
.expect("Failed to build result digest");
70+
71+
Err("run_post_compute not fully implemented yet".into())
4672
}
4773

4874
fn get_challenge(&self, chain_task_id: &str) -> Result<String, ReplicateStatusCause> {

0 commit comments

Comments
 (0)