Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 02fd54d

Browse files
committed
Merge branch 'master' into ao-past-session-slashing-client
* master: runtime: past session slashing runtime API (#6667) cli: enable BEEFY by default on test networks (#7293) pallets: implement `Default` for `GenesisConfig` in `no_std` (#7271) Update quote to 1.0.27 (#7280) PVF: Refactor workers into separate crates, remove host dependency (#7253)
2 parents 92c5228 + 7104195 commit 02fd54d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+982
-759
lines changed

Cargo.lock

+242-200
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tikv-jemallocator = "0.5.0"
2424

2525
# Crates in our workspace, defined as dependencies so we can pass them feature flags.
2626
polkadot-cli = { path = "cli", features = [ "kusama-native", "westend-native", "rococo-native" ] }
27-
polkadot-node-core-pvf-worker = { path = "node/core/pvf/worker" }
27+
polkadot-node-core-pvf-prepare-worker = { path = "node/core/pvf/prepare-worker" }
2828
polkadot-overseer = { path = "node/overseer" }
2929

3030
[dev-dependencies]
@@ -81,7 +81,9 @@ members = [
8181
"node/core/parachains-inherent",
8282
"node/core/provisioner",
8383
"node/core/pvf",
84-
"node/core/pvf/worker",
84+
"node/core/pvf/common",
85+
"node/core/pvf/execute-worker",
86+
"node/core/pvf/prepare-worker",
8587
"node/core/pvf-checker",
8688
"node/core/runtime-api",
8789
"node/network/approval-distribution",
@@ -208,7 +210,7 @@ try-runtime = [ "polkadot-cli/try-runtime" ]
208210
fast-runtime = [ "polkadot-cli/fast-runtime" ]
209211
runtime-metrics = [ "polkadot-cli/runtime-metrics" ]
210212
pyroscope = ["polkadot-cli/pyroscope"]
211-
jemalloc-allocator = ["polkadot-node-core-pvf-worker/jemalloc-allocator", "polkadot-overseer/jemalloc-allocator"]
213+
jemalloc-allocator = ["polkadot-node-core-pvf-prepare-worker/jemalloc-allocator", "polkadot-overseer/jemalloc-allocator"]
212214

213215

214216

cli/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ pyroscope_pprofrs = { version = "0.2", optional = true }
2323

2424
service = { package = "polkadot-service", path = "../node/service", default-features = false, optional = true }
2525
polkadot-client = { path = "../node/client", optional = true }
26-
polkadot-node-core-pvf-worker = { path = "../node/core/pvf/worker", optional = true }
26+
polkadot-node-core-pvf-execute-worker = { path = "../node/core/pvf/execute-worker", optional = true }
27+
polkadot-node-core-pvf-prepare-worker = { path = "../node/core/pvf/prepare-worker", optional = true }
2728
polkadot-performance-test = { path = "../node/test/performance-test", optional = true }
2829

2930
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -54,7 +55,8 @@ cli = [
5455
"frame-benchmarking-cli",
5556
"try-runtime-cli",
5657
"polkadot-client",
57-
"polkadot-node-core-pvf-worker",
58+
"polkadot-node-core-pvf-execute-worker",
59+
"polkadot-node-core-pvf-prepare-worker",
5860
]
5961
runtime-benchmarks = [
6062
"service/runtime-benchmarks",

cli/src/cli.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ pub struct RunCmd {
114114
#[arg(long = "grandpa-pause", num_args = 2)]
115115
pub grandpa_pause: Vec<u32>,
116116

117-
/// Enable the BEEFY gadget (only on Rococo or Wococo for now).
117+
/// Disable the BEEFY gadget
118+
/// (currently enabled by default on Rococo, Wococo and Versi).
118119
#[arg(long)]
119-
pub beefy: bool,
120+
pub no_beefy: bool,
120121

121122
/// Add the destination address to the jaeger agent.
122123
///

cli/src/command.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -298,12 +298,9 @@ where
298298
.map_err(Error::from)?;
299299
let chain_spec = &runner.config().chain_spec;
300300

301-
// Disallow BEEFY on production networks.
302-
if cli.run.beefy &&
303-
(chain_spec.is_polkadot() || chain_spec.is_kusama() || chain_spec.is_westend())
304-
{
305-
return Err(Error::Other("BEEFY disallowed on production networks".to_string()))
306-
}
301+
// By default, enable BEEFY on test networks.
302+
let enable_beefy = (chain_spec.is_rococo() || chain_spec.is_wococo() || chain_spec.is_versi()) &&
303+
!cli.run.no_beefy;
307304

308305
set_default_ss58_version(chain_spec);
309306

@@ -346,7 +343,7 @@ where
346343
config,
347344
service::IsCollator::No,
348345
grandpa_pause,
349-
cli.run.beefy,
346+
enable_beefy,
350347
jaeger_agent,
351348
None,
352349
false,
@@ -495,7 +492,7 @@ pub fn run() -> Result<()> {
495492

496493
#[cfg(not(target_os = "android"))]
497494
{
498-
polkadot_node_core_pvf_worker::prepare_worker_entrypoint(
495+
polkadot_node_core_pvf_prepare_worker::worker_entrypoint(
499496
&cmd.socket_path,
500497
Some(&cmd.node_impl_version),
501498
);
@@ -517,7 +514,7 @@ pub fn run() -> Result<()> {
517514

518515
#[cfg(not(target_os = "android"))]
519516
{
520-
polkadot_node_core_pvf_worker::execute_worker_entrypoint(
517+
polkadot_node_core_pvf_execute_worker::worker_entrypoint(
521518
&cmd.socket_path,
522519
Some(&cmd.node_impl_version),
523520
);

node/core/pvf/Cargo.toml

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ version.workspace = true
44
authors.workspace = true
55
edition.workspace = true
66

7+
[[bin]]
8+
name = "puppet_worker"
9+
path = "bin/puppet_worker.rs"
10+
711
[dependencies]
812
always-assert = "0.1"
913
futures = "0.3.21"
@@ -13,12 +17,16 @@ libc = "0.2.139"
1317
pin-project = "1.0.9"
1418
rand = "0.8.5"
1519
slotmap = "1.0"
20+
tempfile = "3.3.0"
1621
tokio = { version = "1.24.2", features = ["fs", "process"] }
1722

1823
parity-scale-codec = { version = "3.4.0", default-features = false, features = ["derive"] }
1924

2025
polkadot-parachain = { path = "../../../parachain" }
2126
polkadot-core-primitives = { path = "../../../core-primitives" }
27+
polkadot-node-core-pvf-common = { path = "common" }
28+
polkadot-node-core-pvf-execute-worker = { path = "execute-worker" }
29+
polkadot-node-core-pvf-prepare-worker = { path = "prepare-worker" }
2230
polkadot-node-metrics = { path = "../../metrics" }
2331
polkadot-node-primitives = { path = "../../primitives" }
2432
polkadot-primitives = { path = "../../../primitives" }
@@ -34,4 +42,6 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
3442
[dev-dependencies]
3543
assert_matches = "1.4.0"
3644
hex-literal = "0.3.4"
37-
tempfile = "3.3.0"
45+
46+
adder = { package = "test-parachain-adder", path = "../../../parachain/test-parachains/adder" }
47+
halt = { package = "test-parachain-halt", path = "../../../parachain/test-parachains/halt" }

node/core/pvf/worker/bin/puppet_worker.rs renamed to node/core/pvf/bin/puppet_worker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
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-
polkadot_node_core_pvf_worker::decl_puppet_worker_main!();
17+
polkadot_node_core_pvf::decl_puppet_worker_main!();

node/core/pvf/common/Cargo.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "polkadot-node-core-pvf-common"
3+
version.workspace = true
4+
authors.workspace = true
5+
edition.workspace = true
6+
7+
[dependencies]
8+
cpu-time = "1.0.0"
9+
futures = "0.3.21"
10+
gum = { package = "tracing-gum", path = "../../../gum" }
11+
libc = "0.2.139"
12+
tokio = { version = "1.24.2", features = ["fs", "process", "io-util"] }
13+
14+
parity-scale-codec = { version = "3.4.0", default-features = false, features = ["derive"] }
15+
16+
polkadot-parachain = { path = "../../../../parachain" }
17+
polkadot-primitives = { path = "../../../../primitives" }
18+
19+
sc-executor-common = { git = "https://github.com/paritytech/substrate", branch = "master" }
20+
sc-executor-wasmtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
21+
22+
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
23+
sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
24+
25+
[build-dependencies]
26+
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
File renamed without changes.

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

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
use crate::prepare::PrepareStats;
18+
use parity_scale_codec::{Decode, Encode};
19+
use std::fmt;
20+
21+
/// Result of PVF preparation performed by the validation host. Contains stats about the preparation if
22+
/// successful
23+
pub type PrepareResult = Result<PrepareStats, PrepareError>;
24+
25+
/// An error that occurred during the prepare part of the PVF pipeline.
26+
#[derive(Debug, Clone, Encode, Decode)]
27+
pub enum PrepareError {
28+
/// During the prevalidation stage of preparation an issue was found with the PVF.
29+
Prevalidation(String),
30+
/// Compilation failed for the given PVF.
31+
Preparation(String),
32+
/// An unexpected panic has occurred in the preparation worker.
33+
Panic(String),
34+
/// Failed to prepare the PVF due to the time limit.
35+
TimedOut,
36+
/// An IO error occurred. This state is reported by either the validation host or by the worker.
37+
IoErr(String),
38+
/// The temporary file for the artifact could not be created at the given cache path. This state is reported by the
39+
/// validation host (not by the worker).
40+
CreateTmpFileErr(String),
41+
/// The response from the worker is received, but the file cannot be renamed (moved) to the final destination
42+
/// location. This state is reported by the validation host (not by the worker).
43+
RenameTmpFileErr(String),
44+
}
45+
46+
impl PrepareError {
47+
/// Returns whether this is a deterministic error, i.e. one that should trigger reliably. Those
48+
/// errors depend on the PVF itself and the sc-executor/wasmtime logic.
49+
///
50+
/// Non-deterministic errors can happen spuriously. Typically, they occur due to resource
51+
/// starvation, e.g. under heavy load or memory pressure. Those errors are typically transient
52+
/// but may persist e.g. if the node is run by overwhelmingly underpowered machine.
53+
pub fn is_deterministic(&self) -> bool {
54+
use PrepareError::*;
55+
match self {
56+
Prevalidation(_) | Preparation(_) | Panic(_) => true,
57+
TimedOut | IoErr(_) | CreateTmpFileErr(_) | RenameTmpFileErr(_) => false,
58+
}
59+
}
60+
}
61+
62+
impl fmt::Display for PrepareError {
63+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64+
use PrepareError::*;
65+
match self {
66+
Prevalidation(err) => write!(f, "prevalidation: {}", err),
67+
Preparation(err) => write!(f, "preparation: {}", err),
68+
Panic(err) => write!(f, "panic: {}", err),
69+
TimedOut => write!(f, "prepare: timeout"),
70+
IoErr(err) => write!(f, "prepare: io error while receiving response: {}", err),
71+
CreateTmpFileErr(err) => write!(f, "prepare: error creating tmp file: {}", err),
72+
RenameTmpFileErr(err) => write!(f, "prepare: error renaming tmp file: {}", err),
73+
}
74+
}
75+
}
76+
77+
/// Some internal error occurred.
78+
///
79+
/// Should only ever be used for validation errors independent of the candidate and PVF, or for errors we ruled out
80+
/// during pre-checking (so preparation errors are fine).
81+
#[derive(Debug, Clone, Encode, Decode)]
82+
pub enum InternalValidationError {
83+
/// Some communication error occurred with the host.
84+
HostCommunication(String),
85+
/// Could not find or open compiled artifact file.
86+
CouldNotOpenFile(String),
87+
/// An error occurred in the CPU time monitor thread. Should be totally unrelated to validation.
88+
CpuTimeMonitorThread(String),
89+
/// Some non-deterministic preparation error occurred.
90+
NonDeterministicPrepareError(PrepareError),
91+
}
92+
93+
impl fmt::Display for InternalValidationError {
94+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95+
use InternalValidationError::*;
96+
match self {
97+
HostCommunication(err) =>
98+
write!(f, "validation: some communication error occurred with the host: {}", err),
99+
CouldNotOpenFile(err) =>
100+
write!(f, "validation: could not find or open compiled artifact file: {}", err),
101+
CpuTimeMonitorThread(err) =>
102+
write!(f, "validation: an error occurred in the CPU time monitor thread: {}", err),
103+
NonDeterministicPrepareError(err) => write!(f, "validation: prepare: {}", err),
104+
}
105+
}
106+
}

node/core/pvf/common/src/execute.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
use crate::error::InternalValidationError;
18+
use parity_scale_codec::{Decode, Encode};
19+
use polkadot_parachain::primitives::ValidationResult;
20+
use polkadot_primitives::ExecutorParams;
21+
use std::time::Duration;
22+
23+
/// The payload of the one-time handshake that is done when a worker process is created. Carries
24+
/// data from the host to the worker.
25+
#[derive(Encode, Decode)]
26+
pub struct Handshake {
27+
/// The executor parameters.
28+
pub executor_params: ExecutorParams,
29+
}
30+
31+
/// The response from an execution job on the worker.
32+
#[derive(Encode, Decode)]
33+
pub enum Response {
34+
/// The job completed successfully.
35+
Ok {
36+
/// The result of parachain validation.
37+
result_descriptor: ValidationResult,
38+
/// The amount of CPU time taken by the job.
39+
duration: Duration,
40+
},
41+
/// The candidate is invalid.
42+
InvalidCandidate(String),
43+
/// The job timed out.
44+
TimedOut,
45+
/// An unexpected panic has occurred in the execution worker.
46+
Panic(String),
47+
/// Some internal error occurred.
48+
InternalError(InternalValidationError),
49+
}
50+
51+
impl Response {
52+
/// Creates an invalid response from a context `ctx` and a message `msg` (which can be empty).
53+
pub fn format_invalid(ctx: &'static str, msg: &str) -> Self {
54+
if msg.is_empty() {
55+
Self::InvalidCandidate(ctx.to_string())
56+
} else {
57+
Self::InvalidCandidate(format!("{}: {}", ctx, msg))
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)