Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Return the result of PVF preparation directly
  • Loading branch information
slumber committed Sep 27, 2021
commit 11de2079dd6e6fd68f9edfd9fdabf392f45f9ea6
10 changes: 0 additions & 10 deletions node/core/pvf/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ impl AsRef<[u8]> for CompiledArtifact {
}
}

/// A final product of preparation process. Contains either a ready to run compiled artifact or
/// a description what went wrong.
#[derive(Encode, Decode)]
pub enum Artifact {
/// An error occurred during the prepare part of the PVF pipeline.
Error(PrepareError),
/// The PVF passed all the checks and is ready for execution.
Compiled(CompiledArtifact),
}

/// Identifier of an artifact. Right now it only encodes a code hash of the PVF. But if we get to
/// multiple engine implementations the artifact ID should include the engine type as well.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
Expand Down
14 changes: 7 additions & 7 deletions node/core/pvf/src/prepare/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use crate::{
artifacts::{Artifact, CompiledArtifact, PrepareError},
artifacts::{CompiledArtifact, PrepareError},
worker_common::{
bytes_to_path, framed_recv, framed_send, path_to_bytes, spawn_with_program_path,
tmpfile_in, worker_event_loop, IdleWorker, SpawnErr, WorkerHandle,
Expand Down Expand Up @@ -286,11 +286,11 @@ pub fn worker_entrypoint(socket_path: &str) {
);

let result = match prepare_artifact(&code) {
Artifact::Error(err) => {
Err(err) => {
// Serialized error will be written into the socket.
Err(err)
},
Artifact::Compiled(compiled_artifact) => {
Ok(compiled_artifact) => {
// Write the serialized artifact into a temp file.
// Since a compiled artifact can be heavy, we send an empty
// `Ok` to indicate the success.
Expand All @@ -313,14 +313,14 @@ pub fn worker_entrypoint(socket_path: &str) {
});
}

fn prepare_artifact(code: &[u8]) -> Artifact {
fn prepare_artifact(code: &[u8]) -> Result<CompiledArtifact, PrepareError> {
let blob = match crate::executor_intf::prevalidate(code) {
Err(err) => return Artifact::Error(PrepareError::Prevalidation(format!("{:?}", err))),
Err(err) => return Err(PrepareError::Prevalidation(format!("{:?}", err))),
Ok(b) => b,
};

match crate::executor_intf::prepare(blob) {
Ok(compiled_artifact) => Artifact::Compiled(CompiledArtifact::new(compiled_artifact)),
Err(err) => Artifact::Error(PrepareError::Preparation(format!("{:?}", err))),
Ok(compiled_artifact) => Ok(CompiledArtifact::new(compiled_artifact)),
Err(err) => Err(PrepareError::Preparation(format!("{:?}", err))),
}
}