Skip to content

Commit

Permalink
Optimise slasher DB layout and switch to MDBX (sigp#2776)
Browse files Browse the repository at this point in the history
## Issue Addressed

Closes sigp#2286
Closes sigp#2538
Closes sigp#2342

## Proposed Changes

Part II of major slasher optimisations after sigp#2767

These changes will be backwards-incompatible due to the move to MDBX (and the schema change) 😱 

* [x] Shrink attester keys from 16 bytes to 7 bytes.
* [x] Shrink attester records from 64 bytes to 6 bytes.
* [x] Separate `DiskConfig` from regular `Config`.
* [x] Add configuration for the LRU cache size.
* [x] Add a "migration" that deletes any legacy LMDB database.
  • Loading branch information
michaelsproul committed Dec 21, 2021
1 parent a290a3c commit 3b61ac9
Show file tree
Hide file tree
Showing 26 changed files with 943 additions and 546 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
# Deny warnings in CI
RUSTFLAGS: "-D warnings"
# The Nightly version used for cargo-udeps, might need updating from time to time.
PINNED_NIGHTLY: nightly-2021-06-09
PINNED_NIGHTLY: nightly-2021-12-01
jobs:
target-branch-check:
name: target-branch-check
Expand Down Expand Up @@ -54,6 +54,12 @@ jobs:
run: npm install -g ganache-cli
- name: Install make
run: choco install -y make
- uses: KyleMayes/install-llvm-action@v1
with:
version: "13.0"
directory: ${{ runner.temp }}/llvm
- name: Set LIBCLANG_PATH
run: echo "LIBCLANG_PATH=$((gcm clang).source -replace "clang.exe")" >> $env:GITHUB_ENV
- name: Run tests in release
run: make test-release
beacon-chain-tests:
Expand Down
151 changes: 118 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@
passthrough = [
"RUSTFLAGS",
]

# These custom images are required to work around the lack of Clang in the default `cross` images.
# We need Clang to run `bindgen` for MDBX, and the `BINDGEN_EXTRA_CLANG_ARGS` flags must also be set
# while cross-compiling for ARM to prevent bindgen from attempting to include headers from the host.
#
# For more information see https://github.com/rust-embedded/cross/pull/608
[target.x86_64-unknown-linux-gnu]
image = "michaelsproul/cross-clang:x86_64-latest"

[target.aarch64-unknown-linux-gnu]
image = "michaelsproul/cross-clang:aarch64-latest"
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM rust:1.53.0 AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake
FROM rust:1.56.1-bullseye AS builder
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
COPY . lighthouse
ARG PORTABLE
ENV PORTABLE $PORTABLE
Expand Down
6 changes: 1 addition & 5 deletions beacon_node/beacon_chain/tests/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,7 @@ fn block_gossip_verification() {
fn verify_block_for_gossip_slashing_detection() {
let slasher_dir = tempdir().unwrap();
let slasher = Arc::new(
Slasher::open(
SlasherConfig::new(slasher_dir.path().into()).for_testing(),
test_logger(),
)
.unwrap(),
Slasher::open(SlasherConfig::new(slasher_dir.path().into()), test_logger()).unwrap(),
);

let inner_slasher = slasher.clone();
Expand Down
10 changes: 9 additions & 1 deletion beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,20 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
Arg::with_name("slasher-max-db-size")
.long("slasher-max-db-size")
.help(
"Maximum size of the LMDB database used by the slasher."
"Maximum size of the MDBX database used by the slasher."
)
.value_name("GIGABYTES")
.requires("slasher")
.takes_value(true)
)
.arg(
Arg::with_name("slasher-att-cache-size")
.long("slasher-att-cache-size")
.help("Set the maximum number of attestation roots for the slasher to cache")
.value_name("COUNT")
.requires("slasher")
.takes_value(true)
)
.arg(
Arg::with_name("slasher-chunk-size")
.long("slasher-chunk-size")
Expand Down
6 changes: 6 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@ pub fn get_config<E: EthSpec>(
slasher_config.max_db_size_mbs = max_db_size_gbs * 1024;
}

if let Some(attestation_cache_size) =
clap_utils::parse_optional(cli_args, "slasher-att-cache-size")?
{
slasher_config.attestation_root_cache_size = attestation_cache_size;
}

if let Some(chunk_size) = clap_utils::parse_optional(cli_args, "slasher-chunk-size")? {
slasher_config.chunk_size = chunk_size;
}
Expand Down
Loading

0 comments on commit 3b61ac9

Please sign in to comment.