Discard Executor (#1855)

closes #622 

Pros:
* simpler interface, just functions:
`create_runtime_from_artifact_bytes()` and `execute_artifact()`

Cons:
* extra overhead of constructing executor semantics each time

I could make it a combination of
* `create_runtime_config(params)` (such that we could clone the
constructed semantics)
* `create_runtime(blob, config)`
* `execute_artifact(blob, config, params)`

Not sure if it's worth it though.

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
Julian Eager
2023-10-15 05:06:00 +08:00
committed by GitHub
parent 7c87d61f5a
commit 9f7656df15
5 changed files with 77 additions and 87 deletions
+4 -4
View File
@@ -29,20 +29,20 @@ pub fn validate_candidate(
code: &[u8],
params: &[u8],
) -> Result<Vec<u8>, Box<dyn std::error::Error>> {
use polkadot_node_core_pvf_execute_worker::Executor;
use polkadot_node_core_pvf_execute_worker::execute_artifact;
use polkadot_node_core_pvf_prepare_worker::{prepare, prevalidate};
let code = sp_maybe_compressed_blob::decompress(code, 10 * 1024 * 1024)
.expect("Decompressing code failed");
let blob = prevalidate(&code)?;
let compiled_artifact_blob = prepare(blob, &ExecutorParams::default())?;
let executor_params = ExecutorParams::default();
let compiled_artifact_blob = prepare(blob, &executor_params)?;
let executor = Executor::new(ExecutorParams::default())?;
let result = unsafe {
// SAFETY: This is trivially safe since the artifact is obtained by calling `prepare`
// and is written into a temporary directory in an unmodified state.
executor.execute(&compiled_artifact_blob, params)?
execute_artifact(&compiled_artifact_blob, &executor_params, params)?
};
Ok(result)