From 47b22d5256487c814b15030882faf59a4e9e9f06 Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 28 Feb 2023 02:20:49 +0000 Subject: [PATCH] Allow compilation with no slasher backend (#3888) ## Proposed Changes Allowing compiling without MDBX by running: ```bash CARGO_INSTALL_EXTRA_FLAGS="--no-default-features" make ``` The reasons to do this are several: - Save compilation time if the slasher won't be used - Work around compilation errors in slasher backend dependencies (our pinned version of MDBX is currently not compiling on FreeBSD with certain compiler versions). ## Additional Info When I opened this PR we were using resolver v1 which [doesn't disable default features in dependencies](https://doc.rust-lang.org/cargo/reference/features.html#resolver-version-2-command-line-flags), and `mdbx` is default for the `slasher` crate. Even after the resolver got changed to v2 in #3697 compiling with `--no-default-features` _still_ wasn't turning off the slasher crate's default features, so I added `default-features = false` in all the places we depend on it. Co-authored-by: Michael Sproul --- Makefile | 15 ++++++++++++--- beacon_node/Cargo.toml | 2 +- beacon_node/beacon_chain/Cargo.toml | 2 +- beacon_node/client/Cargo.toml | 2 +- book/src/installation-source.md | 9 +++++++++ lighthouse/Cargo.toml | 2 +- slasher/service/Cargo.toml | 2 +- 7 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 05c6c74d5..89362d12d 100644 --- a/Makefile +++ b/Makefile @@ -38,15 +38,24 @@ PROFILE ?= release # they run for different forks. FORKS=phase0 altair merge capella +# Extra flags for Cargo +CARGO_INSTALL_EXTRA_FLAGS?= + # Builds the Lighthouse binary in release (optimized). # # Binaries will most likely be found in `./target/release` install: - cargo install --path lighthouse --force --locked --features "$(FEATURES)" --profile "$(PROFILE)" + cargo install --path lighthouse --force --locked \ + --features "$(FEATURES)" \ + --profile "$(PROFILE)" \ + $(CARGO_INSTALL_EXTRA_FLAGS) # Builds the lcli binary in release (optimized). install-lcli: - cargo install --path lcli --force --locked --features "$(FEATURES)" --profile "$(PROFILE)" + cargo install --path lcli --force --locked \ + --features "$(FEATURES)" \ + --profile "$(PROFILE)" \ + $(CARGO_INSTALL_EXTRA_FLAGS) # The following commands use `cross` to build a cross-compile. # @@ -124,7 +133,7 @@ run-ef-tests: test-beacon-chain: $(patsubst %,test-beacon-chain-%,$(FORKS)) test-beacon-chain-%: - env FORK_NAME=$* cargo test --release --features fork_from_env -p beacon_chain + env FORK_NAME=$* cargo test --release --features fork_from_env,slasher/lmdb -p beacon_chain # Run the tests in the `operation_pool` crate for all known forks. test-op-pool: $(patsubst %,test-op-pool-%,$(FORKS)) diff --git a/beacon_node/Cargo.toml b/beacon_node/Cargo.toml index a2acd6055..3c37f41de 100644 --- a/beacon_node/Cargo.toml +++ b/beacon_node/Cargo.toml @@ -36,7 +36,7 @@ clap_utils = { path = "../common/clap_utils" } hyper = "0.14.4" lighthouse_version = { path = "../common/lighthouse_version" } hex = "0.4.2" -slasher = { path = "../slasher" } +slasher = { path = "../slasher", default-features = false } monitoring_api = { path = "../common/monitoring_api" } sensitive_url = { path = "../common/sensitive_url" } http_api = { path = "http_api" } diff --git a/beacon_node/beacon_chain/Cargo.toml b/beacon_node/beacon_chain/Cargo.toml index 5b8583304..5599e6f97 100644 --- a/beacon_node/beacon_chain/Cargo.toml +++ b/beacon_node/beacon_chain/Cargo.toml @@ -53,7 +53,7 @@ fork_choice = { path = "../../consensus/fork_choice" } task_executor = { path = "../../common/task_executor" } derivative = "2.1.1" itertools = "0.10.0" -slasher = { path = "../../slasher" } +slasher = { path = "../../slasher", default-features = false } eth2 = { path = "../../common/eth2" } strum = { version = "0.24.0", features = ["derive"] } logging = { path = "../../common/logging" } diff --git a/beacon_node/client/Cargo.toml b/beacon_node/client/Cargo.toml index 9a49843a9..876458eea 100644 --- a/beacon_node/client/Cargo.toml +++ b/beacon_node/client/Cargo.toml @@ -39,7 +39,7 @@ time = "0.3.5" directory = {path = "../../common/directory"} http_api = { path = "../http_api" } http_metrics = { path = "../http_metrics" } -slasher = { path = "../../slasher" } +slasher = { path = "../../slasher", default-features = false } slasher_service = { path = "../../slasher/service" } monitoring_api = {path = "../../common/monitoring_api"} execution_layer = { path = "../execution_layer" } diff --git a/book/src/installation-source.md b/book/src/installation-source.md index 8e515a41b..c89dd1add 100644 --- a/book/src/installation-source.md +++ b/book/src/installation-source.md @@ -133,6 +133,15 @@ Commonly used features include: * `slasher-lmdb`: support for the LMDB slasher backend. * `jemalloc`: use [`jemalloc`][jemalloc] to allocate memory. Enabled by default on Linux and macOS. Not supported on Windows. +* `spec-minimal`: support for the minimal preset (useful for testing). + +Default features (e.g. `slasher-mdbx`) may be opted out of using the `--no-default-features` +argument for `cargo`, which can plumbed in via the `CARGO_INSTALL_EXTRA_FLAGS` environment variable. +E.g. + +``` +CARGO_INSTALL_EXTRA_FLAGS="--no-default-features" make +``` [jemalloc]: https://jemalloc.net/ diff --git a/lighthouse/Cargo.toml b/lighthouse/Cargo.toml index 2c0f1ec1c..ecac53fb1 100644 --- a/lighthouse/Cargo.toml +++ b/lighthouse/Cargo.toml @@ -55,7 +55,7 @@ malloc_utils = { path = "../common/malloc_utils" } directory = { path = "../common/directory" } unused_port = { path = "../common/unused_port" } database_manager = { path = "../database_manager" } -slasher = { path = "../slasher" } +slasher = { path = "../slasher", default-features = false } [dev-dependencies] tempfile = "3.1.0" diff --git a/slasher/service/Cargo.toml b/slasher/service/Cargo.toml index 63cf1e464..0a787defa 100644 --- a/slasher/service/Cargo.toml +++ b/slasher/service/Cargo.toml @@ -9,7 +9,7 @@ beacon_chain = { path = "../../beacon_node/beacon_chain" } directory = { path = "../../common/directory" } lighthouse_network = { path = "../../beacon_node/lighthouse_network" } network = { path = "../../beacon_node/network" } -slasher = { path = ".." } +slasher = { path = "..", default-features = false } slog = "2.5.2" slot_clock = { path = "../../common/slot_clock" } state_processing = { path = "../../consensus/state_processing" }