mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 02:21:03 +00:00
Move artifacts states into memory in PVF validation host (#3907)
* pvf host: store only compiled artifacts on disk * Correctly handle failed artifacts * Serialize result of PVF preparation uniquely * Set the artifact state depending on the result * Return the result of PVF preparation directly * Move PrepareError to the error module * Update doc comments * Update misleading comment * Cleanup docs * Conclude a test job with an error Co-authored-by: Sergei Shulepov <sergei@parity.io>
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::error::PrepareError;
|
||||
use always_assert::always;
|
||||
use async_std::path::{Path, PathBuf};
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
@@ -23,30 +24,19 @@ use std::{
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
/// A final product of preparation process. Contains either a ready to run compiled artifact or
|
||||
/// a description what went wrong.
|
||||
/// A wrapper for the compiled PVF code.
|
||||
#[derive(Encode, Decode)]
|
||||
pub enum Artifact {
|
||||
/// During the prevalidation stage of preparation an issue was found with the PVF.
|
||||
PrevalidationErr(String),
|
||||
/// Compilation failed for the given PVF.
|
||||
PreparationErr(String),
|
||||
/// This state indicates that the process assigned to prepare the artifact wasn't responsible
|
||||
/// or were killed. This state is reported by the validation host (not by the worker).
|
||||
DidntMakeIt,
|
||||
/// The PVF passed all the checks and is ready for execution.
|
||||
Compiled { compiled_artifact: Vec<u8> },
|
||||
pub struct CompiledArtifact(Vec<u8>);
|
||||
|
||||
impl CompiledArtifact {
|
||||
pub fn new(code: Vec<u8>) -> Self {
|
||||
Self(code)
|
||||
}
|
||||
}
|
||||
|
||||
impl Artifact {
|
||||
/// Serializes this struct into a byte buffer.
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
self.encode()
|
||||
}
|
||||
|
||||
/// Deserialize the given byte buffer to an artifact.
|
||||
pub fn deserialize(mut bytes: &[u8]) -> Result<Self, String> {
|
||||
Artifact::decode(&mut bytes).map_err(|e| format!("{:?}", e))
|
||||
impl AsRef<[u8]> for CompiledArtifact {
|
||||
fn as_ref(&self) -> &[u8] {
|
||||
self.0.as_slice()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +107,9 @@ pub enum ArtifactState {
|
||||
},
|
||||
/// A task to prepare this artifact is scheduled.
|
||||
Preparing,
|
||||
/// The code couldn't be compiled due to an error. Such artifacts
|
||||
/// never reach the executor and stay in the host's memory.
|
||||
FailedToProcess(PrepareError),
|
||||
}
|
||||
|
||||
/// A container of all known artifact ids and their states.
|
||||
|
||||
Reference in New Issue
Block a user