Modularise slasher backend (#3443)

## Proposed Changes

Enable multiple database backends for the slasher, either MDBX (default) or LMDB. The backend can be selected using `--slasher-backend={lmdb,mdbx}`.

## Additional Info

In order to abstract over the two library's different handling of database lifetimes I've used `Box::leak` to give the `Environment` type a `'static` lifetime. This was the only way I could think of using 100% safe code to construct a self-referential struct `SlasherDB`, where the `OpenDatabases` refers to the `Environment`. I think this is OK, as the `Environment` is expected to live for the life of the program, and both database engines leave the database in a consistent state after each write. The memory claimed for memory-mapping will be freed by the OS and appropriately flushed regardless of whether the `Environment` is actually dropped.

We are depending on two `sigp` forks of `libmdbx-rs` and `lmdb-rs`, to give us greater control over MDBX OS support and LMDB's version.
This commit is contained in:
Michael Sproul
2022-08-15 01:30:56 +00:00
parent 71fd0b42f2
commit 92d597ad23
25 changed files with 905 additions and 230 deletions

View File

@@ -1,4 +1,5 @@
use clap::{App, Arg};
use strum::VariantNames;
pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
App::new("beacon_node")
@@ -628,6 +629,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
[disabled by default].")
.requires("slasher")
)
.arg(
Arg::with_name("slasher-backend")
.long("slasher-backend")
.help("Set the database backend to be used by the slasher.")
.takes_value(true)
.possible_values(slasher::DatabaseBackend::VARIANTS)
.requires("slasher")
)
.arg(
Arg::with_name("wss-checkpoint")
.long("wss-checkpoint")