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

Commit 5303d8c

Browse files
98.6% OF DEVELOPERS CANNOT REVIEW THIS PR! [read more...] (#7337)
* [WIP] PVF: Split out worker binaries * Address compilation problems and re-design a bit * Reorganize once more, fix tests * Reformat with new nightly to make `cargo fmt` test happy * Address `clippy` warnings * Add temporary trace to debug zombienet tests * Fix zombienet node upgrade test * Fix malus and its CI * Fix building worker binaries with malus * More fixes for malus * Remove unneeded cli subcommands * Support placing auxiliary binaries to `/usr/libexec` * Fix spelling * Spelling Co-authored-by: Marcin S. <[email protected]> * Implement review comments (mostly nits) * Fix worker node version flag * Rework getting the worker paths * Address a couple of review comments * Minor restructuring * Fix CI error * Add tests for worker binaries detection * Improve tests; try to fix CI * Move workers module into separate file * Try to fix failing test and workers not printing latest version - Tests were not finding the worker binaries - Workers were not being rebuilt when the version changed - Made some errors easier to read * Make a bunch of fixes * Rebuild nodes on version change * Fix more issues * Fix tests * Pass node version from node into dependencies to avoid recompiles - [X] get version in CLI - [X] pass it in to service - [X] pass version along to PVF - [X] remove rerun from service - [X] add rerun to CLI - [X] don’t rerun pvf/worker’s (these should be built by nodes which have rerun enabled) * Some more improvements for smoother tests - [X] Fix tests - [X] Make puppet workers pass None for version and remove rerun - [X] Make test collators self-contained * Add back rerun to PVF workers * Move worker binaries into files in cli crate As a final optimization I've separated out each worker binary from its own crate into the CLI crate. Before, the worker bin shared a crate with the worker lib, so when the binaries got recompiled so did the libs and everything transitively depending on the libs. This commit fixes this regression that was causing recompiles after every commit. * Fix bug (was passing worker version for node version) * Move workers out of cli into root src/bin/ dir - [X] Pass in node version from top-level (polkadot) - [X] Add build.rs with rerun-git-head to root dir * Add some sanity checks for workers to dockerfiles * Update malus + [X] Make it self-contained + [X] Undo multiple binary changes * Try to fix clippy errors * Address `cargo run` issue - [X] Add default-run for polkadot - [X] Add note about installation to error * Update readme (installation instructions) * Allow disabling external workers for local/testing setups + [X] cli flag to enable single-binary mode + [X] Add message to error * Revert unnecessary Cargo.lock changes * Remove unnecessary build scripts from collators * Add back missing malus commands (should fix failing ZN job) * Some minor fixes * Update Cargo.lock * Fix some build errors * Undo self-contained binaries; cli flag to disable version check + [X] Remove --dont-run-external-workers + [X] Add --disable-worker-version-check + [X] Remove PVF subcommands + [X] Redo malus changes * Try to fix failing job and add some docs for local tests --------- Co-authored-by: Dmitry Sinyavin <[email protected]> Co-authored-by: s0me0ne-unkn0wn <[email protected]> Co-authored-by: parity-processbot <>
1 parent 35bd316 commit 5303d8c

48 files changed

Lines changed: 1432 additions & 571 deletions

File tree

Some content is hidden

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

Cargo.lock

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

Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
name = "polkadot"
33
path = "src/main.rs"
44

5+
[[bin]]
6+
name = "polkadot-execute-worker"
7+
path = "src/bin/execute-worker.rs"
8+
9+
[[bin]]
10+
name = "polkadot-prepare-worker"
11+
path = "src/bin/prepare-worker.rs"
12+
513
[package]
614
name = "polkadot"
715
description = "Implementation of a `https://polkadot.network` node in Rust based on the Substrate framework."
816
license = "GPL-3.0-only"
917
rust-version = "1.64.0" # workspace properties
1018
readme = "README.md"
19+
default-run = "polkadot"
1120
authors.workspace = true
1221
edition.workspace = true
1322
version.workspace = true
@@ -28,6 +37,10 @@ polkadot-node-core-pvf = { path = "node/core/pvf" }
2837
polkadot-node-core-pvf-prepare-worker = { path = "node/core/pvf/prepare-worker" }
2938
polkadot-overseer = { path = "node/overseer" }
3039

40+
# Needed for worker binaries.
41+
polkadot-node-core-pvf-common = { path = "node/core/pvf/common" }
42+
polkadot-node-core-pvf-execute-worker = { path = "node/core/pvf/execute-worker" }
43+
3144
[dev-dependencies]
3245
assert_cmd = "2.0.4"
3346
nix = { version = "0.26.1", features = ["signal"] }
@@ -36,6 +49,9 @@ tokio = "1.24.2"
3649
substrate-rpc-client = { git = "https://github.com/paritytech/substrate", branch = "master" }
3750
polkadot-core-primitives = { path = "core-primitives" }
3851

52+
[build-dependencies]
53+
substrate-build-script-utils = { git = "https://github.com/paritytech/substrate", branch = "master" }
54+
3955
[workspace]
4056
members = [
4157
"cli",
@@ -226,6 +242,8 @@ license-file = ["LICENSE", "0"]
226242
maintainer-scripts = "scripts/packaging/deb-maintainer-scripts"
227243
assets = [
228244
["target/release/polkadot", "/usr/bin/", "755"],
245+
["target/release/polkadot-prepare-worker", "/usr/lib/polkadot/", "755"],
246+
["target/release/polkadot-execute-worker", "/usr/lib/polkadot/", "755"],
229247
["scripts/packaging/polkadot.service", "/lib/systemd/system/", "644"]
230248
]
231249
conf-files = [

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ git checkout <latest tagged release>
9191
cargo build --release
9292
```
9393

94-
Note that compilation is a memory intensive process. We recommend having 4 GiB of physical RAM or swap available (keep in mind that if a build hits swap it tends to be very slow).
94+
**Note:** compilation is a memory intensive process. We recommend having 4 GiB of physical RAM or swap available (keep in mind that if a build hits swap it tends to be very slow).
95+
96+
**Note:** if you want to move the built `polkadot` binary somewhere (e.g. into $PATH) you will also need to move `polkadot-execute-worker` and `polkadot-prepare-worker`. You can let cargo do all this for you by running `cargo install --path .`.
9597

9698
#### Build from Source with Docker
9799

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@
1616

1717
fn main() {
1818
substrate_build_script_utils::generate_cargo_keys();
19+
// For the node/worker version check, make sure we always rebuild the node and binary workers
20+
// when the version changes.
21+
substrate_build_script_utils::rerun_if_git_head_changed();
1922
}

cli/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ pyro = { package = "pyroscope", version = "0.5.3", optional = true }
2222
pyroscope_pprofrs = { version = "0.2", optional = true }
2323

2424
service = { package = "polkadot-service", path = "../node/service", default-features = false, optional = true }
25-
polkadot-node-core-pvf-execute-worker = { path = "../node/core/pvf/execute-worker", optional = true }
26-
polkadot-node-core-pvf-prepare-worker = { path = "../node/core/pvf/prepare-worker", optional = true }
2725
polkadot-performance-test = { path = "../node/test/performance-test", optional = true }
2826

2927
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
@@ -53,8 +51,6 @@ cli = [
5351
"sc-tracing",
5452
"frame-benchmarking-cli",
5553
"try-runtime-cli",
56-
"polkadot-node-core-pvf-execute-worker",
57-
"polkadot-node-core-pvf-prepare-worker",
5854
"service",
5955
]
6056
runtime-benchmarks = [

cli/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ fn main() {
1919
println!("cargo:rustc-cfg=build_type=\"{}\"", profile);
2020
}
2121
substrate_build_script_utils::generate_cargo_keys();
22+
// For the node/worker version check, make sure we always rebuild the node when the version
23+
// changes.
24+
substrate_build_script_utils::rerun_if_git_head_changed();
2225
}

cli/src/cli.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
//! Polkadot CLI library.
1818
1919
use clap::Parser;
20+
use std::path::PathBuf;
21+
22+
/// The version of the node. The passed-in version of the workers should match this.
23+
pub const NODE_VERSION: &'static str = env!("SUBSTRATE_CLI_IMPL_VERSION");
2024

2125
#[allow(missing_docs)]
2226
#[derive(Debug, Parser)]
@@ -42,14 +46,6 @@ pub enum Subcommand {
4246
/// Revert the chain to a previous state.
4347
Revert(sc_cli::RevertCmd),
4448

45-
#[allow(missing_docs)]
46-
#[command(name = "prepare-worker", hide = true)]
47-
PvfPrepareWorker(ValidationWorkerCommand),
48-
49-
#[allow(missing_docs)]
50-
#[command(name = "execute-worker", hide = true)]
51-
PvfExecuteWorker(ValidationWorkerCommand),
52-
5349
/// Sub-commands concerned with benchmarking.
5450
/// The pallet benchmarking moved to the `pallet` sub-command.
5551
#[command(subcommand)]
@@ -148,6 +144,17 @@ pub struct RunCmd {
148144
/// **Dangerous!** Do not touch unless explicitly adviced to.
149145
#[arg(long)]
150146
pub overseer_channel_capacity_override: Option<usize>,
147+
148+
/// Path to the directory where auxiliary worker binaries reside. If not specified, the main
149+
/// binary's directory is searched first, then `/usr/lib/polkadot` is searched. TESTING ONLY: if
150+
/// the path points to an executable rather then directory, that executable is used both as
151+
/// preparation and execution worker.
152+
#[arg(long, value_name = "PATH")]
153+
pub workers_path: Option<PathBuf>,
154+
155+
/// TESTING ONLY: disable the version check between nodes and workers.
156+
#[arg(long, hide = true)]
157+
pub disable_worker_version_check: bool,
151158
}
152159

153160
#[allow(missing_docs)]

cli/src/command.rs

Lines changed: 22 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
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::cli::{Cli, Subcommand};
17+
use crate::cli::{Cli, Subcommand, NODE_VERSION};
1818
use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
1919
use futures::future::TryFutureExt;
2020
use log::info;
@@ -55,7 +55,7 @@ impl SubstrateCli for Cli {
5555
}
5656

5757
fn impl_version() -> String {
58-
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
58+
NODE_VERSION.into()
5959
}
6060

6161
fn description() -> String {
@@ -272,6 +272,9 @@ where
272272
None
273273
};
274274

275+
let node_version =
276+
if cli.run.disable_worker_version_check { None } else { Some(NODE_VERSION.to_string()) };
277+
275278
runner.run_node_until_exit(move |config| async move {
276279
let hwbench = (!cli.run.no_hardware_benchmarks)
277280
.then_some(config.database.path().map(|database_path| {
@@ -283,16 +286,23 @@ where
283286
let database_source = config.database.clone();
284287
let task_manager = service::build_full(
285288
config,
286-
service::IsCollator::No,
287-
grandpa_pause,
288-
enable_beefy,
289-
jaeger_agent,
290-
None,
291-
false,
292-
overseer_gen,
293-
cli.run.overseer_channel_capacity_override,
294-
maybe_malus_finality_delay,
295-
hwbench,
289+
service::NewFullParams {
290+
is_collator: service::IsCollator::No,
291+
grandpa_pause,
292+
enable_beefy,
293+
jaeger_agent,
294+
telemetry_worker_handle: None,
295+
node_version,
296+
workers_path: cli.run.workers_path,
297+
workers_names: None,
298+
overseer_enable_anyways: false,
299+
overseer_gen,
300+
overseer_message_channel_capacity_override: cli
301+
.run
302+
.overseer_channel_capacity_override,
303+
malus_finality_delay: maybe_malus_finality_delay,
304+
hwbench,
305+
},
296306
)
297307
.map(|full| full.task_manager)?;
298308

@@ -419,50 +429,6 @@ pub fn run() -> Result<()> {
419429
))
420430
})?)
421431
},
422-
Some(Subcommand::PvfPrepareWorker(cmd)) => {
423-
let mut builder = sc_cli::LoggerBuilder::new("");
424-
builder.with_colors(false);
425-
let _ = builder.init();
426-
427-
#[cfg(target_os = "android")]
428-
{
429-
return Err(sc_cli::Error::Input(
430-
"PVF preparation workers are not supported under this platform".into(),
431-
)
432-
.into())
433-
}
434-
435-
#[cfg(not(target_os = "android"))]
436-
{
437-
polkadot_node_core_pvf_prepare_worker::worker_entrypoint(
438-
&cmd.socket_path,
439-
Some(&cmd.node_impl_version),
440-
);
441-
Ok(())
442-
}
443-
},
444-
Some(Subcommand::PvfExecuteWorker(cmd)) => {
445-
let mut builder = sc_cli::LoggerBuilder::new("");
446-
builder.with_colors(false);
447-
let _ = builder.init();
448-
449-
#[cfg(target_os = "android")]
450-
{
451-
return Err(sc_cli::Error::Input(
452-
"PVF execution workers are not supported under this platform".into(),
453-
)
454-
.into())
455-
}
456-
457-
#[cfg(not(target_os = "android"))]
458-
{
459-
polkadot_node_core_pvf_execute_worker::worker_entrypoint(
460-
&cmd.socket_path,
461-
Some(&cmd.node_impl_version),
462-
);
463-
Ok(())
464-
}
465-
},
466432
Some(Subcommand::Benchmark(cmd)) => {
467433
let runner = cli.create_runner(cmd)?;
468434
let chain_spec = &runner.config().chain_spec;

0 commit comments

Comments
 (0)