Skip to content

Commit b585893

Browse files
eagrmrcnski
andauthored
Preserve artifact cache unless stale (#1918)
Co-authored-by: Marcin S <[email protected]>
1 parent 794ee98 commit b585893

File tree

22 files changed

+535
-244
lines changed

22 files changed

+535
-244
lines changed

Cargo.lock

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/node/core/candidate-validation/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use polkadot_node_core_pvf::{
2727
InternalValidationError, InvalidCandidate as WasmInvalidCandidate, PrepareError,
28-
PrepareJobKind, PrepareStats, PvfPrepData, ValidationError, ValidationHost,
28+
PrepareJobKind, PvfPrepData, ValidationError, ValidationHost,
2929
};
3030
use polkadot_node_primitives::{
3131
BlockData, InvalidCandidate, PoV, ValidationResult, POV_BOMB_LIMIT, VALIDATION_CODE_BOMB_LIMIT,
@@ -794,7 +794,7 @@ trait ValidationBackend {
794794
validation_result
795795
}
796796

797-
async fn precheck_pvf(&mut self, pvf: PvfPrepData) -> Result<PrepareStats, PrepareError>;
797+
async fn precheck_pvf(&mut self, pvf: PvfPrepData) -> Result<(), PrepareError>;
798798
}
799799

800800
#[async_trait]
@@ -824,7 +824,7 @@ impl ValidationBackend for ValidationHost {
824824
})?
825825
}
826826

