Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Address a couple of TODOs
Browse files Browse the repository at this point in the history
Addresses a couple of follow-up TODOs from
#7153.
  • Loading branch information
mrcnski committed May 1, 2023
1 parent fc481bc commit b03e1b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
10 changes: 4 additions & 6 deletions node/core/pvf/worker/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use polkadot_node_core_pvf::{
};
use polkadot_parachain::primitives::ValidationResult;
use std::{
panic,
path::{Path, PathBuf},
sync::mpsc::channel,
thread,
Expand Down Expand Up @@ -115,11 +114,10 @@ pub fn worker_entrypoint(socket_path: &str, node_version: Option<&str>) {
if execute_thread.is_finished() {
let _ = finished_tx.send(());
break execute_thread.join().unwrap_or_else(|e| {
// TODO: Use `Panic` error once that is implemented.
Response::format_internal(
"execute thread error",
&stringify_panic_payload(e),
)
Response::Panic(format!(
"execute thread error: {}",
&stringify_panic_payload(e)
))
})
}
// If this thread is not selected, the join handle is dropped and the thread will
Expand Down
25 changes: 10 additions & 15 deletions node/core/pvf/worker/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use polkadot_node_core_pvf::{
framed_recv, framed_send, CompiledArtifact, MemoryStats, PrepareError, PrepareResult,
PrepareStats, PvfPrepData,
};
use std::{panic, path::PathBuf, sync::mpsc::channel, thread, time::Duration};
use std::{path::PathBuf, sync::mpsc::channel, thread, time::Duration};
use tokio::{io, net::UnixStream};

async fn recv_request(stream: &mut UnixStream) -> io::Result<(PvfPrepData, PathBuf)> {
Expand Down Expand Up @@ -202,18 +202,13 @@ pub fn worker_entrypoint(socket_path: &str, node_version: Option<&str>) {
}

fn prepare_artifact(pvf: PvfPrepData) -> Result<CompiledArtifact, PrepareError> {
// TODO: Is this necessary? Panics are already caught by `std::thread::join`.
panic::catch_unwind(|| {
let blob = match prevalidate(&pvf.code()) {
Err(err) => return Err(PrepareError::Prevalidation(format!("{:?}", err))),
Ok(b) => b,
};

match prepare(blob, &pvf.executor_params()) {
Ok(compiled_artifact) => Ok(CompiledArtifact::new(compiled_artifact)),
Err(err) => Err(PrepareError::Preparation(format!("{:?}", err))),
}
})
.map_err(|panic_payload| PrepareError::Panic(stringify_panic_payload(panic_payload)))
.and_then(|inner_result| inner_result)
let blob = match prevalidate(&pvf.code()) {
Err(err) => return Err(PrepareError::Prevalidation(format!("{:?}", err))),
Ok(b) => b,
};

match prepare(blob, &pvf.executor_params()) {
Ok(compiled_artifact) => Ok(CompiledArtifact::new(compiled_artifact)),
Err(err) => Err(PrepareError::Preparation(format!("{:?}", err))),
}
}

0 comments on commit b03e1b0

Please sign in to comment.