From f4f818d43a33ba1caf95cb1db4160ba90824eb2d Mon Sep 17 00:00:00 2001 From: smtmfft <99081233+smtmfft@users.noreply.github.com> Date: Fri, 20 Sep 2024 08:39:40 +0800 Subject: [PATCH] fix(raiko): refine error return (#378) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(raiko): refine error return * fix lint Signed-off-by: smtmfft * fix lint Signed-off-by: smtmfft * fix zk entrypoint log level Signed-off-by: smtmfft * Update host/src/server/api/v2/mod.rs Co-authored-by: Petar Vujović --------- Signed-off-by: smtmfft Co-authored-by: Petar Vujović --- docker/entrypoint.sh | 2 +- host/src/proof.rs | 11 ++++++----- host/src/server/api/v2/mod.rs | 10 ++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 7ef85385..5fc5d82b 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -182,5 +182,5 @@ if [[ -n $ZK ]]; then update_raiko_sgx_instance_id $RAIKO_CONF_BASE_CONFIG update_docker_chain_specs $RAIKO_CONF_CHAIN_SPECS - RUST_LOG=debug /opt/raiko/bin/raiko-host "$@" + /opt/raiko/bin/raiko-host "$@" fi \ No newline at end of file diff --git a/host/src/proof.rs b/host/src/proof.rs index 3fc65a32..31a56e72 100644 --- a/host/src/proof.rs +++ b/host/src/proof.rs @@ -111,8 +111,8 @@ impl ProofActor { } result = Self::handle_message(proof_request, key.clone(), &opts, &chain_specs) => { match result { - Ok(()) => { - info!("Host handling message"); + Ok(status) => { + info!("Host handling message: {status:?}"); } Err(error) => { error!("Worker failed due to: {error:?}"); @@ -151,14 +151,14 @@ impl ProofActor { key: TaskDescriptor, opts: &Opts, chain_specs: &SupportedChainSpecs, - ) -> HostResult<()> { + ) -> HostResult { let mut manager = get_task_manager(&opts.clone().into()); let status = manager.get_task_proving_status(&key).await?; if let Some(latest_status) = status.iter().last() { if !matches!(latest_status.0, TaskStatus::Registered) { - return Ok(()); + return Ok(latest_status.0); } } @@ -178,7 +178,8 @@ impl ProofActor { manager .update_task_progress(key, status, proof.as_deref()) .await - .map_err(|e| e.into()) + .map_err(HostError::from)?; + Ok(status) } } diff --git a/host/src/server/api/v2/mod.rs b/host/src/server/api/v2/mod.rs index 65f4894e..6985369b 100644 --- a/host/src/server/api/v2/mod.rs +++ b/host/src/server/api/v2/mod.rs @@ -84,8 +84,14 @@ impl From> for Status { impl From for Status { fn from(status: TaskStatus) -> Self { - Self::Ok { - data: ProofResponse::Status { status }, + match status { + TaskStatus::Success | TaskStatus::WorkInProgress | TaskStatus::Registered => Self::Ok { + data: ProofResponse::Status { status }, + }, + _ => Self::Error { + error: "task_failed".to_string(), + message: format!("Task failed with status: {status:?}"), + }, } } }