827-
async fn precheck_pvf(&mut self, pvf: PvfPrepData) -> Result<PrepareStats, PrepareError> {
827+
async fn precheck_pvf(&mut self, pvf: PvfPrepData) -> Result<(), PrepareError> {
828828
let (tx, rx) = oneshot::channel();
829829
if let Err(err) = self.precheck_pvf(pvf, tx).await {
830830
// Return an IO error if there was an error communicating with the host.

polkadot/node/core/candidate-validation/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl ValidationBackend for MockValidateCandidateBackend {
377377
result
378378
}
379379

380-
async fn precheck_pvf(&mut self, _pvf: PvfPrepData) -> Result<PrepareStats, PrepareError> {
380+
async fn precheck_pvf(&mut self, _pvf: PvfPrepData) -> Result<(), PrepareError> {
381381
unreachable!()
382382
}
383383
}
@@ -1014,11 +1014,11 @@ fn pov_decompression_failure_is_invalid() {
10141014
}
10151015

10161016
struct MockPreCheckBackend {
1017-
result: Result<PrepareStats, PrepareError>,
1017+
result: Result<(), PrepareError>,
10181018
}
10191019

10201020
impl MockPreCheckBackend {
1021-
fn with_hardcoded_result(result: Result<PrepareStats, PrepareError>) -> Self {
1021+
fn with_hardcoded_result(result: Result<(), PrepareError>) -> Self {
10221022
Self { result }
10231023
}
10241024
}
@@ -1034,7 +1034,7 @@ impl ValidationBackend for MockPreCheckBackend {
10341034
unreachable!()
10351035
}
10361036

1037-
async fn precheck_pvf(&mut self, _pvf: PvfPrepData) -> Result<PrepareStats, PrepareError> {
1037+
async fn precheck_pvf(&mut self, _pvf: PvfPrepData) -> Result<(), PrepareError> {
10381038
self.result.clone()
10391039
}
10401040
}
@@ -1051,7 +1051,7 @@ fn precheck_works() {
10511051

10521052
let (check_fut, check_result) = precheck_pvf(
10531053
ctx.sender(),
1054-
MockPreCheckBackend::with_hardcoded_result(Ok(PrepareStats::default())),
1054+
MockPreCheckBackend::with_hardcoded_result(Ok(())),
10551055
relay_parent,
10561056
validation_code_hash,
10571057
)
@@ -1113,7 +1113,7 @@ fn precheck_invalid_pvf_blob_compression() {
11131113

11141114
let (check_fut, check_result) = precheck_pvf(
11151115
ctx.sender(),
1116-
MockPreCheckBackend::with_hardcoded_result(Ok(PrepareStats::default())),
1116+
MockPreCheckBackend::with_hardcoded_result(Ok(())),
11171117
relay_parent,
11181118
validation_code_hash,
11191119
)

polkadot/node/core/pvf/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ license.workspace = true
88

99
[dependencies]
1010
always-assert = "0.1"
11+
blake3 = "1.5"
1112
cfg-if = "1.0"
1213
futures = "0.3.21"
1314
futures-timer = "3.0.2"

polkadot/node/core/pvf/benches/host_prepare_rococo_runtime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl TestHost {
5656
&self,
5757
code: &[u8],
5858
executor_params: ExecutorParams,
59-
) -> Result<PrepareStats, PrepareError> {
59+
) -> Result<(), PrepareError> {
6060
let (result_tx, result_rx) = futures::channel::oneshot::channel();
6161

6262
let code = sp_maybe_compressed_blob::decompress(code, 16 * 1024 * 1024)

polkadot/node/core/pvf/common/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ seccompiler = "0.4.0"
3636
assert_matches = "1.4.0"
3737
tempfile = "3.3.0"
3838

39+
[build-dependencies]
40+
substrate-build-script-utils = { path = "../../../../../substrate/utils/build-script-utils" }
41+
3942
[features]
4043
# This feature is used to export test code to other crates without putting it in the production build.
4144
test-utils = []
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (C) Parity Technologies (UK) Ltd.
2+
// This file is part of Polkadot.
3+
4+
// Polkadot is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Polkadot is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
16+
17+
fn main() {
18+
substrate_build_script_utils::generate_wasmtime_version();
19+
}

polkadot/node/core/pvf/common/src/error.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17-
use crate::prepare::PrepareStats;
17+
use crate::prepare::{PrepareSuccess, PrepareWorkerSuccess};
1818
use parity_scale_codec::{Decode, Encode};
1919
use std::fmt;
2020

21-
/// Result of PVF preparation performed by the validation host. Contains stats about the preparation
22-
/// if successful
23-
pub type PrepareResult = Result<PrepareStats, PrepareError>;
21+
/// Result of PVF preparation from a worker, with checksum of the compiled PVF and stats of the
22+
/// preparation if successful.
23+
pub type PrepareWorkerResult = Result<PrepareWorkerSuccess, PrepareError>;
24+
25+
/// Result of PVF preparation propagated all the way back to the host, with path to the concluded
26+
/// artifact and stats of the preparation if successful.
27+
pub type PrepareResult = Result<PrepareSuccess, PrepareError>;
28+
29+
/// Result of prechecking PVF performed by the validation host. Contains stats about the preparation
30+
/// if successful.
31+
pub type PrecheckResult = Result<(), PrepareError>;
2432

2533
/// An error that occurred during the prepare part of the PVF pipeline.
26-
// Codec indexes are intended to stabilize pre-encoded payloads (see `OOM_PAYLOAD` below)
34+
// Codec indexes are intended to stabilize pre-encoded payloads (see `OOM_PAYLOAD`)
2735
#[derive(Debug, Clone, Encode, Decode)]
2836
pub enum PrepareError {
2937
/// During the prevalidation stage of preparation an issue was found with the PVF.

polkadot/node/core/pvf/common/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub use sp_tracing;
3131

3232
const LOG_TARGET: &str = "parachain::pvf-common";
3333

34+
pub const RUNTIME_VERSION: &str = env!("SUBSTRATE_WASMTIME_VERSION");
35+
3436
use std::{
3537
io::{self, Read, Write},
3638
mem,

polkadot/node/core/pvf/common/src/prepare.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,25 @@
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

1717
use parity_scale_codec::{Decode, Encode};
18+
use std::path::PathBuf;
19+
20+
/// Result from prepare worker if successful.
21+
#[derive(Debug, Clone, Default, Encode, Decode)]
22+
pub struct PrepareWorkerSuccess {
23+
/// Checksum of the compiled PVF.
24+
pub checksum: String,
25+
/// Stats of the current preparation run.
26+
pub stats: PrepareStats,
27+
}
28+
29+
/// Result of PVF preparation if successful.
30+
#[derive(Debug, Clone, Default)]
31+
pub struct PrepareSuccess {
32+
/// Canonical path to the compiled artifact.
33+
pub path: PathBuf,
34+
/// Stats of the current preparation run.
35+
pub stats: PrepareStats,
36+
}
1837

1938
/// Preparation statistics, including the CPU time and memory taken.
2039
#[derive(Debug, Clone, Default, Encode, Decode)]

0 commit comments

Comments
 (0)