diff --git a/polkadot/node/core/pvf/common/src/error.rs b/polkadot/node/core/pvf/common/src/error.rs index 53565b92eb37..384a0781d6dc 100644 --- a/polkadot/node/core/pvf/common/src/error.rs +++ b/polkadot/node/core/pvf/common/src/error.rs @@ -76,9 +76,6 @@ pub enum PrepareError { Kernel(String), } -/// Pre-encoded length-prefixed `PrepareResult::Err(PrepareError::OutOfMemory)` -pub const OOM_PAYLOAD: &[u8] = b"\x02\x00\x00\x00\x00\x00\x00\x00\x01\x08"; - impl PrepareError { /// Returns whether this is a deterministic error, i.e. one that should trigger reliably. Those /// errors depend on the PVF itself and the sc-executor/wasmtime logic. @@ -174,11 +171,3 @@ impl fmt::Display for InternalValidationError { } } } - -#[test] -fn pre_encoded_payloads() { - let oom_enc = PrepareResult::Err(PrepareError::OutOfMemory).encode(); - let mut oom_payload = oom_enc.len().to_le_bytes().to_vec(); - oom_payload.extend(oom_enc); - assert_eq!(oom_payload, OOM_PAYLOAD); -} diff --git a/polkadot/node/core/pvf/prepare-worker/src/lib.rs b/polkadot/node/core/pvf/prepare-worker/src/lib.rs index 6b0091f5d9e5..58fc292eb456 100644 --- a/polkadot/node/core/pvf/prepare-worker/src/lib.rs +++ b/polkadot/node/core/pvf/prepare-worker/src/lib.rs @@ -40,7 +40,7 @@ use nix::{ use os_pipe::{self, PipeWriter}; use parity_scale_codec::{Decode, Encode}; use polkadot_node_core_pvf_common::{ - error::{PrepareError, PrepareResult, OOM_PAYLOAD}, + error::{PrepareError, PrepareResult}, executor_intf::create_runtime_from_artifact_bytes, framed_recv_blocking, framed_send_blocking, prepare::{MemoryStats, PrepareJobKind, PrepareStats}, @@ -614,7 +614,7 @@ fn get_total_cpu_usage(rusage: Usage) -> Duration { /// - `pipe_write`: A `os_pipe::PipeWriter` structure, the writing end of a pipe. /// /// - `response`: Child process response -fn send_child_response(mut pipe_write: &PipeWriter, response: Result) -> ! { +fn send_child_response(mut pipe_write: &PipeWriter, response: JobResponse) -> ! { pipe_write .write_all(response.encode().as_slice()) .unwrap_or_else(|_| process::exit(libc::EXIT_FAILURE)); @@ -625,3 +625,17 @@ fn send_child_response(mut pipe_write: &PipeWriter, response: Result PrepareError { PrepareError::Kernel(format!("{}: {}: {}", context, errno, io::Error::last_os_error())) } + +type JobResponse = Result; + +/// Pre-encoded length-prefixed `Result::Err(PrepareError::OutOfMemory)` +const OOM_PAYLOAD: &[u8] = b"\x02\x00\x00\x00\x00\x00\x00\x00\x01\x08"; + +#[test] +fn pre_encoded_payloads() { + // NOTE: This must match the type of `response` in `send_child_response`. + let oom_enc: JobResponse = Result::Err(PrepareError::OutOfMemory).encode(); + let mut oom_payload = oom_enc.len().to_le_bytes().to_vec(); + oom_payload.extend(oom_enc); + assert_eq!(oom_payload, OOM_PAYLOAD); +} diff --git a/polkadot/node/core/pvf/tests/it/main.rs b/polkadot/node/core/pvf/tests/it/main.rs index 54a686a3e798..9c299147471a 100644 --- a/polkadot/node/core/pvf/tests/it/main.rs +++ b/polkadot/node/core/pvf/tests/it/main.rs @@ -126,7 +126,7 @@ impl TestHost { } #[tokio::test] -async fn terminates_on_timeout() { +async fn execute_job_terminates_on_timeout() { let host = TestHost::new().await; let start = std::time::Instant::now();